use of net.minecraft.nbt.CompoundNBT in project BluePower by Qmunity.
the class TileEjector method load.
/**
* This function gets called whenever the world/chunk loads
*/
@Override
public void load(BlockState blockState, CompoundNBT tCompound) {
super.load(blockState, tCompound);
for (int i = 0; i < 9; i++) {
CompoundNBT tc = tCompound.getCompound("inventory" + i);
inventory.set(i, new ItemStack((IItemProvider) tc));
}
}
use of net.minecraft.nbt.CompoundNBT in project BluePower by Qmunity.
the class ItemStackDatabase method loadItemStacks.
public List<ItemStack> loadItemStacks() {
if (cache == null) {
File targetRegistryName = new File(saveLocation);
List<ItemStack> stacks = new ArrayList<ItemStack>();
if (targetRegistryName.exists()) {
File[] files = targetRegistryName.listFiles();
for (File file : files) {
try {
FileInputStream fos = new FileInputStream(file);
DataInputStream dos = new DataInputStream(fos);
short short1 = dos.readShort();
byte[] abyte = new byte[short1];
dos.read(abyte);
ByteArrayInputStream byteStream = new ByteArrayInputStream(abyte);
CompoundNBT tag = CompressedStreamTools.readCompressed(byteStream);
ItemStack stack = ItemStack.of(tag);
if (stack.getItem() != Items.AIR) {
stacks.add(stack);
} else {
BluePower.log.error("Couldn't retrieve an itemstack with item id: " + tag.getShort("id"));
Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(tag.getString("owner"), tag.getString("name")));
if (item != null && item != Items.AIR) {
ItemStack backupStack = new ItemStack(item, stack.getCount());
backupStack.setDamageValue(tag.getShort("Damage"));
if (stack.hasTag()) {
backupStack.setTag(stack.getTag());
}
stacks.add(backupStack);
BluePower.log.info("Successfully retrieved stack via its name: " + tag.getString("owner") + ":" + tag.getString("name"));
} else {
BluePower.log.error("Couldn't retrieve the item via its name: " + tag.getString("owner") + ":" + tag.getString("name"));
}
}
dos.close();
} catch (IOException e) {
BluePower.log.error("Exception : " + e);
}
}
}
cache = stacks;
}
return cache;
}
use of net.minecraft.nbt.CompoundNBT in project BluePower by Qmunity.
the class ItemFloppyDisk method finaliseDisk.
public static void finaliseDisk(ItemStack itemStack, String name, MinecraftColor color) {
CompoundNBT nbt = new CompoundNBT();
nbt.putInt("color", color.getHex());
nbt.putString("name", name);
itemStack.setTag(nbt);
}
use of net.minecraft.nbt.CompoundNBT in project BluePower by Qmunity.
the class TileBPMultipart method getUpdatePacket.
@Override
public SUpdateTileEntityPacket getUpdatePacket() {
CompoundNBT nbtTag = new CompoundNBT();
save(nbtTag);
return new SUpdateTileEntityPacket(getBlockPos(), 1, nbtTag);
}
use of net.minecraft.nbt.CompoundNBT in project BluePower by Qmunity.
the class TileBPMultipart method onDataPacket.
@Override
public void onDataPacket(NetworkManager networkManager, SUpdateTileEntityPacket packet) {
List<BlockState> states = getStates();
CompoundNBT tagCompound = packet.getTag();
super.onDataPacket(networkManager, packet);
load(getBlockState(), tagCompound);
if (level.isClientSide) {
// Update if needed
if (!getStates().equals(states)) {
level.blockEntityChanged(getBlockPos(), this.getTileEntity());
}
}
}
Aggregations