diff --git a/Fabric/src/main/java/tschipp/carryon/events/CommonEvents.java b/Fabric/src/main/java/tschipp/carryon/events/CommonEvents.java index f0de4d7..cb9d6f0 100644 --- a/Fabric/src/main/java/tschipp/carryon/events/CommonEvents.java +++ b/Fabric/src/main/java/tschipp/carryon/events/CommonEvents.java @@ -21,6 +21,7 @@ package tschipp.carryon.events; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents; import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.CommonLifecycleEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; @@ -33,6 +34,7 @@ import net.minecraft.core.Direction; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.packs.PackType; import net.minecraft.world.InteractionResult; +import net.minecraft.world.level.GameRules; import tschipp.carryon.CarryOnCommon; import tschipp.carryon.common.carry.CarryOnData; import tschipp.carryon.common.carry.CarryOnData.CarryType; @@ -132,10 +134,13 @@ public class CommonEvents { CarryOnCommon.onCarryTick(player); }); - - ServerPlayerEvents.COPY_FROM.register(((oldPlayer, newPlayer, alive) -> { - PlacementHandler.placeCarriedOnDeath(oldPlayer, newPlayer, !alive); - })); + ServerLivingEntityEvents.AFTER_DEATH.register((entity, damageSource)->{ + if (!(entity instanceof ServerPlayer)) return; + var player = (ServerPlayer) entity; + var carry = CarryOnDataManager.getCarryData(player); + if (!carry.isCarrying() || player.level().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) && !carry.isCarrying(CarryType.PLAYER)) return; + PlacementHandler.placeCarried(player); + }); PlayerBlockBreakEvents.BEFORE.register(((world, player, pos, state, blockEntity) -> {