aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/world/entity/projectile/ThrownPotion.java.patch
blob: b61b8d9855db5b9e198526f5c16251aafa76804d (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
--- a/net/minecraft/world/entity/projectile/ThrownPotion.java
+++ b/net/minecraft/world/entity/projectile/ThrownPotion.java
@@ -1,19 +1,21 @@
 package net.minecraft.world.entity.projectile;
 
+import java.util.Iterator;
 import java.util.List;
 import java.util.function.Predicate;
 import javax.annotation.Nullable;
 import net.minecraft.core.BlockPos;
 import net.minecraft.core.Direction;
 import net.minecraft.nbt.CompoundTag;
+import net.minecraft.server.level.ServerPlayer;
 import net.minecraft.tags.BlockTags;
 import net.minecraft.world.effect.MobEffect;
 import net.minecraft.world.effect.MobEffectInstance;
 import net.minecraft.world.entity.AreaEffectCloud;
 import net.minecraft.world.entity.Entity;
 import net.minecraft.world.entity.EntityType;
-import net.minecraft.world.entity.LivingEntity;
 import net.minecraft.world.entity.animal.axolotl.Axolotl;
+import net.minecraft.world.entity.player.Player;
 import net.minecraft.world.item.Item;
 import net.minecraft.world.item.ItemStack;
 import net.minecraft.world.item.Items;
@@ -22,28 +24,40 @@
 import net.minecraft.world.item.alchemy.Potions;
 import net.minecraft.world.level.Level;
 import net.minecraft.world.level.block.AbstractCandleBlock;
-import net.minecraft.world.level.block.CampfireBlock;
-import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.block.state.IBlockData;
 import net.minecraft.world.phys.AABB;
 import net.minecraft.world.phys.BlockHitResult;
 import net.minecraft.world.phys.EntityHitResult;
 import net.minecraft.world.phys.HitResult;
+// CraftBukkit start
+import java.util.HashMap;
+import java.util.Map;
+import net.minecraft.world.effect.MobEffects;
+import net.minecraft.world.level.block.Blocks;
+import net.minecraft.world.level.block.CampfireBlock;
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.entity.LivingEntity;
+// CraftBukkit end
 
 public class ThrownPotion extends ThrowableItemProjectile implements ItemSupplier {
-    public static final double SPLASH_RANGE = 4.0;
-    private static final double SPLASH_RANGE_SQ = 16.0;
-    public static final Predicate<LivingEntity> WATER_SENSITIVE_OR_ON_FIRE = livingEntity -> livingEntity.isSensitiveToWater() || livingEntity.isOnFire();
 
+    public static final double SPLASH_RANGE = 4.0D;
+    private static final double SPLASH_RANGE_SQ = 16.0D;
+    public static final Predicate<net.minecraft.world.entity.LivingEntity> WATER_SENSITIVE_OR_ON_FIRE = (entityliving) -> {
+        return entityliving.isSensitiveToWater() || entityliving.isOnFire();
+    };
+
     public ThrownPotion(EntityType<? extends ThrownPotion> entityType, Level level) {
         super(entityType, level);
     }
 
-    public ThrownPotion(Level level, LivingEntity shooter) {
+    public ThrownPotion(Level level, net.minecraft.world.entity.LivingEntity shooter) {
         super(EntityType.POTION, shooter, level);
     }
 
-    public ThrownPotion(Level level, double x, double y, double z) {
-        super(EntityType.POTION, x, y, z, level);
+    public ThrownPotion(Level level, double x, double d1, double y) {
+        super(EntityType.POTION, x, d1, y, level);
     }
 
     @Override
@@ -60,21 +74,26 @@
     protected void onHitBlock(BlockHitResult result) {
         super.onHitBlock(result);
         if (!this.level().isClientSide) {
-            ItemStack item = this.getItem();
-            Potion potion = PotionUtils.getPotion(item);
-            List<MobEffectInstance> mobEffects = PotionUtils.getMobEffects(item);
-            boolean flag = potion == Potions.WATER && mobEffects.isEmpty();
-            Direction direction = result.getDirection();
-            BlockPos blockPos = result.getBlockPos();
-            BlockPos blockPos1 = blockPos.relative(direction);
+            ItemStack itemstack = this.getItem();
+            Potion potionregistry = PotionUtils.getPotion(itemstack);
+            List<MobEffectInstance> list = PotionUtils.getMobEffects(itemstack);
+            boolean flag = potionregistry == Potions.WATER && list.isEmpty();
+            Direction enumdirection = result.getDirection();
+            BlockPos blockposition = result.getBlockPos();
+            BlockPos blockposition1 = blockposition.relative(enumdirection);
+
             if (flag) {
-                this.dowseFire(blockPos1);
-                this.dowseFire(blockPos1.relative(direction.getOpposite()));
+                this.dowseFire(blockposition1);
+                this.dowseFire(blockposition1.relative(enumdirection.getOpposite()));
+                Iterator iterator = Direction.Plane.HORIZONTAL.iterator();
 
-                for (Direction direction1 : Direction.Plane.HORIZONTAL) {
-                    this.dowseFire(blockPos1.relative(direction1));
+                while (iterator.hasNext()) {
+                    Direction enumdirection1 = (Direction) iterator.next();
+
+                    this.dowseFire(blockposition1.relative(enumdirection1));
                 }
             }
+
         }
     }
 
@@ -82,123 +101,199 @@
     protected void onHit(HitResult result) {
         super.onHit(result);
         if (!this.level().isClientSide) {
-            ItemStack item = this.getItem();
-            Potion potion = PotionUtils.getPotion(item);
-            List<MobEffectInstance> mobEffects = PotionUtils.getMobEffects(item);
-            boolean flag = potion == Potions.WATER && mobEffects.isEmpty();
+            ItemStack itemstack = this.getItem();
+            Potion potionregistry = PotionUtils.getPotion(itemstack);
+            List<MobEffectInstance> list = PotionUtils.getMobEffects(itemstack);
+            boolean flag = potionregistry == Potions.WATER && list.isEmpty();
+
             if (flag) {
                 this.applyWater();
-            } else if (!mobEffects.isEmpty()) {
+            } else if (true || !list.isEmpty()) { // CraftBukkit - Call event even if no effects to apply
                 if (this.isLingering()) {
-                    this.makeAreaOfEffectCloud(item, potion);
+                    this.makeAreaOfEffectCloud(itemstack, potionregistry, result); // CraftBukkit - Pass MovingObjectPosition
                 } else {
-                    this.applySplash(mobEffects, result.getType() == HitResult.Type.ENTITY ? ((EntityHitResult)result).getEntity() : null);
+                    this.applySplash(list, result.getType() == HitResult.EnumMovingObjectType.ENTITY ? ((EntityHitResult) result).getEntity() : null, result); // CraftBukkit - Pass MovingObjectPosition
                 }
             }
 
-            int i = potion.hasInstantEffects() ? 2007 : 2002;
-            this.level().levelEvent(i, this.blockPosition(), PotionUtils.getColor(item));
+            int i = potionregistry.hasInstantEffects() ? 2007 : 2002;
+
+            this.level().levelEvent(i, this.blockPosition(), PotionUtils.getColor(itemstack));
             this.discard();
         }
     }
 
     private void applyWater() {
-        AABB aABB = this.getBoundingBox().inflate(4.0, 2.0, 4.0);
+        AABB axisalignedbb = this.getBoundingBox().inflate(4.0D, 2.0D, 4.0D);
+        List<net.minecraft.world.entity.LivingEntity> list = this.level().getEntitiesOfClass(net.minecraft.world.entity.LivingEntity.class, axisalignedbb, ThrownPotion.WATER_SENSITIVE_OR_ON_FIRE);
+        Iterator iterator = list.iterator();
 
-        for (LivingEntity livingEntity : this.level().getEntitiesOfClass(LivingEntity.class, aABB, WATER_SENSITIVE_OR_ON_FIRE)) {
-            double d = this.distanceToSqr(livingEntity);
-            if (d < 16.0) {
-                if (livingEntity.isSensitiveToWater()) {
-                    livingEntity.hurt(this.damageSources().indirectMagic(this, this.getOwner()), 1.0F);
+        while (iterator.hasNext()) {
+            net.minecraft.world.entity.LivingEntity entityliving = (net.minecraft.world.entity.LivingEntity) iterator.next();
+            double d0 = this.distanceToSqr((Entity) entityliving);
+
+            if (d0 < 16.0D) {
+                if (entityliving.isSensitiveToWater()) {
+                    entityliving.hurt(this.damageSources().indirectMagic(this, this.getOwner()), 1.0F);
                 }
 
-                if (livingEntity.isOnFire() && livingEntity.isAlive()) {
-                    livingEntity.extinguishFire();
+                if (entityliving.isOnFire() && entityliving.isAlive()) {
+                    entityliving.extinguishFire();
                 }
             }
         }
 
-        for (Axolotl axolotl : this.level().getEntitiesOfClass(Axolotl.class, aABB)) {
+        List<Axolotl> list1 = this.level().getEntitiesOfClass(Axolotl.class, axisalignedbb);
+        Iterator iterator1 = list1.iterator();
+
+        while (iterator1.hasNext()) {
+            Axolotl axolotl = (Axolotl) iterator1.next();
+
             axolotl.rehydrate();
         }
+
     }
 
-    private void applySplash(List<MobEffectInstance> effectInstances, @Nullable Entity target) {
-        AABB aABB = this.getBoundingBox().inflate(4.0, 2.0, 4.0);
-        List<LivingEntity> entitiesOfClass = this.level().getEntitiesOfClass(LivingEntity.class, aABB);
-        if (!entitiesOfClass.isEmpty()) {
-            Entity effectSource = this.getEffectSource();
+    private void applySplash(List<MobEffectInstance> list, @Nullable Entity entity, HitResult position) { // CraftBukkit - Pass MovingObjectPosition
+        AABB axisalignedbb = this.getBoundingBox().inflate(4.0D, 2.0D, 4.0D);
+        List<net.minecraft.world.entity.LivingEntity> list1 = this.level().getEntitiesOfClass(net.minecraft.world.entity.LivingEntity.class, axisalignedbb);
+        Map<LivingEntity, Double> affected = new HashMap<LivingEntity, Double>(); // CraftBukkit
 
-            for (LivingEntity livingEntity : entitiesOfClass) {
-                if (livingEntity.isAffectedByPotions()) {
-                    double d = this.distanceToSqr(livingEntity);
-                    if (d < 16.0) {
+        if (!list1.isEmpty()) {
+            Entity entity1 = this.getEffectSource();
+            Iterator iterator = list1.iterator();
+
+            while (iterator.hasNext()) {
+                net.minecraft.world.entity.LivingEntity entityliving = (net.minecraft.world.entity.LivingEntity) iterator.next();
+
+                if (entityliving.isAffectedByPotions()) {
+                    double d0 = this.distanceToSqr((Entity) entityliving);
+
+                    if (d0 < 16.0D) {
                         double d1;
-                        if (livingEntity == target) {
-                            d1 = 1.0;
+
+                        if (entityliving == entity) {
+                            d1 = 1.0D;
                         } else {
-                            d1 = 1.0 - Math.sqrt(d) / 4.0;
+                            d1 = 1.0D - Math.sqrt(d0) / 4.0D;
                         }
 
-                        for (MobEffectInstance mobEffectInstance : effectInstances) {
-                            MobEffect effect = mobEffectInstance.getEffect();
-                            if (effect.isInstantenous()) {
-                                effect.applyInstantenousEffect(this, this.getOwner(), livingEntity, mobEffectInstance.getAmplifier(), d1);
-                            } else {
-                                int i = mobEffectInstance.mapDuration(i1 -> (int)(d1 * (double)i1 + 0.5));
-                                MobEffectInstance mobEffectInstance1 = new MobEffectInstance(
-                                    effect, i, mobEffectInstance.getAmplifier(), mobEffectInstance.isAmbient(), mobEffectInstance.isVisible()
-                                );
-                                if (!mobEffectInstance1.endsWithin(20)) {
-                                    livingEntity.addEffect(mobEffectInstance1, effectSource);
-                                }
-                            }
+                        // CraftBukkit start
+                        affected.put((LivingEntity) entityliving.getBukkitEntity(), d1);
+                    }
+                }
+            }
+        }
+
+        org.bukkit.event.entity.PotionSplashEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPotionSplashEvent(this, position, affected);
+        if (!event.isCancelled() && list != null && !list.isEmpty()) { // do not process effects if there are no effects to process
+            Entity entity1 = this.getEffectSource();
+            for (LivingEntity victim : event.getAffectedEntities()) {
+                if (!(victim instanceof CraftLivingEntity)) {
+                    continue;
+                }
+
+                net.minecraft.world.entity.LivingEntity entityliving = ((CraftLivingEntity) victim).getHandle();
+                double d1 = event.getIntensity(victim);
+                // CraftBukkit end
+
+                Iterator iterator1 = list.iterator();
+
+                while (iterator1.hasNext()) {
+                    MobEffectInstance mobeffect = (MobEffectInstance) iterator1.next();
+                    MobEffect mobeffectlist = mobeffect.getEffect();
+                    // CraftBukkit start - Abide by PVP settings - for players only!
+                    if (!this.level().pvpMode && this.getOwner() instanceof ServerPlayer && entityliving instanceof ServerPlayer && entityliving != this.getOwner()) {
+                        if (mobeffectlist == MobEffects.MOVEMENT_SLOWDOWN || mobeffectlist == MobEffects.DIG_SLOWDOWN || mobeffectlist == MobEffects.HARM || mobeffectlist == MobEffects.BLINDNESS
+                                || mobeffectlist == MobEffects.HUNGER || mobeffectlist == MobEffects.WEAKNESS || mobeffectlist == MobEffects.POISON) {
+                            continue;
                         }
                     }
+                    // CraftBukkit end
+
+                    if (mobeffectlist.isInstantenous()) {
+                        mobeffectlist.applyInstantenousEffect(this, this.getOwner(), entityliving, mobeffect.getAmplifier(), d1);
+                    } else {
+                        int i = mobeffect.mapDuration((j) -> {
+                            return (int) (d1 * (double) j + 0.5D);
+                        });
+                        MobEffectInstance mobeffect1 = new MobEffectInstance(mobeffectlist, i, mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.isVisible());
+
+                        if (!mobeffect1.endsWithin(20)) {
+                            entityliving.addEffect(mobeffect1, entity1, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.POTION_SPLASH); // CraftBukkit
+                        }
+                    }
                 }
             }
         }
+
     }
 
-    private void makeAreaOfEffectCloud(ItemStack stack, Potion potion) {
-        AreaEffectCloud areaEffectCloud = new AreaEffectCloud(this.level(), this.getX(), this.getY(), this.getZ());
-        Entity owner = this.getOwner();
-        if (owner instanceof LivingEntity) {
-            areaEffectCloud.setOwner((LivingEntity)owner);
+    private void makeAreaOfEffectCloud(ItemStack itemstack, Potion potionregistry, HitResult position) { // CraftBukkit - Pass MovingObjectPosition
+        AreaEffectCloud entityareaeffectcloud = new AreaEffectCloud(this.level(), this.getX(), this.getY(), this.getZ());
+        Entity entity = this.getOwner();
+
+        if (entity instanceof net.minecraft.world.entity.LivingEntity) {
+            entityareaeffectcloud.setOwner((net.minecraft.world.entity.LivingEntity) entity);
         }
 
-        areaEffectCloud.setRadius(3.0F);
-        areaEffectCloud.setRadiusOnUse(-0.5F);
-        areaEffectCloud.setWaitTime(10);
-        areaEffectCloud.setRadiusPerTick(-areaEffectCloud.getRadius() / (float)areaEffectCloud.getDuration());
-        areaEffectCloud.setPotion(potion);
+        entityareaeffectcloud.setRadius(3.0F);
+        entityareaeffectcloud.setRadiusOnUse(-0.5F);
+        entityareaeffectcloud.setWaitTime(10);
+        entityareaeffectcloud.setRadiusPerTick(-entityareaeffectcloud.getRadius() / (float) entityareaeffectcloud.getDuration());
+        entityareaeffectcloud.setPotion(potionregistry);
+        Iterator iterator = PotionUtils.getCustomEffects(itemstack).iterator();
 
-        for (MobEffectInstance mobEffectInstance : PotionUtils.getCustomEffects(stack)) {
-            areaEffectCloud.addEffect(new MobEffectInstance(mobEffectInstance));
+        while (iterator.hasNext()) {
+            MobEffectInstance mobeffect = (MobEffectInstance) iterator.next();
+
+            entityareaeffectcloud.addEffect(new MobEffectInstance(mobeffect));
         }
 
-        CompoundTag tag = stack.getTag();
-        if (tag != null && tag.contains("CustomPotionColor", 99)) {
-            areaEffectCloud.setFixedColor(tag.getInt("CustomPotionColor"));
+        CompoundTag nbttagcompound = itemstack.getTag();
+
+        if (nbttagcompound != null && nbttagcompound.contains("CustomPotionColor", 99)) {
+            entityareaeffectcloud.setFixedColor(nbttagcompound.getInt("CustomPotionColor"));
         }
 
-        this.level().addFreshEntity(areaEffectCloud);
+        // CraftBukkit start
+        org.bukkit.event.entity.LingeringPotionSplashEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callLingeringPotionSplashEvent(this, position, entityareaeffectcloud);
+        if (!(event.isCancelled() || entityareaeffectcloud.isRemoved())) {
+            this.level().addFreshEntity(entityareaeffectcloud);
+        } else {
+            entityareaeffectcloud.discard();
+        }
+        // CraftBukkit end
     }
 
-    private boolean isLingering() {
+    public boolean isLingering() {
         return this.getItem().is(Items.LINGERING_POTION);
     }
 
     private void dowseFire(BlockPos pos) {
-        BlockState blockState = this.level().getBlockState(pos);
-        if (blockState.is(BlockTags.FIRE)) {
-            this.level().destroyBlock(pos, false, this);
-        } else if (AbstractCandleBlock.isLit(blockState)) {
-            AbstractCandleBlock.extinguish(null, blockState, this.level(), pos);
-        } else if (CampfireBlock.isLitCampfire(blockState)) {
-            this.level().levelEvent(null, 1009, pos, 0);
-            CampfireBlock.dowse(this.getOwner(), this.level(), pos, blockState);
-            this.level().setBlockAndUpdate(pos, blockState.setValue(CampfireBlock.LIT, Boolean.valueOf(false)));
+        IBlockData iblockdata = this.level().getBlockState(pos);
+
+        if (iblockdata.is(BlockTags.FIRE)) {
+            // CraftBukkit start
+            if (CraftEventFactory.callEntityChangeBlockEvent(this, pos, Blocks.AIR.defaultBlockState())) {
+                this.level().destroyBlock(pos, false, this);
+            }
+            // CraftBukkit end
+        } else if (AbstractCandleBlock.isLit(iblockdata)) {
+            // CraftBukkit start
+            if (CraftEventFactory.callEntityChangeBlockEvent(this, pos, iblockdata.setValue(AbstractCandleBlock.LIT, false))) {
+                AbstractCandleBlock.extinguish((Player) null, iblockdata, this.level(), pos);
+            }
+            // CraftBukkit end
+        } else if (CampfireBlock.isLitCampfire(iblockdata)) {
+            // CraftBukkit start
+            if (CraftEventFactory.callEntityChangeBlockEvent(this, pos, iblockdata.setValue(CampfireBlock.LIT, false))) {
+                this.level().levelEvent((Player) null, 1009, pos, 0);
+                CampfireBlock.dowse(this.getOwner(), this.level(), pos, iblockdata);
+                this.level().setBlockAndUpdate(pos, (IBlockData) iblockdata.setValue(CampfireBlock.LIT, false));
+            }
+            // CraftBukkit end
         }
+
     }
 }