diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/entity/EntityBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/entity/EntityBridge.java index 5d9086596..8b3df1b2f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/entity/EntityBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/entity/EntityBridge.java @@ -11,6 +11,7 @@ import net.minecraft.world.entity.boss.enderdragon.EnderDragon; import net.minecraft.world.phys.Vec3; import org.bukkit.craftbukkit.v.entity.CraftEntity; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.projectiles.ProjectileSource; import java.util.List; @@ -69,6 +70,8 @@ public interface EntityBridge extends ICommandSourceBridge, InjectEntityBridge { void bridge$revive(); + void bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause cause); + default boolean bridge$forge$isPartEntity() { return this instanceof EnderDragonPart; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/entity/LivingEntityBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/entity/LivingEntityBridge.java index 4b0f4a4e3..04a37578f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/entity/LivingEntityBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/entity/LivingEntityBridge.java @@ -16,6 +16,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import org.bukkit.craftbukkit.v.entity.CraftLivingEntity; +import org.bukkit.event.entity.EntityKnockbackEvent; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; @@ -53,6 +54,8 @@ public interface LivingEntityBridge extends EntityBridge { Optional bridge$getEffectCause(); + void bridge$pushKnockbackCause(Entity attacker, EntityKnockbackEvent.KnockbackCause cause); + @Override CraftLivingEntity bridge$getBukkitEntity(); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/world/level/levelgen/StructureStartBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/world/level/levelgen/StructureStartBridge.java index a111b990b..2a5e46787 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/world/level/levelgen/StructureStartBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/world/level/levelgen/StructureStartBridge.java @@ -1,8 +1,11 @@ package io.izzel.arclight.common.bridge.core.world.level.levelgen; +import org.bukkit.craftbukkit.v.persistence.CraftPersistentDataContainer; import org.bukkit.event.world.AsyncStructureGenerateEvent; public interface StructureStartBridge { void bridge$setGenerateCause(AsyncStructureGenerateEvent.Cause cause); + + CraftPersistentDataContainer bridge$getPersistentDataContainer(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inject/InjectEntityBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inject/InjectEntityBridge.java index b5f10fe52..5735c80eb 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inject/InjectEntityBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/inject/InjectEntityBridge.java @@ -1,5 +1,6 @@ package io.izzel.arclight.common.bridge.inject; +import io.izzel.arclight.common.bridge.core.entity.EntityBridge; import org.bukkit.craftbukkit.v.entity.CraftEntity; public interface InjectEntityBridge { @@ -7,4 +8,8 @@ public interface InjectEntityBridge { default CraftEntity bridge$getBukkitEntity() { throw new IllegalStateException("Not implemented"); } + + default EntityBridge bridge() { + return (EntityBridge) this; + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerListMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerListMixin.java index 074251a86..96761f253 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerListMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/server/management/PlayerListMixin.java @@ -64,6 +64,7 @@ import org.bukkit.craftbukkit.v.entity.CraftPlayer; import org.bukkit.craftbukkit.v.util.CraftChatMessage; import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; @@ -594,4 +595,10 @@ public ServerStatsCounter getPlayerStats(UUID uuid, String displayName) { } return serverstatisticmanager; } + + @Inject(method = "remove", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;stopRiding()V")) + private void arclight$removeMount(ServerPlayer serverPlayer, CallbackInfo ci) { + serverPlayer.getRootVehicle().getPassengersAndSelf().forEach(entity -> + ((EntityBridge) entity).bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.PLAYER_QUIT)); + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/AreaEffectCloudEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/AreaEffectCloudEntityMixin.java index b71481cc2..ef4ad43a2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/AreaEffectCloudEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/AreaEffectCloudEntityMixin.java @@ -18,6 +18,7 @@ import org.bukkit.craftbukkit.v.entity.CraftLivingEntity; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.AreaEffectCloudApplyEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -107,6 +108,7 @@ public void tick() { } } else { if (this.tickCount >= this.waitTime + this.duration) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); this.discard(); return; } @@ -123,6 +125,7 @@ public void tick() { if (this.radiusPerTick != 0.0F) { f += this.radiusPerTick; if (f < 0.5F) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); this.discard(); return; } @@ -176,6 +179,7 @@ public void tick() { if (this.radiusOnUse != 0.0F) { f += this.radiusOnUse; if (f < 0.5F) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); this.discard(); return; } @@ -186,6 +190,7 @@ public void tick() { if (this.durationOnUse != 0) { this.duration += this.durationOnUse; if (this.duration <= 0) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); this.discard(); return; } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityMixin.java index adb6e193a..a42f0cc37 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/EntityMixin.java @@ -79,6 +79,7 @@ import org.bukkit.event.entity.EntityDropItemEvent; import org.bukkit.event.entity.EntityPortalEvent; import org.bukkit.event.entity.EntityPoseChangeEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.vehicle.VehicleBlockCollisionEvent; @@ -326,6 +327,39 @@ public SoundEvent getSwimHighSpeedSplashSound0() { this.unsetRemoved(); } + private transient EntityRemoveEvent.Cause arclight$removeCause; + + @Override + public void bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause cause) { + this.arclight$removeCause = cause; + } + + public void discard(EntityRemoveEvent.Cause cause) { + this.arclight$removeCause = cause; + this.discard(); + } + + public void remove(Entity.RemovalReason removalReason, EntityRemoveEvent.Cause cause) { + this.arclight$removeCause = cause; + this.remove(removalReason); + } + + @Inject(method = "kill", at = @At("HEAD")) + private void arclight$killed(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DEATH); + } + + @Inject(method = "onBelowWorld", at = @At("HEAD")) + private void arclight$outOfWorld(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.OUT_OF_WORLD); + } + + @Inject(method = "setRemoved", at = @At("HEAD")) + private void arclight$removeEvent(Entity.RemovalReason removalReason, CallbackInfo ci) { + CraftEventFactory.callEntityRemoveEvent((Entity) (Object) this, arclight$removeCause); + arclight$removeCause = null; + } + @Inject(method = "getMaxAirSupply", cancellable = true, at = @At("RETURN")) private void arclight$useBukkitMaxAir(CallbackInfoReturnable cir) { cir.setReturnValue(this.maxAirTicks); @@ -461,7 +495,7 @@ public void postTick() { @Redirect(method = "lavaHurt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setSecondsOnFire(I)V")) public void arclight$setOnFireFromLava$bukkitEvent(Entity entity, int seconds) { if ((Object) this instanceof LivingEntity && remainingFireTicks <= 0) { - var damager = (lastLavaContact == null) ? null : CraftBlock.at(level(), lastLavaContact); + var damager = (lastLavaContact == null) ? null : CraftBlock.at(level(), lastLavaContact); var damagee = this.getBukkitEntity(); EntityCombustEvent combustEvent = new EntityCombustByBlockEvent(damager, damagee, 15); Bukkit.getPluginManager().callEvent(combustEvent); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ExperienceOrbMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ExperienceOrbMixin.java index 5affb4c77..1d51baade 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ExperienceOrbMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ExperienceOrbMixin.java @@ -10,6 +10,7 @@ import net.minecraft.world.item.enchantment.Enchantments; import org.bukkit.craftbukkit.v.entity.CraftLivingEntity; import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.entity.EntityTargetLivingEntityEvent; import org.bukkit.event.player.PlayerExpCooldownChangeEvent; @@ -38,6 +39,21 @@ public abstract class ExperienceOrbMixin extends EntityMixin { private transient Player arclight$lastPlayer; + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/ExperienceOrb;discard()V")) + private void arclight$tickDespawn(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } + + @Inject(method = "merge", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/ExperienceOrb;discard()V")) + private void arclight$merge(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.MERGE); + } + + @Inject(method = "playerTouch", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/ExperienceOrb;discard()V")) + private void arclight$pickup(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.PICKUP); + } + @Inject(method = "tick", at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/entity/Entity;tick()V")) private void arclight$captureLast(CallbackInfo ci) { arclight$lastPlayer = this.followingPlayer; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LightningBoltMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LightningBoltMixin.java index 215876f01..1df8fb12e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LightningBoltMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LightningBoltMixin.java @@ -7,6 +7,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityRemoveEvent; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -22,6 +23,11 @@ public abstract class LightningBoltMixin extends EntityMixin { public boolean isSilent = false; + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LightningBolt;discard()V")) + private void arclight$tickDespawn(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } + @Redirect(method = "tick", at = @At(value = "FIELD", opcode = Opcodes.GETFIELD, ordinal = 0, target = "Lnet/minecraft/world/entity/LightningBolt;life:I")) private int arclight$silent(LightningBolt lightningBolt) { return isSilent ? 0 : this.life; diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LivingEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LivingEntityMixin.java index 2b3082e38..0357d43df 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LivingEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/LivingEntityMixin.java @@ -53,6 +53,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.gameevent.GameEvent; +import net.minecraft.world.phys.Vec3; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.craftbukkit.v.CraftEquipmentSlot; @@ -64,8 +65,10 @@ import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityExhaustionEvent; +import org.bukkit.event.entity.EntityKnockbackEvent; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.entity.EntityResurrectEvent; import org.bukkit.event.entity.EntityTeleportEvent; import org.bukkit.event.player.PlayerItemConsumeEvent; @@ -493,6 +496,38 @@ public boolean isAlive() { } } + @Inject(method = "blockedByShield", at = @At("HEAD")) + private void arclight$shieldKnockback(LivingEntity livingEntity, CallbackInfo ci) { + this.bridge$pushKnockbackCause(null, EntityKnockbackEvent.KnockbackCause.SHIELD_BLOCK); + } + + private transient Entity arclight$knockbackAttacker; + private transient EntityKnockbackEvent.KnockbackCause arclight$knockbackCause; + + @Override + public void bridge$pushKnockbackCause(Entity attacker, EntityKnockbackEvent.KnockbackCause cause) { + this.arclight$knockbackAttacker = attacker; + this.arclight$knockbackCause = cause; + } + + public void knockback(double d, double e, double f, Entity attacker, EntityKnockbackEvent.KnockbackCause cause) { + this.bridge$pushKnockbackCause(attacker, cause); + this.knockback(d, e, f); + } + + @Redirect(method = "knockback", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;setDeltaMovement(DDD)V")) + private void arclight$knockbackEvent(LivingEntity instance, double x, double y, double z, double d, double e, double f) { + var attacker = arclight$knockbackAttacker; + var cause = arclight$knockbackCause == null ? EntityKnockbackEvent.KnockbackCause.UNKNOWN : arclight$knockbackCause; + arclight$knockbackAttacker = null; + arclight$knockbackCause = null; + var raw = (new Vec3(e, 0.0, f)).normalize().scale(d); + var event = CraftEventFactory.callEntityKnockbackEvent(this.getBukkitEntity(), attacker, cause, d, raw, x, y, z); + if (!event.isCancelled()) { + instance.setDeltaMovement(event.getFinalKnockback().getX(), event.getFinalKnockback().getY(), event.getFinalKnockback().getZ()); + } + } + /** * @author IzzelAliz * @reason @@ -608,6 +643,7 @@ public boolean hurt(DamageSource source, float amount) { d1 = (Math.random() - Math.random()) * 0.01D; } + this.bridge$pushKnockbackCause(entity1, entity1 == null ? EntityKnockbackEvent.KnockbackCause.DAMAGE : EntityKnockbackEvent.KnockbackCause.ENTITY_ATTACK); this.knockback(0.4F, d1, d0); if (!flag) { this.indicateDamage(d1, d0); @@ -1176,4 +1212,9 @@ protected void equipEventAndSound(EquipmentSlot slot, ItemStack oldItem, ItemSta public void bridge$playEquipSound(EquipmentSlot slot, ItemStack oldItem, ItemStack newItem, boolean silent) { this.equipEventAndSound(slot, oldItem, newItem, silent); } + + @Inject(method = "tickDeath", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;remove(Lnet/minecraft/world/entity/Entity$RemovalReason;)V")) + private void arclight$killedCause(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DEATH); + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/MobMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/MobMixin.java index 058d1a179..970d37f24 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/MobMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/MobMixin.java @@ -26,6 +26,8 @@ import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityCombustByEntityEvent; +import org.bukkit.event.entity.EntityKnockbackEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.entity.EntityTargetLivingEntityEvent; import org.bukkit.event.entity.EntityTransformEvent; @@ -211,6 +213,11 @@ public boolean setTarget(LivingEntity livingEntity, EntityTargetEvent.TargetReas arclight$item = itemEntity; } + @Inject(method = "pickUpItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/item/ItemEntity;discard()V")) + private void arclight$pickupCause(ItemEntity itemEntity, CallbackInfo ci) { + itemEntity.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.PICKUP); + } + @Override public void bridge$captureItemDrop(ItemEntity itemEntity) { this.arclight$item = itemEntity; @@ -336,6 +343,11 @@ public ItemStack equipItemIfPossible(ItemStack stack) { this.arclight$transform = null; } + @Inject(method = "convertTo", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Mob;discard()V")) + private void arclight$transformCause(EntityType entityType, boolean bl, CallbackInfoReturnable cir) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.TRANSFORMATION); + } + public T convertTo(EntityType entityType, boolean flag, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) { ((WorldBridge) this.level()).bridge$pushAddEntityReason(spawnReason); bridge$pushTransformReason(transformReason); @@ -351,13 +363,23 @@ public T convertTo(EntityType entityType, boolean flag, Entit @Redirect(method = "doHurtTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setSecondsOnFire(I)V")) public void arclight$attackCombust(Entity entity, int seconds) { - EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), seconds); + EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.bridge$getBukkitEntity(), seconds); org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent); if (!combustEvent.isCancelled()) { ((EntityBridge) entity).bridge$setOnFire(combustEvent.getDuration(), false); } } + @Inject(method = "doHurtTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;knockback(DDD)V")) + private void arclight$attackKnockback(Entity entity, CallbackInfoReturnable cir) { + ((LivingEntityBridge) entity).bridge$pushKnockbackCause((Entity) (Object) this, EntityKnockbackEvent.KnockbackCause.ENTITY_ATTACK); + } + + @Inject(method = "checkDespawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Mob;discard()V")) + private void arclight$naturalDespawn(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } + @Override public ResourceLocation bridge$getLootTable() { return this.getDefaultLootTable(); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/warden/DiggingMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/warden/DiggingMixin.java new file mode 100644 index 000000000..46f9c3dad --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/ai/behavior/warden/DiggingMixin.java @@ -0,0 +1,19 @@ +package io.izzel.arclight.common.mixin.core.world.entity.ai.behavior.warden; + +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.ai.behavior.warden.Digging; +import net.minecraft.world.entity.monster.warden.Warden; +import org.bukkit.event.entity.EntityRemoveEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Digging.class) +public class DiggingMixin { + + @Inject(method = "stop(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/monster/warden/Warden;J)V", at = @At("HEAD")) + private void arclight$despawn(ServerLevel serverLevel, E warden, long l, CallbackInfo ci) { + warden.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/BucketableMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/BucketableMixin.java index a194ac842..c5a020cd0 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/BucketableMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/BucketableMixin.java @@ -15,6 +15,7 @@ import net.minecraft.world.level.Level; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.player.PlayerBucketEntityEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -53,6 +54,7 @@ static Optional bucketM CriteriaTriggers.FILLED_BUCKET.trigger((ServerPlayer) player, itemstack1); } + entity.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.PICKUP); entity.discard(); return Optional.of(InteractionResult.sidedSuccess(level.isClientSide)); } else { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/DolphinMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/DolphinMixin.java index a42b4ba0c..5414a6a94 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/DolphinMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/DolphinMixin.java @@ -1,6 +1,7 @@ package io.izzel.arclight.common.mixin.core.world.entity.animal; import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityRemoveEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -20,6 +21,11 @@ public abstract class DolphinMixin extends PathfinderMobMixin { } } + @Inject(method = "pickUpItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/item/ItemEntity;discard()V")) + private void arclight$pickCause(ItemEntity itemEntity, CallbackInfo ci) { + itemEntity.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.PICKUP); + } + @Inject(method = "getMaxAirSupply", cancellable = true, at = @At("RETURN")) private void arclight$useBukkitMaxAir(CallbackInfoReturnable cir) { cir.setReturnValue(this.maxAirTicks); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/FoxMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/FoxMixin.java index 620d86474..3292c7dd1 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/FoxMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/FoxMixin.java @@ -5,10 +5,13 @@ import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.ItemStack; import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityRemoveEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.UUID; @@ -23,4 +26,9 @@ public abstract class FoxMixin extends AnimalMixin implements FoxEntityBridge { private boolean arclight$pickupEvent(Fox foxEntity, ItemStack stack, ItemEntity itemEntity) { return CraftEventFactory.callEntityPickupItemEvent((Fox) (Object) this, itemEntity, stack.getCount() - 1, !this.canHoldItem(stack)).isCancelled(); } + + @Inject(method = "pickUpItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/item/ItemEntity;discard()V")) + private void arclight$pickCause(ItemEntity itemEntity, CallbackInfo ci) { + itemEntity.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.PICKUP); + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/PandaMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/PandaMixin.java index d6c8d5650..f00470ed6 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/PandaMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/PandaMixin.java @@ -1,11 +1,11 @@ package io.izzel.arclight.common.mixin.core.world.entity.animal; -import io.izzel.arclight.common.mixin.core.world.entity.animal.AnimalMixin; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.animal.Panda; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.ItemStack; import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityRemoveEvent; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -30,6 +30,7 @@ protected void pickUpItem(ItemEntity itemEntity) { this.setItemSlot(EquipmentSlot.MAINHAND, itemstack); this.handDropChances[EquipmentSlot.MAINHAND.getIndex()] = 2.0F; this.take(itemEntity, itemstack.getCount()); + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.PICKUP); itemEntity.discard(); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/PigMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/PigMixin.java index ec688ca60..1a04c4cb8 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/PigMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/PigMixin.java @@ -7,6 +7,7 @@ import net.minecraft.world.entity.monster.ZombifiedPiglin; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -23,6 +24,7 @@ public abstract class PigMixin extends AnimalMixin { ci.cancel(); } else { ((WorldBridge) this.level()).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.LIGHTNING); + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.TRANSFORMATION); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/ShoulderRidingEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/ShoulderRidingEntityMixin.java new file mode 100644 index 000000000..58d74cc1d --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/ShoulderRidingEntityMixin.java @@ -0,0 +1,18 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal; + +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.animal.ShoulderRidingEntity; +import org.bukkit.event.entity.EntityRemoveEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(ShoulderRidingEntity.class) +public abstract class ShoulderRidingEntityMixin extends TameableAnimalMixin { + + @Inject(method = "setEntityOnShoulder", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/ShoulderRidingEntity;discard()V")) + private void arclight$pickCause(ServerPlayer serverPlayer, CallbackInfoReturnable cir) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.PICKUP); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/camel/CamelMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/camel/CamelMixin.java new file mode 100644 index 000000000..d1011eb77 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/camel/CamelMixin.java @@ -0,0 +1,25 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal.camel; + +import io.izzel.arclight.common.mixin.core.world.entity.animal.horse.AbstractHorseMixin; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.animal.camel.Camel; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(Camel.class) +public abstract class CamelMixin extends AbstractHorseMixin { + + // @formatter:off + @Shadow public abstract void standUpInstantly(); + // @formatter:on + + @Override + protected boolean damageEntity0(DamageSource damagesource, float f) { + boolean hurt = super.damageEntity0(damagesource, f); + if (!hurt) { + return false; + } + this.standUpInstantly(); + return true; + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/frog/ShootTongueMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/frog/ShootTongueMixin.java new file mode 100644 index 000000000..d13273c53 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/frog/ShootTongueMixin.java @@ -0,0 +1,19 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal.frog; + +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.animal.frog.Frog; +import net.minecraft.world.entity.animal.frog.ShootTongue; +import org.bukkit.event.entity.EntityRemoveEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ShootTongue.class) +public class ShootTongueMixin { + + @Inject(method = "eatEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;remove(Lnet/minecraft/world/entity/Entity$RemovalReason;)V")) + private void arclight$eatCause(ServerLevel serverLevel, Frog frog, CallbackInfo ci) { + frog.getTongueTarget().ifPresent(entity -> entity.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DEATH)); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/frog/TadpoleMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/frog/TadpoleMixin.java index df15883aa..85098ab44 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/frog/TadpoleMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/frog/TadpoleMixin.java @@ -1,8 +1,18 @@ package io.izzel.arclight.common.mixin.core.world.entity.animal.frog; +import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; import net.minecraft.world.entity.animal.frog.Tadpole; +import org.bukkit.event.entity.EntityRemoveEvent; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(Tadpole.class) -public abstract class TadpoleMixin { +public abstract class TadpoleMixin extends PathfinderMobMixin { + + @Inject(method = "ageUp()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/frog/Tadpole;discard()V")) + private void arclight$ageUp(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.TRANSFORMATION); + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/horse/LlamaMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/horse/LlamaMixin.java index 27b745c09..d098aabe8 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/horse/LlamaMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/horse/LlamaMixin.java @@ -5,7 +5,7 @@ import org.spongepowered.asm.mixin.Shadow; @Mixin(Llama.class) -public abstract class LlamaMixin { +public abstract class LlamaMixin extends AbstractHorseMixin { // @formatter:off @Shadow private void setStrength(int p_30841_) {} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/horse/SkeletonHorseMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/horse/SkeletonHorseMixin.java new file mode 100644 index 000000000..c47c6f5b0 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/horse/SkeletonHorseMixin.java @@ -0,0 +1,17 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal.horse; + +import net.minecraft.world.entity.animal.horse.SkeletonHorse; +import org.bukkit.event.entity.EntityRemoveEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(SkeletonHorse.class) +public abstract class SkeletonHorseMixin extends AbstractHorseMixin { + + @Inject(method = "aiStep", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/horse/SkeletonHorse;discard()V")) + private void arclight$despawn(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/horse/TraderLlamaMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/horse/TraderLlamaMixin.java new file mode 100644 index 000000000..5881a576d --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/animal/horse/TraderLlamaMixin.java @@ -0,0 +1,17 @@ +package io.izzel.arclight.common.mixin.core.world.entity.animal.horse; + +import net.minecraft.world.entity.animal.horse.TraderLlama; +import org.bukkit.event.entity.EntityRemoveEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(TraderLlama.class) +public abstract class TraderLlamaMixin extends LlamaMixin { + + @Inject(method = "maybeDespawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/horse/TraderLlama;discard()V")) + private void arclight$despawn(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/EnderCrystalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/EnderCrystalMixin.java index 035528478..3b3dd3e6d 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/EnderCrystalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/EnderCrystalMixin.java @@ -9,6 +9,7 @@ import net.minecraft.world.level.Level; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.entity.ExplosionPrimeEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -29,6 +30,7 @@ public abstract class EnderCrystalMixin extends EntityMixin { @Inject(method = "hurt", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/boss/enderdragon/EndCrystal;remove(Lnet/minecraft/world/entity/Entity$RemovalReason;)V")) private void arclight$entityDamage(DamageSource source, float amount, CallbackInfoReturnable cir) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DEATH); if (CraftEventFactory.handleNonLivingEntityDamageEvent((EndCrystal) (Object) this, source, amount)) { cir.setReturnValue(false); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/EnderDragonMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/EnderDragonMixin.java index e0a1127f3..59f2c7156 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/EnderDragonMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/EnderDragonMixin.java @@ -25,11 +25,14 @@ import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import javax.annotation.Nullable; import java.util.ArrayList; @@ -58,6 +61,16 @@ public abstract class EnderDragonMixin extends MobMixin { } } + @Inject(method = "kill", at = @At("HEAD")) + private void arclight$killed(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DEATH); + } + + @Inject(method = "tickDeath", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/boss/enderdragon/EnderDragon;remove(Lnet/minecraft/world/entity/Entity$RemovalReason;)V")) + private void arclight$killed2(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DEATH); + } + /** * @author IzzelAliz * @reason diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/phases/DragonSittingFlamingPhaseMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/phases/DragonSittingFlamingPhaseMixin.java new file mode 100644 index 000000000..bad3d81bc --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/enderdragon/phases/DragonSittingFlamingPhaseMixin.java @@ -0,0 +1,22 @@ +package io.izzel.arclight.common.mixin.core.world.entity.boss.enderdragon.phases; + +import net.minecraft.world.entity.AreaEffectCloud; +import net.minecraft.world.entity.boss.enderdragon.phases.DragonSittingFlamingPhase; +import org.bukkit.event.entity.EntityRemoveEvent; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(DragonSittingFlamingPhase.class) +public class DragonSittingFlamingPhaseMixin { + + @Shadow @Nullable private AreaEffectCloud flame; + + @Inject(method = "end", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/AreaEffectCloud;discard()V")) + private void arclight$despawn(CallbackInfo ci) { + this.flame.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/wither/WitherBossMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/wither/WitherBossMixin.java index 7efdb2fe0..48d613347 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/wither/WitherBossMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/boss/wither/WitherBossMixin.java @@ -16,12 +16,16 @@ import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.entity.ExplosionPrimeEvent; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.List; @@ -42,6 +46,11 @@ public abstract class WitherBossMixin extends PathfinderMobMixin { @Shadow @Final public ServerBossEvent bossEvent; // @formatter:on + @Inject(method = "checkDespawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/boss/wither/WitherBoss;discard()V")) + private void arclight$despawn(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } + /** * @author IzzelAliz * @reason diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/ArmorStandMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/ArmorStandMixin.java index d112b734e..53ba7656a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/ArmorStandMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/ArmorStandMixin.java @@ -19,6 +19,7 @@ import org.bukkit.craftbukkit.v.inventory.CraftItemStack; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.inventory.EquipmentSlot; import org.spongepowered.asm.mixin.Final; @@ -121,6 +122,7 @@ protected boolean shouldDropExperience() { } private void arclight$callEntityDeath() { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DEATH); Collection captureDrops = this.bridge$common$getCapturedDrops(); List drops; if (captureDrops == null) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/LeashFenceKnotEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/LeashFenceKnotEntityMixin.java index 1a8ad5325..47ee168f4 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/LeashFenceKnotEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/decoration/LeashFenceKnotEntityMixin.java @@ -11,6 +11,7 @@ import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.AABB; import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityRemoveEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -56,6 +57,7 @@ public InteractionResult interact(final Player entityhuman, final InteractionHan } } if (die) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DROP); this.discard(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/FallingBlockEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/FallingBlockEntityMixin.java index b49f80330..a92bd735c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/FallingBlockEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/FallingBlockEntityMixin.java @@ -4,13 +4,13 @@ import io.izzel.arclight.common.mixin.core.world.entity.EntityMixin; import io.izzel.arclight.common.mod.mixins.annotation.TransformAccess; import net.minecraft.core.BlockPos; -import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.item.FallingBlockEntity; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -28,9 +28,41 @@ public abstract class FallingBlockEntityMixin extends EntityMixin { @Shadow public static FallingBlockEntity fall(Level p_201972_, BlockPos p_201973_, BlockState p_201974_) { return null; } // @formatter:on + @Inject(method = "tick", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/entity/item/FallingBlockEntity;discard()V")) + private void arclight$despawn1(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } + + @Inject(method = "tick", at = @At(value = "INVOKE", ordinal = 2, target = "Lnet/minecraft/world/entity/item/FallingBlockEntity;discard()V")) + private void arclight$despawn2(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } + + @Inject(method = "tick", at = @At(value = "INVOKE", ordinal = 5, target = "Lnet/minecraft/world/entity/item/FallingBlockEntity;discard()V")) + private void arclight$despawn3(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } + + @Inject(method = "tick", at = @At(value = "INVOKE", ordinal = 1, target = "Lnet/minecraft/world/entity/item/FallingBlockEntity;discard()V")) + private void arclight$drop1(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DROP); + } + + @Inject(method = "tick", at = @At(value = "INVOKE", ordinal = 3, target = "Lnet/minecraft/world/entity/item/FallingBlockEntity;discard()V")) + private void arclight$drop2(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DROP); + } + + @Inject(method = "tick", at = @At(value = "INVOKE", ordinal = 4, target = "Lnet/minecraft/world/entity/item/FallingBlockEntity;discard()V")) + private void arclight$drop3(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DROP); + } + @Inject(method = "tick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) private void arclight$entityChangeBlock(CallbackInfo ci, Block block, BlockPos pos) { if (!CraftEventFactory.callEntityChangeBlockEvent((FallingBlockEntity) (Object) this, pos, this.blockState)) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + this.discard(); ci.cancel(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/HangingEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/HangingEntityMixin.java index 7516e0168..955078783 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/HangingEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/HangingEntityMixin.java @@ -15,6 +15,7 @@ import net.minecraft.world.phys.Vec3; import org.bukkit.Bukkit; import org.bukkit.entity.Hanging; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakEvent; import org.objectweb.asm.Opcodes; @@ -52,6 +53,8 @@ public abstract class HangingEntityMixin extends EntityMixin { Bukkit.getPluginManager().callEvent(event); if (this.isRemoved() || event.isCancelled()) { ci.cancel(); + } else { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DROP); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/ItemEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/ItemEntityMixin.java index c1a654346..9b88517a3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/ItemEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/ItemEntityMixin.java @@ -19,6 +19,7 @@ import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.entity.Item; import org.bukkit.event.entity.EntityPickupItemEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -51,6 +52,11 @@ public abstract class ItemEntityMixin extends EntityMixin implements ItemEntityB } } + @Inject(method = "merge(Lnet/minecraft/world/entity/item/ItemEntity;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/entity/item/ItemEntity;Lnet/minecraft/world/item/ItemStack;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/item/ItemEntity;discard()V")) + private static void arclight$itemMergeCause(ItemEntity from, ItemStack stack1, ItemEntity to, ItemStack stack2, CallbackInfo ci) { + to.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.MERGE); + } + @Inject(method = "hurt", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/item/ItemEntity;markHurt()V")) private void arclight$damageNonLiving(DamageSource source, float amount, CallbackInfoReturnable cir) { if (CraftEventFactory.handleNonLivingEntityDamageEvent((ItemEntity) (Object) this, source, amount)) { @@ -58,6 +64,11 @@ public abstract class ItemEntityMixin extends EntityMixin implements ItemEntityB } } + @Inject(method = "hurt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/item/ItemEntity;discard()V")) + private void arclight$dead(DamageSource source, float amount, CallbackInfoReturnable cir) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DEATH); + } + /** * @author IzzelAliz * @reason @@ -106,6 +117,7 @@ public void playerTouch(final Player entity) { this.bridge$forge$firePlayerItemPickupEvent(entity, copy); entity.take((ItemEntity) (Object) this, i); if (itemstack.isEmpty()) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.PICKUP); this.discard(); itemstack.setCount(i); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/PrimedTntMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/PrimedTntMixin.java index 01c3458d2..c0d786ced 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/PrimedTntMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/item/PrimedTntMixin.java @@ -9,6 +9,7 @@ import net.minecraft.world.level.Level; import org.bukkit.Bukkit; import org.bukkit.entity.Explosive; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.entity.ExplosionPrimeEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -63,6 +64,7 @@ public void tick() { if (!this.level().isClientSide) { this.explode(); } + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.EXPLODE); this.discard(); } else { this.updateInWaterStateAndDoFluidPushing(); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/CreeperMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/CreeperMixin.java index 5ff853976..96e2d0061 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/CreeperMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/CreeperMixin.java @@ -14,6 +14,7 @@ import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreeperPowerEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.entity.ExplosionPrimeEvent; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -57,6 +58,7 @@ public final void explodeCreeper() { if (!event.isCancelled()) { this.dead = true; this.level().explode((Creeper) (Object) this, this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), Level.ExplosionInteraction.MOB); + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.EXPLODE); this.discard(); this.spawnLingeringCloud(); } else { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/EndermiteMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/EndermiteMixin.java new file mode 100644 index 000000000..ff92ee847 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/EndermiteMixin.java @@ -0,0 +1,18 @@ +package io.izzel.arclight.common.mixin.core.world.entity.monster; + +import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; +import net.minecraft.world.entity.monster.Endermite; +import org.bukkit.event.entity.EntityRemoveEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Endermite.class) +public abstract class EndermiteMixin extends PathfinderMobMixin { + + @Inject(method = "aiStep", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/monster/Endermite;discard()V")) + private void arclight$despawn(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/PillagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/PillagerMixin.java new file mode 100644 index 000000000..4e9e28486 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/PillagerMixin.java @@ -0,0 +1,19 @@ +package io.izzel.arclight.common.mixin.core.world.entity.monster; + +import io.izzel.arclight.common.mixin.core.world.entity.raider.RaiderMixin; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.monster.Pillager; +import org.bukkit.event.entity.EntityRemoveEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Pillager.class) +public abstract class PillagerMixin extends RaiderMixin { + + @Inject(method = "pickUpItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/item/ItemEntity;discard()V")) + private void arclight$pickup(ItemEntity itemEntity, CallbackInfo ci) { + itemEntity.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.PICKUP); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Silverfish_MergeWithStoneGoalMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Silverfish_MergeWithStoneGoalMixin.java index 87b1d49bd..17576b991 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Silverfish_MergeWithStoneGoalMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/Silverfish_MergeWithStoneGoalMixin.java @@ -7,6 +7,7 @@ import net.minecraft.world.level.block.InfestedBlock; import net.minecraft.world.level.block.state.BlockState; import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityRemoveEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -26,4 +27,9 @@ public Silverfish_MergeWithStoneGoalMixin(PathfinderMob creatureIn, double speed ci.cancel(); } } + + @Inject(method = "start", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/PathfinderMob;discard()V")) + private void arclight$enterBlock(CallbackInfo ci) { + this.mob.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.ENTER_BLOCK); + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/piglin/PiglinAiMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/piglin/PiglinAiMixin.java index 04a9719fd..2e369ae3c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/piglin/PiglinAiMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/monster/piglin/PiglinAiMixin.java @@ -12,12 +12,15 @@ import net.minecraft.world.item.Items; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.craftbukkit.v.inventory.CraftItemStack; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.entity.PiglinBarterEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.List; import java.util.stream.Collectors; @@ -51,6 +54,7 @@ protected static void pickUpItem(Piglin piglinEntity, ItemEntity itemEntity) { if (itemEntity.getItem().getItem() == Items.GOLD_NUGGET && !CraftEventFactory.callEntityPickupItemEvent(piglinEntity, itemEntity, 0, false).isCancelled()) { piglinEntity.take(itemEntity, itemEntity.getItem().getCount()); itemstack = itemEntity.getItem(); + itemEntity.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.PICKUP); itemEntity.discard(); } else if (!CraftEventFactory.callEntityPickupItemEvent(piglinEntity, itemEntity, itemEntity.getItem().getCount() - 1, false).isCancelled()) { piglinEntity.take(itemEntity, 1); @@ -116,4 +120,9 @@ private static boolean isBarterItem(ItemStack itemstack, Piglin piglin) { private static boolean arclight$customLove2(ItemStack stack, Piglin piglin) { return isLovedByPiglin(stack, piglin); } + + @Inject(method = "removeOneItemFromItemEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/item/ItemEntity;discard()V")) + private static void arclight$pickup(ItemEntity itemEntity, CallbackInfoReturnable cir) { + itemEntity.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.PICKUP); + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/InventoryCarrierMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/InventoryCarrierMixin.java index ac9d80786..5d2e311da 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/InventoryCarrierMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/InventoryCarrierMixin.java @@ -7,6 +7,7 @@ import net.minecraft.world.entity.npc.InventoryCarrier; import net.minecraft.world.item.ItemStack; import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityRemoveEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; @@ -41,6 +42,7 @@ static void pickUpItem(Mob mob, InventoryCarrier carrier, ItemEntity itemEntity) ItemStack itemstack1 = simplecontainer.addItem(itemstack); mob.take(itemEntity, i - itemstack1.getCount()); if (itemstack1.isEmpty()) { + itemEntity.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.PICKUP); itemEntity.discard(); } else { itemstack.setCount(itemstack1.getCount()); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/VillagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/VillagerMixin.java index 1608b2de4..283157c0a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/VillagerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/VillagerMixin.java @@ -11,6 +11,7 @@ import org.bukkit.entity.Villager; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityPotionEffectEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.entity.EntityTransformEvent; import org.bukkit.event.entity.VillagerReplenishTradeEvent; import org.spongepowered.asm.mixin.Mixin; @@ -52,6 +53,7 @@ public abstract class VillagerMixin extends AbstractVillagerMixin { ci.cancel(); } else { ((WorldBridge) serverWorld).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.LIGHTNING); + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.TRANSFORMATION); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/WanderingTraderMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/WanderingTraderMixin.java index dea8e31d0..9a0458c1b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/WanderingTraderMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/npc/WanderingTraderMixin.java @@ -7,10 +7,13 @@ import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.inventory.CraftMerchantRecipe; import org.bukkit.entity.AbstractVillager; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.entity.VillagerAcquireTradeEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(WanderingTrader.class) public abstract class WanderingTraderMixin extends AbstractVillagerMixin { @@ -27,4 +30,9 @@ public abstract class WanderingTraderMixin extends AbstractVillagerMixin { } return false; } + + @Inject(method = "maybeDespawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/npc/WanderingTrader;discard()V")) + private void arclight$despawn(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/PlayerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/PlayerMixin.java index 807fde95b..12e410fa9 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/PlayerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/player/PlayerMixin.java @@ -4,6 +4,7 @@ import com.mojang.datafixers.util.Either; import io.izzel.arclight.common.bridge.core.entity.EntityBridge; import io.izzel.arclight.common.bridge.core.entity.InternalEntityBridge; +import io.izzel.arclight.common.bridge.core.entity.LivingEntityBridge; import io.izzel.arclight.common.bridge.core.entity.player.PlayerEntityBridge; import io.izzel.arclight.common.bridge.core.entity.player.ServerPlayerEntityBridge; import io.izzel.arclight.common.bridge.core.inventory.IInventoryBridge; @@ -68,6 +69,7 @@ import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityCombustByEntityEvent; import org.bukkit.event.entity.EntityExhaustionEvent; +import org.bukkit.event.entity.EntityKnockbackEvent; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.player.PlayerBedLeaveEvent; @@ -136,7 +138,8 @@ public abstract class PlayerMixin extends LivingEntityMixin implements PlayerEnt @Shadow public abstract void setRemainingFireTicks(int p_36353_); // @formatter:on - @Shadow public abstract boolean isCreative(); + @Shadow + public abstract boolean isCreative(); public boolean fauxSleeping; public int oldLevel; @@ -325,6 +328,7 @@ public void attack(final Entity entity) { if (flag6) { if (i > 0) { if (entity instanceof LivingEntity) { + ((LivingEntityBridge) entity).bridge$pushKnockbackCause((Entity) (Object) this, EntityKnockbackEvent.KnockbackCause.ENTITY_ATTACK); ((LivingEntity) entity).knockback(i * 0.5f, Mth.sin(this.getYRot() * 0.017453292f), -Mth.cos(this.getYRot() * 0.017453292f)); } else { entity.push(-Mth.sin(this.getYRot() * 0.017453292f) * i * 0.5f, 0.1, Mth.cos(this.getYRot() * 0.017453292f) * i * 0.5f); @@ -338,6 +342,7 @@ public void attack(final Entity entity) { double entityReachSq = Mth.square(this.bridge$forge$getEntityReach()); // Use entity reach instead of constant 9.0. Vanilla uses bottom center-to-center checks here, so don't update this to use canReach, since it uses closest-corner checks. for (final LivingEntity entityliving : list) { if (entityliving != (Object) this && entityliving != entity && !this.isAlliedTo(entityliving) && (!(entityliving instanceof ArmorStand) || !((ArmorStand) entityliving).isMarker()) && this.distanceToSqr(entityliving) < entityReachSq && entityliving.hurt(((DamageSourceBridge) this.damageSources().playerAttack((net.minecraft.world.entity.player.Player) (Object) this)).bridge$sweep(), f5)) { + ((LivingEntityBridge) entityliving).bridge$pushKnockbackCause((Entity) (Object) this, EntityKnockbackEvent.KnockbackCause.SWEEP_ATTACK); entityliving.knockback(0.4f, Mth.sin(this.getYRot() * 0.017453292f), -Mth.cos(this.getYRot() * 0.017453292f)); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/AbstractArrowMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/AbstractArrowMixin.java index 0ba3c374b..3e388c7cf 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/AbstractArrowMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/AbstractArrowMixin.java @@ -14,6 +14,7 @@ import org.bukkit.craftbukkit.v.entity.CraftItem; import org.bukkit.entity.AbstractArrow; import org.bukkit.event.entity.EntityCombustByEntityEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.player.PlayerPickupArrowEvent; import org.bukkit.projectiles.ProjectileSource; import org.objectweb.asm.Opcodes; @@ -51,6 +52,16 @@ public abstract class AbstractArrowMixin extends ProjectileMixin { } } + @Inject(method = "onHitEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/AbstractArrow;discard()V")) + private void arclight$hit(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.HIT); + } + + @Inject(method = "tickDespawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/AbstractArrow;discard()V")) + private void arclight$despawn(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } + /** * @author IzzelAliz * @reason @@ -70,6 +81,7 @@ public void playerTouch(Player playerEntity) { } if ((this.pickup == net.minecraft.world.entity.projectile.AbstractArrow.Pickup.ALLOWED && playerEntity.getInventory().add(itemstack)) || (this.pickup == net.minecraft.world.entity.projectile.AbstractArrow.Pickup.CREATIVE_ONLY && playerEntity.getAbilities().instabuild)) { playerEntity.take((net.minecraft.world.entity.projectile.AbstractArrow) (Object) this, 1); + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.PICKUP); this.discard(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/AbstractHurtingProjectileMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/AbstractHurtingProjectileMixin.java index a36a65ce8..48cd6bb3e 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/AbstractHurtingProjectileMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/AbstractHurtingProjectileMixin.java @@ -7,6 +7,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.phys.HitResult; import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityRemoveEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -41,6 +42,11 @@ public void setDirection(double d0, double d1, double d2) { this.zPower = d2 / d3 * 0.1D; } + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/AbstractHurtingProjectile;discard()V")) + private void arclight$despawn(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } + @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/AbstractHurtingProjectile;onHit(Lnet/minecraft/world/phys/HitResult;)V")) private void arclight$preOnHit(AbstractHurtingProjectile abstractHurtingProjectile, HitResult hitResult) { this.preOnHit(hitResult); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/DragonFireballMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/DragonFireballMixin.java new file mode 100644 index 000000000..3615d7ab0 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/DragonFireballMixin.java @@ -0,0 +1,18 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import net.minecraft.world.entity.projectile.DragonFireball; +import net.minecraft.world.phys.HitResult; +import org.bukkit.event.entity.EntityRemoveEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(DragonFireball.class) +public abstract class DragonFireballMixin extends ProjectileMixin { + + @Inject(method = "onHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/DragonFireball;discard()V")) + private void arclight$hit(HitResult hitResult, CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.HIT); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/EvokerFangsMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/EvokerFangsMixin.java index 5338a7bdf..03a484559 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/EvokerFangsMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/EvokerFangsMixin.java @@ -5,10 +5,12 @@ import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageSources; import net.minecraft.world.entity.projectile.EvokerFangs; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityRemoveEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(EvokerFangs.class) public abstract class EvokerFangsMixin extends EntityMixin { @@ -17,4 +19,9 @@ public abstract class EvokerFangsMixin extends EntityMixin { private DamageSource arclight$entityDamage(DamageSources instance) { return ((DamageSourceBridge) instance.magic()).bridge$customCausingEntity((EvokerFangs) (Object) this); } + + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/EvokerFangs;discard()V")) + private void arclight$despawn(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/EyeOfEnderMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/EyeOfEnderMixin.java new file mode 100644 index 000000000..dfbd79b5e --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/EyeOfEnderMixin.java @@ -0,0 +1,28 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import io.izzel.arclight.common.mixin.core.world.entity.EntityMixin; +import net.minecraft.world.entity.projectile.EyeOfEnder; +import net.minecraft.world.item.ItemStack; +import org.bukkit.event.entity.EntityRemoveEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(EyeOfEnder.class) +public abstract class EyeOfEnderMixin extends EntityMixin { + + @Shadow public boolean surviveAfterDeath; + + @Redirect(method = "setItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;hasTag()Z")) + private boolean arclight$allowItemChange(ItemStack instance) { + return true; + } + + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/EyeOfEnder;discard()V")) + private void arclight$drop(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(this.surviveAfterDeath ? EntityRemoveEvent.Cause.DROP : EntityRemoveEvent.Cause.DESPAWN); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FireworkRocketEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FireworkRocketEntityMixin.java index 6da585abc..2532a72ee 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FireworkRocketEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FireworkRocketEntityMixin.java @@ -3,6 +3,7 @@ import io.izzel.arclight.common.mixin.core.world.entity.EntityMixin; import net.minecraft.world.entity.projectile.FireworkRocketEntity; import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityRemoveEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -15,6 +16,8 @@ public abstract class FireworkRocketEntityMixin extends EntityMixin { private void arclight$fireworksExplode(CallbackInfo ci) { if (CraftEventFactory.callFireworkExplodeEvent((FireworkRocketEntity) (Object) this).isCancelled()) { ci.cancel(); + } else { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.EXPLODE); } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FishingHookMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FishingHookMixin.java index 0e344e57b..09cdeeaab 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FishingHookMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/FishingHookMixin.java @@ -25,6 +25,7 @@ import net.minecraft.world.phys.HitResult; import org.bukkit.Bukkit; import org.bukkit.entity.FishHook; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.player.PlayerFishEvent; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -34,6 +35,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.Collections; import java.util.List; @@ -110,6 +112,16 @@ public abstract class FishingHookMixin extends ProjectileMixin implements Fishin return Mth.nextInt(random, this.minLureTime, this.maxLureTime); } + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/FishingHook;discard()V")) + private void arclight$tickDespawn(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } + + @Inject(method = "shouldStopFishing", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/FishingHook;discard()V")) + private void arclight$fishDespawn(Player player, CallbackInfoReturnable cir) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } + /** * @author IzzelAliz * @reason @@ -186,6 +198,7 @@ public int retrieve(ItemStack stack) { } } + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); this.discard(); return rodDamage == null ? i : rodDamage; } else { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/LargeFireballMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/LargeFireballMixin.java index 920252017..539024e48 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/LargeFireballMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/LargeFireballMixin.java @@ -8,7 +8,9 @@ import net.minecraft.world.level.Explosion; import net.minecraft.world.level.GameRules; import net.minecraft.world.level.Level; +import net.minecraft.world.phys.HitResult; import org.bukkit.Bukkit; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.entity.ExplosionPrimeEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -29,6 +31,11 @@ public abstract class LargeFireballMixin extends AbstractHurtingProjectileMixin this.isIncendiary = level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING); } + @Inject(method = "onHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/LargeFireball;discard()V")) + private void arclight$explode(HitResult hitResult, CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.HIT); + } + @Redirect(method = "onHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;explode(Lnet/minecraft/world/entity/Entity;DDDFZLnet/minecraft/world/level/Level$ExplosionInteraction;)Lnet/minecraft/world/level/Explosion;")) private Explosion arclight$explodePrime(Level world, Entity entityIn, double xIn, double yIn, double zIn, float explosionRadius, boolean causesFire, Level.ExplosionInteraction interaction) { ExplosionPrimeEvent event = new ExplosionPrimeEvent((org.bukkit.entity.Explosive) this.getBukkitEntity()); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/LlamaSpitMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/LlamaSpitMixin.java new file mode 100644 index 000000000..9a7562203 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/LlamaSpitMixin.java @@ -0,0 +1,23 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import net.minecraft.world.entity.projectile.LlamaSpit; +import net.minecraft.world.phys.BlockHitResult; +import org.bukkit.event.entity.EntityRemoveEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(LlamaSpit.class) +public abstract class LlamaSpitMixin extends ProjectileMixin { + + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/LlamaSpit;discard()V")) + private void arclight$despawn(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } + + @Inject(method = "onHitBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/LlamaSpit;discard()V")) + private void arclight$hit(BlockHitResult blockHitResult, CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.HIT); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ShulkerBulletMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ShulkerBulletMixin.java index 853f6ecf1..ea00a48af 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ShulkerBulletMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ShulkerBulletMixin.java @@ -9,8 +9,10 @@ import net.minecraft.world.entity.projectile.ShulkerBullet; import net.minecraft.world.level.Level; import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.phys.HitResult; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.EntityPotionEffectEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -39,6 +41,21 @@ public abstract class ShulkerBulletMixin extends EntityMixin { ((LivingEntityBridge) result.getEntity()).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.ATTACK); } + @Inject(method = "onHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/ShulkerBullet;destroy()V")) + private void arclight$hitCause(HitResult hitResult, CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.HIT); + } + + @Inject(method = "checkDespawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/ShulkerBullet;discard()V")) + private void arclight$despawn(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } + + @Inject(method = "hurt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/ShulkerBullet;destroy()V")) + private void arclight$dead(DamageSource damageSource, float f, CallbackInfoReturnable cir) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DEATH); + } + @Inject(method = "hurt", cancellable = true, at = @At("HEAD")) private void arclight$damageBullet(DamageSource source, float amount, CallbackInfoReturnable cir) { if (CraftEventFactory.handleNonLivingEntityDamageEvent((ShulkerBullet) (Object) this, source, amount, false)) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/SmallFireballMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/SmallFireballMixin.java index 54987110f..df6a93230 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/SmallFireballMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/SmallFireballMixin.java @@ -9,9 +9,11 @@ import net.minecraft.world.level.GameRules; import net.minecraft.world.level.Level; import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.EntityCombustByEntityEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -48,4 +50,9 @@ public abstract class SmallFireballMixin extends FireballMixin { ci.cancel(); } } + + @Inject(method = "onHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/SmallFireball;discard()V")) + private void arclight$hitCause(HitResult hitResult, CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.HIT); + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/SnowballMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/SnowballMixin.java new file mode 100644 index 000000000..4074782db --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/SnowballMixin.java @@ -0,0 +1,18 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import net.minecraft.world.entity.projectile.Snowball; +import net.minecraft.world.phys.HitResult; +import org.bukkit.event.entity.EntityRemoveEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Snowball.class) +public abstract class SnowballMixin extends ThrowableItemProjectileMixin { + + @Inject(method = "onHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/Snowball;discard()V")) + private void arclight$hitCause(HitResult hitResult, CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.HIT); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownEggMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownEggMixin.java index f386f30b1..cf7a20bd3 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownEggMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownEggMixin.java @@ -14,6 +14,7 @@ import org.bukkit.entity.Ageable; import org.bukkit.entity.Egg; import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.player.PlayerEggThrowEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -68,6 +69,7 @@ protected void onHit(final HitResult result) { } } this.level().broadcastEntityEvent((ThrownEgg) (Object) this, (byte) 3); + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.HIT); this.discard(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownEnderpearlMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownEnderpearlMixin.java index 0a4e2ba2e..100a85b8f 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownEnderpearlMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownEnderpearlMixin.java @@ -6,8 +6,8 @@ import net.minecraft.world.damagesource.DamageSources; import net.minecraft.world.entity.projectile.ThrownEnderpearl; import net.minecraft.world.phys.HitResult; -import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -17,6 +17,16 @@ @Mixin(ThrownEnderpearl.class) public abstract class ThrownEnderpearlMixin extends ThrowableProjectileMixin { + @Inject(method = "onHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/ThrownEnderpearl;discard()V")) + private void arclight$hit(HitResult hitResult, CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.HIT); + } + + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/ThrownEnderpearl;discard()V")) + private void arclight$despawn(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DESPAWN); + } + @Inject(method = "onHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) private void arclight$spawnEndermite(HitResult result, CallbackInfo ci) { ((WorldBridge) this.level()).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.ENDER_PEARL); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownExperienceBottleMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownExperienceBottleMixin.java index 8332b3bc0..9bcfbb38a 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownExperienceBottleMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownExperienceBottleMixin.java @@ -7,6 +7,7 @@ import net.minecraft.world.item.alchemy.Potions; import net.minecraft.world.phys.HitResult; import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.entity.ExpBottleEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -29,6 +30,7 @@ protected void onHit(HitResult result) { this.level().levelEvent(2002, this.blockPosition(), PotionUtils.getColor(Potions.WATER)); } ExperienceOrb.award((ServerLevel) this.level(), this.position(), i); + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.HIT); this.discard(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownPotionMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownPotionMixin.java index 2e3e5eee8..530e31876 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownPotionMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownPotionMixin.java @@ -22,6 +22,7 @@ import org.bukkit.craftbukkit.v.entity.CraftLivingEntity; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.EntityPotionEffectEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.entity.LingeringPotionSplashEvent; import org.bukkit.event.entity.PotionSplashEvent; import org.spongepowered.asm.mixin.Mixin; @@ -54,6 +55,11 @@ public abstract class ThrownPotionMixin extends ThrowableItemProjectileMixin { arclight$hitResult = null; } + @Inject(method = "onHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/ThrownPotion;discard()V")) + private void arclight$hitCause(HitResult hitResult, CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.HIT); + } + /** * @author IzzelAliz * @reason diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownTridentMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownTridentMixin.java index 771c88acb..d48583244 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownTridentMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/ThrownTridentMixin.java @@ -7,14 +7,21 @@ import net.minecraft.world.entity.projectile.ThrownTrident; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.weather.LightningStrikeEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ThrownTrident.class) public abstract class ThrownTridentMixin extends AbstractArrowMixin implements TridentEntityBridge { + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/ThrownTrident;discard()V")) + private void arclight$dropCause(CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DROP); + } @Redirect(method = "onHitEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) private boolean arclight$lightning(Level world, Entity entityIn) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/WindChargeMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/WindChargeMixin.java new file mode 100644 index 000000000..40203d3fb --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/WindChargeMixin.java @@ -0,0 +1,24 @@ +package io.izzel.arclight.common.mixin.core.world.entity.projectile; + +import net.minecraft.world.entity.projectile.WindCharge; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.HitResult; +import org.bukkit.event.entity.EntityRemoveEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(WindCharge.class) +public abstract class WindChargeMixin extends AbstractHurtingProjectileMixin { + + @Inject(method = "onHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/WindCharge;discard()V")) + private void arclight$hitCause(HitResult hitResult, CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.HIT); + } + + @Inject(method = "onHitBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/WindCharge;discard()V")) + private void arclight$hitBlock(BlockHitResult blockHitResult, CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.HIT); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/WitherSkullMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/WitherSkullMixin.java index 6e21861e7..5a26d78fd 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/WitherSkullMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/projectile/WitherSkullMixin.java @@ -6,9 +6,11 @@ import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.phys.HitResult; import org.bukkit.Bukkit; import org.bukkit.event.entity.EntityPotionEffectEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.entity.ExplosionPrimeEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -19,6 +21,11 @@ @Mixin(WitherSkull.class) public abstract class WitherSkullMixin extends AbstractHurtingProjectileMixin { + @Inject(method = "onHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/projectile/WitherSkull;discard()V")) + private void arclight$hitCause(HitResult hitResult, CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.HIT); + } + @Inject(method = "onHitEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;heal(F)V")) private void arclight$heal(EntityHitResult result, CallbackInfo ci) { ((LivingEntityBridge) this.getOwner()).bridge$pushHealReason(EntityRegainHealthEvent.RegainReason.WITHER); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/raider/RaiderMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/raider/RaiderMixin.java index 2fd35cf77..53b476937 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/raider/RaiderMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/raider/RaiderMixin.java @@ -4,11 +4,13 @@ import io.izzel.arclight.common.mixin.core.world.entity.PathfinderMobMixin; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.raid.Raid; import net.minecraft.world.entity.raid.Raider; import net.minecraft.world.item.ItemStack; import org.bukkit.event.entity.EntityPotionEffectEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -22,4 +24,9 @@ public abstract class RaiderMixin extends PathfinderMobMixin { private void arclight$raid(DamageSource cause, CallbackInfo ci, Entity entity, Raid raid, ItemStack itemStack, Player playerEntity) { ((PlayerEntityBridge) playerEntity).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.PATROL_CAPTAIN); } + + @Inject(method = "pickUpItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/item/ItemEntity;discard()V")) + private void arclight$pickup(ItemEntity itemEntity, CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.PICKUP); + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/MinecartTNTMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/MinecartTNTMixin.java index f1bece524..00ad58a0b 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/MinecartTNTMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/MinecartTNTMixin.java @@ -8,10 +8,12 @@ import net.minecraft.world.level.ExplosionDamageCalculator; import net.minecraft.world.level.Level; import org.bukkit.Bukkit; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.entity.ExplosionPrimeEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(MinecartTNT.class) @@ -30,4 +32,9 @@ public abstract class MinecartTNTMixin extends AbstractMinecartMixin { } return level.explode((MinecartTNT) (Object) this, x, y, z, event.getRadius(), event.getFire(), interaction); } + + @Inject(method = "explode(Lnet/minecraft/world/damagesource/DamageSource;D)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/vehicle/MinecartTNT;discard()V")) + private void arclight$explodeCause(DamageSource damageSource, double d, CallbackInfo ci) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.EXPLODE); + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/VehicleEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/VehicleEntityMixin.java index 1226f13d3..7f22eb045 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/VehicleEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/entity/vehicle/VehicleEntityMixin.java @@ -7,6 +7,7 @@ import net.minecraft.world.level.gameevent.GameEvent; import org.bukkit.Bukkit; import org.bukkit.entity.Vehicle; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.vehicle.VehicleDamageEvent; import org.bukkit.event.vehicle.VehicleDestroyEvent; import org.spongepowered.asm.mixin.Mixin; @@ -64,6 +65,7 @@ public boolean hurt(DamageSource source, float amount) { return true; } // CraftBukkit end + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DEATH); this.discard(); } } else { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/ExplosionMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/ExplosionMixin.java index 48f87e159..49eb3aa82 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/ExplosionMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/ExplosionMixin.java @@ -36,11 +36,13 @@ import net.minecraft.world.phys.Vec3; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.craftbukkit.v.entity.CraftLivingEntity; import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.block.BlockExplodeEvent; import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.TNTPrimeEvent; import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntityKnockbackEvent; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; @@ -223,6 +225,14 @@ public void explode() { d9 *= d11; Vec3 vec3d1 = new Vec3(d5, d7, d9); + // CraftBukkit start - Call EntityKnockbackEvent + if (entity instanceof LivingEntity) { + var result = entity.getDeltaMovement().add(vec3d1); + var event = CraftEventFactory.callEntityKnockbackEvent((CraftLivingEntity) entity.bridge$getBukkitEntity(), source, EntityKnockbackEvent.KnockbackCause.EXPLOSION, d13, vec3d1, result.x, result.y, result.z); + vec3d1 = (event.isCancelled()) ? Vec3.ZERO : new Vec3(event.getFinalKnockback().getX(), event.getFinalKnockback().getY(), event.getFinalKnockback().getZ()); + } + // CraftBukkit end + entity.setDeltaMovement(entity.getDeltaMovement().add(vec3d1)); if (entity instanceof Player playerentity) { if (!playerentity.isSpectator() && (!playerentity.isCreative() || !playerentity.getAbilities().flying)) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/GameRules_ValueMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/GameRules_ValueMixin.java new file mode 100644 index 000000000..fa8794ff0 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/GameRules_ValueMixin.java @@ -0,0 +1,20 @@ +package io.izzel.arclight.common.mixin.core.world.level; + +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.GameRules; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(GameRules.Value.class) +public abstract class GameRules_ValueMixin { + + // @formatter:off + @Shadow public abstract void onChanged(@Nullable MinecraftServer minecraftServer); + // @formatter:on + + public void onChanged(ServerLevel level) { + this.onChanged(level.getServer()); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DecoratedPotBlockMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DecoratedPotBlockMixin.java new file mode 100644 index 000000000..a73c0fca6 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/DecoratedPotBlockMixin.java @@ -0,0 +1,29 @@ +package io.izzel.arclight.common.mixin.core.world.level.block; + +import net.minecraft.world.entity.projectile.Projectile; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.DecoratedPotBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.phys.BlockHitResult; +import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(DecoratedPotBlock.class) +public abstract class DecoratedPotBlockMixin { + + // @formatter:off + @Shadow public abstract FluidState getFluidState(BlockState arg); + // @formatter:on + + @Inject(method = "onProjectileHit", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private void arclight$entityChangeBlock(Level level, BlockState blockState, BlockHitResult blockHitResult, Projectile projectile, CallbackInfo ci) { + if (!CraftEventFactory.callEntityChangeBlockEvent(projectile, blockHitResult.getBlockPos(), this.getFluidState(blockState).createLegacyBlock())) { + ci.cancel(); + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/BeehiveBlockEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/BeehiveBlockEntityMixin.java index 491ccbff3..98009a57c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/BeehiveBlockEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/BeehiveBlockEntityMixin.java @@ -18,6 +18,7 @@ import org.bukkit.craftbukkit.v.block.CraftBlock; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityEnterBlockEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.entity.EntityTargetEvent; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -82,6 +83,11 @@ public List releaseBees(BlockState blockState, BeehiveBlockEntity.BeeRel } } + @Inject(method = "addOccupantWithPresetTicks", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;discard()V")) + private void arclight$enterBlockCause(Entity entity, boolean bl, int i, CallbackInfo ci) { + entity.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.ENTER_BLOCK); + } + private static boolean releaseBee(Level world, BlockPos pos, BlockState state, BeehiveBlockEntity.BeeData beeData, @Nullable List list, BeehiveBlockEntity.BeeReleaseStatus status, @Nullable BlockPos pos1, boolean force) { arclight$force = force; try { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/CrafterBlockEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/CrafterBlockEntityMixin.java index 4396da8e5..c1eadb6bd 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/CrafterBlockEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/CrafterBlockEntityMixin.java @@ -18,7 +18,7 @@ public abstract class CrafterBlockEntityMixin extends LockableBlockEntityMixin { @Shadow private NonNullList items; public List transaction = new java.util.ArrayList<>(); - private int maxStack = 1; + private int maxStack = MAX_STACK; @Override public List getContents() { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/EndGatewayBlockEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/EndGatewayBlockEntityMixin.java index 0303ed4d5..50a706318 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/EndGatewayBlockEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/EndGatewayBlockEntityMixin.java @@ -14,6 +14,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.craftbukkit.v.entity.CraftPlayer; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -39,6 +40,11 @@ public abstract class EndGatewayBlockEntityMixin extends BlockEntityMixin { } } + @Inject(method = "teleportEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setPortalCooldown()V")) + private static void arclight$teleportCause(Level level, BlockPos pos, BlockState state, Entity entityIn, TheEndGatewayBlockEntity entity, CallbackInfo ci) { + entityIn.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.HIT); + } + private static void arclight$playerTeleport(Level level, BlockPos pos, BlockState state, Entity entityIn, TheEndGatewayBlockEntity entity, BlockPos dest) { CraftPlayer player = ((ServerPlayerEntityBridge) entityIn).bridge$getBukkitEntity(); Location location = new Location(level.bridge$getWorld(), dest.getX() + 0.5D, dest.getY() + 0.5D, dest.getZ() + 0.5D); @@ -68,5 +74,10 @@ public static class VanillaLike { ci.cancel(); } } + + @Inject(method = "teleportEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setPortalCooldown()V")) + private static void arclight$teleportCause(Level level, BlockPos pos, BlockState state, Entity entityIn, TheEndGatewayBlockEntity entity, CallbackInfo ci) { + entityIn.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.HIT); + } } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/HopperBlockEntityMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/HopperBlockEntityMixin.java index ea705dc76..48fb5b476 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/HopperBlockEntityMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/block/entity/HopperBlockEntityMixin.java @@ -26,6 +26,7 @@ import org.bukkit.craftbukkit.v.inventory.CraftItemStack; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Item; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.inventory.HopperInventorySearchEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.event.inventory.InventoryPickupItemEvent; @@ -125,6 +126,11 @@ public abstract class HopperBlockEntityMixin extends LockableBlockEntityMixin { } } + @Inject(method = "addItem(Lnet/minecraft/world/Container;Lnet/minecraft/world/entity/item/ItemEntity;)Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/item/ItemEntity;discard()V")) + private static void arclight$pickupCause(Container container, ItemEntity itemEntity, CallbackInfoReturnable cir) { + itemEntity.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.PICKUP); + } + private static Container runHopperInventorySearchEvent(Container inventory, CraftBlock hopper, CraftBlock searchLocation, HopperInventorySearchEvent.ContainerType containerType) { var event = new HopperInventorySearchEvent((inventory != null) ? new CraftInventory(inventory) : null, containerType, hopper, searchLocation); Bukkit.getServer().getPluginManager().callEvent(event); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/dimension/end/DragonRespawnAnimation_4_Mixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/dimension/end/DragonRespawnAnimation_4_Mixin.java new file mode 100644 index 000000000..139ccc0e3 --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/dimension/end/DragonRespawnAnimation_4_Mixin.java @@ -0,0 +1,26 @@ +package io.izzel.arclight.common.mixin.core.world.level.dimension.end; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.boss.enderdragon.EndCrystal; +import net.minecraft.world.level.dimension.end.EndDragonFight; +import org.bukkit.event.entity.EntityRemoveEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.List; + +@Mixin(targets = "net/minecraft/world/level/dimension/end/DragonRespawnAnimation$4") +public class DragonRespawnAnimation_4_Mixin { + + @Inject(method = "tick", at = @At("HEAD")) + private void arclight$explode(ServerLevel serverLevel, EndDragonFight endDragonFight, List list, int i, BlockPos blockPos, CallbackInfo ci) { + if (i >= 100) { + for (var endCrystal : list) { + endCrystal.bridge().bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.EXPLODE); + } + } + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/entity/EntityAccessMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/entity/EntityAccessMixin.java new file mode 100644 index 000000000..b439f56ba --- /dev/null +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/entity/EntityAccessMixin.java @@ -0,0 +1,23 @@ +package io.izzel.arclight.common.mixin.core.world.level.entity; + +import io.izzel.arclight.common.bridge.core.entity.EntityBridge; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.entity.EntityAccess; +import org.bukkit.event.entity.EntityRemoveEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(EntityAccess.class) +public interface EntityAccessMixin { + + // @formatter:off + @Shadow void setRemoved(Entity.RemovalReason arg); + // @formatter:on + + default void setRemoved(Entity.RemovalReason reason, EntityRemoveEvent.Cause cause) { + if (this instanceof EntityBridge bridge) { + bridge.bridge$pushEntityRemoveCause(cause); + } + setRemoved(reason); + } +} diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/entity/PersistentEntitySectionManagerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/entity/PersistentEntitySectionManagerMixin.java index 36605b6b0..bce0cdde1 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/entity/PersistentEntitySectionManagerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/entity/PersistentEntitySectionManagerMixin.java @@ -1,5 +1,6 @@ package io.izzel.arclight.common.mixin.core.world.level.entity; +import io.izzel.arclight.common.bridge.core.entity.EntityBridge; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.ChunkPos; @@ -11,6 +12,7 @@ import net.minecraft.world.level.entity.EntitySectionStorage; import net.minecraft.world.level.entity.PersistentEntitySectionManager; import org.bukkit.craftbukkit.v.event.CraftEventFactory; +import org.bukkit.event.entity.EntityRemoveEvent; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -80,4 +82,11 @@ public boolean isPending(long cord) { List entities = getEntities(chunkEntities.getPos()); CraftEventFactory.callEntitiesLoadEvent(((EntityStorage) permanentStorage).level, chunkEntities.getPos(), entities); } + + @Inject(method = "unloadEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/entity/EntityAccess;setRemoved(Lnet/minecraft/world/entity/Entity$RemovalReason;)V")) + private void arclight$unloadCause(EntityAccess entityAccess, CallbackInfo ci) { + if (entityAccess instanceof EntityBridge bridge) { + bridge.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.UNLOAD); + } + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/levelgen/structure/StructureStartMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/levelgen/structure/StructureStartMixin.java index 34f7a086e..2d4d1c663 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/levelgen/structure/StructureStartMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/levelgen/structure/StructureStartMixin.java @@ -2,6 +2,7 @@ import io.izzel.arclight.common.bridge.core.world.level.levelgen.StructureStartBridge; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import net.minecraft.util.RandomSource; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.StructureManager; @@ -12,6 +13,10 @@ import net.minecraft.world.level.levelgen.structure.StructurePiece; import net.minecraft.world.level.levelgen.structure.StructureStart; import net.minecraft.world.level.levelgen.structure.pieces.PiecesContainer; +import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceSerializationContext; +import org.bukkit.craftbukkit.v.persistence.CraftPersistentDataContainer; +import org.bukkit.craftbukkit.v.persistence.CraftPersistentDataTypeRegistry; +import org.bukkit.craftbukkit.v.persistence.DirtyCraftPersistentDataContainer; import org.bukkit.craftbukkit.v.util.CraftStructureTransformer; import org.bukkit.craftbukkit.v.util.TransformerGeneratorAccess; import org.bukkit.event.world.AsyncStructureGenerateEvent; @@ -20,6 +25,9 @@ import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.List; @@ -68,4 +76,33 @@ public void placeInChunk(WorldGenLevel p_226851_, StructureManager p_226852_, Ch this.structure.afterPlace(p_226851_, p_226852_, p_226853_, p_226854_, p_226855_, p_226856_, this.pieceContainer); } } + + private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry(); + public DirtyCraftPersistentDataContainer persistentDataContainer = new DirtyCraftPersistentDataContainer(DATA_TYPE_REGISTRY); + + @Override + public CraftPersistentDataContainer bridge$getPersistentDataContainer() { + return persistentDataContainer; + } + + @Inject(method = "createTag", at = @At("RETURN")) + private void arclight$writeBukkitContainer(StructurePieceSerializationContext structurePieceSerializationContext, ChunkPos chunkPos, CallbackInfoReturnable cir) { + var tag = cir.getReturnValue(); + if (tag != null) { + if (!persistentDataContainer.isEmpty()) { + tag.put("StructureBukkitValues", persistentDataContainer.toTagCompound()); + } + } + } + + @Inject(method = "loadStaticStart", at = @At("RETURN")) + private static void arclight$readBukkitContainer(StructurePieceSerializationContext structurePieceSerializationContext, CompoundTag compoundTag, long l, CallbackInfoReturnable cir) { + var structureStart = cir.getReturnValue(); + if (structureStart != null) { + var nbt = compoundTag.get("StructureBukkitValues"); + if (nbt instanceof CompoundTag tag) { + ((StructureStartBridge) (Object) structureStart).bridge$getPersistentDataContainer().putAll(tag); + } + } + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/levelgen/structure/templatesystem/StructurePlaceSettingsMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/levelgen/structure/templatesystem/StructurePlaceSettingsMixin.java index 6dc982650..01651a754 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/levelgen/structure/templatesystem/StructurePlaceSettingsMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/level/levelgen/structure/templatesystem/StructurePlaceSettingsMixin.java @@ -25,7 +25,7 @@ public class StructurePlaceSettingsMixin { @Inject(method = "getRandomPalette", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/structure/templatesystem/StructurePlaceSettings;getRandom(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/util/RandomSource;")) private void arclight$forcePalette(List list, BlockPos p_74389_, CallbackInfoReturnable cir) { var i = list.size(); - if (this.palette > 0) { + if (this.palette >= 0) { if (this.palette >= i) { throw new IllegalArgumentException("Palette index out of bounds. Got " + this.palette + " where there are only " + i + " palettes available."); } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/optimization/general/activationrange/EntityMixin_ActivationRange.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/optimization/general/activationrange/EntityMixin_ActivationRange.java index 4635fb910..d48cb62a7 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/optimization/general/activationrange/EntityMixin_ActivationRange.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/optimization/general/activationrange/EntityMixin_ActivationRange.java @@ -1,5 +1,6 @@ package io.izzel.arclight.common.mixin.optimization.general.activationrange; +import io.izzel.arclight.common.bridge.core.entity.EntityBridge; import io.izzel.arclight.common.bridge.core.world.WorldBridge; import io.izzel.arclight.common.bridge.optimization.EntityBridge_ActivationRange; import io.izzel.arclight.common.mod.ArclightConstants; @@ -16,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(Entity.class) -public abstract class EntityMixin_ActivationRange implements EntityBridge_ActivationRange { +public abstract class EntityMixin_ActivationRange implements EntityBridge_ActivationRange, EntityBridge { // @formatter:off @Shadow public abstract void refreshDimensions(); diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/optimization/general/activationrange/entity/ItemEntityMixin_ActivationRange.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/optimization/general/activationrange/entity/ItemEntityMixin_ActivationRange.java index 46a394314..5eadbdfe9 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/optimization/general/activationrange/entity/ItemEntityMixin_ActivationRange.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/optimization/general/activationrange/entity/ItemEntityMixin_ActivationRange.java @@ -6,6 +6,7 @@ import io.izzel.arclight.common.mod.ArclightConstants; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.ItemStack; +import org.bukkit.event.entity.EntityRemoveEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -33,6 +34,7 @@ public void inactiveTick() { @Override public void bridge$forge$optimization$discardItemEntity() { if (!this.level().isClientSide && this.age >= ((WorldBridge) this.level()).bridge$spigotConfig().itemDespawnRate) { + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.DEATH); this.discard(); } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/entity/animal/MushroomCowMixin_Vanilla.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/entity/animal/MushroomCowMixin_Vanilla.java index 51357e87a..160bd9569 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/entity/animal/MushroomCowMixin_Vanilla.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/vanilla/world/entity/animal/MushroomCowMixin_Vanilla.java @@ -12,6 +12,7 @@ import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityDropItemEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.entity.EntityTransformEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -33,6 +34,7 @@ public abstract class MushroomCowMixin_Vanilla extends EntityMixin_Vanilla { ci.cancel(); } else { ((WorldBridge) this.level()).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SHEARED); + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.TRANSFORMATION); this.discard(); } } diff --git a/arclight-common/src/main/resources/arclight.accesswidener b/arclight-common/src/main/resources/arclight.accesswidener index 5212eb891..4bb2662cb 100644 --- a/arclight-common/src/main/resources/arclight.accesswidener +++ b/arclight-common/src/main/resources/arclight.accesswidener @@ -8,6 +8,7 @@ accessible method net/minecraft/world/entity/item/PrimedTnt explode ()V extendable class net/minecraft/world/item/crafting/Ingredient accessible method net/minecraft/world/damagesource/DamageSource (Lnet/minecraft/core/Holder;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/Vec3;)V accessible method net/minecraft/server/level/ServerLevel getEntities ()Lnet/minecraft/world/level/entity/LevelEntityGetter; +accessible field net/minecraft/world/entity/animal/MushroomCow stewEffects Ljava/util/List; # Older versions accessible field net/minecraft/world/level/chunk/storage/ChunkSerializer BLOCK_STATE_CODEC Lcom/mojang/serialization/Codec; # TODO field net/minecraft/server/PlayerAdvancements f_135964_ diff --git a/arclight-common/src/main/resources/mixins.arclight.core.json b/arclight-common/src/main/resources/mixins.arclight.core.json index aa06c626e..e7b32f8ee 100644 --- a/arclight-common/src/main/resources/mixins.arclight.core.json +++ b/arclight-common/src/main/resources/mixins.arclight.core.json @@ -119,6 +119,7 @@ "world.entity.ai.behavior.StartAttackingMixin", "world.entity.ai.behavior.StopAttackingIfTargetInvalidMixin", "world.entity.ai.behavior.VillagerMakeLoveMixin", + "world.entity.ai.behavior.warden.DiggingMixin", "world.entity.ai.brain.BrainUtilMixin", "world.entity.ai.goal.BreakDoorGoalMixin", "world.entity.ai.goal.DefendVillageTargetGoalMixin", @@ -163,6 +164,7 @@ "world.entity.animal.RabbitMixin", "world.entity.animal.Sheep1Mixin", "world.entity.animal.SheepMixin", + "world.entity.animal.ShoulderRidingEntityMixin", "world.entity.animal.SnifferMixin", "world.entity.animal.SnowGolemMixin", "world.entity.animal.TameableAnimalMixin", @@ -170,13 +172,18 @@ "world.entity.animal.TurtleMixin", "world.entity.animal.WolfMixin", "world.entity.animal.axolotl.AxolotlMixin", + "world.entity.animal.camel.CamelMixin", + "world.entity.animal.frog.ShootTongueMixin", "world.entity.animal.frog.TadpoleMixin", "world.entity.animal.goat.GoatMixin", "world.entity.animal.horse.AbstractHorseMixin", "world.entity.animal.horse.LlamaMixin", + "world.entity.animal.horse.SkeletonHorseMixin", "world.entity.animal.horse.TraderLlamaEntity_FollowTraderGoalMixin", + "world.entity.animal.horse.TraderLlamaMixin", "world.entity.boss.enderdragon.EnderCrystalMixin", "world.entity.boss.enderdragon.EnderDragonMixin", + "world.entity.boss.enderdragon.phases.DragonSittingFlamingPhaseMixin", "world.entity.boss.enderdragon.phases.EnderDragonPhaseManagerMixin", "world.entity.boss.wither.WitherBossMixin", "world.entity.decoration.ArmorStandMixin", @@ -193,6 +200,7 @@ "world.entity.monster.EnderMan_EndermanLeaveBlockGoalMixin", "world.entity.monster.EnderMan_EndermanTakeBlockGoalMixin", "world.entity.monster.EnderManMixin", + "world.entity.monster.EndermiteMixin", "world.entity.monster.Evoker_EvokerSummonSpellGoalMixin", "world.entity.monster.Ghast_GhastShootFireballGoalMixin", "world.entity.monster.GuardianMixin", @@ -200,6 +208,7 @@ "world.entity.monster.Illusioner_BlindnessSpellGoalMixin", "world.entity.monster.Illusioner_MirrorSpellGoalMixin", "world.entity.monster.Phantom_AttackPlayerTargetGoalMixin", + "world.entity.monster.PillagerMixin", "world.entity.monster.RavagerMixin", "world.entity.monster.ShulkerMixin", "world.entity.monster.Silverfish_MergeWithStoneGoalMixin", @@ -227,14 +236,18 @@ "world.entity.projectile.AbstractArrowMixin", "world.entity.projectile.AbstractHurtingProjectileMixin", "world.entity.projectile.ArrowEntityMixin", + "world.entity.projectile.DragonFireballMixin", "world.entity.projectile.EvokerFangsMixin", + "world.entity.projectile.EyeOfEnderMixin", "world.entity.projectile.FireballMixin", "world.entity.projectile.FireworkRocketEntityMixin", "world.entity.projectile.FishingHookMixin", "world.entity.projectile.LargeFireballMixin", + "world.entity.projectile.LlamaSpitMixin", "world.entity.projectile.ProjectileMixin", "world.entity.projectile.ShulkerBulletMixin", "world.entity.projectile.SmallFireballMixin", + "world.entity.projectile.SnowballMixin", "world.entity.projectile.SpectralArrowMixin", "world.entity.projectile.ThrowableItemProjectileMixin", "world.entity.projectile.ThrowableProjectileMixin", @@ -243,6 +256,7 @@ "world.entity.projectile.ThrownExperienceBottleMixin", "world.entity.projectile.ThrownPotionMixin", "world.entity.projectile.ThrownTridentMixin", + "world.entity.projectile.WindChargeMixin", "world.entity.projectile.WitherSkullMixin", "world.entity.raid.RaidManagerMixin", "world.entity.raid.RaidMixin", @@ -343,6 +357,7 @@ "world.item.enchantment.DamageEnchantmentMixin", "world.item.enchantment.FrostWalkerEnchantmentMixin", "world.level.ExplosionMixin", + "world.level.GameRules_ValueMixin", "world.level.LevelMixin", "world.level.block.BambooSaplingBlockMixin", "world.level.block.BambooStalkBlockMixin", @@ -380,6 +395,7 @@ "world.level.block.CoralWallFanBlockMixin", "world.level.block.CropBlockMixin", "world.level.block.DaylightDetectorBlockMixin", + "world.level.block.DecoratedPotBlockMixin", "world.level.block.DetectorRailBlockMixin", "world.level.block.DiodeBlockMixin", "world.level.block.DirtPathBlockMixin", @@ -493,6 +509,8 @@ "world.level.chunk.storage.ChunkLoaderMixin", "world.level.chunk.storage.ChunkSerializerMixin", "world.level.chunk.storage.RegionFileCacheMixin", + "world.level.dimension.end.DragonRespawnAnimation_4_Mixin", + "world.level.entity.EntityAccessMixin", "world.level.entity.PersistentEntitySectionManagerMixin", "world.level.gameevent.GameEventDispatcherMixin", "world.level.gameevent.vibrations.VibrationListenerMixin", diff --git a/arclight-forge/src/main/java/io/izzel/arclight/forge/mixin/core/world/entity/animal/MushroomCowMixin_Forge.java b/arclight-forge/src/main/java/io/izzel/arclight/forge/mixin/core/world/entity/animal/MushroomCowMixin_Forge.java index 1ec7adafe..80284f7cc 100644 --- a/arclight-forge/src/main/java/io/izzel/arclight/forge/mixin/core/world/entity/animal/MushroomCowMixin_Forge.java +++ b/arclight-forge/src/main/java/io/izzel/arclight/forge/mixin/core/world/entity/animal/MushroomCowMixin_Forge.java @@ -11,6 +11,7 @@ import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityDropItemEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.entity.EntityTransformEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; @@ -41,6 +42,7 @@ public abstract class MushroomCowMixin_Forge extends MobMixin_Forge { cir.setReturnValue(Collections.emptyList()); } else { ((WorldBridge) this.level()).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SHEARED); + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.TRANSFORMATION); this.discard(); } } diff --git a/arclight-neoforge/src/main/java/io/izzel/arclight/neoforge/mixin/core/world/entity/animal/MushroomCowMixin_NeoForge.java b/arclight-neoforge/src/main/java/io/izzel/arclight/neoforge/mixin/core/world/entity/animal/MushroomCowMixin_NeoForge.java index 594b9345d..b902e1b86 100644 --- a/arclight-neoforge/src/main/java/io/izzel/arclight/neoforge/mixin/core/world/entity/animal/MushroomCowMixin_NeoForge.java +++ b/arclight-neoforge/src/main/java/io/izzel/arclight/neoforge/mixin/core/world/entity/animal/MushroomCowMixin_NeoForge.java @@ -11,6 +11,7 @@ import org.bukkit.craftbukkit.v.event.CraftEventFactory; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntityDropItemEvent; +import org.bukkit.event.entity.EntityRemoveEvent; import org.bukkit.event.entity.EntityTransformEvent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -35,6 +36,7 @@ public abstract class MushroomCowMixin_NeoForge extends MobMixin_NeoForge { ci.cancel(); } else { ((WorldBridge) this.level()).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.SHEARED); + this.bridge$pushEntityRemoveCause(EntityRemoveEvent.Cause.TRANSFORMATION); this.discard(); } }