use of com.nukkitx.protocol.bedrock.data.inventory.ItemData in project Protocol by CloudburstMC.
the class CraftingDataSerializer_v291 method readShapelessRecipe.
protected CraftingData readShapelessRecipe(ByteBuf buffer, BedrockPacketHelper helper, CraftingDataType type, BedrockSession session) {
List<ItemData> inputs = new ObjectArrayList<>();
helper.readArray(buffer, inputs, buf -> helper.readItem(buf, session));
List<ItemData> outputs = new ObjectArrayList<>();
helper.readArray(buffer, outputs, buf -> helper.readItem(buf, session));
UUID uuid = helper.readUuid(buffer);
return new CraftingData(type, -1, -1, -1, -1, inputs, outputs, uuid, null);
}
use of com.nukkitx.protocol.bedrock.data.inventory.ItemData in project Protocol by CloudburstMC.
the class CraftingDataSerializer_v291 method readShapedRecipe.
protected CraftingData readShapedRecipe(ByteBuf buffer, BedrockPacketHelper helper, CraftingDataType type, BedrockSession session) {
int width = VarInts.readInt(buffer);
int height = VarInts.readInt(buffer);
int inputCount = width * height;
List<ItemData> inputs = new ObjectArrayList<>(inputCount);
for (int i = 0; i < inputCount; i++) {
inputs.add(helper.readItem(buffer, session));
}
List<ItemData> outputs = new ObjectArrayList<>();
helper.readArray(buffer, outputs, buf -> helper.readItem(buf, session));
UUID uuid = helper.readUuid(buffer);
return new CraftingData(type, width, height, -1, -1, inputs, outputs, uuid, null);
}
use of com.nukkitx.protocol.bedrock.data.inventory.ItemData in project Protocol by CloudburstMC.
the class CreativeContentSerializer_v407 method readCreativeItem.
protected ItemData readCreativeItem(ByteBuf buffer, BedrockPacketHelper helper, BedrockSession session) {
int netId = VarInts.readUnsignedInt(buffer);
ItemData item = helper.readItemInstance(buffer, session);
item.setNetId(netId);
return item;
}
use of com.nukkitx.protocol.bedrock.data.inventory.ItemData in project Protocol by CloudburstMC.
the class CraftingDataSerializer_v407 method readShapelessRecipe.
protected CraftingData readShapelessRecipe(ByteBuf buffer, BedrockPacketHelper helper, CraftingDataType type, BedrockSession session) {
String recipeId = helper.readString(buffer);
List<ItemData> inputs = new ObjectArrayList<>();
helper.readArray(buffer, inputs, helper::readRecipeIngredient);
List<ItemData> outputs = new ObjectArrayList<>();
helper.readArray(buffer, outputs, buf -> helper.readItemInstance(buf, session));
UUID uuid = helper.readUuid(buffer);
String craftingTag = helper.readString(buffer);
int priority = VarInts.readInt(buffer);
int networkId = VarInts.readUnsignedInt(buffer);
return new CraftingData(type, recipeId, -1, -1, -1, -1, inputs, outputs, uuid, craftingTag, priority, networkId);
}
use of com.nukkitx.protocol.bedrock.data.inventory.ItemData in project ProxyPass by CloudburstMC.
the class DownstreamPacketHandler method dumpCreativeItems.
private void dumpCreativeItems(ItemData[] contents) {
// Load up block palette for conversion, if we can find it.
Object object = proxy.loadGzipNBT("block_palette.nbt");
List<NbtMap> paletteTags = null;
if (object instanceof NbtMap) {
NbtMap map = (NbtMap) object;
paletteTags = map.getList("blocks", NbtType.COMPOUND);
} else {
log.warn("Failed to load block palette for creative content dump. Output will contain block runtime IDs!");
}
List<CreativeItemEntry> entries = new ArrayList<>();
for (ItemData data : contents) {
int runtimeId = data.getId();
StartGamePacket.ItemEntry entry = this.itemEntries.get(runtimeId);
if (entry == null) {
log.info("Could not find entry for item with runtime ID {}", runtimeId);
continue;
}
String id = entry.getIdentifier();
Integer damage = data.getDamage() == 0 ? null : (int) data.getDamage();
String blockTag = null;
Integer blockRuntimeId = null;
if (data.getBlockRuntimeId() != 0 && paletteTags != null) {
blockTag = encodeNbtToString(paletteTags.get(data.getBlockRuntimeId()));
} else if (data.getBlockRuntimeId() != 0) {
blockRuntimeId = data.getBlockRuntimeId();
}
NbtMap tag = data.getTag();
String tagData = null;
if (tag != null) {
tagData = encodeNbtToString(tag);
}
entries.add(new CreativeItemEntry(id, damage, blockRuntimeId, blockTag, tagData));
}
CreativeItems items = new CreativeItems(entries);
proxy.saveJson("creative_items.json", items);
}
Aggregations