Java Code Examples for net.minecraft.nbt.NBTUtil#readBlockState()

The following examples show how to use net.minecraft.nbt.NBTUtil#readBlockState() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MaterialCache.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void readMapFromNBT(NBTTagCompound nbt, String tagName, IdentityHashMap<IBlockState, ItemStack> map)
{
    if (nbt.hasKey(tagName, Constants.NBT.TAG_LIST))
    {
        NBTTagList list = nbt.getTagList(tagName, Constants.NBT.TAG_COMPOUND);
        final int count = list.tagCount();

        for (int i = 0; i < count; ++i)
        {
            NBTTagCompound tag = list.getCompoundTagAt(i);

            if (tag.hasKey("Block", Constants.NBT.TAG_COMPOUND) &&
                tag.hasKey("Item", Constants.NBT.TAG_COMPOUND))
            {
                IBlockState state = NBTUtil.readBlockState(tag.getCompoundTag("Block"));

                if (state != null)
                {
                    ItemStack stack = new ItemStack(tag.getCompoundTag("Item"));
                    this.buildItemsForStates.put(state, stack);
                }
            }
        }
    }
}
 
Example 2
Source File: RenderBlockTileEntity.java    From MiningGadgets with MIT License 5 votes vote down vote up
@Override
public void read(CompoundNBT tag) {
    super.read(tag);
    renderBlock = NBTUtil.readBlockState(tag.getCompound("renderBlock"));
    originalDurability = tag.getInt("originalDurability");
    priorDurability = tag.getInt("priorDurability");
    durability = tag.getInt("durability");
    ticksSinceMine = tag.getInt("ticksSinceMine");
    playerUUID = tag.getUniqueId("playerUUID");
    gadgetUpgrades = UpgradeTools.getUpgradesFromTag(tag);
    breakType = MiningProperties.BreakTypes.values()[tag.getByte("breakType")];
    gadgetFilters = MiningProperties.deserializeItemStackList(tag.getCompound("gadgetFilters"));
    gadgetIsWhitelist = tag.getBoolean("gadgetIsWhitelist");
    blockAllowed = tag.getBoolean("blockAllowed");
}
 
Example 3
Source File: SchematicBase.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected boolean readPaletteFromLitematicaFormatTag(NBTTagList tagList, ILitematicaBlockStatePalette palette)
{
    final int size = tagList.tagCount();
    List<IBlockState> list = new ArrayList<>(size);

    for (int id = 0; id < size; ++id)
    {
        NBTTagCompound tag = tagList.getCompoundTagAt(id);
        IBlockState state = NBTUtil.readBlockState(tag);
        list.add(state);
    }

    return palette.setMapping(list);
}