diff --git a/src/main/java/com/b1n_ry/yigd/events/ServerEventHandler.java b/src/main/java/com/b1n_ry/yigd/events/ServerEventHandler.java index 1445c7e..7ec82b9 100644 --- a/src/main/java/com/b1n_ry/yigd/events/ServerEventHandler.java +++ b/src/main/java/com/b1n_ry/yigd/events/ServerEventHandler.java @@ -29,15 +29,6 @@ import java.util.UUID; public class ServerEventHandler { - @SubscribeEvent - public void onDrop(LivingDeathEvent event) { - LivingEntity e = event.getEntity(); - if (e.level().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY)) return; - if (!(e instanceof ServerPlayer player)) return; - - Yigd.DEATH_HANDLER.onPlayerDeath(player, player.serverLevel(), player.position(), event.getSource()); - } - @SubscribeEvent public void onEndOfTick(ServerTickEvent.Post event) { List methodsToRun = new ArrayList<>(Yigd.END_OF_TICK); diff --git a/src/main/java/com/b1n_ry/yigd/mixin/LivingEntityMixin.java b/src/main/java/com/b1n_ry/yigd/mixin/LivingEntityMixin.java new file mode 100644 index 0000000..f15a484 --- /dev/null +++ b/src/main/java/com/b1n_ry/yigd/mixin/LivingEntityMixin.java @@ -0,0 +1,30 @@ +package com.b1n_ry.yigd.mixin; + +import com.b1n_ry.yigd.DeathHandler; +import com.b1n_ry.yigd.Yigd; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.level.GameRules; +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(value = LivingEntity.class, priority = 500) +public class LivingEntityMixin { + @Inject(method = "dropAllDeathLoot", at = @At("HEAD")) + private void onDeath(ServerLevel level, DamageSource damageSource, CallbackInfo ci) { + LivingEntity entity = (LivingEntity) (Object) this; + + if (!(entity instanceof ServerPlayer player)) return; + + if (!player.isDeadOrDying()) return; + if (player.isSpectator()) return; + + if (level.getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY)) return; + + Yigd.DEATH_HANDLER.onPlayerDeath(player, level, player.position(), damageSource); + } +} diff --git a/src/main/resources/yigd.mixins.json b/src/main/resources/yigd.mixins.json index 463ef9a..04b6fd4 100644 --- a/src/main/resources/yigd.mixins.json +++ b/src/main/resources/yigd.mixins.json @@ -8,6 +8,7 @@ "CompassItemMixin", "EndPlatformFeatureMixin", "LevelChunkMixin", + "LivingEntityMixin", "RegistryDataLoaderMixin" ], "client": [