@Override public T read(PacketWrapper wrapper) throws Exception { return wrapper.read(type); }
/** * Take a value from the input and write to the output. * * @param type The type to read and write. * @param <T> The return type of the type you wish to pass through. * @return The type which was read/written. * @throws Exception If it failed to read or write */ public <T> T passthrough(Type<T> type) throws Exception { T value = read(type); write(type, value); return value; }
public static ChunkBulkSection read(PacketWrapper wrapper, boolean skylight) throws Exception { ChunkBulkSection bulkSection = new ChunkBulkSection(); bulkSection.setX(wrapper.read(Type.INT)); bulkSection.setZ(wrapper.read(Type.INT)); bulkSection.setBitMask(wrapper.read(Type.UNSIGNED_SHORT)); int bitCount = Integer.bitCount(bulkSection.getBitMask()); bulkSection.setLength((bitCount * ((4096 * 2) + 2048)) + (skylight ? bitCount * 2048 : 0) + 256); // Thanks MCProtocolLib return bulkSection; } }
public static void transformChunkBulk(PacketWrapper packetWrapper) throws Exception { boolean skyLightSent = packetWrapper.read(Type.BOOLEAN); int columnCount = packetWrapper.read(Type.VAR_INT); int[] chunkX = new int[columnCount]; int[] chunkZ = new int[columnCount]; chunkX[i] = packetWrapper.read(Type.INT); chunkZ[i] = packetWrapper.read(Type.INT); primaryBitMask[i] = packetWrapper.read(Type.UNSIGNED_SHORT); int size = calcSize(Integer.bitCount(primaryBitMask[i]), skyLightSent, true); CustomByteType customByteType = new CustomByteType(size); data[i] = transformChunkData(packetWrapper.read(customByteType), primaryBitMask[i], skyLightSent, true); totalSize += data[i].length;
public static void transformMultiBlockChange(PacketWrapper packetWrapper) throws Exception { packetWrapper.passthrough(Type.INT); packetWrapper.passthrough(Type.INT); int count = packetWrapper.read(Type.VAR_INT); packetWrapper.write(Type.SHORT, (short) count); packetWrapper.write(Type.INT, count * 4); for (int i = 0; i < count; i++) { packetWrapper.passthrough(Type.UNSIGNED_BYTE); packetWrapper.passthrough(Type.UNSIGNED_BYTE); int blockData = packetWrapper.read(Type.VAR_INT); BlockState state = ReplacementRegistry1_7_6_10to1_8.replace(BlockState.rawToState(blockData)); blockData = BlockState.stateToRaw(state); packetWrapper.write(Type.SHORT, (short) blockData); } } }
} else { if (rtype == Type.NOTHING) { return read(type); // retry } else { Exception e = new IOException("Unable to read type " + type.getTypeName() + ", found " + read.getKey().getTypeName());
public static void transformChunk(PacketWrapper packetWrapper) throws Exception { ClientWorld world = packetWrapper.user().get(ClientWorld.class); Chunk chunk = packetWrapper.read(new Chunk1_8Type(world)); packetWrapper.write(new Chunk1_7_10WriteOnlyType(world), chunk); for (ChunkSection section : chunk.getSections()){ if (section == null) continue; for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { int block = section.getBlock(x, y, z); BlockState state = BlockState.rawToState(block); state = ReplacementRegistry1_7_6_10to1_8.replace(state); section.setBlock(x, y, z, state.getId(), state.getData()); } } } } }
public static void transformChunk(PacketWrapper packetWrapper) throws Exception { ClientWorld world = packetWrapper.user().get(ClientWorld.class); Chunk chunk = packetWrapper.read(new Chunk1_9_1_2Type(world));