Java Code Examples for net.minecraft.nbt.NBTTagCompound.setString()

The following are Jave code examples for showing how to use setString() of the net.minecraft.nbt.NBTTagCompound 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: StructPro   File: Blueprint.java   View Source Code Vote up 6 votes
/**
 * Write to schematic tags
 * @return Control tag
 */
private NBTTagCompound getSchematic() {
    NBTTagCompound tag = new NBTTagCompound();
    tag.setString("Materials", "Alpha");
    tag.setShort("Width", (short) getWidth());
    tag.setShort("Height", (short) getHeight());
    tag.setShort("Length", (short) getLength());
    tag.setByteArray("AddBlocks", new byte[0]);
    byte[] blocksID = new byte[getBlocks().length];
    for (int i = 0; i < getBlocks().length; ++i) {
        blocksID[i] = (byte) getBlock(i);
    }
    tag.setByteArray("Blocks", blocksID);
    tag.setByteArray("AddBlocks", getAddBlocks(getBlocks()));
    tag.setByteArray("Data", getMetas());
    NBTTagList tileEntities = new NBTTagList();
    for (NBTTagCompound tile : getTiles()) {
        if (tile != null) {
            tileEntities.appendTag(tile);
        }
    }
    tag.setTag("TileEntities", tileEntities);
    return tag;
}
 
Example 2
Project: DecompiledMinecraft   File: Entity.java   View Source Code Vote up 6 votes
/**
 * Like writeToNBTOptional but does not check if the entity is ridden. Used for saving ridden entities with their
 * riders.
 */
public boolean writeMountToNBT(NBTTagCompound tagCompund)
{
    String s = this.getEntityString();

    if (!this.isDead && s != null)
    {
        tagCompund.setString("id", s);
        this.writeToNBT(tagCompund);
        return true;
    }
    else
    {
        return false;
    }
}
 
Example 3
Project: Bewitchment   File: TileOven.java   View Source Code Vote up 6 votes
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
	super.writeToNBT(compound);
	compound.setTag("items", inventory.saveToNbt());

	if (inventory.hasCustomName()) {
		compound.setString("CustomName", this.customName);
	}

	compound.setInteger("WorkTime", (short) this.workTime);
	compound.setInteger("totalWorkTime", (short) this.totalWorkTime);
	compound.setInteger("BurnTime", (short) this.burnTime);
	compound.setInteger("itemBurnTime", (short) this.itemBurnTime);
	compound.setBoolean("isBurning", this.isBurning);
	return compound;
}
 
Example 4
Project: BaseClient   File: EntityItem.java   View Source Code Vote up 6 votes
/**
 * (abstract) Protected helper method to write subclass entity data to NBT.
 */
public void writeEntityToNBT(NBTTagCompound tagCompound)
{
    tagCompound.setShort("Health", (short)((byte)this.health));
    tagCompound.setShort("Age", (short)this.age);
    tagCompound.setShort("PickupDelay", (short)this.delayBeforeCanPickup);

    if (this.getThrower() != null)
    {
        tagCompound.setString("Thrower", this.thrower);
    }

    if (this.getOwner() != null)
    {
        tagCompound.setString("Owner", this.owner);
    }

    if (this.getEntityItem() != null)
    {
        tagCompound.setTag("Item", this.getEntityItem().writeToNBT(new NBTTagCompound()));
    }
}
 
Example 5
Project: Backmemed   File: CommandResultStats.java   View Source Code Vote up 6 votes
public void writeStatsToNBT(NBTTagCompound tagcompound)
{
    NBTTagCompound nbttagcompound = new NBTTagCompound();

    for (CommandResultStats.Type commandresultstats$type : CommandResultStats.Type.values())
    {
        String s = this.entitiesID[commandresultstats$type.getTypeID()];
        String s1 = this.objectives[commandresultstats$type.getTypeID()];

        if (s != null && s1 != null)
        {
            nbttagcompound.setString(commandresultstats$type.getTypeName() + "Name", s);
            nbttagcompound.setString(commandresultstats$type.getTypeName() + "Objective", s1);
        }
    }

    if (!nbttagcompound.hasNoTags())
    {
        tagcompound.setTag("CommandStats", nbttagcompound);
    }
}
 
Example 6
Project: DecompiledMinecraft   File: TileEntityHopper.java   View Source Code Vote up 6 votes
public void writeToNBT(NBTTagCompound compound)
{
    super.writeToNBT(compound);
    NBTTagList nbttaglist = new NBTTagList();

    for (int i = 0; i < this.inventory.length; ++i)
    {
        if (this.inventory[i] != null)
        {
            NBTTagCompound nbttagcompound = new NBTTagCompound();
            nbttagcompound.setByte("Slot", (byte)i);
            this.inventory[i].writeToNBT(nbttagcompound);
            nbttaglist.appendTag(nbttagcompound);
        }
    }

    compound.setTag("Items", nbttaglist);
    compound.setInteger("TransferCooldown", this.transferCooldown);

    if (this.hasCustomName())
    {
        compound.setString("CustomName", this.customName);
    }
}
 
Example 7
Project: DecompiledMinecraft   File: ScoreboardSaveData.java   View Source Code Vote up 6 votes
protected void func_96497_d(NBTTagCompound p_96497_1_)
{
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    boolean flag = false;

    for (int i = 0; i < 19; ++i)
    {
        ScoreObjective scoreobjective = this.theScoreboard.getObjectiveInDisplaySlot(i);

        if (scoreobjective != null)
        {
            nbttagcompound.setString("slot_" + i, scoreobjective.getName());
            flag = true;
        }
    }

    if (flag)
    {
        p_96497_1_.setTag("DisplaySlots", nbttagcompound);
    }
}
 
Example 8
Project: CustomWorldGen   File: TileEntityFurnace.java   View Source Code Vote up 5 votes
public NBTTagCompound writeToNBT(NBTTagCompound compound)
{
    super.writeToNBT(compound);
    compound.setInteger("BurnTime", this.furnaceBurnTime);
    compound.setInteger("CookTime", this.cookTime);
    compound.setInteger("CookTimeTotal", this.totalCookTime);
    NBTTagList nbttaglist = new NBTTagList();

    for (int i = 0; i < this.furnaceItemStacks.length; ++i)
    {
        if (this.furnaceItemStacks[i] != null)
        {
            NBTTagCompound nbttagcompound = new NBTTagCompound();
            nbttagcompound.setByte("Slot", (byte)i);
            this.furnaceItemStacks[i].writeToNBT(nbttagcompound);
            nbttaglist.appendTag(nbttagcompound);
        }
    }

    compound.setTag("Items", nbttaglist);

    if (this.hasCustomName())
    {
        compound.setString("CustomName", this.furnaceCustomName);
    }

    return compound;
}
 
Example 9
Project: ObsidianSuite   File: AnimationParenting.java   View Source Code Vote up 5 votes
public static NBTTagCompound getSaveData(ModelObj model)
{
	NBTTagCompound parentNBT = new NBTTagCompound();
	NBTTagList parentNBTList = new NBTTagList();

	for (PartObj part : model.getPartObjs())
	{
		Set<PartObj> children = part.getChildren();
		List<PartObj> mergeParts = part.getMergedParts();
		if (!children.isEmpty() || !mergeParts.isEmpty())
		{
			NBTTagCompound parentCompound = new NBTTagCompound();
			parentCompound.setString("Parent", part.getName());

			int i = 0;
			for (PartObj child : children)
			{
				String name = child.getName();
				if (child.hasBend())
				{
					name += "*";
				}
				parentCompound.setString("Child" + i, name);
				i++;
			}
			
			for(int j = 0; j < mergeParts.size(); j++)
			{
				PartObj mergedPart = mergeParts.get(j);
				parentCompound.setString("Merged" + j, mergedPart.getName());
			}

			parentNBTList.appendTag(parentCompound);
		}

	}

	parentNBT.setTag("Parenting", parentNBTList);
	return parentNBT;
}
 
Example 10
Project: CustomWorldGen   File: TileEntityHopper.java   View Source Code Vote up 5 votes
public NBTTagCompound writeToNBT(NBTTagCompound compound)
{
    super.writeToNBT(compound);

    if (!this.checkLootAndWrite(compound))
    {
        NBTTagList nbttaglist = new NBTTagList();

        for (int i = 0; i < this.inventory.length; ++i)
        {
            if (this.inventory[i] != null)
            {
                NBTTagCompound nbttagcompound = new NBTTagCompound();
                nbttagcompound.setByte("Slot", (byte)i);
                this.inventory[i].writeToNBT(nbttagcompound);
                nbttaglist.appendTag(nbttagcompound);
            }
        }

        compound.setTag("Items", nbttaglist);
    }

    compound.setInteger("TransferCooldown", this.transferCooldown);

    if (this.hasCustomName())
    {
        compound.setString("CustomName", this.customName);
    }

    return compound;
}
 
Example 11
Project: pnc-repressurized   File: TileEntitySentryTurret.java   View Source Code Vote up 5 votes
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
    super.writeToNBT(tag);
    tag.setTag("Items", inventory.serializeNBT());
    tag.setByte("redstoneMode", (byte) redstoneMode);
    tag.setString("entityFilter", entityFilter);
    return tag;
}
 
Example 12
Project: Backmemed   File: CommandBlockBaseLogic.java   View Source Code Vote up 5 votes
public NBTTagCompound writeToNBT(NBTTagCompound p_189510_1_)
{
    p_189510_1_.setString("Command", this.commandStored);
    p_189510_1_.setInteger("SuccessCount", this.successCount);
    p_189510_1_.setString("CustomName", this.customName);
    p_189510_1_.setBoolean("TrackOutput", this.trackOutput);

    if (this.lastOutput != null && this.trackOutput)
    {
        p_189510_1_.setString("LastOutput", ITextComponent.Serializer.componentToJson(this.lastOutput));
    }

    this.resultStats.writeStatsToNBT(p_189510_1_);
    return p_189510_1_;
}
 
Example 13
Project: DecompiledMinecraft   File: EntityList.java   View Source Code Vote up 5 votes
/**
 * create a new instance of an entity from NBT store
 */
public static Entity createEntityFromNBT(NBTTagCompound nbt, World worldIn)
{
    Entity entity = null;

    if ("Minecart".equals(nbt.getString("id")))
    {
        nbt.setString("id", EntityMinecart.EnumMinecartType.byNetworkID(nbt.getInteger("Type")).getName());
        nbt.removeTag("Type");
    }

    try
    {
        Class <? extends Entity > oclass = (Class)stringToClassMapping.get(nbt.getString("id"));

        if (oclass != null)
        {
            entity = (Entity)oclass.getConstructor(new Class[] {World.class}).newInstance(new Object[] {worldIn});
        }
    }
    catch (Exception exception)
    {
        exception.printStackTrace();
    }

    if (entity != null)
    {
        entity.readFromNBT(nbt);
    }
    else
    {
        logger.warn("Skipping Entity with id " + nbt.getString("id"));
    }

    return entity;
}
 
Example 14
Project: Adventurers-Toolbox   File: TConstructCompat.java   View Source Code Vote up 5 votes
public static void preInit() {
	//Add soulforged steel as a liquid
	if (Loader.isModLoaded("betterwithmods")) {
		Fluid soulforgedSteel = new Fluid("soulforged_steel", new ResourceLocation("tconstruct:blocks/fluids/molten_metal"), new ResourceLocation("tconstruct:blocks/fluids/molten_metal_flow"));
		FluidRegistry.registerFluid(soulforgedSteel);
		FluidRegistry.addBucketForFluid(soulforgedSteel);

		NBTTagCompound tag = new NBTTagCompound();
		tag.setString("fluid", soulforgedSteel.getName());
		tag.setString("ore", "SoulforgedSteel");
		tag.setBoolean("toolforge", false);
		FMLInterModComms.sendMessage("tconstruct", "integrateSmeltery", tag);
	}
}
 
Example 15
Project: Backmemed   File: TileEntityEnchantmentTable.java   View Source Code Vote up 5 votes
public NBTTagCompound writeToNBT(NBTTagCompound compound)
{
    super.writeToNBT(compound);

    if (this.hasCustomName())
    {
        compound.setString("CustomName", this.customName);
    }

    return compound;
}
 
Example 16
Project: ObsidianSuite   File: AnimationSequence.java   View Source Code Vote up 5 votes
public NBTTagCompound getSaveData()
{
	NBTTagCompound sequenceData = new NBTTagCompound();
	NBTTagList animationList = new NBTTagList();
	for(AnimationPart animation : getAnimationList())
		animationList.appendTag(animation.getSaveData());
	sequenceData.setTag("Animations", animationList);
	sequenceData.setString("EntityName", entityName);
	sequenceData.setString("Name", animationName);
	sequenceData.setInteger("FPS", fps);
	sequenceData.setTag("Actions", getActionsSaveData());
	return sequenceData;
}
 
Example 17
Project: DecompiledMinecraft   File: EntityPigZombie.java   View Source Code Vote up 5 votes
/**
 * (abstract) Protected helper method to write subclass entity data to NBT.
 */
public void writeEntityToNBT(NBTTagCompound tagCompound)
{
    super.writeEntityToNBT(tagCompound);
    tagCompound.setShort("Anger", (short)this.angerLevel);

    if (this.angerTargetUUID != null)
    {
        tagCompound.setString("HurtBy", this.angerTargetUUID.toString());
    }
    else
    {
        tagCompound.setString("HurtBy", "");
    }
}
 
Example 18
Project: Industrial-Foregoing   File: MaterialStoneWorkFactoryTile.java   View Source Code Vote up 5 votes
public void nextMode(int id) {
    Map.Entry<ItemStackHandler, Mode> it = getEntry(id);
    modeList.replace(it.getKey(), Mode.values()[(Arrays.asList(Mode.values()).indexOf(it.getValue()) + 1) % Mode.values().length]);
    if (TeslaCoreLib.INSTANCE.isClientSide()) {
        NBTTagCompound compound = this.setupSpecialNBTMessage("CHANGE_MODE");
        Map.Entry<ItemStackHandler, Mode> mode = getEntry(id);
        compound.setInteger("id", id);
        compound.setString("value", mode.getValue().toString());
        this.sendToServer(compound);
    }
}
 
Example 19
Project: CustomWorldGen   File: Entity.java   View Source Code Vote up 5 votes
protected HoverEvent getHoverEvent()
{
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    String s = EntityList.getEntityString(this);
    nbttagcompound.setString("id", this.getCachedUniqueIdString());

    if (s != null)
    {
        nbttagcompound.setString("type", s);
    }

    nbttagcompound.setString("name", this.getName());
    return new HoverEvent(HoverEvent.Action.SHOW_ENTITY, new TextComponentString(nbttagcompound.toString()));
}
 
Example 20
Project: HeroUtils   File: IMC.java   View Source Code Vote up 3 votes
/**
 * Blacklist an item for a specified host.
 * <p/>
 * This can be used to prevent certain components to be installed in select
 * devices, via the devices class. For example, this is used to prevent
 * components that would not be functional in certain devices to be
 * installed in those devices, such as graphics cards in micro-controllers.
 * <p/>
 * The host class is the class of the environment the component would be
 * installed in, e.g. {@link li.cil.oc.api.internal.Tablet}.
 *
 * @param name  the name of the component being blacklisted.
 * @param host  the class of the host to blacklist the component for.
 * @param stack the item stack representing the blacklisted component.
 */
public static void blacklistHost(String name, Class host, ItemStack stack) {
    final NBTTagCompound nbt = new NBTTagCompound();
    nbt.setString("name", name);
    nbt.setString("host", host.getName());
    final NBTTagCompound stackNbt = new NBTTagCompound();
    stack.writeToNBT(stackNbt);
    nbt.setTag("item", stackNbt);
    FMLInterModComms.sendMessage(MOD_ID, "blacklistHost", nbt);
}