aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/world/item/ChorusFruitItem.java.patch
blob: 8f1c09e300169026a7a7e8a68ed43d4a3f80bb28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
--- a/net/minecraft/world/item/ChorusFruitItem.java
+++ b/net/minecraft/world/item/ChorusFruitItem.java
@@ -5,6 +5,7 @@
 import net.minecraft.sounds.SoundEvents;
 import net.minecraft.sounds.SoundSource;
 import net.minecraft.util.Mth;
+import net.minecraft.world.entity.Entity;
 import net.minecraft.world.entity.LivingEntity;
 import net.minecraft.world.entity.animal.Fox;
 import net.minecraft.world.entity.player.Player;
@@ -13,50 +14,62 @@
 import net.minecraft.world.phys.Vec3;
 
 public class ChorusFruitItem extends Item {
+
     public ChorusFruitItem(Item.Properties properties) {
         super(properties);
     }
 
     @Override
     public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity entityLiving) {
-        ItemStack itemStack = super.finishUsingItem(stack, level, entityLiving);
+        ItemStack itemstack1 = super.finishUsingItem(stack, level, entityLiving);
+
         if (!level.isClientSide) {
-            for (int i = 0; i < 16; i++) {
-                double d = entityLiving.getX() + (entityLiving.getRandom().nextDouble() - 0.5) * 16.0;
-                double d1 = Mth.clamp(
-                    entityLiving.getY() + (double)(entityLiving.getRandom().nextInt(16) - 8),
-                    (double)level.getMinBuildHeight(),
-                    (double)(level.getMinBuildHeight() + ((ServerLevel)level).getLogicalHeight() - 1)
-                );
-                double d2 = entityLiving.getZ() + (entityLiving.getRandom().nextDouble() - 0.5) * 16.0;
+            for (int i = 0; i < 16; ++i) {
+                double d0 = entityLiving.getX() + (entityLiving.getRandom().nextDouble() - 0.5D) * 16.0D;
+                double d1 = Mth.clamp(entityLiving.getY() + (double) (entityLiving.getRandom().nextInt(16) - 8), (double) level.getMinBuildHeight(), (double) (level.getMinBuildHeight() + ((ServerLevel) level).getLogicalHeight() - 1));
+                double d2 = entityLiving.getZ() + (entityLiving.getRandom().nextDouble() - 0.5D) * 16.0D;
+
                 if (entityLiving.isPassenger()) {
                     entityLiving.stopRiding();
                 }
 
-                Vec3 vec3 = entityLiving.position();
-                if (entityLiving.randomTeleport(d, d1, d2, true)) {
-                    level.gameEvent(GameEvent.TELEPORT, vec3, GameEvent.Context.of(entityLiving));
-                    SoundSource soundSource;
-                    SoundEvent soundEvent;
+                Vec3 vec3d = entityLiving.position();
+
+                // CraftBukkit start - handle canceled status of teleport event
+                java.util.Optional<Boolean> status = entityLiving.randomTeleport(d0, d1, d2, true, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT);
+
+                if (!status.isPresent()) {
+                    // teleport event was canceled, no more tries
+                    break;
+                }
+
+                if (status.get()) {
+                    // CraftBukkit end
+                    level.gameEvent(GameEvent.TELEPORT, vec3d, GameEvent.Context.of((Entity) entityLiving));
+                    SoundEvent soundeffect;
+                    SoundSource soundcategory;
+
                     if (entityLiving instanceof Fox) {
-                        soundEvent = SoundEvents.FOX_TELEPORT;
-                        soundSource = SoundSource.NEUTRAL;
+                        soundeffect = SoundEvents.FOX_TELEPORT;
+                        soundcategory = SoundSource.NEUTRAL;
                     } else {
-                        soundEvent = SoundEvents.CHORUS_FRUIT_TELEPORT;
-                        soundSource = SoundSource.PLAYERS;
+                        soundeffect = SoundEvents.CHORUS_FRUIT_TELEPORT;
+                        soundcategory = SoundSource.PLAYERS;
                     }
 
-                    level.playSound(null, entityLiving.getX(), entityLiving.getY(), entityLiving.getZ(), soundEvent, soundSource);
+                    level.playSound((Player) null, entityLiving.getX(), entityLiving.getY(), entityLiving.getZ(), soundeffect, soundcategory);
                     entityLiving.resetFallDistance();
                     break;
                 }
             }
 
-            if (entityLiving instanceof Player player) {
-                player.getCooldowns().addCooldown(this, 20);
+            if (entityLiving instanceof Player) {
+                Player entityhuman = (Player) entityLiving;
+
+                entityhuman.getCooldowns().addCooldown(this, 20);
             }
         }
 
-        return itemStack;
+        return itemstack1;
     }
 }