SPIGOT-7744: Fix exception for shooting projectiles with flame enchantment

By: Doc <nachito94@msn.com>
This commit is contained in:
CraftBukkit/Spigot 2024-06-13 21:38:40 -04:00
parent 1498e34f2c
commit 8a61d81e90
2 changed files with 48 additions and 15 deletions

View File

@ -14,7 +14,33 @@
public abstract class EntityArrow extends IProjectile {
private static final double ARROW_BASE_DAMAGE = 2.0D;
@@ -242,7 +249,7 @@
@@ -86,7 +93,14 @@
}
protected EntityArrow(EntityTypes<? extends EntityArrow> entitytypes, double d0, double d1, double d2, World world, ItemStack itemstack, @Nullable ItemStack itemstack1) {
+ // CraftBukkit start - handle the owner before the rest of things
+ this(entitytypes, d0, d1, d2, world, itemstack, itemstack1, null);
+ }
+
+ protected EntityArrow(EntityTypes<? extends EntityArrow> entitytypes, double d0, double d1, double d2, World world, ItemStack itemstack, @Nullable ItemStack itemstack1, @Nullable EntityLiving ownerEntity) {
this(entitytypes, world);
+ this.setOwner(ownerEntity);
+ // CraftBukkit end
this.pickupItemStack = itemstack.copy();
this.setCustomName((IChatBaseComponent) itemstack.get(DataComponents.CUSTOM_NAME));
Unit unit = (Unit) itemstack.remove(DataComponents.INTANGIBLE_PROJECTILE);
@@ -116,8 +130,8 @@
}
protected EntityArrow(EntityTypes<? extends EntityArrow> entitytypes, EntityLiving entityliving, World world, ItemStack itemstack, @Nullable ItemStack itemstack1) {
- this(entitytypes, entityliving.getX(), entityliving.getEyeY() - 0.10000000149011612D, entityliving.getZ(), world, itemstack, itemstack1);
- this.setOwner(entityliving);
+ this(entitytypes, entityliving.getX(), entityliving.getEyeY() - 0.10000000149011612D, entityliving.getZ(), world, itemstack, itemstack1, entityliving); // CraftBukkit
+ // this.setOwner(entityliving); // SPIGOT-7744 - Moved to the above constructor
}
public void setSoundEvent(SoundEffect soundeffect) {
@@ -242,7 +256,7 @@
}
if (object != null && !flag) {
@ -23,7 +49,7 @@
this.hasImpulse = true;
if (projectiledeflection != ProjectileDeflection.NONE) {
@@ -333,7 +340,7 @@
@@ -333,7 +347,7 @@
protected void tickDespawn() {
++this.life;
if (this.life >= 1200) {
@ -32,7 +58,7 @@
}
}
@@ -380,7 +387,7 @@
@@ -380,7 +394,7 @@
}
if (this.piercingIgnoreEntityIds.size() >= this.getPierceLevel() + 1) {
@ -41,7 +67,7 @@
return;
}
@@ -401,7 +408,13 @@
@@ -401,7 +415,13 @@
int k = entity.getRemainingFireTicks();
if (this.isOnFire() && !flag) {
@ -56,7 +82,7 @@
}
if (entity.hurt(damagesource, (float) i)) {
@@ -447,7 +460,7 @@
@@ -447,7 +467,7 @@
this.playSound(this.soundEvent, 1.0F, 1.2F / (this.random.nextFloat() * 0.2F + 0.9F));
if (this.getPierceLevel() <= 0) {
@ -65,7 +91,7 @@
}
} else {
entity.setRemainingFireTicks(k);
@@ -458,7 +471,7 @@
@@ -458,7 +478,7 @@
this.spawnAtLocation(this.getPickupItem(), 0.1F);
}
@ -74,7 +100,7 @@
}
}
@@ -614,7 +627,7 @@
@@ -614,7 +634,7 @@
}
if (nbttagcompound.contains("weapon", 10)) {
@ -83,7 +109,7 @@
} else {
this.firedFromWeapon = null;
}
@@ -627,34 +640,30 @@
@@ -627,34 +647,30 @@
Entity entity1 = entity;
byte b0 = 0;
@ -129,7 +155,7 @@
}
this.pickup = entityarrow_pickupstatus;
@@ -663,9 +672,24 @@
@@ -663,9 +679,24 @@
@Override
public void playerTouch(EntityHuman entityhuman) {
if (!this.level().isClientSide && (this.inGround || this.isNoPhysics()) && this.shakeTime <= 0) {

View File

@ -1,29 +1,36 @@
--- a/net/minecraft/world/item/enchantment/effects/Ignite.java
+++ b/net/minecraft/world/item/enchantment/effects/Ignite.java
@@ -8,6 +8,10 @@
@@ -8,6 +8,11 @@
import net.minecraft.world.item.enchantment.LevelBasedValue;
import net.minecraft.world.phys.Vec3D;
+// CraftBukkit start
+import org.bukkit.event.entity.EntityCombustByEntityEvent;
+import org.bukkit.event.entity.EntityCombustEvent;
+// CraftBukkit end
+
public record Ignite(LevelBasedValue duration) implements EnchantmentEntityEffect {
public static final MapCodec<Ignite> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
@@ -18,7 +22,15 @@
@@ -18,7 +23,21 @@
@Override
public void apply(WorldServer worldserver, int i, EnchantedItemInUse enchantediteminuse, Entity entity, Vec3D vec3d) {
- entity.igniteForSeconds(this.duration.calculate(i));
+ // CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item
+ EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(enchantediteminuse.owner().getBukkitEntity(), entity.getBukkitEntity(), this.duration.calculate(i));
+ org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
+ EntityCombustEvent entityCombustEvent;
+ if (enchantediteminuse.owner() != null) {
+ entityCombustEvent = new EntityCombustByEntityEvent(enchantediteminuse.owner().getBukkitEntity(), entity.getBukkitEntity(), this.duration.calculate(i));
+ } else {
+ entityCombustEvent = new EntityCombustEvent(entity.getBukkitEntity(), this.duration.calculate(i));
+ }
+
+ if (combustEvent.isCancelled()) {
+ org.bukkit.Bukkit.getPluginManager().callEvent(entityCombustEvent);
+ if (entityCombustEvent.isCancelled()) {
+ return;
+ }
+ entity.igniteForSeconds(combustEvent.getDuration(), false);
+
+ entity.igniteForSeconds(entityCombustEvent.getDuration(), false);
+ // CraftBukkit end
}