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

The following examples show how to use us.myles.ViaVersion.api.type.Type. These examples are extracted from open source projects. 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 Project: ViaVersion   Author: ViaVersion   File: Protocol1_9To1_8.java    License: 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 #2
Source Project: ViaRewind   Author: ViaVersion   File: ShulkerReplacement.java    License: 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 #3
Source Project: ViaRewind   Author: ViaVersion   File: Cooldown.java    License: 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 #4
Source Project: ViaRewind   Author: ViaVersion   File: Windows.java    License: 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 #5
Source Project: ViaVersion   Author: ViaVersion   File: ArmorListener.java    License: 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 #6
Source Project: ViaVersion   Author: ViaVersion   File: Protocol1_12_2To1_12_1.java    License: 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 #7
Source Project: ViaVersion   Author: ViaVersion   File: EntityTracker1_9.java    License: 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 #8
Source Project: ViaVersion   Author: ViaVersion   File: ItemRewriter.java    License: 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 #9
Source Project: ViaVersion   Author: ViaVersion   File: TagRewriter.java    License: 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 #10
Source Project: ViaVersion   Author: ViaVersion   File: ConnectionData.java    License: 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 #11
Source Project: ViaVersion   Author: ViaVersion   File: MetadataRewriter.java    License: 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 #12
Source Project: ViaVersion   Author: ViaVersion   File: BlockEntity.java    License: MIT License 5 votes vote down vote up
private static void updateBlockEntity(Position pos, short id, CompoundTag tag, UserConnection connection) throws Exception {
    PacketWrapper wrapper = new PacketWrapper(0x09, null, connection);
    wrapper.write(Type.POSITION, pos);
    wrapper.write(Type.UNSIGNED_BYTE, id);
    wrapper.write(Type.NBT, tag);
    wrapper.send(Protocol1_9_1_2To1_9_3_4.class, false);
}
 
Example #13
Source Project: ViaRewind   Author: ViaVersion   File: ItemArrayType.java    License: MIT License 5 votes vote down vote up
@Override
public Item[] read(ByteBuf buffer) throws Exception {
	int amount = Type.SHORT.read(buffer);
	Item[] items = new Item[amount];

	for(int i = 0; i < amount; ++i) {
		items[i] = (compressed ? Types1_7_6_10.COMPRESSED_NBT_ITEM : Types1_7_6_10.ITEM).read(buffer);
	}
	return items;
}
 
Example #14
Source Project: ViaBackwards   Author: ViaVersion   File: EntityRewriterBase.java    License: MIT License 5 votes vote down vote up
public void registerRespawn(ClientboundPacketType packetType) {
    protocol.registerOutgoing(packetType, new PacketRemapper() {
        @Override
        public void registerMap() {
            map(Type.INT);
            handler(wrapper -> {
                ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
                clientWorld.setEnvironment(wrapper.get(Type.INT, 0));
            });
        }
    });
}
 
Example #15
Source Project: ViaBackwards   Author: ViaVersion   File: BungeePlugin.java    License: MIT License 5 votes vote down vote up
private void sendRespawn(UserConnection connection, int dimension) {
    PacketWrapper packet = new PacketWrapper(ClientboundPackets1_15.RESPAWN.ordinal(), null, connection);
    packet.write(Type.INT, dimension);
    packet.write(Type.LONG, 0L);
    packet.write(Type.UNSIGNED_BYTE, (short) 0);
    packet.write(Type.STRING, "default");
    try {
        packet.send(Protocol1_15_2To1_16.class, true, true);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #16
Source Project: ViaVersion   Author: ViaVersion   File: StringTypeTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testStringWrite() throws Exception {
    // Write
    final ByteBuf buf = Unpooled.buffer();
    Type.STRING.write(buf, "\uD83E\uDDFD"); // Sponge Emoji
    Assertions.assertEquals(ByteBufUtil.hexDump(buf), "04f09fa7bd");
}
 
Example #17
Source Project: ViaBackwards   Author: ViaVersion   File: EntityRewriterBase.java    License: MIT License 5 votes vote down vote up
public void registerJoinGame(ClientboundPacketType packetType, EntityType playerType) {
    protocol.registerOutgoing(packetType, new PacketRemapper() {
        @Override
        public void registerMap() {
            map(Type.INT); // 0 - Entity ID
            map(Type.UNSIGNED_BYTE); // 1 - Gamemode
            map(Type.INT); // 2 - Dimension
            handler(wrapper -> {
                ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
                clientChunks.setEnvironment(wrapper.get(Type.INT, 1));
                getEntityTracker(wrapper.user()).trackEntityType(wrapper.get(Type.INT, 0), playerType);
            });
        }
    });
}
 
Example #18
Source Project: ViaVersion   Author: ViaVersion   File: FlatVarIntItemType.java    License: MIT License 5 votes vote down vote up
@Override
public Item read(ByteBuf buffer) throws Exception {
    boolean present = buffer.readBoolean();
    if (!present) {
        return null;
    } else {
        Item item = new Item();
        item.setIdentifier(Type.VAR_INT.readPrimitive(buffer));
        item.setAmount(buffer.readByte());
        item.setTag(Type.NBT.read(buffer));
        return item;
    }
}
 
Example #19
Source Project: ViaBackwards   Author: ViaVersion   File: RecipeRewriter1_14.java    License: MIT License 5 votes vote down vote up
public void handleCraftingShapeless(PacketWrapper wrapper) throws Exception {
    wrapper.passthrough(Type.STRING); // Group
    int ingredientsNo = wrapper.passthrough(Type.VAR_INT);
    for (int j = 0; j < ingredientsNo; j++) {
        Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
        for (Item item : items) {
            rewriter.handleItemToClient(item);
        }
    }
    rewriter.handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
}
 
Example #20
Source Project: ViaRewind   Author: ViaVersion   File: EntityTracker.java    License: MIT License 5 votes vote down vote up
public boolean setSpectating(int spectating) {
	if (spectating!=this.playerId && getPassenger(spectating)!=-1) {

		PacketWrapper sneakPacket = new PacketWrapper(0x0B, null, getUser());
		sneakPacket.write(Type.VAR_INT, playerId);
		sneakPacket.write(Type.VAR_INT, 0);  //Start sneaking
		sneakPacket.write(Type.VAR_INT, 0);  //Action Parameter

		PacketWrapper unsneakPacket = new PacketWrapper(0x0B, null, getUser());
		unsneakPacket.write(Type.VAR_INT, playerId);
		unsneakPacket.write(Type.VAR_INT, 1);  //Stop sneaking
		unsneakPacket.write(Type.VAR_INT, 0);  //Action Parameter

		PacketUtil.sendToServer(sneakPacket, Protocol1_7_6_10TO1_8.class, true, true);

		setSpectating(this.playerId);
		return false;  //Entity has Passenger
	}

	if (this.spectating!=spectating && this.spectating!=this.playerId) {
		PacketWrapper unmount = new PacketWrapper(0x1B, null, this.getUser());
		unmount.write(Type.INT, this.playerId);
		unmount.write(Type.INT, -1);
		unmount.write(Type.BOOLEAN, false);
		PacketUtil.sendPacket(unmount, Protocol1_7_6_10TO1_8.class);
	}
	this.spectating = spectating;
	if (spectating!=this.playerId) {
		PacketWrapper mount = new PacketWrapper(0x1B, null, this.getUser());
		mount.write(Type.INT, this.playerId);
		mount.write(Type.INT, this.spectating);
		mount.write(Type.BOOLEAN, false);
		PacketUtil.sendPacket(mount, Protocol1_7_6_10TO1_8.class);
	}
	return true;
}
 
Example #21
Source Project: ViaVersion   Author: ViaVersion   File: AbstractMetaListType.java    License: MIT License 5 votes vote down vote up
@Override
public void write(final ByteBuf buffer, final List<Metadata> object) throws Exception {
    final Type<Metadata> type = this.getType();

    for (final Metadata metadata : object) {
        type.write(buffer, metadata);
    }

    this.writeEnd(type, buffer);
}
 
Example #22
Source Project: ViaVersion   Author: ViaVersion   File: FlatItemArrayType.java    License: MIT License 5 votes vote down vote up
@Override
public Item[] read(ByteBuf buffer) throws Exception {
    int amount = Type.SHORT.readPrimitive(buffer);
    Item[] array = new Item[amount];
    for (int i = 0; i < amount; i++) {
        array[i] = Type.FLAT_ITEM.read(buffer);
    }
    return array;
}
 
Example #23
Source Project: ViaVersion   Author: ViaVersion   File: Protocol1_14_4To1_14_3.java    License: MIT License 5 votes vote down vote up
@Override
protected void registerPackets() {
    registerOutgoing(ClientboundPackets1_14.TRADE_LIST, new PacketRemapper() {
        @Override
        public void registerMap() {
            handler(new PacketHandler() {
                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    wrapper.passthrough(Type.VAR_INT);
                    int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
                    for (int i = 0; i < size; i++) {
                        wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
                        wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
                        if (wrapper.passthrough(Type.BOOLEAN)) {
                            wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
                        }
                        wrapper.passthrough(Type.BOOLEAN);
                        wrapper.passthrough(Type.INT);
                        wrapper.passthrough(Type.INT);
                        wrapper.passthrough(Type.INT);
                        wrapper.passthrough(Type.INT);
                        wrapper.passthrough(Type.FLOAT);
                        wrapper.write(Type.INT, 0); // demand value added in pre5
                    }
                }
            });
        }
    });
}
 
Example #24
Source Project: ViaRewind   Author: ViaVersion   File: Chunk1_8Type.java    License: MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
    ByteBuf buf = output.alloc().buffer();

    for (int i = 0; i < chunk.getSections().length; i++) {
        if ((chunk.getBitmask() & 1 << i) == 0) continue;
        CHUNK_SECTION_TYPE.write(buf, chunk.getSections()[i]);
    }

    for (int i = 0; i < chunk.getSections().length; i++) {
        if ((chunk.getBitmask() & 1 << i) == 0) continue;
        chunk.getSections()[i].writeBlockLight(buf);
    }

    boolean skyLight = world.getEnvironment() == Environment.NORMAL;
    if (skyLight) {
        for (int i = 0; i < chunk.getSections().length; i++) {
            if ((chunk.getBitmask() & 1 << i) == 0) continue;
            chunk.getSections()[i].writeSkyLight(buf);
        }
    }

    if (chunk.isGroundUp() && chunk.isBiomeData()) {
        for (int biome : chunk.getBiomeData()) {
            buf.writeByte((byte) biome);
        }
    }

    output.writeInt(chunk.getX());
    output.writeInt(chunk.getZ());
    output.writeBoolean(chunk.isGroundUp());
    output.writeShort(chunk.getBitmask());
    Type.VAR_INT.write(output, buf.readableBytes());
    output.writeBytes(buf, buf.readableBytes());
    buf.release();
}
 
Example #25
Source Project: ViaRewind   Author: ViaVersion   File: ScoreboardPackets.java    License: MIT License 5 votes vote down vote up
public static void register(Protocol protocol) {
	/*  OUTGOING  */

	//Display Scoreboard
	protocol.registerOutgoing(State.PLAY, 0x38, 0x3D);

	//Scoreboard Objective
	protocol.registerOutgoing(State.PLAY, 0x3F, 0x3B);

	//Scoreboard Team
	protocol.registerOutgoing(State.PLAY, 0x41, 0x3E, new PacketRemapper() {
		@Override
		public void registerMap() {
			map(Type.STRING);
			map(Type.BYTE);
			handler(new PacketHandler() {
				@Override
				public void handle(PacketWrapper packetWrapper) throws Exception {
					byte mode = packetWrapper.get(Type.BYTE, 0);
					if (mode == 0 || mode == 2) {
						packetWrapper.passthrough(Type.STRING);  //Display Name
						packetWrapper.passthrough(Type.STRING);  //Prefix
						packetWrapper.passthrough(Type.STRING);  //Suffix
						packetWrapper.passthrough(Type.BYTE);  //Friendly Flags
						packetWrapper.passthrough(Type.STRING);  //Name Tag Visibility
						packetWrapper.read(Type.STRING);  //Skip Collision Rule
						packetWrapper.passthrough(Type.BYTE);  //Friendly Flags
					}

					if (mode == 0 || mode == 3 || mode == 4) {
						packetWrapper.passthrough(Type.STRING_ARRAY);
					}
				}
			});
		}
	});

	//Update Score
	protocol.registerOutgoing(State.PLAY, 0x42, 0x3C);
}
 
Example #26
Source Project: ViaRewind   Author: ViaVersion   File: WitherBossBar.java    License: MIT License 5 votes vote down vote up
private void updateLocation() {
	PacketWrapper packetWrapper = new PacketWrapper(0x18, null, this.connection);
	packetWrapper.write(Type.VAR_INT, entityId);
	packetWrapper.write(Type.INT, (int) (locX * 32d));
	packetWrapper.write(Type.INT, (int) (locY * 32d));
	packetWrapper.write(Type.INT, (int) (locZ * 32d));
	packetWrapper.write(Type.BYTE, (byte)0);
	packetWrapper.write(Type.BYTE, (byte)0);
	packetWrapper.write(Type.BOOLEAN, false);

	PacketUtil.sendPacket(packetWrapper, Protocol1_8TO1_9.class, true, true);
}
 
Example #27
Source Project: ViaRewind   Author: ViaVersion   File: Cooldown.java    License: MIT License 5 votes vote down vote up
private void hideBossBar() {
	if (bossUUID==null) return;
	PacketWrapper wrapper = new PacketWrapper(0x0C, null, getUser());
	wrapper.write(Type.UUID, bossUUID);
	wrapper.write(Type.VAR_INT, 1);
	PacketUtil.sendPacket(wrapper, Protocol1_8TO1_9.class, false, true);
	bossUUID = null;
}
 
Example #28
Source Project: ViaVersion   Author: ViaVersion   File: ArrayType.java    License: MIT License 5 votes vote down vote up
@Override
public T[] read(ByteBuf buffer) throws Exception {
    int amount = Type.VAR_INT.readPrimitive(buffer);
    T[] array = (T[]) Array.newInstance(elementType.getOutputClass(), amount);

    for (int i = 0; i < amount; i++) {
        array[i] = elementType.read(buffer);
    }
    return array;
}
 
Example #29
Source Project: ViaBackwards   Author: ViaVersion   File: RecipeRewriter1_15.java    License: MIT License 5 votes vote down vote up
public void handleStonecutting(PacketWrapper wrapper) throws Exception {
    wrapper.passthrough(Type.STRING);
    Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
    for (Item item : items) {
        rewriter.handleItemToClient(item);
    }

    rewriter.handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
}
 
Example #30
Source Project: ViaVersion   Author: ViaVersion   File: CommonBoss.java    License: 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;
}