com.nukkitx.protocol.bedrock.packet.CraftingDataPacket Java Examples
The following examples show how to use
com.nukkitx.protocol.bedrock.packet.CraftingDataPacket.
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: CraftingDataSerializer_v340.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void serialize(ByteBuf buffer, CraftingDataPacket packet) { BedrockUtils.writeArray(buffer, packet.getCraftingData(), (buf, craftingData) -> { VarInts.writeInt(buf, craftingData.getType().ordinal()); switch (craftingData.getType()) { case SHAPELESS: case SHAPELESS_CHEMISTRY: case SHULKER_BOX: BedrockUtils.writeArray(buf, craftingData.getInputs(), BedrockUtils::writeItemData); BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData); BedrockUtils.writeUuid(buf, craftingData.getUuid()); break; case SHAPED: case SHAPED_CHEMISTRY: VarInts.writeInt(buf, craftingData.getWidth()); VarInts.writeInt(buf, craftingData.getHeight()); int count = craftingData.getWidth() * craftingData.getHeight(); ItemData[] inputs = craftingData.getInputs(); for (int i = 0; i < count; i++) { BedrockUtils.writeItemData(buf, inputs[i]); } BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData); BedrockUtils.writeUuid(buf, craftingData.getUuid()); break; case FURNACE: case FURNACE_DATA: VarInts.writeInt(buf, craftingData.getInputId()); if (craftingData.getType() == CraftingType.FURNACE_DATA) { VarInts.writeInt(buf, craftingData.getInputDamage()); } BedrockUtils.writeItemData(buf, craftingData.getOutputs()[0]); break; case MULTI: BedrockUtils.writeUuid(buf, craftingData.getUuid()); break; } }); buffer.writeBoolean(packet.isCleanRecipes()); }
Example #2
Source File: CraftingDataSerializer_v313.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void serialize(ByteBuf buffer, CraftingDataPacket packet) { BedrockUtils.writeArray(buffer, packet.getCraftingData(), (buf, craftingData) -> { VarInts.writeInt(buf, craftingData.getType().ordinal()); switch (craftingData.getType()) { case SHAPELESS: case SHAPELESS_CHEMISTRY: case SHULKER_BOX: BedrockUtils.writeArray(buf, craftingData.getInputs(), BedrockUtils::writeItemData); BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData); BedrockUtils.writeUuid(buf, craftingData.getUuid()); break; case SHAPED: case SHAPED_CHEMISTRY: VarInts.writeInt(buf, craftingData.getWidth()); VarInts.writeInt(buf, craftingData.getHeight()); int count = craftingData.getWidth() * craftingData.getHeight(); ItemData[] inputs = craftingData.getInputs(); for (int i = 0; i < count; i++) { BedrockUtils.writeItemData(buf, inputs[i]); } BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData); BedrockUtils.writeUuid(buf, craftingData.getUuid()); break; case FURNACE: case FURNACE_DATA: VarInts.writeInt(buf, craftingData.getInputId()); if (craftingData.getType() == CraftingType.FURNACE_DATA) { VarInts.writeInt(buf, craftingData.getInputDamage()); } BedrockUtils.writeItemData(buf, craftingData.getOutputs()[0]); break; case MULTI: BedrockUtils.writeUuid(buf, craftingData.getUuid()); break; } }); buffer.writeBoolean(packet.isCleanRecipes()); }
Example #3
Source File: CraftingDataSerializer_v332.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void serialize(ByteBuf buffer, CraftingDataPacket packet) { BedrockUtils.writeArray(buffer, packet.getCraftingData(), (buf, craftingData) -> { VarInts.writeInt(buf, craftingData.getType().ordinal()); switch (craftingData.getType()) { case SHAPELESS: case SHAPELESS_CHEMISTRY: case SHULKER_BOX: BedrockUtils.writeArray(buf, craftingData.getInputs(), BedrockUtils::writeItemData); BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData); BedrockUtils.writeUuid(buf, craftingData.getUuid()); break; case SHAPED: case SHAPED_CHEMISTRY: VarInts.writeInt(buf, craftingData.getWidth()); VarInts.writeInt(buf, craftingData.getHeight()); int count = craftingData.getWidth() * craftingData.getHeight(); ItemData[] inputs = craftingData.getInputs(); for (int i = 0; i < count; i++) { BedrockUtils.writeItemData(buf, inputs[i]); } BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData); BedrockUtils.writeUuid(buf, craftingData.getUuid()); break; case FURNACE: case FURNACE_DATA: VarInts.writeInt(buf, craftingData.getInputId()); if (craftingData.getType() == CraftingType.FURNACE_DATA) { VarInts.writeInt(buf, craftingData.getInputDamage()); } BedrockUtils.writeItemData(buf, craftingData.getOutputs()[0]); break; case MULTI: BedrockUtils.writeUuid(buf, craftingData.getUuid()); break; } }); buffer.writeBoolean(packet.isCleanRecipes()); }
Example #4
Source File: CraftingDataSerializer_v291.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void serialize(ByteBuf buffer, CraftingDataPacket packet) { BedrockUtils.writeArray(buffer, packet.getCraftingData(), (buf, craftingData) -> { VarInts.writeInt(buf, craftingData.getType().ordinal()); switch (craftingData.getType()) { case SHAPELESS: case SHAPELESS_CHEMISTRY: case SHULKER_BOX: BedrockUtils.writeArray(buf, craftingData.getInputs(), BedrockUtils::writeItemData); BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData); BedrockUtils.writeUuid(buf, craftingData.getUuid()); break; case SHAPED: case SHAPED_CHEMISTRY: VarInts.writeInt(buf, craftingData.getWidth()); VarInts.writeInt(buf, craftingData.getHeight()); int count = craftingData.getWidth() * craftingData.getHeight(); ItemData[] inputs = craftingData.getInputs(); for (int i = 0; i < count; i++) { BedrockUtils.writeItemData(buf, inputs[i]); } BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData); BedrockUtils.writeUuid(buf, craftingData.getUuid()); break; case FURNACE: case FURNACE_DATA: VarInts.writeInt(buf, craftingData.getInputId()); if (craftingData.getType() == CraftingType.FURNACE_DATA) { VarInts.writeInt(buf, craftingData.getInputDamage()); } BedrockUtils.writeItemData(buf, craftingData.getOutputs()[0]); break; case MULTI: BedrockUtils.writeUuid(buf, craftingData.getUuid()); break; } }); buffer.writeBoolean(packet.isCleanRecipes()); }
Example #5
Source File: RecipeUtils.java From ProxyPass with GNU Affero General Public License v3.0 | 4 votes |
public static void writeRecipes(CraftingDataPacket packet, ProxyPass proxy) { List<CraftingDataEntry> entries = new ArrayList<>(); for (CraftingData craftingData : packet.getCraftingData()) { CraftingDataEntry entry = new CraftingDataEntry(); CraftingType type = craftingData.getType(); entry.type = type.ordinal(); if (type != CraftingType.MULTI) { entry.block = craftingData.getCraftingTag(); } else { entry.uuid = craftingData.getUuid(); } if (type == CraftingType.SHAPED || type == CraftingType.SHAPELESS || type == CraftingType.SHAPELESS_CHEMISTRY || type == CraftingType.SHULKER_BOX || type == CraftingType.SHAPED_CHEMISTRY) { entry.id = craftingData.getRecipeId(); entry.priority = craftingData.getPriority(); entry.output = writeItemArray(craftingData.getOutputs(), true); } if (type == CraftingType.SHAPED || type == CraftingType.SHAPED_CHEMISTRY) { int charCounter = 0; ItemData[] inputs = craftingData.getInputs(); Map<Item, Character> charItemMap = new HashMap<>(); char[][] shape = new char[craftingData.getHeight()][craftingData.getWidth()]; for (int height = 0; height < craftingData.getHeight(); height++) { Arrays.fill(shape[height], ' '); int index = height * craftingData.getWidth(); for (int width = 0; width < craftingData.getWidth(); width++) { int slot = index + width; Item item = itemFromNetwork(inputs[slot], false); if (item == Item.EMPTY) { continue; } Character shapeChar = charItemMap.get(item); if (shapeChar == null) { shapeChar = SHAPE_CHARS[charCounter++]; charItemMap.put(item, shapeChar); } shape[height][width] = shapeChar; } } String[] shapeString = new String[shape.length]; for (int i = 0; i < shape.length; i++) { shapeString[i] = new String(shape[i]); } entry.shape = shapeString; Map<Character, Item> itemMap = new HashMap<>(); for (Map.Entry<Item, Character> mapEntry : charItemMap.entrySet()) { itemMap.put(mapEntry.getValue(), mapEntry.getKey()); } entry.input = itemMap; } if (type == CraftingType.SHAPELESS || type == CraftingType.SHAPELESS_CHEMISTRY || type == CraftingType.SHULKER_BOX) { entry.input = writeItemArray(craftingData.getInputs(), false); } if (type == CraftingType.FURNACE || type == CraftingType.FURNACE_DATA) { Integer damage = craftingData.getInputDamage(); if (damage == 0x7fff) damage = -1; if (damage == 0) damage = null; entry.input = new Item(craftingData.getInputId(), damage, null, null); entry.output = itemFromNetwork(craftingData.getOutputs()[0], true); } entries.add(entry); } Recipes recipes = new Recipes(ProxyPass.CODEC.getProtocolVersion(), entries, packet.getPotionMixData(), packet.getContainerMixData()); proxy.saveJson("recipes.json", recipes); }
Example #6
Source File: CraftingDataSerializer_v354.java From Protocol with Apache License 2.0 | 4 votes |
@Override public void serialize(ByteBuf buffer, CraftingDataPacket packet) { BedrockUtils.writeArray(buffer, packet.getCraftingData(), (buf, craftingData) -> { VarInts.writeInt(buf, craftingData.getType().ordinal()); switch (craftingData.getType()) { case SHAPELESS: case SHAPELESS_CHEMISTRY: case SHULKER_BOX: BedrockUtils.writeArray(buf, craftingData.getInputs(), BedrockUtils::writeItemData); BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData); BedrockUtils.writeUuid(buf, craftingData.getUuid()); BedrockUtils.writeString(buf, craftingData.getCraftingTag()); break; case SHAPED: case SHAPED_CHEMISTRY: VarInts.writeInt(buf, craftingData.getWidth()); VarInts.writeInt(buf, craftingData.getHeight()); int count = craftingData.getWidth() * craftingData.getHeight(); ItemData[] inputs = craftingData.getInputs(); for (int i = 0; i < count; i++) { BedrockUtils.writeItemData(buf, inputs[i]); } BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData); BedrockUtils.writeUuid(buf, craftingData.getUuid()); BedrockUtils.writeString(buf, craftingData.getCraftingTag()); break; case FURNACE: case FURNACE_DATA: VarInts.writeInt(buf, craftingData.getInputId()); if (craftingData.getType() == CraftingType.FURNACE_DATA) { VarInts.writeInt(buf, craftingData.getInputDamage()); } BedrockUtils.writeItemData(buf, craftingData.getOutputs()[0]); BedrockUtils.writeString(buf, craftingData.getCraftingTag()); break; case MULTI: BedrockUtils.writeUuid(buf, craftingData.getUuid()); break; } }); buffer.writeBoolean(packet.isCleanRecipes()); }
Example #7
Source File: CraftingDataSerializer_v354.java From Protocol with Apache License 2.0 | 4 votes |
@Override public void deserialize(ByteBuf buffer, CraftingDataPacket packet) { BedrockUtils.readArray(buffer, packet.getCraftingData(), buf -> { int typeInt = VarInts.readInt(buf); CraftingType type = CraftingType.byId(typeInt); if (type == null) { // TODO: 23/04/19 log type return null; } switch (type) { case SHAPELESS: case SHAPELESS_CHEMISTRY: case SHULKER_BOX: int inputCount = VarInts.readUnsignedInt(buf); ItemData[] inputs = new ItemData[inputCount]; for (int i = 0; i < inputCount; i++) { inputs[i] = BedrockUtils.readItemData(buf); } int outputCount = VarInts.readUnsignedInt(buf); ItemData[] outputs = new ItemData[outputCount]; for (int i = 0; i < outputCount; i++) { outputs[i] = BedrockUtils.readItemData(buf); } UUID uuid = BedrockUtils.readUuid(buf); String craftingTag = BedrockUtils.readString(buf); return new CraftingData(type, -1, -1, -1, -1, inputs, outputs, uuid, craftingTag); case SHAPED: case SHAPED_CHEMISTRY: int width = VarInts.readInt(buf); int height = VarInts.readInt(buf); int inputCount2 = width * height; ItemData[] inputs2 = new ItemData[inputCount2]; for (int i = 0; i < inputCount2; i++) { inputs2[i] = BedrockUtils.readItemData(buf); } int outputCount2 = VarInts.readUnsignedInt(buf); ItemData[] outputs2 = new ItemData[outputCount2]; for (int i = 0; i < outputCount2; i++) { outputs2[i] = BedrockUtils.readItemData(buf); } UUID uuid2 = BedrockUtils.readUuid(buf); String craftingTag2 = BedrockUtils.readString(buf); return new CraftingData(type, width, height, -1, -1, inputs2, outputs2, uuid2, craftingTag2); case FURNACE: case FURNACE_DATA: int inputId = VarInts.readInt(buf); int inputDamage = type == CraftingType.FURNACE_DATA ? VarInts.readInt(buf) : -1; ItemData[] output = new ItemData[]{BedrockUtils.readItemData(buf)}; String craftingTag3 = BedrockUtils.readString(buf); return new CraftingData(type, -1, -1, inputId, inputDamage, null, output, null, craftingTag3); case MULTI: UUID uuid3 = BedrockUtils.readUuid(buf); return CraftingData.fromMulti(uuid3); } throw new IllegalArgumentException("Unhandled crafting data type: " + type); }); packet.setCleanRecipes(buffer.readBoolean()); }
Example #8
Source File: CraftingDataSerializer_v388.java From Protocol with Apache License 2.0 | 4 votes |
@Override public void serialize(ByteBuf buffer, CraftingDataPacket packet) { BedrockUtils.writeArray(buffer, packet.getCraftingData(), (buf, craftingData) -> { VarInts.writeInt(buf, craftingData.getType().ordinal()); switch (craftingData.getType()) { case SHAPELESS: case SHAPELESS_CHEMISTRY: case SHULKER_BOX: BedrockUtils.writeString(buf, craftingData.getRecipeId()); BedrockUtils.writeArray(buf, craftingData.getInputs(), BedrockUtils::writeRecipeIngredient); BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData); BedrockUtils.writeUuid(buf, craftingData.getUuid()); BedrockUtils.writeString(buf, craftingData.getCraftingTag()); VarInts.writeInt(buf, craftingData.getPriority()); break; case SHAPED: case SHAPED_CHEMISTRY: BedrockUtils.writeString(buf, craftingData.getRecipeId()); VarInts.writeInt(buf, craftingData.getWidth()); VarInts.writeInt(buf, craftingData.getHeight()); int count = craftingData.getWidth() * craftingData.getHeight(); ItemData[] inputs = craftingData.getInputs(); for (int i = 0; i < count; i++) { BedrockUtils.writeRecipeIngredient(buf, inputs[i]); } BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData); BedrockUtils.writeUuid(buf, craftingData.getUuid()); BedrockUtils.writeString(buf, craftingData.getCraftingTag()); VarInts.writeInt(buf, craftingData.getPriority()); break; case FURNACE: case FURNACE_DATA: VarInts.writeInt(buf, craftingData.getInputId()); if (craftingData.getType() == CraftingType.FURNACE_DATA) { VarInts.writeInt(buf, craftingData.getInputDamage()); } BedrockUtils.writeItemData(buf, craftingData.getOutputs()[0]); BedrockUtils.writeString(buf, craftingData.getCraftingTag()); break; case MULTI: BedrockUtils.writeUuid(buf, craftingData.getUuid()); break; } }); BedrockUtils.writeArray(buffer, packet.getPotionMixData(), (buf, potionMixData) -> { VarInts.writeInt(buf, potionMixData.getFromPotionId()); VarInts.writeInt(buf, potionMixData.getIngredient()); VarInts.writeInt(buf, potionMixData.getToPotionId()); }); BedrockUtils.writeArray(buffer, packet.getContainerMixData(), (buf, containerMixData) -> { VarInts.writeInt(buf, containerMixData.getFromItemId()); VarInts.writeInt(buf, containerMixData.getIngredient()); VarInts.writeInt(buf, containerMixData.getToItemId()); }); buffer.writeBoolean(packet.isCleanRecipes()); }
Example #9
Source File: CraftingDataSerializer_v340.java From Protocol with Apache License 2.0 | 4 votes |
@Override public void deserialize(ByteBuf buffer, CraftingDataPacket packet) { BedrockUtils.readArray(buffer, packet.getCraftingData(), buf -> { int typeInt = VarInts.readInt(buf); CraftingType type = CraftingType.byId(typeInt); if (type == null) { // TODO: 23/04/19 log type return null; } switch (type) { case SHAPELESS: case SHAPELESS_CHEMISTRY: case SHULKER_BOX: int inputCount = VarInts.readUnsignedInt(buf); ItemData[] inputs = new ItemData[inputCount]; for (int i = 0; i < inputCount; i++) { inputs[i] = BedrockUtils.readItemData(buf); } int outputCount = VarInts.readUnsignedInt(buf); ItemData[] outputs = new ItemData[outputCount]; for (int i = 0; i < outputCount; i++) { outputs[i] = BedrockUtils.readItemData(buf); } UUID uuid = BedrockUtils.readUuid(buf); return new CraftingData(type, -1, -1, -1, -1, inputs, outputs, uuid, null); case SHAPED: case SHAPED_CHEMISTRY: int width = VarInts.readInt(buf); int height = VarInts.readInt(buf); int inputCount2 = width * height; ItemData[] inputs2 = new ItemData[inputCount2]; for (int i = 0; i < inputCount2; i++) { inputs2[i] = BedrockUtils.readItemData(buf); } int outputCount2 = VarInts.readUnsignedInt(buf); ItemData[] outputs2 = new ItemData[outputCount2]; for (int i = 0; i < outputCount2; i++) { outputs2[i] = BedrockUtils.readItemData(buf); } UUID uuid2 = BedrockUtils.readUuid(buf); return new CraftingData(type, width, height, -1, -1, inputs2, outputs2, uuid2, null); case FURNACE: case FURNACE_DATA: int inputId = VarInts.readInt(buf); int inputDamage = type == CraftingType.FURNACE_DATA ? VarInts.readInt(buf) : -1; ItemData[] output = new ItemData[]{BedrockUtils.readItemData(buf)}; return new CraftingData(type, -1, -1, inputId, inputDamage, null, output, null, null); case MULTI: UUID uuid3 = BedrockUtils.readUuid(buf); return CraftingData.fromMulti(uuid3); } throw new IllegalArgumentException("Unhandled crafting data type: " + type); }); packet.setCleanRecipes(buffer.readBoolean()); }
Example #10
Source File: CraftingDataSerializer_v313.java From Protocol with Apache License 2.0 | 4 votes |
@Override public void deserialize(ByteBuf buffer, CraftingDataPacket packet) { BedrockUtils.readArray(buffer, packet.getCraftingData(), buf -> { int typeInt = VarInts.readInt(buf); CraftingType type = CraftingType.byId(typeInt); if (type == null) { // TODO: 23/04/19 log type return null; } switch (type) { case SHAPELESS: case SHAPELESS_CHEMISTRY: case SHULKER_BOX: int inputCount = VarInts.readUnsignedInt(buf); ItemData[] inputs = new ItemData[inputCount]; for (int i = 0; i < inputCount; i++) { inputs[i] = BedrockUtils.readItemData(buf); } int outputCount = VarInts.readUnsignedInt(buf); ItemData[] outputs = new ItemData[outputCount]; for (int i = 0; i < outputCount; i++) { outputs[i] = BedrockUtils.readItemData(buf); } UUID uuid = BedrockUtils.readUuid(buf); return new CraftingData(type, -1, -1, -1, -1, inputs, outputs, uuid, null); case SHAPED: case SHAPED_CHEMISTRY: int width = VarInts.readInt(buf); int height = VarInts.readInt(buf); int inputCount2 = width * height; ItemData[] inputs2 = new ItemData[inputCount2]; for (int i = 0; i < inputCount2; i++) { inputs2[i] = BedrockUtils.readItemData(buf); } int outputCount2 = VarInts.readUnsignedInt(buf); ItemData[] outputs2 = new ItemData[outputCount2]; for (int i = 0; i < outputCount2; i++) { outputs2[i] = BedrockUtils.readItemData(buf); } UUID uuid2 = BedrockUtils.readUuid(buf); return new CraftingData(type, width, height, -1, -1, inputs2, outputs2, uuid2, null); case FURNACE: case FURNACE_DATA: int inputId = VarInts.readInt(buf); int inputDamage = type == CraftingType.FURNACE_DATA ? VarInts.readInt(buf) : -1; ItemData[] output = new ItemData[]{BedrockUtils.readItemData(buf)}; return new CraftingData(type, -1, -1, inputId, inputDamage, null, output, null, null); case MULTI: UUID uuid3 = BedrockUtils.readUuid(buf); return CraftingData.fromMulti(uuid3); } throw new IllegalArgumentException("Unhandled crafting data type: " + type); }); packet.setCleanRecipes(buffer.readBoolean()); }
Example #11
Source File: CraftingDataSerializer_v361.java From Protocol with Apache License 2.0 | 4 votes |
@Override public void serialize(ByteBuf buffer, CraftingDataPacket packet) { BedrockUtils.writeArray(buffer, packet.getCraftingData(), (buf, craftingData) -> { VarInts.writeInt(buf, craftingData.getType().ordinal()); switch (craftingData.getType()) { case SHAPELESS: case SHAPELESS_CHEMISTRY: case SHULKER_BOX: BedrockUtils.writeString(buf, craftingData.getRecipeId()); BedrockUtils.writeArray(buf, craftingData.getInputs(), BedrockUtils::writeRecipeIngredient); BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData); BedrockUtils.writeUuid(buf, craftingData.getUuid()); BedrockUtils.writeString(buf, craftingData.getCraftingTag()); VarInts.writeInt(buf, craftingData.getPriority()); break; case SHAPED: case SHAPED_CHEMISTRY: BedrockUtils.writeString(buf, craftingData.getRecipeId()); VarInts.writeInt(buf, craftingData.getWidth()); VarInts.writeInt(buf, craftingData.getHeight()); int count = craftingData.getWidth() * craftingData.getHeight(); ItemData[] inputs = craftingData.getInputs(); for (int i = 0; i < count; i++) { BedrockUtils.writeRecipeIngredient(buf, inputs[i]); } BedrockUtils.writeArray(buf, craftingData.getOutputs(), BedrockUtils::writeItemData); BedrockUtils.writeUuid(buf, craftingData.getUuid()); BedrockUtils.writeString(buf, craftingData.getCraftingTag()); VarInts.writeInt(buf, craftingData.getPriority()); break; case FURNACE: case FURNACE_DATA: VarInts.writeInt(buf, craftingData.getInputId()); if (craftingData.getType() == CraftingType.FURNACE_DATA) { VarInts.writeInt(buf, craftingData.getInputDamage()); } BedrockUtils.writeItemData(buf, craftingData.getOutputs()[0]); BedrockUtils.writeString(buf, craftingData.getCraftingTag()); break; case MULTI: BedrockUtils.writeUuid(buf, craftingData.getUuid()); break; } }); buffer.writeBoolean(packet.isCleanRecipes()); }
Example #12
Source File: CraftingDataSerializer_v361.java From Protocol with Apache License 2.0 | 4 votes |
@Override public void deserialize(ByteBuf buffer, CraftingDataPacket packet) { BedrockUtils.readArray(buffer, packet.getCraftingData(), buf -> { int typeInt = VarInts.readInt(buf); CraftingType type = CraftingType.byId(typeInt); if (type == null) { throw new IllegalArgumentException("Unknown crafting type: " + typeInt); } switch (type) { case SHAPELESS: case SHAPELESS_CHEMISTRY: case SHULKER_BOX: String recipeId = BedrockUtils.readString(buf); int inputCount = VarInts.readUnsignedInt(buf); ItemData[] inputs = new ItemData[inputCount]; for (int i = 0; i < inputCount; i++) { inputs[i] = BedrockUtils.readRecipeIngredient(buf); } int outputCount = VarInts.readUnsignedInt(buf); ItemData[] outputs = new ItemData[outputCount]; for (int i = 0; i < outputCount; i++) { outputs[i] = BedrockUtils.readItemData(buf); } UUID uuid = BedrockUtils.readUuid(buf); String craftingTag = BedrockUtils.readString(buf); int priority = VarInts.readInt(buf); return new CraftingData(type, recipeId, -1, -1, -1, -1, inputs, outputs, uuid, craftingTag, priority); case SHAPED: case SHAPED_CHEMISTRY: recipeId = BedrockUtils.readString(buf); int width = VarInts.readInt(buf); int height = VarInts.readInt(buf); inputCount = width * height; inputs = new ItemData[inputCount]; for (int i = 0; i < inputCount; i++) { inputs[i] = BedrockUtils.readRecipeIngredient(buf); } outputCount = VarInts.readUnsignedInt(buf); outputs = new ItemData[outputCount]; for (int i = 0; i < outputCount; i++) { outputs[i] = BedrockUtils.readItemData(buf); } uuid = BedrockUtils.readUuid(buf); craftingTag = BedrockUtils.readString(buf); priority = VarInts.readInt(buf); return new CraftingData(type, recipeId, width, height, -1, -1, inputs, outputs, uuid, craftingTag, priority); case FURNACE: case FURNACE_DATA: int inputId = VarInts.readInt(buf); int inputDamage = type == CraftingType.FURNACE_DATA ? VarInts.readInt(buf) : -1; ItemData[] output = new ItemData[]{BedrockUtils.readItemData(buf)}; craftingTag = BedrockUtils.readString(buf); return new CraftingData(type, null, -1, -1, inputId, inputDamage, null, output, null, craftingTag, -1); case MULTI: uuid = BedrockUtils.readUuid(buf); return CraftingData.fromMulti(uuid); default: throw new IllegalArgumentException("Unhandled crafting data type: " + type); } }); packet.setCleanRecipes(buffer.readBoolean()); }
Example #13
Source File: CraftingDataSerializer_v332.java From Protocol with Apache License 2.0 | 4 votes |
@Override public void deserialize(ByteBuf buffer, CraftingDataPacket packet) { BedrockUtils.readArray(buffer, packet.getCraftingData(), buf -> { int typeInt = VarInts.readInt(buf); CraftingType type = CraftingType.byId(typeInt); if (type == null) { // TODO: 23/04/19 log type return null; } switch (type) { case SHAPELESS: case SHAPELESS_CHEMISTRY: case SHULKER_BOX: int inputCount = VarInts.readUnsignedInt(buf); ItemData[] inputs = new ItemData[inputCount]; for (int i = 0; i < inputCount; i++) { inputs[i] = BedrockUtils.readItemData(buf); } int outputCount = VarInts.readUnsignedInt(buf); ItemData[] outputs = new ItemData[outputCount]; for (int i = 0; i < outputCount; i++) { outputs[i] = BedrockUtils.readItemData(buf); } UUID uuid = BedrockUtils.readUuid(buf); return new CraftingData(type, -1, -1, -1, -1, inputs, outputs, uuid, null); case SHAPED: case SHAPED_CHEMISTRY: int width = VarInts.readInt(buf); int height = VarInts.readInt(buf); int inputCount2 = width * height; ItemData[] inputs2 = new ItemData[inputCount2]; for (int i = 0; i < inputCount2; i++) { inputs2[i] = BedrockUtils.readItemData(buf); } int outputCount2 = VarInts.readUnsignedInt(buf); ItemData[] outputs2 = new ItemData[outputCount2]; for (int i = 0; i < outputCount2; i++) { outputs2[i] = BedrockUtils.readItemData(buf); } UUID uuid2 = BedrockUtils.readUuid(buf); return new CraftingData(type, width, height, -1, -1, inputs2, outputs2, uuid2, null); case FURNACE: case FURNACE_DATA: int inputId = VarInts.readInt(buf); int inputDamage = type == CraftingType.FURNACE_DATA ? VarInts.readInt(buf) : -1; ItemData[] output = new ItemData[]{BedrockUtils.readItemData(buf)}; return new CraftingData(type, -1, -1, inputId, inputDamage, null, output, null, null); case MULTI: UUID uuid3 = BedrockUtils.readUuid(buf); return CraftingData.fromMulti(uuid3); } throw new IllegalArgumentException("Unhandled crafting data type: " + type); }); packet.setCleanRecipes(buffer.readBoolean()); }
Example #14
Source File: CraftingDataSerializer_v291.java From Protocol with Apache License 2.0 | 4 votes |
@Override public void deserialize(ByteBuf buffer, CraftingDataPacket packet) { BedrockUtils.readArray(buffer, packet.getCraftingData(), buf -> { int typeInt = VarInts.readInt(buf); CraftingType type = CraftingType.byId(typeInt); if (type == null) { // TODO: 23/04/19 log type return null; } switch (type) { case SHAPELESS: case SHAPELESS_CHEMISTRY: case SHULKER_BOX: int inputCount = VarInts.readUnsignedInt(buf); ItemData[] inputs = new ItemData[inputCount]; for (int i = 0; i < inputCount; i++) { inputs[i] = BedrockUtils.readItemData(buf); } int outputCount = VarInts.readUnsignedInt(buf); ItemData[] outputs = new ItemData[outputCount]; for (int i = 0; i < outputCount; i++) { outputs[i] = BedrockUtils.readItemData(buf); } UUID uuid = BedrockUtils.readUuid(buf); return new CraftingData(type, -1, -1, -1, -1, inputs, outputs, uuid, null); case SHAPED: case SHAPED_CHEMISTRY: int width = VarInts.readInt(buf); int height = VarInts.readInt(buf); int inputCount2 = width * height; ItemData[] inputs2 = new ItemData[inputCount2]; for (int i = 0; i < inputCount2; i++) { inputs2[i] = BedrockUtils.readItemData(buf); } int outputCount2 = VarInts.readUnsignedInt(buf); ItemData[] outputs2 = new ItemData[outputCount2]; for (int i = 0; i < outputCount2; i++) { outputs2[i] = BedrockUtils.readItemData(buf); } UUID uuid2 = BedrockUtils.readUuid(buf); return new CraftingData(type, width, height, -1, -1, inputs2, outputs2, uuid2, null); case FURNACE: case FURNACE_DATA: int inputId = VarInts.readInt(buf); int inputDamage = type == CraftingType.FURNACE_DATA ? VarInts.readInt(buf) : -1; ItemData[] output = new ItemData[]{BedrockUtils.readItemData(buf)}; return new CraftingData(type, -1, -1, inputId, inputDamage, null, output, null, null); case MULTI: UUID uuid3 = BedrockUtils.readUuid(buf); return CraftingData.fromMulti(uuid3); } throw new IllegalArgumentException("Unhandled crafting data type: " + type); }); packet.setCleanRecipes(buffer.readBoolean()); }