Java Code Examples for net.minecraft.nbt.NBTTagCompound#removeTag()

The following examples show how to use net.minecraft.nbt.NBTTagCompound#removeTag() . 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: FluidStorageInventoryHandler.java    From ExtraCells1 with MIT License 6 votes vote down vote up
private FluidStack readFluidStackFromSlot(int slotID)
{
	if (storage.stackTagCompound == null)
		storage.stackTagCompound = new NBTTagCompound();
	NBTTagCompound nbt = storage.stackTagCompound;

	// Temporary Code, will stay 5 versions!
	int oldFluidID = nbt.getInteger("FluidID#" + slotID);
	long oldFluidAmount = nbt.getLong("FluidAmount#" + slotID);
	if (oldFluidID > 0 && oldFluidAmount > 0)
	{
		return new FluidStack(oldFluidID, (int) oldFluidAmount);
	}
	nbt.removeTag("FluidID#" + slotID);
	nbt.removeTag("FluidAmount#" + slotID);

	return FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag("Fluid#" + slotID));
}
 
Example 2
Source File: VanillaStructure.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void writeEntitiesToTag(NBTTagCompound tag)
{
    NBTTagList tagList = new NBTTagList();

    for (EntityInfo info : this.entities)
    {
        NBTTagCompound entityData = new NBTTagCompound();
        NBTUtils.writeVec3dToListTag(info.pos, entityData, "pos");
        NBTUtils.writeBlockPosToListTag(new BlockPos(info.pos), entityData, "blockPos");
        NBTTagCompound entityTag = info.nbt.copy();

        entityTag.removeTag("Pos");
        entityData.setTag("nbt", entityTag);

        tagList.appendTag(entityData);
    }

    tag.setTag("entities", tagList);
}
 
Example 3
Source File: FluidStorageInventoryHandler.java    From ExtraCells1 with MIT License 6 votes vote down vote up
private void writeFluidStackToSlot(int slotID, FluidStack input)
{
	cachedInventory.set(slotID, input);

	if (storage.stackTagCompound == null)
		storage.stackTagCompound = new NBTTagCompound();
	NBTTagCompound nbt = storage.stackTagCompound;

	if (input != null)
	{
		NBTTagCompound fluidTag = new NBTTagCompound();
		input.writeToNBT(fluidTag);
		nbt.setCompoundTag("Fluid#" + slotID, fluidTag);
	} else
	{
		nbt.removeTag("Fluid#" + slotID);
	}
}
 
Example 4
Source File: SlimeBlock.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
@Override
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
	NBTTagCompound data = entity.getEntityData();
	if (data.hasKey(Reference.MOD_ID + ":slime")) {
		entity.motionY = data.getDouble(Reference.MOD_ID + ":slime");
		data.removeTag(Reference.MOD_ID + ":slime");
	}

	if (Math.abs(entity.motionY) < 0.1 && !entity.isSneaking()) {
		double d = 0.4 + Math.abs(entity.motionY) * 0.2;
		entity.motionX *= d;
		entity.motionZ *= d;
	}
}
 
Example 5
Source File: ItemRailConfigurator.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
public MCPos getLinkedRail(ItemStack stack){
    NBTTagCompound tag = stack.getSubCompound("linkingRail");
    if(tag != null) {
        if(tag.hasKey("dim")) {
            //Legacy conversion FIXME remove in 1.13
            tag.setInteger("d", tag.getInteger("dim"));
            tag.removeTag("dim");
        }
        return new MCPos(tag);
    }
    return null;
}
 
Example 6
Source File: TileArcanePackager.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void writeCustomNBT(NBTTagCompound compound) {
    super.writeCustomNBT(compound);
    compound.removeTag("AspectFilter");

    compound.setByte("progress", progress);

    byte settings = (byte) (autoStart ? 1 : 0);
    settings |= useEssentia ? 2 : 0;
    settings |= disguise ? 4 : 0;
    compound.setByte("settings", settings);
}
 
Example 7
Source File: PlayerCivilization.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
public NBTTagCompound writeNBT() {
	NBTTagCompound c = new NBTTagCompound();
	c.setTag("reputations", buildNBTReputationList());
	c.setTag("quests", buildQuestCompound(quests));
	c.setTag("nextQuests", buildQuestCompound(nextQuests));
	c.setInteger("completedQuests", completedQuests);
	c.setTag("completedQuestsByProvince", buildCompletedQuestsByProvince());

	if (inCiv != null) {
		c.setTag("inCiv", inCiv.writeNBT());
	} else {
		c.removeTag("inCiv");
	}
	return c;
}
 
Example 8
Source File: EntityToroNpc.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void writeEntityToNBT(NBTTagCompound compound) {
	super.writeEntityToNBT(compound);
	String civ = s(getCivilization());
	if (isSet(civ)) {
		compound.setString("civilization", s(getCivilization()));
	} else {
		compound.removeTag("civilization");
	}
}
 
Example 9
Source File: EntityElevatorCapsule.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
public void copyDataFromOld(Entity entityIn)
{
	NBTTagCompound nbttagcompound = entityIn.writeToNBT(new NBTTagCompound());
	nbttagcompound.removeTag("Dimension");
	nbttagcompound.removeTag("Passengers");
	this.readFromNBT(nbttagcompound);
	this.timeUntilPortal = entityIn.timeUntilPortal;
}
 
Example 10
Source File: NBTUtils.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Writes the ItemStacks in <b>items</b> to the NBTTagCompound <b>nbt</b>
 * in a NBTTagList by the name <b>tagName</b>.
 * @param nbt
 * @param items
 * @param tagName the NBTTagList tag name where the items will be written to
 * @param keepExtraSlots set to true to append existing items in slots that are outside of the currently written slot range
 */
@Nonnull
public static NBTTagCompound writeItemsToTag(@Nonnull NBTTagCompound nbt, NonNullList<ItemStack> items,
        @Nonnull String tagName, boolean keepExtraSlots)
{
    int invSlots = items.size();
    NBTTagList nbtTagList = createTagListForItems(items);

    if (keepExtraSlots && nbt.hasKey(tagName, Constants.NBT.TAG_LIST))
    {
        // Read the old items and append any existing items that are outside the current written slot range
        NBTTagList nbtTagListExisting = nbt.getTagList(tagName, Constants.NBT.TAG_COMPOUND);
        final int count = nbtTagListExisting.tagCount();

        for (int i = 0; i < count; i++)
        {
            NBTTagCompound tag = nbtTagListExisting.getCompoundTagAt(i);
            int slotNum = tag.getShort("Slot");

            if (slotNum >= invSlots)
            {
                nbtTagList.appendTag(tag);
            }
        }
    }

    // Write the items to the compound tag
    if (nbtTagList.tagCount() > 0)
    {
        nbt.setTag(tagName, nbtTagList);
    }
    else
    {
        nbt.removeTag(tagName);
    }

    return nbt;
}
 
Example 11
Source File: Experience.java    From Levels with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the amount of Attribute Tokens the specific NBT tag has.
 * @param nbt
 * @param tokens
 */
public static void setAttributeTokens(NBTTagCompound nbt, int tokens)
{
	if (nbt != null)
	{
		if (tokens > 0)
			nbt.setInteger("TOKENS", tokens);
		else
			nbt.removeTag("TOKENS");
	}
}
 
Example 12
Source File: EntityRocket.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
/**
 * Prepares this entity in new dimension by copying NBT data from entity in old dimension
 */
public void copyDataFromOld(Entity entityIn)
{
	NBTTagCompound nbttagcompound = entityIn.writeToNBT(new NBTTagCompound());
	nbttagcompound.removeTag("Dimension");
	nbttagcompound.removeTag("Passengers");
	this.readFromNBT(nbttagcompound);
	this.timeUntilPortal = entityIn.timeUntilPortal;
}
 
Example 13
Source File: BlockPosEU.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void removeFromNBT(NBTTagCompound nbt)
{
    if (nbt == null)
    {
        return;
    }

    nbt.removeTag("BlockPos");
}
 
Example 14
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void removeCornerPositionTag(ItemStack stack, Mode mode, boolean isStart)
{
    int sel = this.getSelectionIndex(stack);
    NBTTagCompound tag = this.getModeTag(stack, mode);
    tag = NBTUtils.getCompoundTag(tag, TAG_NAME_CORNERS + "_" + sel, true);
    tag.removeTag(isStart ? "Pos1" : "Pos2");
}
 
Example 15
Source File: GolemUpgrade.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void removeUpgrade(NBTTagCompound compound) {
    if(compound.hasKey(UPGRADE_COMPOUND)) {
        compound.removeTag(getTagName());
    }
}
 
Example 16
Source File: TileBlockProtector.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void writeCustomNBT(NBTTagCompound compound) {
    super.writeCustomNBT(compound);
    compound.removeTag("AspectFilter");
    compound.setInteger("ProtectRange", range);
}
 
Example 17
Source File: NBTUtils.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Stores a cached snapshot of the current inventory in a compound tag <b>InvCache</b>.
 * It is meant for tooltip use in the ItemBlocks.
 * @param nbt
 * @return
 */
public static NBTTagCompound storeCachedInventory(NBTTagCompound nbt, IItemHandler inv, int maxEntries)
{
    NBTTagList list = new NBTTagList();
    int stacks = 0;
    long items = 0;
    final int size = inv.getSlots();

    for (int slot = 0; slot < size; slot++)
    {
        ItemStack stack = inv.getStackInSlot(slot);

        if (stack.isEmpty() == false)
        {
            if (stacks < maxEntries)
            {
                NBTTagCompound tag = new NBTTagCompound();
                tag.setString("dn", stack.getDisplayName());
                tag.setInteger("c", stack.getCount());
                list.appendTag(tag);
            }

            stacks++;
            items += stack.getCount();
        }
    }

    if (stacks > 0)
    {
        NBTTagCompound wrapper = new NBTTagCompound();
        wrapper.setTag("il", list);
        wrapper.setInteger("ts", stacks);
        wrapper.setLong("ti", items);
        nbt.setTag("InvCache", wrapper);
    }
    else
    {
        nbt.removeTag("InvCache");
    }

    return nbt;
}
 
Example 18
Source File: BlockTeleportRail.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Prepares this entity in new dimension by copying NBT data from entity in old dimension
 */
private static void copyDataFromOld(Entity newEntity, Entity entityIn){
    NBTTagCompound nbttagcompound = entityIn.writeToNBT(new NBTTagCompound());
    nbttagcompound.removeTag("Dimension");
    newEntity.readFromNBT(nbttagcompound);
}
 
Example 19
Source File: NBTUtils.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void removePositionFromTileEntityNBT(@Nonnull NBTTagCompound tag)
{
    tag.removeTag("x");
    tag.removeTag("y");
    tag.removeTag("z");
}
 
Example 20
Source File: ItemRuler.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Writes the given block position to the selected module, to the selected position.
 * If the given position is null, or is equal to the stored position, then the position is removed.
 */
public void setOrRemovePosition(ItemStack rulerStack, BlockPosEU pos, boolean isPos1, boolean adjustPosition)
{
    ItemStack moduleStack = this.getSelectedModuleStack(rulerStack, ModuleType.TYPE_MEMORY_CARD_MISC);

    if (moduleStack.isEmpty() == false)
    {
        if (adjustPosition)
        {
            pos = pos.offset(pos.getFacing());
        }

        int selected = this.getLocationSelection(rulerStack);
        NBTTagList tagList = NBTUtils.getTagList(moduleStack, TAG_WRAPPER, TAG_LOCATIONS, Constants.NBT.TAG_COMPOUND, true);

        if (selected >= tagList.tagCount())
        {
            tagList.appendTag(new NBTTagCompound());
        }

        NBTTagCompound tag = tagList.getCompoundTagAt(selected);
        String tagName = isPos1 ? "Pos1" : "Pos2";
        BlockPosEU oldPos = BlockPosEU.readFromTag(tag.getCompoundTag(tagName));

        if (pos == null || pos.equals(oldPos))
        {
            tag.removeTag(tagName);
        }
        else
        {
            tag.setTag(tagName, pos.writeToTag(new NBTTagCompound()));
        }

        if (selected >= tagList.tagCount())
        {
            tagList = NBTUtils.insertToTagList(tagList, tag, selected);
        }
        else
        {
            tagList.set(selected, tag);
        }

        NBTUtils.setTagList(moduleStack, TAG_WRAPPER, TAG_LOCATIONS, tagList);

        this.setSelectedModuleStack(rulerStack, ModuleType.TYPE_MEMORY_CARD_MISC, moduleStack);
    }
}