From 4eb4b2c37f53d63197a185c426b1889b2b107af1 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Sun, 10 Feb 2019 15:22:34 -0200 Subject: [PATCH] Use ByteBuf#order, more sanity check on block entity handler --- .../api/type/types/version/ChunkSectionType1_8.java | 8 ++------ .../providers/blockentities/BannerHandler.java | 12 +++++++++--- .../providers/blockentities/BedHandler.java | 6 ++++-- .../providers/blockentities/SkullHandler.java | 7 +++++-- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/types/version/ChunkSectionType1_8.java b/common/src/main/java/us/myles/ViaVersion/api/type/types/version/ChunkSectionType1_8.java index 2cc3f478b..7a496f670 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/type/types/version/ChunkSectionType1_8.java +++ b/common/src/main/java/us/myles/ViaVersion/api/type/types/version/ChunkSectionType1_8.java @@ -4,9 +4,7 @@ import io.netty.buffer.ByteBuf; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import us.myles.ViaVersion.api.type.Type; -import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.nio.ShortBuffer; public class ChunkSectionType1_8 extends Type { @@ -19,12 +17,10 @@ public class ChunkSectionType1_8 extends Type { ChunkSection chunkSection = new ChunkSection(); chunkSection.clearPalette(); - byte[] blockData = new byte[ChunkSection.SIZE * 2]; - buffer.readBytes(blockData); - ShortBuffer blockBuf = ByteBuffer.wrap(blockData).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer(); + ByteBuf littleEndianView = buffer.order(ByteOrder.LITTLE_ENDIAN); for (int i = 0; i < ChunkSection.SIZE; i++) { - int mask = blockBuf.get(); + int mask = littleEndianView.readShort(); int type = mask >> 4; int data = mask & 0xF; chunkSection.setBlock(i, type, data); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BannerHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BannerHandler.java index c321f409f..7e071d31a 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BannerHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BannerHandler.java @@ -29,7 +29,11 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler { int blockId = storage.get(position).getOriginal(); - int color = (int) tag.get("Base").getValue(); + Tag base = tag.get("Base"); + int color = 0; + if (base != null) { + color = ((Number) tag.get("Base").getValue()).intValue(); + } // Standing banner if (blockId >= BANNER_START && blockId <= BANNER_STOP) { blockId += ((15 - color) * 16); @@ -43,8 +47,10 @@ public class BannerHandler implements BlockEntityProvider.BlockEntityHandler { if (tag.get("Patterns") instanceof ListTag) { for (Tag pattern : (ListTag) tag.get("Patterns")) { if (pattern instanceof CompoundTag) { - IntTag c = ((CompoundTag) pattern).get("Color"); - c.setValue(15 - c.getValue()); // Invert color id + Tag c = ((CompoundTag) pattern).get("Color"); + if (c instanceof IntTag) { + ((IntTag)c).setValue(15 - (int) c.getValue()); // Invert color id + } } } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BedHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BedHandler.java index f676a4c9a..3558a9fed 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BedHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/BedHandler.java @@ -23,8 +23,10 @@ public class BedHandler implements BlockEntityProvider.BlockEntityHandler { // RED_BED + FIRST_BED int blockId = storage.get(position).getOriginal() - 972 + 748; - int color = (int) tag.get("color").getValue(); - blockId += (color * 16); + Tag color = tag.get("color"); + if (color != null) { + blockId += (((Number) color.getValue()).intValue() * 16); + } return blockId; } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java index 90b0b745b..5198ba9cf 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/providers/blockentities/SkullHandler.java @@ -25,9 +25,12 @@ public class SkullHandler implements BlockEntityProvider.BlockEntityHandler { int id = storage.get(position).getOriginal(); if (id >= SKULL_WALL_START && id <= SKULL_END) { - id += (byte) tag.get("SkullType").getValue() * 20; + Tag skullType = tag.get("SkullType"); + if (skullType != null) { + id += ((Number) tag.get("SkullType").getValue()).intValue() * 20; + } if (tag.contains("Rot")) { - id += (byte) tag.get("Rot").getValue(); + id += ((Number) tag.get("Rot").getValue()).intValue(); } } else { Via.getPlatform().getLogger().warning("Why does this block have the skull block entity? " + tag);