use of com.nukkitx.protocol.bedrock.data.inventory.ItemData in project Geyser by GeyserMC.
the class ItemFrameEntity method setItemInFrame.
public void setItemInFrame(EntityMetadata<ItemStack, ?> entityMetadata) {
if (entityMetadata.getValue() != null) {
this.heldItem = entityMetadata.getValue();
ItemData itemData = ItemTranslator.translateToBedrock(session, heldItem);
ItemMapping mapping = session.getItemMappings().getMapping(entityMetadata.getValue());
NbtMapBuilder builder = NbtMap.builder();
builder.putByte("Count", (byte) itemData.getCount());
if (itemData.getTag() != null) {
builder.put("tag", itemData.getTag());
}
builder.putShort("Damage", (short) itemData.getDamage());
builder.putString("Name", mapping.getBedrockIdentifier());
NbtMapBuilder tag = getDefaultTag().toBuilder();
tag.put("Item", builder.build());
tag.putFloat("ItemDropChance", 1.0f);
tag.putFloat("ItemRotation", rotation);
cachedTag = tag.build();
changed = true;
} else if (cachedTag != null) {
cachedTag = getDefaultTag();
changed = true;
}
}
use of com.nukkitx.protocol.bedrock.data.inventory.ItemData in project Geyser by GeyserMC.
the class GeyserItemStack method getItemData.
public ItemData getItemData(GeyserSession session) {
ItemData itemData = ItemTranslator.translateToBedrock(session, getItemStack());
itemData.setNetId(getNetId());
// Seems silly - this should probably be on the protocol level
itemData.setUsingNetId(true);
return itemData;
}
use of com.nukkitx.protocol.bedrock.data.inventory.ItemData in project Geyser by GeyserMC.
the class ChestedHorseInventoryTranslator method updateInventory.
@Override
public void updateInventory(GeyserSession session, Inventory inventory) {
ItemData[] bedrockItems = new ItemData[36];
for (int i = 0; i < 36; i++) {
final int offset = i < 9 ? 27 : -9;
bedrockItems[i] = inventory.getItem(this.size + i + offset).getItemData(session);
}
InventoryContentPacket contentPacket = new InventoryContentPacket();
contentPacket.setContainerId(ContainerId.INVENTORY);
contentPacket.setContents(Arrays.asList(bedrockItems));
session.sendUpstreamPacket(contentPacket);
ItemData[] horseItems = new ItemData[chestSize + 1];
// Manually specify the first slot - Java always has two slots (armor and saddle) and one is invisible.
// Bedrock doesn't have this invisible slot.
horseItems[0] = inventory.getItem(this.equipSlot).getItemData(session);
for (int i = 1; i < horseItems.length; i++) {
horseItems[i] = inventory.getItem(i + 1).getItemData(session);
}
InventoryContentPacket horseContentsPacket = new InventoryContentPacket();
horseContentsPacket.setContainerId(inventory.getId());
horseContentsPacket.setContents(Arrays.asList(horseItems));
session.sendUpstreamPacket(horseContentsPacket);
}
use of com.nukkitx.protocol.bedrock.data.inventory.ItemData in project Protocol by CloudburstMC.
the class CraftingDataSerializer_v361 method readShapelessRecipe.
@Override
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, this::readIngredient);
List<ItemData> outputs = new ObjectArrayList<>();
helper.readArray(buffer, outputs, buf -> helper.readItem(buf, session));
UUID uuid = helper.readUuid(buffer);
String craftingTag = helper.readString(buffer);
int priority = VarInts.readInt(buffer);
return new CraftingData(type, recipeId, -1, -1, -1, -1, inputs, outputs, uuid, craftingTag, priority);
}
use of com.nukkitx.protocol.bedrock.data.inventory.ItemData in project Protocol by CloudburstMC.
the class BedrockPacketHelper_v291 method writeEntityData.
@Override
public void writeEntityData(ByteBuf buffer, EntityDataMap entityDataMap) {
Preconditions.checkNotNull(buffer, "buffer");
Preconditions.checkNotNull(entityDataMap, "entityDataDictionary");
VarInts.writeUnsignedInt(buffer, entityDataMap.size());
for (Map.Entry<EntityData, Object> entry : entityDataMap.entrySet()) {
int index = buffer.writerIndex();
VarInts.writeUnsignedInt(buffer, this.entityData.get(entry.getKey()));
Object object = entry.getValue();
EntityData.Type type = EntityData.Type.from(object);
VarInts.writeUnsignedInt(buffer, this.entityDataTypes.get(type));
switch(type) {
case BYTE:
buffer.writeByte((byte) object);
break;
case SHORT:
buffer.writeShortLE((short) object);
break;
case INT:
VarInts.writeInt(buffer, (int) object);
break;
case FLOAT:
buffer.writeFloatLE((float) object);
break;
case STRING:
writeString(buffer, (String) object);
break;
case NBT:
ItemData item;
if (object instanceof NbtMap) {
item = ItemData.builder().id(1).damage(0).count(1).tag((NbtMap) object).build();
} else {
item = (ItemData) object;
}
this.writeItem(buffer, item, null);
break;
case VECTOR3I:
writeVector3i(buffer, (Vector3i) object);
break;
case FLAGS:
int flagsIndex = entry.getKey() == EntityData.FLAGS_2 ? 1 : 0;
object = ((EntityFlags) object).get(flagsIndex, this.entityFlags);
case LONG:
VarInts.writeLong(buffer, (long) object);
break;
case VECTOR3F:
writeVector3f(buffer, (Vector3f) object);
break;
default:
buffer.writerIndex(index);
break;
}
}
}
Aggregations