Search in sources :

Example 86 with CompoundNBT

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));
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ItemStack(net.minecraft.item.ItemStack) IItemProvider(net.minecraft.util.IItemProvider)

Example 87 with CompoundNBT

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;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ArrayList(java.util.ArrayList) Item(net.minecraft.item.Item) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStack(net.minecraft.item.ItemStack)

Example 88 with CompoundNBT

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);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT)

Example 89 with CompoundNBT

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);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) SUpdateTileEntityPacket(net.minecraft.network.play.server.SUpdateTileEntityPacket)

Example 90 with CompoundNBT

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());
        }
    }
}
Also used : IForgeBlockState(net.minecraftforge.common.extensions.IForgeBlockState) BlockState(net.minecraft.block.BlockState) CompoundNBT(net.minecraft.nbt.CompoundNBT)

Aggregations

CompoundNBT (net.minecraft.nbt.CompoundNBT)119 ItemStack (net.minecraft.item.ItemStack)33 ListNBT (net.minecraft.nbt.ListNBT)15 Nonnull (javax.annotation.Nonnull)12 PlayerEntity (net.minecraft.entity.player.PlayerEntity)10 ResourceLocation (net.minecraft.util.ResourceLocation)8 BlockPos (net.minecraft.util.math.BlockPos)8 TileEntity (net.minecraft.tileentity.TileEntity)7 StringTextComponent (net.minecraft.util.text.StringTextComponent)7 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)6 DimensionType (net.minecraft.world.dimension.DimensionType)6 TileBPMultipart (com.bluepowermod.tile.TileBPMultipart)5 Block (net.minecraft.block.Block)5 BlockState (net.minecraft.block.BlockState)5 ArrayList (java.util.ArrayList)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)4 SUpdateTileEntityPacket (net.minecraft.network.play.server.SUpdateTileEntityPacket)4 LongItemStack (com.cjm721.overloaded.storage.stacks.intint.LongItemStack)3 Nullable (javax.annotation.Nullable)3 IItemProvider (net.minecraft.util.IItemProvider)3