Search in sources :

Example 31 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project AgriCraft by AgriCraft.

the class AgriGenome method readFromNBT.

@Override
@SuppressWarnings("unchecked")
public boolean readFromNBT(@Nonnull CompoundNBT tag) {
    if (tag.contains(AgriNBT.GENOME)) {
        ListNBT list = tag.getList(AgriNBT.GENOME, 10);
        for (int i = 0; i < list.size(); i++) {
            CompoundNBT geneTag = list.getCompound(i);
            AgriGeneRegistry.getInstance().get(geneTag.getString(AgriNBT.GENE)).ifPresent(gene -> {
                this.geneMap.put(gene, this.generateGenePairFromNBT(gene, geneTag));
            });
        }
        return this.getPlant().isPlant();
    }
    return false;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT)

Example 32 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project AgriCraft by AgriCraft.

the class IrrigationNetworkLayer method writeToTag.

public CompoundNBT writeToTag() {
    CompoundNBT tag = new CompoundNBT();
    tag.putDouble(AgriNBT.Y1, this.getMin());
    tag.putDouble(AgriNBT.Y2, this.getMax());
    tag.putInt(AgriNBT.LEVEL, this.getVolume());
    return tag;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT)

Example 33 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project BluePower by Qmunity.

the class BlockInsulatedAlloyWire method getCloneItemStack.

@Override
public ItemStack getCloneItemStack(IBlockReader world, BlockPos pos, BlockState state) {
    TileEntity tileentity = world.getBlockEntity(pos);
    ItemStack stack = ItemStack.EMPTY;
    if (tileentity instanceof TileBPMultipart) {
        tileentity = ((TileBPMultipart) tileentity).getTileForState(state);
    }
    if (tileentity instanceof TileInsulatedWire) {
        CompoundNBT nbt = new CompoundNBT();
        nbt.putString("color", ((TileInsulatedWire) tileentity).getColor().name());
        stack = new ItemStack(this, 1, nbt);
    }
    return stack;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CompoundNBT(net.minecraft.nbt.CompoundNBT) TileInsulatedWire(com.bluepowermod.tile.tier1.TileInsulatedWire) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart) ItemStack(net.minecraft.item.ItemStack)

Example 34 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project BluePower by Qmunity.

the class BlockBPMicroblock method getCloneItemStack.

@Override
public ItemStack getCloneItemStack(IBlockReader world, BlockPos pos, BlockState state) {
    TileEntity tileentity = world.getBlockEntity(pos);
    ItemStack stack = ItemStack.EMPTY;
    if (tileentity instanceof TileBPMultipart) {
        tileentity = ((TileBPMultipart) tileentity).getTileForState(state);
    }
    if (tileentity instanceof TileBPMicroblock) {
        CompoundNBT nbt = new CompoundNBT();
        nbt.putString("block", ((TileBPMicroblock) tileentity).getBlock().getRegistryName().toString());
        stack = new ItemStack(this);
        stack.setTag(nbt);
        stack.setHoverName(new TranslationTextComponent(((TileBPMicroblock) tileentity).getBlock().getDescriptionId()).append(new StringTextComponent(" ")).append(new TranslationTextComponent(this.getDescriptionId())));
    }
    return stack;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileBPMicroblock(com.bluepowermod.tile.TileBPMicroblock) CompoundNBT(net.minecraft.nbt.CompoundNBT) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart) ItemStack(net.minecraft.item.ItemStack)

Example 35 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project BluePower by Qmunity.

the class BluePowerAPI method loadSilkySettings.

@Override
public void loadSilkySettings(World world, BlockPos pos, ItemStack stack) {
    TileEntity te = world.getBlockEntity(pos);
    BlockState blockState = world.getBlockState(pos);
    if (te == null)
        throw new IllegalStateException("This block doesn't have a tile entity?!");
    if (stack.isEmpty())
        throw new IllegalArgumentException("ItemStack is empty!");
    if (stack.hasTag()) {
        CompoundNBT tag = stack.getTag();
        if (tag.contains("tileData")) {
            if (te instanceof IAdvancedSilkyRemovable) {
                ((IAdvancedSilkyRemovable) te).readSilkyData(world, pos, tag.getCompound("tileData"));
            } else if (blockState.getBlock() instanceof IAdvancedSilkyRemovable) {
                ((IAdvancedSilkyRemovable) blockState.getBlock()).readSilkyData(world, pos, tag.getCompound("tileData"));
            } else {
                CompoundNBT tileTag = tag.getCompound("tileData");
                tileTag.putInt("x", pos.getX());
                tileTag.putInt("y", pos.getY());
                tileTag.putInt("z", pos.getZ());
                te.load(blockState, tileTag);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) CompoundNBT(net.minecraft.nbt.CompoundNBT) IAdvancedSilkyRemovable(com.bluepowermod.api.block.IAdvancedSilkyRemovable)

Aggregations

CompoundNBT (net.minecraft.nbt.CompoundNBT)127 ItemStack (net.minecraft.item.ItemStack)33 ListNBT (net.minecraft.nbt.ListNBT)19 Nonnull (javax.annotation.Nonnull)12 PlayerEntity (net.minecraft.entity.player.PlayerEntity)10 BlockPos (net.minecraft.util.math.BlockPos)10 ResourceLocation (net.minecraft.util.ResourceLocation)9 BlockState (net.minecraft.block.BlockState)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 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