us.myles.ViaVersion.api.type.Type Java Examples

The following examples show how to use us.myles.ViaVersion.api.type.Type. 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: Windows.java    From ViaRewind with MIT License 6 votes vote down vote up
public static void updateBrewingStand(UserConnection user, Item blazePowder, short windowId) {
	if (blazePowder != null && blazePowder.getIdentifier() != 377) return;
	int amount = blazePowder == null ? 0 : blazePowder.getAmount();
	PacketWrapper openWindow = new PacketWrapper(0x2D, null, user);
	openWindow.write(Type.UNSIGNED_BYTE, windowId);
	openWindow.write(Type.STRING, "minecraft:brewing_stand");
	openWindow.write(Type.STRING, "[{\"translate\":\"container.brewing\"},{\"text\":\": \",\"color\":\"dark_gray\"},{\"text\":\"ยง4" + amount + " \",\"color\":\"dark_red\"},{\"translate\":\"item.blazePowder.name\",\"color\":\"dark_red\"}]");
	openWindow.write(Type.UNSIGNED_BYTE, (short) 420);
	PacketUtil.sendPacket(openWindow, Protocol1_8TO1_9.class);

	Item[] items = user.get(Windows.class).getBrewingItems(windowId);
	for (int i = 0; i < items.length; i++) {
		PacketWrapper setSlot = new PacketWrapper(0x2F, null, user);
		setSlot.write(Type.BYTE, (byte) windowId);
		setSlot.write(Type.SHORT, (short) i);
		setSlot.write(Type.ITEM, items[i]);
		PacketUtil.sendPacket(setSlot, Protocol1_8TO1_9.class);
	}
}
 
Example #2
Source File: ItemRewriter.java    From ViaVersion with MIT License 6 votes vote down vote up
public void registerEntityEquipmentArray(ClientboundPacketType packetType, Type<Item> type) {
    protocol.registerOutgoing(packetType, new PacketRemapper() {
        @Override
        public void registerMap() {
            map(Type.VAR_INT); // 0 - Entity ID

            handler(wrapper -> {
                byte slot;
                do {
                    slot = wrapper.passthrough(Type.BYTE);
                     // & 0x7F into an extra variable if slot is needed
                    toClient.rewrite(wrapper.passthrough(type));
                } while ((slot & 0xFFFFFF80) != 0);
            });
        }
    });
}
 
Example #3
Source File: EntityTracker1_9.java    From ViaVersion with MIT License 6 votes vote down vote up
public void sendMetadataBuffer(int entityId) {
    List<Metadata> metadataList = metadataBuffer.get(entityId);
    if (metadataList != null) {
        PacketWrapper wrapper = new PacketWrapper(0x39, null, getUser());
        wrapper.write(Type.VAR_INT, entityId);
        wrapper.write(Types1_9.METADATA_LIST, metadataList);
        getUser().getProtocolInfo().getPipeline().getProtocol(Protocol1_9To1_8.class).get(MetadataRewriter1_9To1_8.class)
                .handleMetadata(entityId, metadataList, getUser());
        handleMetadata(entityId, metadataList);
        if (!metadataList.isEmpty()) {
            try {
                wrapper.send(Protocol1_9To1_8.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        metadataBuffer.remove(entityId);
    }
}
 
Example #4
Source File: Protocol1_9To1_8.java    From ViaVersion with MIT License 6 votes vote down vote up
@Override
protected void registerPackets() {
    new MetadataRewriter1_9To1_8(this);

    // Disconnect workaround (JSON!)
    registerOutgoing(State.LOGIN, 0x00, 0x00, new PacketRemapper() {
        @Override
        public void registerMap() {
            map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 0 - Reason
        }
    });

    // Other Handlers
    SpawnPackets.register(this);
    InventoryPackets.register(this);
    EntityPackets.register(this);
    PlayerPackets.register(this);
    WorldPackets.register(this);
}
 
Example #5
Source File: Protocol1_12_2To1_12_1.java    From ViaVersion with MIT License 6 votes vote down vote up
@Override
protected void registerPackets() {
    registerOutgoing(ClientboundPackets1_12_1.KEEP_ALIVE, new PacketRemapper() {
        @Override
        public void registerMap() {
            map(Type.VAR_INT, Type.LONG);
        }
    });

    registerIncoming(ServerboundPackets1_12_1.KEEP_ALIVE, new PacketRemapper() {
        @Override
        public void registerMap() {
            map(Type.LONG, Type.VAR_INT);
        }
    });
}
 
Example #6
Source File: ShulkerReplacement.java    From ViaRewind with MIT License 6 votes vote down vote up
public void updateMetadata() {
	PacketWrapper metadataPacket = new PacketWrapper(0x1C, null, user);
	metadataPacket.write(Type.VAR_INT, entityId);

	List<Metadata> metadataList = new ArrayList<>();
	for (Metadata metadata : datawatcher) {
		if (metadata.getId()==11 || metadata.getId()==12 || metadata.getId()==13) continue;
		metadataList.add(new Metadata(metadata.getId(), metadata.getMetaType(), metadata.getValue()));
	}
	metadataList.add(new Metadata(11, MetaType1_9.VarInt, 2));

	MetadataRewriter.transform(Entity1_10Types.EntityType.MAGMA_CUBE, metadataList);

	metadataPacket.write(Types1_8.METADATA_LIST, metadataList);

	PacketUtil.sendPacket(metadataPacket, Protocol1_8TO1_9.class);
}
 
Example #7
Source File: MetadataRewriter.java    From ViaVersion with MIT License 6 votes vote down vote up
public void registerMetadataRewriter(ClientboundPacketType packetType, @Nullable Type<List<Metadata>> oldMetaType, Type<List<Metadata>> newMetaType) {
    protocol.registerOutgoing(packetType, new PacketRemapper() {
        @Override
        public void registerMap() {
            map(Type.VAR_INT); // 0 - Entity ID
            if (oldMetaType != null) {
                map(oldMetaType, newMetaType);
            } else {
                map(newMetaType);
            }
            handler(wrapper -> {
                int entityId = wrapper.get(Type.VAR_INT, 0);
                List<Metadata> metadata = wrapper.get(newMetaType, 0);
                handleMetadata(entityId, metadata, wrapper.user());
            });
        }
    });
}
 
Example #8
Source File: ConnectionData.java    From ViaVersion with MIT License 6 votes vote down vote up
public static void update(UserConnection user, Position position) {
    for (BlockFace face : BlockFace.values()) {
        Position pos = position.getRelative(face);
        int blockState = blockConnectionProvider.getBlockData(user, pos.getX(), pos.getY(), pos.getZ());
        ConnectionHandler handler = connectionHandlerMap.get(blockState);
        if (handler == null) continue;

        int newBlockState = handler.connect(user, pos, blockState);
        PacketWrapper blockUpdatePacket = new PacketWrapper(0x0B, null, user);
        blockUpdatePacket.write(Type.POSITION, pos);
        blockUpdatePacket.write(Type.VAR_INT, newBlockState);
        try {
            blockUpdatePacket.send(Protocol1_13To1_12_2.class, true, true);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
 
Example #9
Source File: ArmorListener.java    From ViaVersion with MIT License 6 votes vote down vote up
public void sendArmorUpdate(Player player) {
    // Ensure that the player is on our pipe
    if (!isOnPipe(player)) return;

    int armor = 0;
    for (ItemStack stack : player.getInventory().getArmorContents()) {
        armor += ArmorType.findById(stack.getTypeId()).getArmorPoints();
    }

    PacketWrapper wrapper = new PacketWrapper(0x4B, null, getUserConnection(player));
    try {
        wrapper.write(Type.VAR_INT, player.getEntityId()); // Player ID
        wrapper.write(Type.INT, 1); // only 1 property
        wrapper.write(Type.STRING, "generic.armor");
        wrapper.write(Type.DOUBLE, 0D); //default 0 armor
        wrapper.write(Type.VAR_INT, 1); // 1 modifier
        wrapper.write(Type.UUID, ARMOR_ATTRIBUTE); // armor modifier uuid
        wrapper.write(Type.DOUBLE, (double) armor); // the modifier value
        wrapper.write(Type.BYTE, (byte) 0);// the modifier operation, 0 is add number

        wrapper.send(Protocol1_9To1_8.class);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #10
Source File: Cooldown.java    From ViaRewind with MIT License 6 votes vote down vote up
private void sendTitle(String title, String subTitle, int fadeIn, int stay, int fadeOut) {
	PacketWrapper timePacket = new PacketWrapper(0x45, null, getUser());
	timePacket.write(Type.VAR_INT, 2);
	timePacket.write(Type.INT, fadeIn);
	timePacket.write(Type.INT, stay);
	timePacket.write(Type.INT, fadeOut);
	PacketWrapper titlePacket = new PacketWrapper(0x45, null, getUser());
	titlePacket.write(Type.VAR_INT, 0);
	titlePacket.write(Type.STRING, title);
	PacketWrapper subtitlePacket = new PacketWrapper(0x45, null, getUser());
	subtitlePacket.write(Type.VAR_INT, 1);
	subtitlePacket.write(Type.STRING, subTitle);

	PacketUtil.sendPacket(titlePacket, Protocol1_8TO1_9.class);
	PacketUtil.sendPacket(subtitlePacket, Protocol1_8TO1_9.class);
	PacketUtil.sendPacket(timePacket, Protocol1_8TO1_9.class);
}
 
Example #11
Source File: TagRewriter.java    From ViaVersion with MIT License 6 votes vote down vote up
public void register(ClientboundPacketType packetType) {
    protocol.registerOutgoing(packetType, new PacketRemapper() {
        @Override
        public void registerMap() {
            handler(wrapper -> {
                handle(wrapper, blockRewriter, newBlockTags);
                handle(wrapper, itemRewriter, newItemTags);

                if (entityRewriter == null && newEntityTags.isEmpty()) return;

                int fluidTagsSize = wrapper.passthrough(Type.VAR_INT);
                for (int i = 0; i < fluidTagsSize; i++) {
                    wrapper.passthrough(Type.STRING);
                    wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
                }

                handle(wrapper, entityRewriter, newEntityTags);
            });
        }
    });
}
 
Example #12
Source File: ComponentRewriter.java    From ViaVersion with MIT License 5 votes vote down vote up
public void registerTitle(ClientboundPacketType packetType) {
    protocol.registerOutgoing(packetType, new PacketRemapper() {
        @Override
        public void registerMap() {
            handler(wrapper -> {
                int action = wrapper.passthrough(Type.VAR_INT);
                if (action >= 0 && action <= 2) {
                    processText(wrapper.passthrough(Type.COMPONENT));
                }
            });
        }
    });
}
 
Example #13
Source File: UserConnection.java    From ViaVersion with MIT License 5 votes vote down vote up
/**
 * Sends a raw packet to the server.
 *
 * @param packet        Raw packet to be sent
 * @param currentThread If {@code true} executes immediately, {@code false} submits a task to EventLoop
 */
public void sendRawPacketToServer(ByteBuf packet, boolean currentThread) {
    ByteBuf buf = packet.alloc().buffer();
    try {
        try {
            Type.VAR_INT.writePrimitive(buf, PacketWrapper.PASSTHROUGH_ID);
        } catch (Exception e) {
            // Should not happen
            Via.getPlatform().getLogger().warning("Type.VAR_INT.write thrown an exception: " + e);
        }
        buf.writeBytes(packet);
        ChannelHandlerContext context = PipelineUtil
                .getPreviousContext(Via.getManager().getInjector().getDecoderName(), channel.pipeline());
        if (currentThread) {
            if (context != null) {
                context.fireChannelRead(buf);
            } else {
                channel.pipeline().fireChannelRead(buf);
            }
        } else {
            try {
                channel.eventLoop().submit(() -> {
                    if (context != null) {
                        context.fireChannelRead(buf);
                    } else {
                        channel.pipeline().fireChannelRead(buf);
                    }
                });
            } catch (Throwable t) {
                // Couldn't schedule
                buf.release();
                throw t;
            }
        }
    } finally {
        packet.release();
    }
}
 
Example #14
Source File: ComponentRewriter.java    From ViaVersion with MIT License 5 votes vote down vote up
public void registerCombatEvent(ClientboundPacketType packetType) {
    protocol.registerOutgoing(packetType, new PacketRemapper() {
        @Override
        public void registerMap() {
            handler(wrapper -> {
                if (wrapper.passthrough(Type.VAR_INT) == 2) {
                    wrapper.passthrough(Type.VAR_INT);
                    wrapper.passthrough(Type.INT);
                    processText(wrapper.passthrough(Type.COMPONENT));
                }
            });
        }
    });
}
 
Example #15
Source File: Chunk1_9_1_2Type.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
    output.writeInt(chunk.getX());
    output.writeInt(chunk.getZ());

    output.writeBoolean(chunk.isFullChunk());
    Type.VAR_INT.writePrimitive(output, chunk.getBitmask());

    ByteBuf buf = output.alloc().buffer();
    try {
        for (int i = 0; i < 16; i++) {
            ChunkSection section = chunk.getSections()[i];
            if (section == null) continue; // Section not set
            Types1_9.CHUNK_SECTION.write(buf, section);
            section.writeBlockLight(buf);

            if (!section.hasSkyLight()) continue; // No sky light, we're done here.
            section.writeSkyLight(buf);

        }
        buf.readerIndex(0);
        Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
        output.writeBytes(buf);
    } finally {
        buf.release(); // release buffer
    }

    // Write biome data
    if (chunk.isBiomeData()) {
        for (int biome : chunk.getBiomeData()) {
            output.writeByte((byte) biome);
        }
    }
}
 
Example #16
Source File: FlatVarIntItemType.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf buffer, Item object) throws Exception {
    if (object == null) {
        buffer.writeBoolean(false);
    } else {
        buffer.writeBoolean(true);
        Type.VAR_INT.writePrimitive(buffer, object.getIdentifier());
        buffer.writeByte(object.getAmount());
        Type.NBT.write(buffer, object.getTag());
    }
}
 
Example #17
Source File: OptionalComponentType.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf buffer, JsonElement object) throws Exception {
    if (object == null) {
        buffer.writeBoolean(false);
    } else {
        buffer.writeBoolean(true);
        Type.COMPONENT.write(buffer, object);
    }
}
 
Example #18
Source File: ItemRewriter.java    From ViaVersion with MIT License 5 votes vote down vote up
public void registerEntityEquipment(ClientboundPacketType packetType, Type<Item> type) {
    protocol.registerOutgoing(packetType, new PacketRemapper() {
        @Override
        public void registerMap() {
            map(Type.VAR_INT); // 0 - Entity ID
            map(Type.VAR_INT); // 1 - Slot ID
            map(type); // 2 - Item

            handler(itemToClientHandler(type));
        }
    });
}
 
Example #19
Source File: BlockRewriter.java    From ViaVersion with MIT License 5 votes vote down vote up
public void registerBlockChange(ClientboundPacketType packetType) {
    protocol.registerOutgoing(packetType, new PacketRemapper() {
        @Override
        public void registerMap() {
            map(positionType);
            map(Type.VAR_INT);
            handler(wrapper -> wrapper.set(Type.VAR_INT, 0, blockStateRewriter.rewrite(wrapper.get(Type.VAR_INT, 0))));
        }
    });
}
 
Example #20
Source File: ChunkSectionType1_13.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public ChunkSection read(ByteBuf buffer) throws Exception {
    ChunkSection chunkSection = new ChunkSection();

    // Reaad bits per block
    int bitsPerBlock = buffer.readUnsignedByte();
    int originalBitsPerBlock = bitsPerBlock;

    if (bitsPerBlock == 0 || bitsPerBlock > 8) {
        bitsPerBlock = GLOBAL_PALETTE;
    }

    int paletteLength = bitsPerBlock == GLOBAL_PALETTE ? 0 : Type.VAR_INT.readPrimitive(buffer);
    // Read palette
    chunkSection.clearPalette();
    for (int i = 0; i < paletteLength; i++) {
        chunkSection.addPaletteEntry(Type.VAR_INT.readPrimitive(buffer));
    }

    // Read blocks
    long[] blockData = new long[Type.VAR_INT.readPrimitive(buffer)];
    if (blockData.length > 0) {
        int expectedLength = (int) Math.ceil(ChunkSection.SIZE * bitsPerBlock / 64.0);
        if (blockData.length != expectedLength) {
            throw new IllegalStateException("Block data length (" + blockData.length + ") does not match expected length (" + expectedLength + ")! bitsPerBlock=" + bitsPerBlock + ", originalBitsPerBlock=" + originalBitsPerBlock);
        }

        for (int i = 0; i < blockData.length; i++) {
            blockData[i] = buffer.readLong();
        }
        CompactArrayUtil.iterateCompactArray(bitsPerBlock, ChunkSection.SIZE, blockData,
                bitsPerBlock == GLOBAL_PALETTE ? chunkSection::setFlatBlock : chunkSection::setPaletteIndex);
    }

    return chunkSection;
}
 
Example #21
Source File: ItemRewriter.java    From ViaVersion with MIT License 5 votes vote down vote up
public void registerClickWindow(ServerboundPacketType packetType, Type<Item> type) {
    protocol.registerIncoming(packetType, new PacketRemapper() {
        @Override
        public void registerMap() {
            map(Type.UNSIGNED_BYTE); // 0 - Window ID
            map(Type.SHORT); // 1 - Slot
            map(Type.BYTE); // 2 - Button
            map(Type.SHORT); // 3 - Action number
            map(Type.VAR_INT); // 4 - Mode
            map(type); // 5 - Clicked Item

            handler(itemToServerHandler(type));
        }
    });
}
 
Example #22
Source File: FlatVarIntItemArrayType.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf buffer, Item[] object) throws Exception {
    Type.SHORT.writePrimitive(buffer, (short) object.length);
    for (Item o : object) {
        Type.FLAT_VAR_INT_ITEM.write(buffer, o);
    }
}
 
Example #23
Source File: Sponge5ArmorListener.java    From ViaVersion with MIT License 5 votes vote down vote up
public void sendArmorUpdate(Player player) {
    // Ensure that the player is on our pipe
    if (!isOnPipe(player.getUniqueId())) return;


    int armor = 0;
    armor += calculate(player.getHelmet());
    armor += calculate(player.getChestplate());
    armor += calculate(player.getLeggings());
    armor += calculate(player.getBoots());

    PacketWrapper wrapper = new PacketWrapper(0x4B, null, getUserConnection(player.getUniqueId()));
    try {
        wrapper.write(Type.VAR_INT, getEntityId(player)); // Player ID
        wrapper.write(Type.INT, 1); // only 1 property
        wrapper.write(Type.STRING, "generic.armor");
        wrapper.write(Type.DOUBLE, 0D); //default 0 armor
        wrapper.write(Type.VAR_INT, 1); // 1 modifier
        wrapper.write(Type.UUID, ARMOR_ATTRIBUTE); // armor modifier uuid
        wrapper.write(Type.DOUBLE, (double) armor); // the modifier value
        wrapper.write(Type.BYTE, (byte) 0);// the modifier operation, 0 is add number

        wrapper.send(Protocol1_9To1_8.class);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #24
Source File: EntityRewriterBase.java    From ViaBackwards with MIT License 5 votes vote down vote up
protected PacketHandler getDimensionHandler(int index) {
    return wrapper -> {
        ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
        int dimensionId = wrapper.get(Type.INT, index);
        clientWorld.setEnvironment(dimensionId);
    };
}
 
Example #25
Source File: WorldPackets1_13_2.java    From ViaBackwards with MIT License 5 votes vote down vote up
public static void register(Protocol1_13_1To1_13_2 protocol) {
    protocol.registerOutgoing(ClientboundPackets1_13.SPAWN_PARTICLE, new PacketRemapper() {
        @Override
        public void registerMap() {
            map(Type.INT); // 0 - Particle ID
            map(Type.BOOLEAN); // 1 - Long Distance
            map(Type.FLOAT); // 2 - X
            map(Type.FLOAT); // 3 - Y
            map(Type.FLOAT); // 4 - Z
            map(Type.FLOAT); // 5 - Offset X
            map(Type.FLOAT); // 6 - Offset Y
            map(Type.FLOAT); // 7 - Offset Z
            map(Type.FLOAT); // 8 - Particle Data
            map(Type.INT); // 9 - Particle Count

            handler(new PacketHandler() {
                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int id = wrapper.get(Type.INT, 0);
                    if (id == 27) {
                        wrapper.write(Type.FLAT_ITEM, wrapper.read(Type.FLAT_VAR_INT_ITEM));
                    }
                }
            });
        }
    });
}
 
Example #26
Source File: PlayerMovementMapper.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void handle(PacketWrapper wrapper) throws Exception {
    MovementTracker tracker = wrapper.user().get(MovementTracker.class);
    tracker.incrementIdlePacket();
    // If packet has the ground data
    if (wrapper.is(Type.BOOLEAN, 0)) {
        tracker.setGround(wrapper.get(Type.BOOLEAN, 0));
    }
}
 
Example #27
Source File: CommonBoss.java    From ViaVersion with MIT License 5 votes vote down vote up
private PacketWrapper getPacket(UpdateAction action, UserConnection connection) {
    try {
        PacketWrapper wrapper = new PacketWrapper(0x0C, null, connection); // TODO don't use fixed packet ids for future support
        wrapper.write(Type.UUID, uuid);
        wrapper.write(Type.VAR_INT, action.getId());
        switch (action) {
            case ADD:
                Protocol1_9To1_8.FIX_JSON.write(wrapper, title);
                wrapper.write(Type.FLOAT, health);
                wrapper.write(Type.VAR_INT, color.getId());
                wrapper.write(Type.VAR_INT, style.getId());
                wrapper.write(Type.BYTE, (byte) flagToBytes());
                break;
            case REMOVE:
                break;
            case UPDATE_HEALTH:
                wrapper.write(Type.FLOAT, health);
                break;
            case UPDATE_TITLE:
                Protocol1_9To1_8.FIX_JSON.write(wrapper, title);
                break;
            case UPDATE_STYLE:
                wrapper.write(Type.VAR_INT, color.getId());
                wrapper.write(Type.VAR_INT, style.getId());
                break;
            case UPDATE_FLAGS:
                wrapper.write(Type.BYTE, (byte) flagToBytes());
                break;
        }

        return wrapper;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #28
Source File: Chunk1_9_3_4Type.java    From ViaVersion with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
    output.writeInt(chunk.getX());
    output.writeInt(chunk.getZ());

    output.writeBoolean(chunk.isFullChunk());
    Type.VAR_INT.writePrimitive(output, chunk.getBitmask());

    ByteBuf buf = output.alloc().buffer();
    try {
        for (int i = 0; i < 16; i++) {
            ChunkSection section = chunk.getSections()[i];
            if (section == null) continue; // Section not set
            Types1_9.CHUNK_SECTION.write(buf, section);
            section.writeBlockLight(buf);

            if (!section.hasSkyLight()) continue; // No sky light, we're done here.
            section.writeSkyLight(buf);
        }
        buf.readerIndex(0);
        Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
        output.writeBytes(buf);
    } finally {
        buf.release(); // release buffer
    }

    // Write biome data
    if (chunk.isBiomeData()) {
        for (int biome : chunk.getBiomeData()) {
            output.writeByte((byte) biome);
        }
    }

    // Write Block Entities
    Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
}
 
Example #29
Source File: ComponentRewriter.java    From ViaVersion with MIT License 5 votes vote down vote up
public void registerChatMessage(ClientboundPacketType packetType) {
    protocol.registerOutgoing(packetType, new PacketRemapper() {
        @Override
        public void registerMap() {
            handler(wrapper -> processText(wrapper.passthrough(Type.COMPONENT)));
        }
    });
}
 
Example #30
Source File: EntityRewriterBase.java    From ViaBackwards with MIT License 5 votes vote down vote up
/**
 * Helper method to handle player, painting, or xp orb trackers without meta changes.
 */
protected void registerExtraTracker(ClientboundPacketType packetType, EntityType entityType, Type intType) {
    getProtocol().registerOutgoing(packetType, new PacketRemapper() {
        @Override
        public void registerMap() {
            map(intType); // 0 - Entity id
            handler(wrapper -> addTrackedEntity(wrapper, (int) wrapper.get(intType, 0), entityType));
        }
    });
}