change: don't allow knocked players to place blocks

This commit is contained in:
Octol1ttle 2024-03-20 19:51:02 +05:00
parent b182a35750
commit f4d2174fba
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF

View file

@ -2,11 +2,13 @@ package ru.octol1ttle.knockdowns.common.events;
import dev.architectury.event.CompoundEventResult;
import dev.architectury.event.EventResult;
import dev.architectury.event.events.common.BlockEvent;
import dev.architectury.event.events.common.EntityEvent;
import dev.architectury.event.events.common.InteractionEvent;
import dev.architectury.event.events.common.PlayerEvent;
import dev.architectury.event.events.common.TickEvent;
import net.minecraft.SharedConstants;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
@ -126,6 +128,12 @@ public class KnockdownsEvents {
}
return EventResult.pass();
});
BlockEvent.PLACE.register((level, pos, state, placer) -> {
if (placer instanceof PlayerEntity player && KnockdownsUtils.isKnockedOrReviving(player)) {
return EventResult.interruptFalse();
}
return EventResult.pass();
});
InteractionEvent.RIGHT_CLICK_ITEM.register((player, hand) -> {
if (KnockdownsUtils.isKnockedOrReviving(player)) {
return CompoundEventResult.interruptFalse(hand == Hand.MAIN_HAND ? player.getMainHandStack() : player.getOffHandStack());