Search in sources :

Example 76 with NBTTagString

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

the class Colony method writeToNBT.

/**
 * Write colony to save data.
 *
 * @param compound compound to write to.
 */
protected void writeToNBT(@NotNull final NBTTagCompound compound) {
    // Core attributes
    compound.setInteger(TAG_ID, id);
    compound.setInteger(TAG_DIMENSION, dimensionId);
    // Basic data
    compound.setString(TAG_NAME, name);
    BlockPosUtil.writeToNBT(compound, TAG_CENTER, center);
    compound.setBoolean(TAG_MANUAL_HIRING, manualHiring);
    // Permissions
    permissions.savePermissions(compound);
    final NBTTagCompound buildingCompound = new NBTTagCompound();
    buildingManager.writeToNBT(buildingCompound);
    compound.setTag(TAG_BUILDING_MANAGER, buildingCompound);
    final NBTTagCompound citizenCompound = new NBTTagCompound();
    citizenManager.writeToNBT(citizenCompound);
    compound.setTag(TAG_CITIZEN_MANAGER, citizenCompound);
    final NBTTagCompound statsCompound = new NBTTagCompound();
    statsManager.writeToNBT(statsCompound);
    compound.setTag(TAG_STATS_MANAGER, statsCompound);
    // Workload
    @NotNull final NBTTagCompound workManagerCompound = new NBTTagCompound();
    workManager.writeToNBT(workManagerCompound);
    compound.setTag(TAG_WORK, workManagerCompound);
    // Waypoints
    @NotNull final NBTTagList wayPointTagList = new NBTTagList();
    for (@NotNull final Map.Entry<BlockPos, IBlockState> entry : wayPoints.entrySet()) {
        @NotNull final NBTTagCompound wayPointCompound = new NBTTagCompound();
        BlockPosUtil.writeToNBT(wayPointCompound, TAG_WAYPOINT, entry.getKey());
        NBTUtil.writeBlockState(wayPointCompound, entry.getValue());
        wayPointTagList.appendTag(wayPointCompound);
    }
    compound.setTag(TAG_WAYPOINT, wayPointTagList);
    // Free blocks
    @NotNull final NBTTagList freeBlocksTagList = new NBTTagList();
    for (@NotNull final Block block : freeBlocks) {
        freeBlocksTagList.appendTag(new NBTTagString(block.getRegistryName().toString()));
    }
    compound.setTag(TAG_FREE_BLOCKS, freeBlocksTagList);
    // Free positions
    @NotNull final NBTTagList freePositionsTagList = new NBTTagList();
    for (@NotNull final BlockPos pos : freePositions) {
        @NotNull final NBTTagCompound wayPointCompound = new NBTTagCompound();
        BlockPosUtil.writeToNBT(wayPointCompound, TAG_FREE_POSITIONS, pos);
        freePositionsTagList.appendTag(wayPointCompound);
    }
    compound.setTag(TAG_FREE_POSITIONS, freePositionsTagList);
    compound.setDouble(TAG_HAPPINESS, overallHappiness);
    compound.setInteger(TAG_ABANDONED, packageManager.getLastContactInHours());
    compound.setBoolean(TAG_MANUAL_HOUSING, manualHousing);
    compound.setTag(TAG_REQUESTMANAGER, getRequestManager().serializeNBT());
    compound.setString(TAG_STYLE, style);
    compound.setBoolean(TAG_RAIDABLE, barbarianManager.canHaveBarbEvents());
    compound.setBoolean(TAG_AUTO_DELETE, canColonyBeAutoDeleted);
    this.colonyTag = compound;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Block(net.minecraft.block.Block) NBTTagString(net.minecraft.nbt.NBTTagString) BlockPos(net.minecraft.util.math.BlockPos) NotNull(org.jetbrains.annotations.NotNull)

Example 77 with NBTTagString

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

the class Permissions method savePermissions.

/**
 * Save the permissionMap to a NBT.
 *
 * @param compound NBT to write to.
 */
public void savePermissions(@NotNull final NBTTagCompound compound) {
    // Owners
    @NotNull final NBTTagList ownerTagList = new NBTTagList();
    for (@NotNull final Player player : players.values()) {
        @NotNull final NBTTagCompound ownersCompound = new NBTTagCompound();
        ownersCompound.setString(TAG_ID, player.getID().toString());
        ownersCompound.setString(TAG_RANK, player.getRank().name());
        ownerTagList.appendTag(ownersCompound);
    }
    compound.setTag(TAG_OWNERS, ownerTagList);
    // Permissions
    @NotNull final NBTTagList permissionsTagList = new NBTTagList();
    for (@NotNull final Map.Entry<Rank, Integer> entry : permissionMap.entrySet()) {
        @NotNull final NBTTagCompound permissionsCompound = new NBTTagCompound();
        permissionsCompound.setString(TAG_RANK, entry.getKey().name());
        @NotNull final NBTTagList flagsTagList = new NBTTagList();
        for (@NotNull final Action action : Action.values()) {
            if (Utils.testFlag(entry.getValue(), action.getFlag())) {
                flagsTagList.appendTag(new NBTTagString(action.name()));
            }
        }
        permissionsCompound.setTag(TAG_FLAGS, flagsTagList);
        permissionsTagList.appendTag(permissionsCompound);
    }
    compound.setTag(TAG_PERMISSIONS, permissionsTagList);
    if (!ownerName.isEmpty()) {
        compound.setString(TAG_OWNER, ownerName);
    }
    if (ownerUUID != null) {
        compound.setString(TAG_OWNER_ID, ownerUUID.toString());
    }
    compound.setBoolean(TAG_UPDATE, updatedPermissionAlready);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) Player(com.minecolonies.api.colony.permissions.Player) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Action(com.minecolonies.api.colony.permissions.Action) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) Rank(com.minecolonies.api.colony.permissions.Rank) NotNull(org.jetbrains.annotations.NotNull)

Example 78 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project Minestuck by mraof.

the class ItemDowel method addInformation.

@Override
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
    if (stack.hasTagCompound()) {
        NBTTagCompound nbttagcompound = stack.getTagCompound();
        NBTTagString contentID = (NBTTagString) nbttagcompound.getTag("contentID");
        NBTTagInt contentMeta = (NBTTagInt) nbttagcompound.getTag("contentMeta");
        if (contentID != null && contentMeta != null && Item.REGISTRY.containsKey(new ResourceLocation(contentID.getString()))) {
            tooltip.add("(" + (AlchemyRecipeHandler.getDecodedItem(stack)).getDisplayName() + ")");
            return;
        } else {
            tooltip.add("(" + I18n.translateToLocal("item.captchaCard.invalid") + ")");
        }
    }
}
Also used : NBTTagInt(net.minecraft.nbt.NBTTagInt) ResourceLocation(net.minecraft.util.ResourceLocation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 79 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project BetterQuesting by Funwayguy.

the class ItemComparison method CompareNBTTag.

public static boolean CompareNBTTag(NBTBase tag1, NBTBase tag2, boolean partial) {
    if ((tag1 == null && tag2 != null) || (tag1 != null && tag2 == null)) {
        return false;
    } else if (tag1 == null && tag2 == null) {
        return true;
    }
    if (tag1 instanceof NBTTagCompound && tag2 instanceof NBTTagCompound) {
        return CompareNBTTagCompound((NBTTagCompound) tag1, (NBTTagCompound) tag2, partial);
    } else if (tag1 instanceof NBTTagList && tag2 instanceof NBTTagList) {
        NBTTagList list1 = (NBTTagList) tag1;
        NBTTagList list2 = (NBTTagList) tag2;
        if (list1.tagCount() > list2.tagCount() || (!partial && list1.tagCount() != list2.tagCount())) {
            // Sample is missing requested tags or is not exact
            return false;
        }
        topLoop: for (int i = 0; i < list1.tagCount(); i++) {
            NBTBase lt1 = list1.getCompoundTagAt(i);
            for (int j = 0; j < list2.tagCount(); j++) {
                if (CompareNBTTag(lt1, list2.getCompoundTagAt(j), partial)) {
                    continue topLoop;
                }
            }
            // Couldn't find requested tag in list
            return false;
        }
    } else if (tag1 instanceof NBTTagIntArray && tag2 instanceof NBTTagIntArray) {
        NBTTagIntArray list1 = (NBTTagIntArray) tag1;
        NBTTagIntArray list2 = (NBTTagIntArray) tag2;
        if (list1.getIntArray().length > list2.getIntArray().length || (!partial && list1.getIntArray().length != list2.getIntArray().length)) {
            // Sample is missing requested tags or is not exact
            return false;
        }
        topLoop: for (int i = 0; i < list1.getIntArray().length; i++) {
            for (int j = 0; j < list2.getIntArray().length; j++) {
                if (list1.getIntArray()[i] == list2.getIntArray()[j]) {
                    continue topLoop;
                }
            }
            // Couldn't find requested integer in list
            return false;
        }
        return false;
    } else if (tag1 instanceof NBTTagByteArray && tag2 instanceof NBTTagByteArray) {
        NBTTagByteArray list1 = (NBTTagByteArray) tag1;
        NBTTagByteArray list2 = (NBTTagByteArray) tag2;
        if (list1.getByteArray().length > list2.getByteArray().length || (!partial && list1.getByteArray().length != list2.getByteArray().length)) {
            // Sample is missing requested tags or is not exact
            return false;
        }
        // Duplicate control
        ArrayList<Integer> usedIdxs = new ArrayList<Integer>();
        topLoop: for (int i = 0; i < list1.getByteArray().length; i++) {
            for (int j = 0; j < list2.getByteArray().length; j++) {
                if (usedIdxs.contains(j)) {
                    continue;
                } else if (list1.getByteArray()[i] == list2.getByteArray()[j]) {
                    usedIdxs.add(j);
                    continue topLoop;
                }
            }
            // Couldn't find requested integer in list
            return false;
        }
        return false;
    } else if (tag1 instanceof NBTTagString && tag2 instanceof NBTTagString) {
        return tag1.equals(tag2);
    } else if (// Standardize numbers to not care about format
    tag1 instanceof NBTPrimitive && tag2 instanceof NBTPrimitive) {
        Number num1 = NBTConverter.getNumber(tag1);
        Number num2 = NBTConverter.getNumber(tag2);
        // Second number will be cast to the requested number format
        if (tag1 instanceof NBTTagFloat || tag1 instanceof NBTTagDouble) {
            return num1.doubleValue() == num2.doubleValue();
        } else {
            return num1.longValue() == num2.longValue();
        }
    } else {
        return tag1.equals(tag2);
    }
    return true;
}
Also used : NBTPrimitive(net.minecraft.nbt.NBTPrimitive) NBTTagFloat(net.minecraft.nbt.NBTTagFloat) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ArrayList(java.util.ArrayList) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray) NBTTagList(net.minecraft.nbt.NBTTagList) NBTBase(net.minecraft.nbt.NBTBase) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagByteArray(net.minecraft.nbt.NBTTagByteArray) NBTTagDouble(net.minecraft.nbt.NBTTagDouble)

Example 80 with NBTTagString

use of net.minecraft.nbt.NBTTagString in project Binnie by ForestryMC.

the class GeneTracker method writeToNBT.

@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
    for (ISpeciesRoot root : AlleleManager.alleleRegistry.getSpeciesRoot().values()) {
        NBTTagCompound nbtRoot = new NBTTagCompound();
        for (IChromosomeType chromo : root.getKaryotype()) {
            NBTTagList nbtChromo = new NBTTagList();
            for (IGene gene : discoveredGenes) {
                if (gene.getSpeciesRoot() == root && gene.getChromosome() == chromo) {
                    nbtChromo.appendTag(new NBTTagString(gene.getAllele().getUID()));
                }
            }
            nbtRoot.setTag(String.valueOf(chromo.ordinal()), nbtChromo);
        }
        nbt.setTag(root.getUID(), nbtRoot);
    }
    return nbt;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IGene(binnie.core.api.genetics.IGene) NBTTagString(net.minecraft.nbt.NBTTagString) IChromosomeType(forestry.api.genetics.IChromosomeType)

Aggregations

NBTTagString (net.minecraft.nbt.NBTTagString)101 NBTTagList (net.minecraft.nbt.NBTTagList)82 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)57 ItemStack (net.minecraft.item.ItemStack)18 NBTTagIntArray (net.minecraft.nbt.NBTTagIntArray)11 NBTBase (net.minecraft.nbt.NBTBase)10 NBTTagByteArray (net.minecraft.nbt.NBTTagByteArray)10 NBTTagInt (net.minecraft.nbt.NBTTagInt)10 NBTTagDouble (net.minecraft.nbt.NBTTagDouble)9 NBTTagFloat (net.minecraft.nbt.NBTTagFloat)9 NBTTagByte (net.minecraft.nbt.NBTTagByte)8 NBTTagLong (net.minecraft.nbt.NBTTagLong)8 ResourceLocation (net.minecraft.util.ResourceLocation)8 List (java.util.List)7 NBTTagShort (net.minecraft.nbt.NBTTagShort)7 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Item (net.minecraft.item.Item)4