mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-12-26 23:52:31 -05:00
Gracefully fail on unknown types/values in ClientboundBlockEventPacket, update to 1.21.4 release
This commit is contained in:
parent
ce8109ef3b
commit
9332151a49
2 changed files with 44 additions and 53 deletions
|
@ -216,9 +216,9 @@ import org.geysermc.mcprotocollib.protocol.packet.status.serverbound.Serverbound
|
||||||
|
|
||||||
public class MinecraftCodec {
|
public class MinecraftCodec {
|
||||||
public static final PacketCodec CODEC = PacketCodec.builder()
|
public static final PacketCodec CODEC = PacketCodec.builder()
|
||||||
.protocolVersion((1 << 30) | 228)
|
.protocolVersion(769)
|
||||||
.helper(MinecraftCodecHelper::new)
|
.helper(MinecraftCodecHelper::new)
|
||||||
.minecraftVersion("1.21.4-rc3")
|
.minecraftVersion("1.21.4")
|
||||||
.state(ProtocolState.HANDSHAKE, MinecraftPacketRegistry.builder()
|
.state(ProtocolState.HANDSHAKE, MinecraftPacketRegistry.builder()
|
||||||
.registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new)
|
.registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new)
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.cloudburstmc.math.vector.Vector3i;
|
import org.cloudburstmc.math.vector.Vector3i;
|
||||||
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
|
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
|
||||||
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
||||||
|
@ -28,6 +29,8 @@ import org.geysermc.mcprotocollib.protocol.data.game.level.block.value.NoteBlock
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.level.block.value.NoteBlockValueType;
|
import org.geysermc.mcprotocollib.protocol.data.game.level.block.value.NoteBlockValueType;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.level.block.value.PistonValue;
|
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.data.game.level.block.value.PistonValueType;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
|
@ -46,73 +49,61 @@ public class ClientboundBlockEventPacket implements MinecraftPacket {
|
||||||
private static final int SHULKER_BOX_HIGHER = 657;
|
private static final int SHULKER_BOX_HIGHER = 657;
|
||||||
private static final int BELL = 811;
|
private static final int BELL = 811;
|
||||||
private static final int DECORATED_POT = 1083;
|
private static final int DECORATED_POT = 1083;
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ClientboundBlockEventPacket.class);
|
||||||
|
|
||||||
private final @NonNull Vector3i position;
|
private final @NonNull Vector3i position;
|
||||||
private final @NonNull BlockValueType type;
|
private final int rawType;
|
||||||
private final @NonNull BlockValue value;
|
private final int rawValue;
|
||||||
|
private @Nullable BlockValueType type;
|
||||||
|
private @Nullable BlockValue value;
|
||||||
private final int blockId;
|
private final int blockId;
|
||||||
|
|
||||||
public ClientboundBlockEventPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
public ClientboundBlockEventPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||||
this.position = helper.readPosition(in);
|
this.position = helper.readPosition(in);
|
||||||
int type = in.readUnsignedByte();
|
this.rawType = in.readUnsignedByte();
|
||||||
int value = in.readUnsignedByte();
|
this.rawValue = in.readUnsignedByte();
|
||||||
this.blockId = helper.readVarInt(in);
|
this.blockId = helper.readVarInt(in);
|
||||||
|
|
||||||
// TODO: Handle this in MinecraftCodecHelper
|
// TODO: Handle this in MinecraftCodecHelper
|
||||||
if (this.blockId == NOTE_BLOCK) {
|
try {
|
||||||
this.type = NoteBlockValueType.from(type);
|
if (this.blockId == NOTE_BLOCK) {
|
||||||
this.value = new NoteBlockValue();
|
this.type = NoteBlockValueType.from(rawType);
|
||||||
} else if (this.blockId == STICKY_PISTON || this.blockId == PISTON) {
|
this.value = new NoteBlockValue();
|
||||||
this.type = PistonValueType.from(type);
|
} else if (this.blockId == STICKY_PISTON || this.blockId == PISTON) {
|
||||||
this.value = new PistonValue(Direction.from(Math.abs((value & 7) % 6)));
|
this.type = PistonValueType.from(rawType);
|
||||||
} else if (this.blockId == MOB_SPAWNER) {
|
this.value = new PistonValue(Direction.from(Math.abs((rawValue & 7) % 6)));
|
||||||
this.type = MobSpawnerValueType.from(type - 1);
|
} else if (this.blockId == MOB_SPAWNER) {
|
||||||
this.value = new MobSpawnerValue();
|
this.type = MobSpawnerValueType.from(rawType - 1);
|
||||||
} else if (this.blockId == CHEST || this.blockId == ENDER_CHEST || this.blockId == TRAPPED_CHEST
|
this.value = new MobSpawnerValue();
|
||||||
|
} else if (this.blockId == CHEST || this.blockId == ENDER_CHEST || this.blockId == TRAPPED_CHEST
|
||||||
|| (this.blockId >= SHULKER_BOX_LOWER && this.blockId <= SHULKER_BOX_HIGHER)) {
|
|| (this.blockId >= SHULKER_BOX_LOWER && this.blockId <= SHULKER_BOX_HIGHER)) {
|
||||||
this.type = ChestValueType.from(type - 1);
|
this.type = ChestValueType.from(rawType - 1);
|
||||||
this.value = new ChestValue(value);
|
this.value = new ChestValue(rawValue);
|
||||||
} else if (this.blockId == END_GATEWAY) {
|
} else if (this.blockId == END_GATEWAY) {
|
||||||
this.type = EndGatewayValueType.from(type - 1);
|
this.type = EndGatewayValueType.from(rawType - 1);
|
||||||
this.value = new EndGatewayValue();
|
this.value = new EndGatewayValue();
|
||||||
} else if (this.blockId == BELL) {
|
} else if (this.blockId == BELL) {
|
||||||
this.type = BellValueType.from(type - 1);
|
this.type = BellValueType.from(rawType - 1);
|
||||||
this.value = new BellValue(Direction.from(Math.abs(value % 6)));
|
this.value = new BellValue(Direction.from(Math.abs(rawValue % 6)));
|
||||||
} else if (this.blockId == DECORATED_POT) {
|
} else if (this.blockId == DECORATED_POT) {
|
||||||
this.type = DecoratedPotValueType.from(type - 1);
|
this.type = DecoratedPotValueType.from(rawType - 1);
|
||||||
this.value = new DecoratedPotValue(WobbleStyle.from(Math.abs(value % 2)));
|
this.value = new DecoratedPotValue(WobbleStyle.from(Math.abs(rawValue % 2)));
|
||||||
} else {
|
} else {
|
||||||
this.type = GenericBlockValueType.from(type);
|
this.type = GenericBlockValueType.from(rawType);
|
||||||
this.value = new GenericBlockValue(value);
|
this.value = new GenericBlockValue(rawValue);
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
this.type = null;
|
||||||
|
this.value = null;
|
||||||
|
log.warn("Unable to deserialize type and value! Message: {} (block: {}, type: {}, value: {})", t.getMessage(), blockId, rawType, rawValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||||
int val = 0;
|
|
||||||
int type = 0;
|
|
||||||
// TODO: Handle this in MinecraftCodecHelper
|
|
||||||
if (this.type instanceof PistonValueType) {
|
|
||||||
val = ((PistonValue) this.value).getDirection().ordinal();
|
|
||||||
type = ((PistonValueType) this.type).ordinal();
|
|
||||||
} else if (this.type instanceof MobSpawnerValueType) {
|
|
||||||
type = ((MobSpawnerValueType) this.type).ordinal() + 1;
|
|
||||||
} else if (this.type instanceof ChestValueType) {
|
|
||||||
val = ((ChestValue) this.value).getViewers();
|
|
||||||
type = ((ChestValueType) this.type).ordinal() + 1;
|
|
||||||
} else if (this.type instanceof EndGatewayValueType) {
|
|
||||||
type = ((EndGatewayValueType) this.type).ordinal() + 1;
|
|
||||||
} else if (this.type instanceof BellValueType) {
|
|
||||||
val = ((BellValue) this.value).getDirection().ordinal();
|
|
||||||
type = ((BellValueType) this.type).ordinal() + 1;
|
|
||||||
} else if (this.type instanceof GenericBlockValueType) {
|
|
||||||
val = ((GenericBlockValue) this.value).getValue();
|
|
||||||
type = ((GenericBlockValueType) this.type).ordinal();
|
|
||||||
}
|
|
||||||
|
|
||||||
helper.writePosition(out, this.position);
|
helper.writePosition(out, this.position);
|
||||||
out.writeByte(type);
|
out.writeByte(rawType);
|
||||||
out.writeByte(val);
|
out.writeByte(rawValue);
|
||||||
helper.writeVarInt(out, this.blockId);
|
helper.writeVarInt(out, this.blockId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue