use of com.nukkitx.nbt.NbtMapBuilder in project Geyser by GeyserMC.
the class ItemFrameEntity method getDefaultTag.
private NbtMap getDefaultTag() {
NbtMapBuilder builder = NbtMap.builder();
builder.putInt("x", bedrockPosition.getX());
builder.putInt("y", bedrockPosition.getY());
builder.putInt("z", bedrockPosition.getZ());
builder.putByte("isMovable", (byte) 1);
builder.putString("id", this.definition.entityType() == EntityType.GLOW_ITEM_FRAME ? "GlowItemFrame" : "ItemFrame");
return builder.build();
}
use of com.nukkitx.nbt.NbtMapBuilder in project Geyser by GeyserMC.
the class ItemFrameEntity method setItemRotation.
public void setItemRotation(IntEntityMetadata entityMetadata) {
rotation = entityMetadata.getPrimitiveValue() * 45;
if (cachedTag == null) {
return;
}
NbtMapBuilder builder = cachedTag.toBuilder();
builder.putFloat("ItemRotation", rotation);
cachedTag = builder.build();
changed = true;
}
use of com.nukkitx.nbt.NbtMapBuilder 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.nbt.NbtMapBuilder in project Geyser by GeyserMC.
the class BlockEntityTranslator method getBlockEntityTag.
public NbtMap getBlockEntityTag(BlockEntityType type, int x, int y, int z, CompoundTag tag, int blockState) {
NbtMapBuilder tagBuilder = getConstantBedrockTag(BlockEntityUtils.getBedrockBlockEntityId(type), x, y, z);
translateTag(tagBuilder, tag, blockState);
return tagBuilder.build();
}
use of com.nukkitx.nbt.NbtMapBuilder in project Geyser by GeyserMC.
the class FlowerPotBlockEntityTranslator method getTag.
/**
* Get the Nukkit CompoundTag of the flower pot.
*
* @param blockState Java block state of flower pot.
* @param position Bedrock position of flower pot.
* @return Bedrock tag of flower pot.
*/
public static NbtMap getTag(GeyserSession session, int blockState, Vector3i position) {
NbtMapBuilder tagBuilder = NbtMap.builder().putInt("x", position.getX()).putInt("y", position.getY()).putInt("z", position.getZ()).putByte("isMovable", (byte) 1).putString("id", "FlowerPot");
// Get the Java name of the plant inside. e.g. minecraft:oak_sapling
String name = BlockStateValues.getFlowerPotValues().get(blockState);
if (name != null) {
// Get the Bedrock CompoundTag of the block.
// This is where we need to store the *Java* name because Bedrock has six minecraft:sapling blocks with different block states.
NbtMap plant = session.getBlockMappings().getFlowerPotBlocks().get(name);
if (plant != null) {
tagBuilder.put("PlantBlock", plant.toBuilder().build());
}
}
return tagBuilder.build();
}
Aggregations