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;
}
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);
}
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") + ")");
}
}
}
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;
}
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;
}
Aggregations