Java Code Examples for net.minecraft.nbt.NBTTagList.tagCount()

The following are Jave code examples for showing how to use tagCount() of the net.minecraft.nbt.NBTTagList class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: rezolve   File: SecurityServerEntity.java   View Source Code Vote up 6 votes
@Override
public void readFromNBT(NBTTagCompound compound) {
	
	if (compound.hasKey("RootUser")) {
		this.rootUser = compound.getString("RootUser");
	}
	
	if (compound.hasKey("Rules")) {
		NBTTagList rulesList = compound.getTagList("Rules", NBT.TAG_COMPOUND);
		this.rules = new ArrayList<Rule>();
		
		for (int i = 0, max = rulesList.tagCount(); i < max; ++i) {
			NBTTagCompound ruleNBT = (NBTTagCompound)rulesList.get(i);
			this.rules.add(new Rule(ruleNBT.getString("ID"), ruleNBT.getString("Name"), ruleNBT.getInteger("Mode")));
		}
	}
	
	if (this.rules == null || this.rules.size() == 0) {
		// Reset rules.
		this.rules = new ArrayList<Rule>();
		this.rules.add(new Rule("<machines>", Rule.MODE_OPEN));
		this.rules.add(new Rule("<players>", Rule.MODE_RESTRICTED));
	}
	
	super.readFromNBT(compound);
}
 
Example 2
Project: DecompiledMinecraft   File: EnchantmentHelper.java   View Source Code Vote up 6 votes
/**
 * Executes the enchantment modifier on the ItemStack passed.
 */
private static void applyEnchantmentModifier(EnchantmentHelper.IModifier modifier, ItemStack stack)
{
    if (stack != null)
    {
        NBTTagList nbttaglist = stack.getEnchantmentTagList();

        if (nbttaglist != null)
        {
            for (int i = 0; i < nbttaglist.tagCount(); ++i)
            {
                int j = nbttaglist.getCompoundTagAt(i).getShort("id");
                int k = nbttaglist.getCompoundTagAt(i).getShort("lvl");

                if (Enchantment.getEnchantmentById(j) != null)
                {
                    modifier.calculateModifier(Enchantment.getEnchantmentById(j), k);
                }
            }
        }
    }
}
 
Example 3
Project: BaseClient   File: ItemBanner.java   View Source Code Vote up 6 votes
/**
 * allows items to add custom lines of information to the mouseover description
 */
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
{
    NBTTagCompound nbttagcompound = stack.getSubCompound("BlockEntityTag", false);

    if (nbttagcompound != null && nbttagcompound.hasKey("Patterns"))
    {
        NBTTagList nbttaglist = nbttagcompound.getTagList("Patterns", 10);

        for (int i = 0; i < nbttaglist.tagCount() && i < 6; ++i)
        {
            NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
            EnumDyeColor enumdyecolor = EnumDyeColor.byDyeDamage(nbttagcompound1.getInteger("Color"));
            TileEntityBanner.EnumBannerPattern tileentitybanner$enumbannerpattern = TileEntityBanner.EnumBannerPattern.getPatternByID(nbttagcompound1.getString("Pattern"));

            if (tileentitybanner$enumbannerpattern != null)
            {
                tooltip.add(StatCollector.translateToLocal("item.banner." + tileentitybanner$enumbannerpattern.getPatternName() + "." + enumdyecolor.getUnlocalizedName()));
            }
        }
    }
}
 
Example 4
Project: DecompiledMinecraft   File: TileEntityChest.java   View Source Code Vote up 6 votes
public void readFromNBT(NBTTagCompound compound)
{
    super.readFromNBT(compound);
    NBTTagList nbttaglist = compound.getTagList("Items", 10);
    this.chestContents = new ItemStack[this.getSizeInventory()];

    if (compound.hasKey("CustomName", 8))
    {
        this.customName = compound.getString("CustomName");
    }

    for (int i = 0; i < nbttaglist.tagCount(); ++i)
    {
        NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
        int j = nbttagcompound.getByte("Slot") & 255;

        if (j >= 0 && j < this.chestContents.length)
        {
            this.chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);
        }
    }
}
 
Example 5
Project: ElementalElaboration   File: TileKTWithInventory.java   View Source Code Vote up 6 votes
public  void readFromNBT(NBTTagCompound tagCompound)
{
    super.readFromNBT(tagCompound);
    NBTTagList tagList = tagCompound.getTagList("Items", 10);
    this.inventory = new ItemStack[this.getSizeInventory()];

    for(int i = 0; i < tagList.tagCount(); ++i)
    {
        NBTTagCompound tempTagCompound = tagList.getCompoundTagAt(i);
        byte slot = tempTagCompound.getByte("Slot");

        if(slot >= 0 && slot < this.inventory.length)
        {
            this.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(tempTagCompound));
        }
    }

    if(tagCompound.hasKey("CustomName", 8))
    {
        this.customName = tagCompound.getString("CustomName");
    }
}
 
Example 6
Project: BaseClient   File: TileEntityDispenser.java   View Source Code Vote up 6 votes
public void readFromNBT(NBTTagCompound compound)
{
    super.readFromNBT(compound);
    NBTTagList nbttaglist = compound.getTagList("Items", 10);
    this.stacks = new ItemStack[this.getSizeInventory()];

    for (int i = 0; i < nbttaglist.tagCount(); ++i)
    {
        NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
        int j = nbttagcompound.getByte("Slot") & 255;

        if (j >= 0 && j < this.stacks.length)
        {
            this.stacks[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);
        }
    }

    if (compound.hasKey("CustomName", 8))
    {
        this.customName = compound.getString("CustomName");
    }
}
 
Example 7
Project: PAYDAY   File: LobbyTileEntity.java   View Source Code Vote up 6 votes
@Override
public void readFromNBT(NBTTagCompound compound) {
	super.readFromNBT(compound);

	NBTTagList list = compound.getTagList("playerList", 10);
	isGameLive = compound.getBoolean("isGameLive");

	players.clear();
	UUID uuid;

	for (int i = 0; i < list.tagCount(); i++) {
		uuid = getUUIDFromTag(list.getCompoundTagAt(i));

		if (worldObj != null && worldObj.playerEntities != null) {
			for (EntityPlayer player : (List<EntityPlayer>) worldObj.playerEntities) {
				if (player.getGameProfile().getId() == uuid) {
					players.add(uuid);
					break;
				}
			}
		}
	}
}
 
Example 8
Project: Bewitchment   File: BrewUtils.java   View Source Code Vote up 6 votes
public static Tuple<List<BrewEffect>, List<PotionEffect>> deSerialize(NBTTagCompound compound) {
	List<PotionEffect> potionEffects = PotionUtils.getEffectsFromTag(compound);
	List<BrewEffect> brewEffects = new ArrayList<>();
	Tuple<List<BrewEffect>, List<PotionEffect>> tuple = new Tuple<>(brewEffects, potionEffects);

	NBTTagList list = (NBTTagList) compound.getTag(BREW_DATA);
	for (int i = 0, size = list.tagCount(); i < size; i++) {
		NBTTagCompound tag = list.getCompoundTagAt(i);
		IBrew brew = BrewRegistry.getRegisteredBrew(tag.getString(BREW_ID));
		int duration = tag.getInteger(BREW_DURATION);
		int amplifier = tag.getInteger(BREW_AMPLIFIER);
		brewEffects.add(new BrewEffect(brew, duration, amplifier));
	}

	return tuple;
}
 
Example 9
Project: Backmemed   File: ItemEnchantedBook.java   View Source Code Vote up 6 votes
/**
 * allows items to add custom lines of information to the mouseover description
 */
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
{
    super.addInformation(stack, playerIn, tooltip, advanced);
    NBTTagList nbttaglist = this.getEnchantments(stack);

    if (nbttaglist != null)
    {
        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            int j = nbttaglist.getCompoundTagAt(i).getShort("id");
            int k = nbttaglist.getCompoundTagAt(i).getShort("lvl");

            if (Enchantment.getEnchantmentByID(j) != null)
            {
                tooltip.add(Enchantment.getEnchantmentByID(j).getTranslatedName(k));
            }
        }
    }
}
 
Example 10
Project: DecompiledMinecraft   File: ItemWritableBook.java   View Source Code Vote up 5 votes
/**
 * this method returns true if the book's NBT Tag List "pages" is valid
 */
public static boolean isNBTValid(NBTTagCompound nbt)
{
    if (nbt == null)
    {
        return false;
    }
    else if (!nbt.hasKey("pages", 9))
    {
        return false;
    }
    else
    {
        NBTTagList nbttaglist = nbt.getTagList("pages", 8);

        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            String s = nbttaglist.getStringTagAt(i);

            if (s == null)
            {
                return false;
            }

            if (s.length() > 32767)
            {
                return false;
            }
        }

        return true;
    }
}
 
Example 11
Project: CustomWorldGen   File: VillageCollection.java   View Source Code Vote up 5 votes
/**
 * reads in data from the NBTTagCompound into this MapDataBase
 */
public void readFromNBT(NBTTagCompound nbt)
{
    this.tickCounter = nbt.getInteger("Tick");
    NBTTagList nbttaglist = nbt.getTagList("Villages", 10);

    for (int i = 0; i < nbttaglist.tagCount(); ++i)
    {
        NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
        Village village = new Village();
        village.readVillageDataFromNBT(nbttagcompound);
        this.villageList.add(village);
    }
}
 
Example 12
Project: Anima-Mundi   File: TileEntityLinkableWorker.java   View Source Code Vote up 5 votes
@Override
public void readFromNBT(NBTTagCompound compound)
{
	if(compound.hasKey("links"))
	{
		NBTTagList linktags = compound.getTagList("links", 10);
		for(int i = 0; i < linktags.tagCount(); i++)
		{
			NBTTagCompound com = linktags.getCompoundTagAt(i);
			links.add(NodeLink.fromNBT(com));
		}
	}
	items.deserializeNBT(compound.getCompoundTag("items"));
	super.readFromNBT(compound);
}
 
Example 13
Project: chunk-logger   File: ChunkListOfPlayers.java   View Source Code Vote up 5 votes
public void readFromNBT(NBTTagList listOfPlayers) {
	int howManyTimesToLoop = listOfPlayers.tagCount();
	for (int i = 0; i < howManyTimesToLoop; i++) {
		NBTTagCompound nbt = listOfPlayers.getCompoundTagAt(i);
		LocalDateTime enterTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(nbt.getLong("enterTime")), ZoneId.systemDefault());
		UUID player = nbt.getUniqueId("PlayerUUID");
		if (nbt.getBoolean("HasLeft")) {
			LocalDateTime leaveTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(nbt.getLong("LeaveTime")), ZoneId.systemDefault());
			Duration stayTime = Duration.ofMillis(nbt.getLong("StayTime"));
			playersInChunk.add(new PlayerInChunk(enterTime, leaveTime, stayTime, player));
		} else {
			playersInChunk.add(new PlayerInChunk(enterTime, player));
		}
	}
}
 
Example 14
Project: BaseClient   File: EnchantmentHelper.java   View Source Code Vote up 5 votes
/**
 * Returns the level of enchantment on the ItemStack passed.
 */
public static int getEnchantmentLevel(int enchID, ItemStack stack)
{
    if (stack == null)
    {
        return 0;
    }
    else
    {
        NBTTagList nbttaglist = stack.getEnchantmentTagList();

        if (nbttaglist == null)
        {
            return 0;
        }
        else
        {
            for (int i = 0; i < nbttaglist.tagCount(); ++i)
            {
                int j = nbttaglist.getCompoundTagAt(i).getShort("id");
                int k = nbttaglist.getCompoundTagAt(i).getShort("lvl");

                if (j == enchID)
                {
                    return k;
                }
            }

            return 0;
        }
    }
}
 
Example 15
Project: MeeCreeps   File: ServerActionManager.java   View Source Code Vote up 5 votes
@Override
public void readFromNBT(NBTTagCompound nbt) {
    NBTTagList list = nbt.getTagList("actions", Constants.NBT.TAG_COMPOUND);
    options = new ArrayList<>();
    optionMap = new HashMap<>();
    for (int i = 0; i < list.tagCount(); i++) {
        ActionOptions opt = new ActionOptions(list.getCompoundTagAt(i));
        options.add(opt);
        optionMap.put(opt.getActionId(), opt);
    }
    lastId = nbt.getInteger("lastId");
}
 
Example 16
Project: BaseClient   File: ItemStack.java   View Source Code Vote up 5 votes
public Multimap<String, AttributeModifier> getAttributeModifiers()
{
    Multimap<String, AttributeModifier> multimap;

    if (this.hasTagCompound() && this.stackTagCompound.hasKey("AttributeModifiers", 9))
    {
        multimap = HashMultimap.<String, AttributeModifier>create();
        NBTTagList nbttaglist = this.stackTagCompound.getTagList("AttributeModifiers", 10);

        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
            AttributeModifier attributemodifier = SharedMonsterAttributes.readAttributeModifierFromNBT(nbttagcompound);

            if (attributemodifier != null && attributemodifier.getID().getLeastSignificantBits() != 0L && attributemodifier.getID().getMostSignificantBits() != 0L)
            {
                multimap.put(nbttagcompound.getString("AttributeName"), attributemodifier);
            }
        }
    }
    else
    {
        multimap = this.getItem().getItemAttributeModifiers();
    }

    return multimap;
}
 
Example 17
Project: Backmemed   File: AnvilChunkLoader.java   View Source Code Vote up 5 votes
@Nullable
public static Entity readWorldEntity(NBTTagCompound compound, World worldIn, boolean p_186051_2_)
{
    Entity entity = createEntityFromNBT(compound, worldIn);

    if (entity == null)
    {
        return null;
    }
    else if (p_186051_2_ && !worldIn.spawnEntityInWorld(entity))
    {
        return null;
    }
    else
    {
        if (compound.hasKey("Passengers", 9))
        {
            NBTTagList nbttaglist = compound.getTagList("Passengers", 10);

            for (int i = 0; i < nbttaglist.tagCount(); ++i)
            {
                Entity entity1 = readWorldEntity(nbttaglist.getCompoundTagAt(i), worldIn, p_186051_2_);

                if (entity1 != null)
                {
                    entity1.startRiding(entity, true);
                }
            }
        }

        return entity;
    }
}
 
Example 18
Project: ObsidianSuite   File: ModelObj.java   View Source Code Vote up 5 votes
public void setPartOrderFromList(NBTTagList order)
{
	ArrayList<Part> newPartList = new ArrayList<Part>();
	for (int i = 0; i < order.tagCount(); i++)
	{
		newPartList.add(getPartFromName(order.getStringTagAt(i)));
	}
	for(Part part : parts)
	{
		if(!newPartList.contains(part))
			newPartList.add(part);
	}
	parts = newPartList;
}
 
Example 19
Project: DecompiledMinecraft   File: Village.java   View Source Code Vote up 4 votes
/**
 * Read this village's data from NBT.
 */
public void readVillageDataFromNBT(NBTTagCompound p_82690_1_)
{
    this.numVillagers = p_82690_1_.getInteger("PopSize");
    this.villageRadius = p_82690_1_.getInteger("Radius");
    this.numIronGolems = p_82690_1_.getInteger("Golems");
    this.lastAddDoorTimestamp = p_82690_1_.getInteger("Stable");
    this.tickCounter = p_82690_1_.getInteger("Tick");
    this.noBreedTicks = p_82690_1_.getInteger("MTick");
    this.center = new BlockPos(p_82690_1_.getInteger("CX"), p_82690_1_.getInteger("CY"), p_82690_1_.getInteger("CZ"));
    this.centerHelper = new BlockPos(p_82690_1_.getInteger("ACX"), p_82690_1_.getInteger("ACY"), p_82690_1_.getInteger("ACZ"));
    NBTTagList nbttaglist = p_82690_1_.getTagList("Doors", 10);

    for (int i = 0; i < nbttaglist.tagCount(); ++i)
    {
        NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
        VillageDoorInfo villagedoorinfo = new VillageDoorInfo(new BlockPos(nbttagcompound.getInteger("X"), nbttagcompound.getInteger("Y"), nbttagcompound.getInteger("Z")), nbttagcompound.getInteger("IDX"), nbttagcompound.getInteger("IDZ"), nbttagcompound.getInteger("TS"));
        this.villageDoorInfoList.add(villagedoorinfo);
    }

    NBTTagList nbttaglist1 = p_82690_1_.getTagList("Players", 10);

    for (int j = 0; j < nbttaglist1.tagCount(); ++j)
    {
        NBTTagCompound nbttagcompound1 = nbttaglist1.getCompoundTagAt(j);

        if (nbttagcompound1.hasKey("UUID"))
        {
            PlayerProfileCache playerprofilecache = MinecraftServer.getServer().getPlayerProfileCache();
            GameProfile gameprofile = playerprofilecache.getProfileByUUID(UUID.fromString(nbttagcompound1.getString("UUID")));

            if (gameprofile != null)
            {
                this.playerReputation.put(gameprofile.getName(), Integer.valueOf(nbttagcompound1.getInteger("S")));
            }
        }
        else
        {
            this.playerReputation.put(nbttagcompound1.getString("Name"), Integer.valueOf(nbttagcompound1.getInteger("S")));
        }
    }
}
 
Example 20
Project: StructPro   File: Blueprint.java   View Source Code Vote up 4 votes
/**
 * Read from schematic tag
 * @param tag Control tag
 * @throws IOException If schematic tag can not be read
 */
private void readSchematic(NBTTagCompound tag) throws IOException {
    String materials = tag.getString("Materials");
    if (!materials.equals("Alpha")) {
        throw new IOException("Materials of schematic is not an alpha: [" + materials + "]");
    }
    setWidth(tag.getShort("Width"));
    setHeight(tag.getShort("Height"));
    setLength(tag.getShort("Length"));
    String dimensions = "[W=" + getWidth() + ";H=" + getHeight() + ";L=" + getLength() + "]";
    String dimLimit = "[W=" + WIDTH_LIMIT + ";H=" + HEIGHT_LIMIT + ";L=" + LENGTH_LIMIT + "]";
    if (getWidth() <= 0 || getHeight() <= 0 || getLength() <= 0) {
        throw new IOException("Schematic has non-positive dimensions: " + dimensions);
    }
    if (getWidth() > WIDTH_LIMIT || getHeight() > HEIGHT_LIMIT || getLength() > LENGTH_LIMIT) {
        throw new IOException("Schematic dimensions are too large: " + dimensions + "/" + dimLimit);
    }
    int size = getSize();
    if (size > VOLUME_LIMIT) {
        throw new IOException("Schematic is too big: " + size + "/" + VOLUME_LIMIT);
    }
    byte[] addBlocks = tag.getByteArray("AddBlocks");
    byte[] blocksID = tag.getByteArray("Blocks");
    if (size != blocksID.length) {
        throw new IOException("Wrong schematic blocks length: " + blocksID.length + "/" + size);
    }
    setBlocks(compose(blocksID, addBlocks));
    setMetas(tag.getByteArray("Data"));
    if (size != getMetas().length) {
        throw new IOException("Wrong schematic metadata length: " + blocksID.length + "/" + size);
    }
    setTiles(new NBTTagCompound[size]);
    NBTTagList tileEntities = tag.getTagList("TileEntities", Constants.NBT.TAG_COMPOUND);
    for(int i = 0; i < tileEntities.tagCount(); i++) {
        NBTTagCompound tile = tileEntities.getCompoundTagAt(i);
        int x = tile.getInteger("x");
        int y = tile.getInteger("y");
        int z = tile.getInteger("z");
        int idx = getIndex(x, y, z);
        if (idx >= 0 && idx < size) {
            setTile(tile, idx);
        }
    }
}