Small qol features

This commit is contained in:
IM23a-spirgif
2025-04-20 20:37:43 +02:00
parent 67d35e8ecf
commit 53eb3f3895
3 changed files with 78 additions and 20 deletions
@@ -8,6 +8,7 @@ import net.minecraft.world.entity.player.Player;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
@@ -22,6 +23,33 @@ public class PlayerExecutionHandler {
public static final double EXECUTION_RANGE = 2.0;
private static final int EXECUTION_DELAY_TICKS = 60;
public static boolean isBeingPlayerExecuted(UUID knockedId) {
return executionAttempts.containsKey(knockedId);
}
public static boolean isExecuting(UUID playerUuid) {
return executionAttempts.values()
.stream()
.anyMatch(attempt -> attempt.executorUuid.equals(playerUuid));
}
@SubscribeEvent
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
if (event.side.isServer()
&& event.phase == TickEvent.Phase.END
&& event.player instanceof ServerPlayer sp
&& isExecuting(sp.getUUID())) {
sp.setDeltaMovement(0, 0, 0);
sp.setSprinting(false);
}
}
@SubscribeEvent
public static void onAttackEntity(AttackEntityEvent event) {
if (event.getEntity() instanceof ServerPlayer sp
&& isExecuting(sp.getUUID())) {
event.setCanceled(true);
}
}
private static final Map<UUID, PlayerExecutionAttempt> executionAttempts = new HashMap<>();
private static class PlayerExecutionAttempt {