Fix: Sticky pistons not retracting on Geyser-Spigot/turning visually into normal pistons on all other platforms (#4891)

This commit is contained in:
chris 2024-07-23 23:12:05 +02:00 committed by GitHub
parent b113a6b185
commit b664395684
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -43,7 +43,15 @@ import org.geysermc.geyser.translator.level.block.entity.BlockEntityTranslator;
import org.geysermc.geyser.translator.level.block.entity.PistonBlockEntity;
import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.value.*;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.value.BellValue;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.value.BlockValue;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.value.ChestValue;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.value.DecoratedPotValue;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.value.EndGatewayValue;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.value.MobSpawnerValue;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.value.NoteBlockValue;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.value.PistonValue;
import org.geysermc.mcprotocollib.protocol.data.game.level.block.value.PistonValueType;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level.ClientboundBlockEventPacket;
@Translator(packet = ClientboundBlockEventPacket.class)
@ -80,7 +88,7 @@ public class JavaBlockEventTranslator extends PacketTranslator<ClientboundBlockE
// See https://github.com/PaperMC/Paper/blob/6fa1983e9ce177a4a412d5b950fd978620174777/patches/server/0304-Fire-BlockPistonRetractEvent-for-all-empty-pistons.patch
if (action == PistonValueType.PULLING || action == PistonValueType.CANCELLED_MID_PUSH) {
BlockState pistonBlock = session.getGeyser().getWorldManager().blockAt(session, position);
if (!pistonBlock.is(Blocks.STICKY_PISTON)) {
if (!isSticky(pistonBlock)) {
return;
}
if (action != PistonValueType.CANCELLED_MID_PUSH) {
@ -99,7 +107,7 @@ public class JavaBlockEventTranslator extends PacketTranslator<ClientboundBlockE
} else {
PistonBlockEntity blockEntity = pistonCache.getPistons().computeIfAbsent(position, pos -> {
BlockState state = session.getGeyser().getWorldManager().blockAt(session, position);
boolean sticky = state.is(Blocks.STICKY_PISTON);
boolean sticky = isSticky(state);
boolean extended = action != PistonValueType.PUSHING;
return new PistonBlockEntity(session, pos, direction, sticky, extended);
});
@ -149,4 +157,8 @@ public class JavaBlockEventTranslator extends PacketTranslator<ClientboundBlockE
session.getGeyser().getLogger().debug("Unhandled block event packet: " + packet);
}
}
private static boolean isSticky(BlockState state) {
return state.is(Blocks.STICKY_PISTON) || (state.is(Blocks.MOVING_PISTON) && "sticky".equals(state.getValue(Properties.PISTON_TYPE)));
}
}