Search in sources :

Example 1 with NBTUtil

use of net.minecraft.nbt.NBTUtil in project BuildCraft by BuildCraft.

the class SchematicBlockDefault method serializeNBT.

@Override
public NBTTagCompound serializeNBT() {
    NBTTagCompound nbt = new NBTTagCompound();
    nbt.setTag("requiredBlockOffsets", NBTUtilBC.writeCompoundList(requiredBlockOffsets.stream().map(NBTUtil::createPosTag)));
    nbt.setTag("blockState", NBTUtil.writeBlockState(new NBTTagCompound(), blockState));
    nbt.setTag("ignoredProperties", NBTUtilBC.writeStringList(ignoredProperties.stream().map(IProperty::getName)));
    if (tileNbt != null) {
        nbt.setTag("tileNbt", tileNbt);
    }
    nbt.setTag("tileRotation", NBTUtilBC.writeEnum(tileRotation));
    nbt.setString("placeBlock", Block.REGISTRY.getNameForObject(placeBlock).toString());
    nbt.setTag("updateBlockOffsets", NBTUtilBC.writeCompoundList(updateBlockOffsets.stream().map(NBTUtil::createPosTag)));
    nbt.setTag("canBeReplacedWithBlocks", NBTUtilBC.writeStringList(canBeReplacedWithBlocks.stream().map(Block.REGISTRY::getNameForObject).map(Object::toString)));
    return nbt;
}
Also used : IProperty(net.minecraft.block.properties.IProperty) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Block(net.minecraft.block.Block) ISchematicBlock(buildcraft.api.schematics.ISchematicBlock) NBTUtil(net.minecraft.nbt.NBTUtil)

Example 2 with NBTUtil

use of net.minecraft.nbt.NBTUtil in project minecolonies by Minecolonies.

the class CompatabilityManager method readFromNBT.

@Override
public void readFromNBT(@NotNull final NBTTagCompound compound) {
    leavesToSaplingMap.putAll(NBTUtils.streamCompound(compound.getTagList(TAG_SAP_LEAVE, Constants.NBT.TAG_COMPOUND)).map(CompatabilityManager::readLeaveSaplingEntryFromNBT).collect(Collectors.toMap(Tuple::getFirst, Tuple::getSecond)));
    final List<ItemStorage> storages = NBTUtils.streamCompound(compound.getTagList(TAG_SAPLINGS, Constants.NBT.TAG_COMPOUND)).map(tempCompound -> new ItemStorage(new ItemStack(tempCompound))).collect(Collectors.toList());
    // Filter duplicated values.
    for (final ItemStorage storage : storages) {
        if (!saplings.contains(storage)) {
            saplings.add(storage);
        }
    }
    final List<IBlockState> states = NBTUtils.streamCompound(compound.getTagList(TAG_ORES, Constants.NBT.TAG_COMPOUND)).map(NBTUtil::readBlockState).collect(Collectors.toList());
    for (final IBlockState state : states) {
        if (!ores.contains(state.getBlock())) {
            ores.add(state.getBlock());
        }
    }
}
Also used : ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) Constants(net.minecraftforge.common.util.Constants) SAPLINGS(com.minecolonies.api.util.constant.Constants.SAPLINGS) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) NBTTagList(net.minecraft.nbt.NBTTagList) Block(net.minecraft.block.Block) OreDictionary(net.minecraftforge.oredict.OreDictionary) CreativeTabs(net.minecraft.creativetab.CreativeTabs) NonNullList(net.minecraft.util.NonNullList) Log(com.minecolonies.api.util.Log) BlockOre(net.minecraft.block.BlockOre) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BiMap(com.google.common.collect.BiMap) World(net.minecraft.world.World) Tuple(net.minecraft.util.Tuple) BlockRedstoneOre(net.minecraft.block.BlockRedstoneOre) Collectors(java.util.stream.Collectors) BlockLeaves(net.minecraft.block.BlockLeaves) IBlockState(net.minecraft.block.state.IBlockState) HashBiMap(com.google.common.collect.HashBiMap) List(java.util.List) NbtTagConstants(com.minecolonies.api.util.constant.NbtTagConstants) NBTUtils(com.minecolonies.api.util.NBTUtils) ItemBlock(net.minecraft.item.ItemBlock) ItemStorage(com.minecolonies.api.crafting.ItemStorage) NotNull(org.jetbrains.annotations.NotNull) NBTUtil(net.minecraft.nbt.NBTUtil) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) Tuple(net.minecraft.util.Tuple) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Aggregations

Block (net.minecraft.block.Block)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTUtil (net.minecraft.nbt.NBTUtil)2 ISchematicBlock (buildcraft.api.schematics.ISchematicBlock)1 BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 ItemStorage (com.minecolonies.api.crafting.ItemStorage)1 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)1 Log (com.minecolonies.api.util.Log)1 NBTUtils (com.minecolonies.api.util.NBTUtils)1 SAPLINGS (com.minecolonies.api.util.constant.Constants.SAPLINGS)1 NbtTagConstants (com.minecolonies.api.util.constant.NbtTagConstants)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 BlockLeaves (net.minecraft.block.BlockLeaves)1 BlockOre (net.minecraft.block.BlockOre)1 BlockRedstoneOre (net.minecraft.block.BlockRedstoneOre)1 IProperty (net.minecraft.block.properties.IProperty)1 IBlockState (net.minecraft.block.state.IBlockState)1