use of cn.nukkit.nbt.tag.ListTag in project Nukkit by Nukkit.
the class BlockBrewingStand method place.
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (!block.down().isTransparent()) {
getLevel().setBlock(block, this, true, true);
CompoundTag nbt = new CompoundTag().putList(new ListTag<>("Items")).putString("id", BlockEntity.BREWING_STAND).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
if (item.hasCustomName()) {
nbt.putString("CustomName", item.getCustomName());
}
if (item.hasCustomBlockData()) {
Map<String, Tag> customData = item.getCustomBlockData().getTags();
for (Map.Entry<String, Tag> tag : customData.entrySet()) {
nbt.put(tag.getKey(), tag.getValue());
}
}
new BlockEntityBrewingStand(getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
return true;
}
return false;
}
use of cn.nukkit.nbt.tag.ListTag in project Nukkit by Nukkit.
the class BlockFurnaceBurning method place.
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
int[] faces = { 2, 5, 3, 4 };
this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]);
this.getLevel().setBlock(block, this, true, true);
CompoundTag nbt = new CompoundTag().putList(new ListTag<>("Items")).putString("id", BlockEntity.FURNACE).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
if (item.hasCustomName()) {
nbt.putString("CustomName", item.getCustomName());
}
if (item.hasCustomBlockData()) {
Map<String, Tag> customData = item.getCustomBlockData().getTags();
for (Map.Entry<String, Tag> tag : customData.entrySet()) {
nbt.put(tag.getKey(), tag.getValue());
}
}
new BlockEntityFurnace(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
return true;
}
use of cn.nukkit.nbt.tag.ListTag in project Nukkit by Nukkit.
the class BlockFallable method onUpdate.
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
Block down = this.down();
if (down.getId() == AIR || down instanceof BlockLiquid) {
this.level.setBlock(this, Block.get(Block.AIR), true, true);
CompoundTag nbt = new CompoundTag().putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", this.x + 0.5)).add(new DoubleTag("", this.y)).add(new DoubleTag("", this.z + 0.5))).putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("", 0)).add(new DoubleTag("", 0)).add(new DoubleTag("", 0))).putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("", 0)).add(new FloatTag("", 0))).putInt("TileID", this.getId()).putByte("Data", this.getDamage());
EntityFallingBlock fall = new EntityFallingBlock(this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
fall.spawnToAll();
}
}
return type;
}
use of cn.nukkit.nbt.tag.ListTag in project Nukkit by Nukkit.
the class BlockEntityFurnace method initBlockEntity.
@Override
protected void initBlockEntity() {
this.inventory = new FurnaceInventory(this);
if (!this.namedTag.contains("Items") || !(this.namedTag.get("Items") instanceof ListTag)) {
this.namedTag.putList(new ListTag<CompoundTag>("Items"));
}
for (int i = 0; i < this.getSize(); i++) {
this.inventory.setItem(i, this.getItem(i));
}
if (!this.namedTag.contains("BurnTime") || this.namedTag.getShort("BurnTime") < 0) {
burnTime = 0;
} else {
burnTime = this.namedTag.getShort("BurnTime");
}
if (!this.namedTag.contains("CookTime") || this.namedTag.getShort("CookTime") < 0 || (this.namedTag.getShort("BurnTime") == 0 && this.namedTag.getShort("CookTime") > 0)) {
cookTime = 0;
} else {
cookTime = this.namedTag.getShort("CookTime");
}
if (!this.namedTag.contains("MaxTime")) {
maxTime = burnTime;
burnDuration = 0;
} else {
maxTime = this.namedTag.getShort("MaxTime");
}
if (this.namedTag.contains("BurnTicks")) {
burnDuration = this.namedTag.getShort("BurnTicks");
this.namedTag.remove("BurnTicks");
}
if (burnTime > 0) {
this.scheduleUpdate();
}
super.initBlockEntity();
}
use of cn.nukkit.nbt.tag.ListTag in project Nukkit by Nukkit.
the class BlockEntityHopper method initBlockEntity.
@Override
protected void initBlockEntity() {
if (this.namedTag.contains("TransferCooldown")) {
this.transferCooldown = this.namedTag.getInt("TransferCooldown");
}
this.inventory = new HopperInventory(this);
if (!this.namedTag.contains("Items") || !(this.namedTag.get("Items") instanceof ListTag)) {
this.namedTag.putList(new ListTag<CompoundTag>("Items"));
}
for (int i = 0; i < this.getSize(); i++) {
this.inventory.setItem(i, this.getItem(i));
}
this.pickupArea = new SimpleAxisAlignedBB(this.x, this.y, this.z, this.x + 1, this.y + 2, this.z + 1);
this.scheduleUpdate();
super.initBlockEntity();
}
Aggregations