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

The following examples show how to use net.minecraft.nbt.NBTTagCompound#setByte() . 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: TileEntityEngine.java    From archimedes-ships with MIT License 6 votes vote down vote up
@Override
public void writeToNBT(NBTTagCompound compound)
{
	super.writeToNBT(compound);
	compound.setInteger("burn", burnTime);
	compound.setShort("fuelCons", (short) engineFuelConsumption);
	compound.setFloat("power", enginePower);
	NBTTagList list = new NBTTagList();
	for (int i = 0; i < getSizeInventory(); i++)
	{
		if (itemstacks[i] != null)
		{
			NBTTagCompound comp = new NBTTagCompound();
			comp.setByte("i", (byte) i);
			itemstacks[i].writeToNBT(comp);
			list.appendTag(comp);
		}
	}
	compound.setTag("inv", list);
}
 
Example 2
Source File: TileEntityBloomeryFurnace.java    From GardenCollection with MIT License 6 votes vote down vote up
@Override
public void writeToNBT (NBTTagCompound tag) {
    super.writeToNBT(tag);

    tag.setShort("BurnTime", (short)furnaceBurnTime);
    tag.setShort("CookTime", (short)furnaceCookTime);

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

    tag.setTag("Items", list);

    if (hasCustomInventoryName())
        tag.setString("CustomName", customName);
}
 
Example 3
Source File: TileEntityElevatorBase.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void writeToNBT(NBTTagCompound tag){
    super.writeToNBT(tag);
    tag.setFloat("extension", extension);
    tag.setFloat("targetExtension", targetExtension);
    tag.setInteger("redstoneMode", redstoneMode);
    tag.setInteger("maxFloorHeight", maxFloorHeight);
    for(int i = 0; i < 6; i++) {
        tag.setBoolean("sideConnected" + i, sidesConnected[i]);
    }

    // Write the ItemStacks in the inventory to NBT
    NBTTagList tagList = new NBTTagList();
    for(int currentIndex = 0; currentIndex < inventory.length; ++currentIndex) {
        if(inventory[currentIndex] != null) {
            NBTTagCompound tagCompound = new NBTTagCompound();
            tagCompound.setByte("Slot", (byte)currentIndex);
            inventory[currentIndex].writeToNBT(tagCompound);
            tagList.appendTag(tagCompound);
        }
    }
    tag.setTag("Items", tagList);

}
 
Example 4
Source File: TileContainer.java    From Production-Line with MIT License 6 votes vote down vote up
@Override
@Nonnull
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    NBTTagCompound nbt = super.writeToNBT(compound);

    NBTTagList slotList = new NBTTagList();
    for (int i = 0; i < this.getSizeInventory(); ++i) {
        if (this.tileSlots.get(i) != null) {
            NBTTagCompound tag = new NBTTagCompound();
            tag.setByte("Slot", (byte) i);
            this.tileSlots.get(i).writeToNBT(tag);
            slotList.appendTag(tag);
        }
    }
    nbt.setTag("Items", slotList);

    if (this.hasCustomName()) {
        nbt.setString("CustomName", this.name);
    }
    return nbt;
}
 
Example 5
Source File: TileEntityTerminalFluid.java    From ExtraCells1 with MIT License 6 votes vote down vote up
@Override
public void writeToNBT(NBTTagCompound nbt)
{
	super.writeToNBT(nbt);
	NBTTagList nbttaglist = new NBTTagList();

	for (int i = 0; i < inventory.slots.size(); ++i)
	{
		if (inventory.slots.get(i) != null)
		{
			NBTTagCompound nbttagcompound1 = new NBTTagCompound();
			nbttagcompound1.setByte("Slot", (byte) i);
			inventory.slots.get(i).writeToNBT(nbttagcompound1);
			nbttaglist.appendTag(nbttagcompound1);
		}
	}
	nbt.setTag("Items", nbttaglist);
	if (getInventory().isInvNameLocalized())
	{
		nbt.setString("CustomName", this.customName);
	}
	nbt.setInteger("currentFluid", currentFluid != null ? currentFluid.getID() : -1);
}
 
Example 6
Source File: EntityEnderArrow.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * (abstract) Protected helper method to write subclass entity data to NBT.
 */
public void writeEntityToNBT(NBTTagCompound tagCompound)
{
    tagCompound.setInteger("xTile", (short)this.blockX);
    tagCompound.setInteger("yTile", (short)this.blockY);
    tagCompound.setInteger("zTile", (short)this.blockZ);
    tagCompound.setInteger("inTile", Block.getIdFromBlock(this.inBlock));
    tagCompound.setByte("inData", (byte)this.inData);
    tagCompound.setShort("life", (short)this.ticksInGround);
    tagCompound.setByte("shake", (byte)this.arrowShake);
    tagCompound.setByte("inGround", (byte)(this.inGround ? 1 : 0));
    tagCompound.setByte("pickup", (byte)this.canBePickedUp);
    tagCompound.setLong("shooterUUIDMost", this.shooterUUID.getMostSignificantBits());
    tagCompound.setLong("shooterUUIDLeast", this.shooterUUID.getLeastSignificantBits());
    if (this.tpTarget != null)
    {
        this.tpTarget.writeToNBT(tagCompound);
    }
    tagCompound.setByte("tpMode", this.tpMode);
    tagCompound.setBoolean("Persistence", this.applyPersistence);
}
 
Example 7
Source File: GT_TileEntity_MegaBlastFurnace.java    From bartworks with MIT License 5 votes vote down vote up
@Override
public void saveNBTData(NBTTagCompound aNBT) {
    super.saveNBTData(aNBT);
    aNBT.setByte("glasTier", glasTier);
    aNBT.setByte("circuitMode", circuitMode);
    aNBT.setLong("lEUt", lEUt);
}
 
Example 8
Source File: TileArcanePackager.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void writeToNBT(NBTTagCompound compound) {
    super.writeToNBT(compound);

    NBTTagList list = new NBTTagList();
    for (int i = 0; i < contents.length; ++i) {
        if (contents[i] != null) {
            NBTTagCompound slot = new NBTTagCompound();
            slot.setByte("Slot", (byte) i);
            contents[i].writeToNBT(slot);
            list.appendTag(slot);
        }
    }
    compound.setTag("Items", list);
}
 
Example 9
Source File: EntityShip.java    From archimedes-ships with MIT License 5 votes vote down vote up
@Override
protected void writeEntityToNBT(NBTTagCompound compound)
{
	super.writeEntityToNBT(compound);
	ByteArrayOutputStream baos = new ByteArrayOutputStream(shipChunk.getMemoryUsage());
	DataOutputStream out = new DataOutputStream(baos);
	try
	{
		ChunkIO.writeAll(out, shipChunk);
		out.flush();
		out.close();
	} catch (IOException e)
	{
		e.printStackTrace();
	}
	compound.setByteArray("chunk", baos.toByteArray());
	compound.setByte("seatX", (byte) seatX);
	compound.setByte("seatY", (byte) seatY);
	compound.setByte("seatZ", (byte) seatZ);
	compound.setByte("front", (byte) frontDirection);
	
	if (!shipChunk.chunkTileEntityMap.isEmpty())
	{
		NBTTagList tileentities = new NBTTagList();
		for (TileEntity tileentity : shipChunk.chunkTileEntityMap.values())
		{
			NBTTagCompound comp = new NBTTagCompound();
			tileentity.writeToNBT(comp);
			tileentities.appendTag(comp);
		}
		compound.setTag("tileent", tileentities);
	}
	
	compound.setString("name", info.shipName);
	if (info.owner != null)
	{
		compound.setString("owner", info.owner);
	}
}
 
Example 10
Source File: MoCEntityHorse.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void writeEntityToNBT(NBTTagCompound nbttagcompound)
{
    super.writeEntityToNBT(nbttagcompound);
    nbttagcompound.setBoolean("Saddle", getIsRideable());
    nbttagcompound.setBoolean("EatingHaystack", getEating());
    nbttagcompound.setBoolean("ChestedHorse", getChestedHorse());
    nbttagcompound.setBoolean("HasReproduced", getHasReproduced());
    nbttagcompound.setBoolean("Bred", getHasBred());
    nbttagcompound.setBoolean("DisplayName", getDisplayName());
    nbttagcompound.setInteger("ArmorType", getArmorType());
    //nbttagcompound.setInteger("InventorySize", getInventorySize());
    //System.out.println("Writing NBT for horse " + getName() + ", getChestedHorse = " + getChestedHorse());
    if (getChestedHorse() && localhorsechest != null)
    {
        NBTTagList nbttaglist = new NBTTagList();
        for (int i = 0; i < localhorsechest.getSizeInventory(); i++)
        {
            // grab the current item stack
            localstack = localhorsechest.getStackInSlot(i);
            if (localstack != null)
            {
                //System.out.println("localstack = " + localstack.toString());
                NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                nbttagcompound1.setByte("Slot", (byte) i);
                localstack.writeToNBT(nbttagcompound1);
                nbttaglist.appendTag(nbttagcompound1);
            }
        }
        nbttagcompound.setTag("Items", nbttaglist);
    }

}
 
Example 11
Source File: Position.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
public void writeToNBT(NBTTagCompound nbttagcompound) {
	if (orientation == null) {
		orientation = ForgeDirection.UNKNOWN;
	}

	nbttagcompound.setDouble("i", x);
	nbttagcompound.setDouble("j", y);
	nbttagcompound.setDouble("k", z);
	nbttagcompound.setByte("orientation", (byte) orientation.ordinal());
}
 
Example 12
Source File: TileGuidanceComputerHatch.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void readDataFromNetwork(ByteBuf in, byte packetId,
		NBTTagCompound nbt) {
	if(packetId == redstoneState)
		nbt.setByte("state", in.readByte());
	else {

		nbt.setShort("status", in.readShort());

	}
}
 
Example 13
Source File: ProgWidgetItemFilter.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
private static void saveItemStackByName(ItemStack stack, NBTTagCompound tag){
    tag.setString("id", GameData.getItemRegistry().getNameForObject(stack.getItem()));
    tag.setByte("Count", (byte)stack.stackSize);
    tag.setShort("Damage", (short)stack.getItemDamage());
    if(stack.hasTagCompound()) {
        tag.setTag("tag", stack.getTagCompound());
    }
}
 
Example 14
Source File: TileEntityCartHopper.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tag){
    tag.setByte("hopperMode", (byte)hopperMode.ordinal());
    tag.setBoolean("interactEngine", interactEngine);
    tag.setByte("pushDir", (byte)pushDir.ordinal());
    tag.setBoolean("pushedLastTick", pushedLastTick);
    return super.writeToNBT(tag);
}
 
Example 15
Source File: BioCulture.java    From bartworks with MIT License 5 votes vote down vote up
public static NBTTagCompound getNBTTagFromCulture(BioCulture bioCulture) {
    if (bioCulture == null)
        return new NBTTagCompound();
    NBTTagCompound ret = new NBTTagCompound();
    ret.setString("Name", bioCulture.name);
    //ret.setInteger("ID", bioCulture.ID);
    ret.setIntArray("Color", new int[]{bioCulture.color.getRed(), bioCulture.color.getGreen(), bioCulture.color.getBlue()});
    ret.setTag("Plasmid", BioData.getNBTTagFromBioData(BioData.convertBioPlasmidToBioData(bioCulture.plasmid)));
    ret.setTag("DNA", BioData.getNBTTagFromBioData(BioData.convertBioDNAToBioData(bioCulture.dDNA)));
    ret.setBoolean("Breedable", bioCulture.bBreedable);
    ret.setByte("Rarety", BW_Util.getByteFromRarity(bioCulture.rarity));
    if (bioCulture.bBreedable)
        ret.setString("Fluid", bioCulture.getFluid().getName());
    return ret;
}
 
Example 16
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 a new NBTTagList and returns that list.
 * @param items
 */
@Nonnull
public static NBTTagList createTagListForItems(NonNullList<ItemStack> items)
{
    NBTTagList nbtTagList = new NBTTagList();
    final int invSlots = items.size();

    // Write all the ItemStacks into a TAG_List
    for (int slotNum = 0; slotNum < invSlots; slotNum++)
    {
        ItemStack stack = items.get(slotNum);

        if (stack.isEmpty() == false)
        {
            NBTTagCompound tag = storeItemStackInTag(stack, new NBTTagCompound());

            if (invSlots <= 127)
            {
                tag.setByte("Slot", (byte) slotNum);
            }
            else
            {
                tag.setShort("Slot", (short) slotNum);
            }

            nbtTagList.appendTag(tag);
        }
    }

    return nbtTagList;
}
 
Example 17
Source File: EntityWitherCat.java    From EnderZoo with Creative Commons Zero v1.0 Universal 4 votes vote down vote up
@Override
public void writeEntityToNBT(NBTTagCompound root) {
  super.writeEntityToNBT(root);
  root.setFloat("scale", getScale());
  root.setByte("growthMode", (byte) getGrowthMode().ordinal());
}
 
Example 18
Source File: TileEntityBabyChest.java    From NewHorizonsCoreMod with GNU General Public License v3.0 4 votes vote down vote up
protected void writeSyncedNBT(NBTTagCompound pTag)
{
    pTag.setByte(NBTVAL_DIRECTION, (byte) _mOrientation.ordinal());
}
 
Example 19
Source File: SyncableUnsignedByte.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void writeToNBT(NBTTagCompound tag, String name) {
	tag.setByte(name, (byte)(value & 0xFF));
}
 
Example 20
Source File: Moment.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
public NBTTagCompound serializeNBT() {
	for (String id : entities.keySet())
		capEntity(id);
	for (BlockPos pos : blocks.keySet())
		capBlock(pos);

	NBTTagCompound momentSerialized = new NBTTagCompound();
	NBTTagList blocksSerialized = new NBTTagList();
	NBTTagCompound entitiesSerialized = new NBTTagCompound();

	momentSerialized.setTag("blocks", blocksSerialized);
	momentSerialized.setTag("entities", entitiesSerialized);

	for (BlockPos position : blocks.keySet()) {
		NBTTagList states = new NBTTagList();
		NBTTagCompound posCompound = new NBTTagCompound();
		posCompound.setLong("pos", position.toLong());
		posCompound.setTag("states", states);

		for (IBlockState state : blocks.get(position)) {
			ResourceLocation regName = state.getBlock().getRegistryName();
			if (regName != null) {
				NBTTagCompound block = new NBTTagCompound();
				block.setString("id", regName.toString());
				block.setByte("data", (byte) state.getBlock().getMetaFromState(state));
				states.appendTag(block);
			}
		}

		blocksSerialized.appendTag(posCompound);
	}

	for (String identifier : entities.keySet()) {
		NBTTagList moments = new NBTTagList();

		for (EntityMoment moment : entities.get(identifier))
			moments.appendTag(moment.serializeNBT());

		entitiesSerialized.setTag(identifier, moments);
	}

	return momentSerialized;
}