Update CommonEvents.java

This commit is contained in:
Hanro50 2025-10-22 19:37:26 +02:00
parent 9a484df16e
commit 21f09b2526

View File

@ -21,6 +21,7 @@
package tschipp.carryon.events; package tschipp.carryon.events;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; 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.entity.event.v1.ServerPlayerEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.CommonLifecycleEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.CommonLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; 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.level.ServerPlayer;
import net.minecraft.server.packs.PackType; import net.minecraft.server.packs.PackType;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.level.GameRules;
import tschipp.carryon.CarryOnCommon; import tschipp.carryon.CarryOnCommon;
import tschipp.carryon.common.carry.CarryOnData; import tschipp.carryon.common.carry.CarryOnData;
import tschipp.carryon.common.carry.CarryOnData.CarryType; import tschipp.carryon.common.carry.CarryOnData.CarryType;
@ -132,10 +134,13 @@ public class CommonEvents {
CarryOnCommon.onCarryTick(player); CarryOnCommon.onCarryTick(player);
}); });
ServerLivingEntityEvents.AFTER_DEATH.register((entity, damageSource)->{
ServerPlayerEvents.COPY_FROM.register(((oldPlayer, newPlayer, alive) -> { if (!(entity instanceof ServerPlayer)) return;
PlacementHandler.placeCarriedOnDeath(oldPlayer, newPlayer, !alive); 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) -> { PlayerBlockBreakEvents.BEFORE.register(((world, player, pos, state, blockEntity) -> {