us.myles.ViaVersion.api.minecraft.BlockChangeRecord Java Examples

The following examples show how to use us.myles.ViaVersion.api.minecraft.BlockChangeRecord. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlockRewriter.java    From ViaVersion with MIT License 5 votes vote down vote up
public void registerMultiBlockChange(ClientboundPacketType packetType) {
    protocol.registerOutgoing(packetType, new PacketRemapper() {
        @Override
        public void registerMap() {
            map(Type.INT); // 0 - Chunk X
            map(Type.INT); // 1 - Chunk Z
            map(Type.BLOCK_CHANGE_RECORD_ARRAY); // 2 - Records
            handler(wrapper -> {
                for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) {
                    record.setBlockId(blockStateRewriter.rewrite(record.getBlockId()));
                }
            });
        }
    });
}
 
Example #2
Source File: BlockChangeRecordType.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public BlockChangeRecord read(ByteBuf buffer) throws Exception {
    short horizontal = Type.UNSIGNED_BYTE.read(buffer);
    short y = Type.UNSIGNED_BYTE.read(buffer);
    int blockId = Type.VAR_INT.readPrimitive(buffer);

    return new BlockChangeRecord(horizontal, y, blockId);
}
 
Example #3
Source File: ConnectionData.java    From ViaVersion with MIT License 5 votes vote down vote up
public static void updateBlock(UserConnection user, Position pos, List<BlockChangeRecord> records) {
    int blockState = blockConnectionProvider.getBlockData(user, pos.getX(), pos.getY(), pos.getZ());
    ConnectionHandler handler = getConnectionHandler(blockState);
    if (handler == null) return;

    int newBlockState = handler.connect(user, pos, blockState);
    records.add(new BlockChangeRecord((short) (((pos.getX() & 0xF) << 4) | (pos.getZ() & 0xF)), pos.getY(), newBlockState));
}
 
Example #4
Source File: BlockChangeRecordType.java    From ViaVersion with MIT License 4 votes vote down vote up
public BlockChangeRecordType() {
    super(BlockChangeRecord.class);
}
 
Example #5
Source File: BlockChangeRecordType.java    From ViaVersion with MIT License 4 votes vote down vote up
@Override
public void write(ByteBuf buffer, BlockChangeRecord object) throws Exception {
    Type.UNSIGNED_BYTE.write(buffer, object.getHorizontal());
    Type.UNSIGNED_BYTE.write(buffer, object.getY());
    Type.VAR_INT.writePrimitive(buffer, object.getBlockId());
}
 
Example #6
Source File: ConnectionData.java    From ViaVersion with MIT License 4 votes vote down vote up
public static void updateChunkSectionNeighbours(UserConnection user, int chunkX, int chunkZ, int chunkSectionY) {
    for (int chunkDeltaX = -1; chunkDeltaX <= 1; chunkDeltaX++) {
        for (int chunkDeltaZ = -1; chunkDeltaZ <= 1; chunkDeltaZ++) {
            if (Math.abs(chunkDeltaX) + Math.abs(chunkDeltaZ) == 0) continue;

            List<BlockChangeRecord> updates = new ArrayList<>();

            if (Math.abs(chunkDeltaX) + Math.abs(chunkDeltaZ) == 2) { // Corner
                for (int blockY = chunkSectionY * 16; blockY < chunkSectionY * 16 + 16; blockY++) {
                    int blockPosX = chunkDeltaX == 1 ? 0 : 15;
                    int blockPosZ = chunkDeltaZ == 1 ? 0 : 15;
                    updateBlock(user,
                            new Position(
                                    ((chunkX + chunkDeltaX) << 4) + blockPosX,
                                    (short) blockY,
                                    ((chunkZ + chunkDeltaZ) << 4) + blockPosZ
                            ),
                            updates
                    );
                }
            } else {
                for (int blockY = chunkSectionY * 16; blockY < chunkSectionY * 16 + 16; blockY++) {
                    int xStart;
                    int xEnd;
                    int zStart;
                    int zEnd;
                    if (chunkDeltaX == 1) {
                        xStart = 0;
                        xEnd = 2;
                        zStart = 0;
                        zEnd = 16;
                    } else if (chunkDeltaX == -1) {
                        xStart = 14;
                        xEnd = 16;
                        zStart = 0;
                        zEnd = 16;
                    } else if (chunkDeltaZ == 1) {
                        xStart = 0;
                        xEnd = 16;
                        zStart = 0;
                        zEnd = 2;
                    } else {
                        xStart = 0;
                        xEnd = 16;
                        zStart = 14;
                        zEnd = 16;
                    }
                    for (int blockX = xStart; blockX < xEnd; blockX++) {
                        for (int blockZ = zStart; blockZ < zEnd; blockZ++) {
                            updateBlock(user,
                                    new Position(
                                            ((chunkX + chunkDeltaX) << 4) + blockX,
                                            (short) blockY,
                                            ((chunkZ + chunkDeltaZ) << 4) + blockZ),
                                    updates
                            );
                        }
                    }
                }
            }

            if (!updates.isEmpty()) {
                PacketWrapper wrapper = new PacketWrapper(0x0F, null, user);
                wrapper.write(Type.INT, chunkX + chunkDeltaX);
                wrapper.write(Type.INT, chunkZ + chunkDeltaZ);
                wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, updates.toArray(EMPTY_RECORDS));
                try {
                    wrapper.send(Protocol1_13To1_12_2.class, true, true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}