use of com.nukkitx.nbt.NbtMap in project JukeboxMC by LucGamesYT.
the class BlockEntityBlastFurnace method fromCompound.
@Override
public void fromCompound(NbtMap compound) {
super.fromCompound(compound);
List<NbtMap> items = compound.getList("Items", NbtType.COMPOUND);
for (NbtMap nbtMap : items) {
Item item = this.toItem(nbtMap);
byte slot = nbtMap.getByte("Slot", (byte) 127);
if (slot == 127) {
this.blastFurnaceInventory.addItem(item, false);
} else {
this.blastFurnaceInventory.setItem(slot, item, false);
}
}
}
use of com.nukkitx.nbt.NbtMap in project JukeboxMC by LucGamesYT.
the class BlockEntityChest method fromCompound.
@Override
public void fromCompound(NbtMap compound) {
super.fromCompound(compound);
List<NbtMap> items = compound.getList("Items", NbtType.COMPOUND);
for (NbtMap nbtMap : items) {
Item item = this.toItem(nbtMap);
byte slot = nbtMap.getByte("Slot", (byte) 127);
if (slot == 127) {
this.chestInventory.addItem(item, false);
} else {
this.chestInventory.setItem(slot, item, false);
}
}
this.pairX = compound.getInt("pairx", 0);
this.pairZ = compound.getInt("pairz", 0);
this.findable = compound.getBoolean("Findable", false);
if (this.isPaired()) {
BlockEntityChest paired = this.getPaired();
if (paired == null) {
return;
}
this.pair(paired);
} else {
this.unpair();
}
}
use of com.nukkitx.nbt.NbtMap in project JukeboxMC by LucGamesYT.
the class BlockEntityChest method toCompound.
@Override
public NbtMapBuilder toCompound() {
NbtMapBuilder builder = super.toCompound();
List<NbtMap> itemsCompoundList = new ArrayList<>();
for (int slot = 0; slot < this.chestInventory.getSize(); slot++) {
NbtMapBuilder itemCompound = NbtMap.builder();
Item item = this.chestInventory.getItem(slot);
itemCompound.putByte("Slot", (byte) slot);
this.fromItem(item, itemCompound);
itemsCompoundList.add(itemCompound.build());
}
builder.putList("Items", NbtType.COMPOUND, itemsCompoundList);
builder.putInt("pairx", this.pairX);
builder.putInt("pairz", this.pairZ);
builder.putBoolean("Findable", this.findable);
return builder;
}
use of com.nukkitx.nbt.NbtMap in project JukeboxMC by LucGamesYT.
the class BlockShulkerBox method placeBlock.
@Override
public boolean placeBlock(Player player, World world, Vector blockPosition, Vector placePosition, Vector clickedPosition, Item itemIndHand, BlockFace blockFace) {
boolean value = super.placeBlock(player, world, blockPosition, placePosition, clickedPosition, itemIndHand, blockFace);
if (value) {
BlockEntityShulkerBox blockEntityShulkerBox = (BlockEntityShulkerBox) BlockEntityType.SHULKER_BOX.<BlockEntityShulkerBox>createBlockEntity(this).setUndyed(false).spawn();
if (itemIndHand.getNBT() != null && itemIndHand.getNBT().containsKey("Items")) {
NbtMap nbt = itemIndHand.getNBT();
List<NbtMap> items = nbt.getList("Items", NbtType.COMPOUND);
for (NbtMap nbtMap : items) {
Item item = blockEntityShulkerBox.toItem(nbtMap);
byte slot = nbtMap.getByte("Slot", (byte) 127);
if (slot == 127) {
blockEntityShulkerBox.getShulkerBoxInventory().addItem(item, false);
} else {
blockEntityShulkerBox.getShulkerBoxInventory().setItem(slot, item, false);
}
}
}
}
return value;
}
use of com.nukkitx.nbt.NbtMap in project JukeboxMC by LucGamesYT.
the class BlockUndyedShulkerBox method placeBlock.
@Override
public boolean placeBlock(Player player, World world, Vector blockPosition, Vector placePosition, Vector clickedPosition, Item itemIndHand, BlockFace blockFace) {
boolean value = super.placeBlock(player, world, blockPosition, placePosition, clickedPosition, itemIndHand, blockFace);
if (value) {
BlockEntityShulkerBox blockEntityShulkerBox = (BlockEntityShulkerBox) BlockEntityType.SHULKER_BOX.<BlockEntityShulkerBox>createBlockEntity(this).setUndyed(true).spawn();
if (itemIndHand.getNBT() != null && itemIndHand.getNBT().containsKey("Items")) {
NbtMap nbt = itemIndHand.getNBT();
List<NbtMap> items = nbt.getList("Items", NbtType.COMPOUND);
for (NbtMap nbtMap : items) {
Item item = blockEntityShulkerBox.toItem(nbtMap);
byte slot = nbtMap.getByte("Slot", (byte) 127);
if (slot == 127) {
blockEntityShulkerBox.getShulkerBoxInventory().addItem(item, false);
} else {
blockEntityShulkerBox.getShulkerBoxInventory().setItem(slot, item, false);
}
}
}
}
return value;
}
Aggregations