Jump to content

Recommended Posts

Posted

I'm updating a mod where, in 1.6, they saved the Data Value of blocks inside their contraptions' Tile Entity classes. Obviously I want to update that to 1.7 and remove the reliance on Data Values. The problem is that everything I try doesn't work. Does someone know how to do this?

Posted

I'm updating a mod where, in 1.6, they saved the Data Value of blocks inside their contraptions' Tile Entity classes. Obviously I want to update that to 1.7 and remove the reliance on Data Values. The problem is that everything I try doesn't work. Does someone know how to do this?

 

What kind of value do you want do save? If it is something like color or direction you could use metadata, otherwise here is what i use:

 

 

public void writeToNBT(NBTTagCompound nbt){
	super.writeToNBT(nbt);

	//saving energy
	nbt.setShort("DimensionEnergy", (short)this.dimensionEnergy);
	nbt.setShort("DimensionEnergyCharging", (short)this.dimensionEnergyCharging);
	nbt.setShort("Energy", (short)this.energy);


	//items
	NBTTagList list = new NBTTagList();
	for(int i=0; i<slots.length; i++){
		if(this.slots[i]!=null){
			NBTTagCompound compound = new NBTTagCompound();
			compound.setByte("Slot", (byte)i);
			this.slots[i].writeToNBT(compound);
			list.appendTag(compound);
		}
	}
	nbt.setTag("Items", list);

	if(this.isInvNameLocalized()){
		nbt.setString("CustomName", this.localizedName);
	}

}

public void readFromNBT(NBTTagCompound nbt){
	super.readFromNBT(nbt);

	//items
	NBTTagList list = nbt.getTagList("Items", 10);
	this.slots = new ItemStack[this.getSizeInventory()];

	for(int i=0; i< list.tagCount(); i++){
		NBTTagCompound compound=list.getCompoundTagAt(i);
		byte b = compound.getByte("Slot");
			if(b >= 0 && b<this.slots.length){
				this.slots[b]= ItemStack.loadItemStackFromNBT(compound);
			}

	}

	this.dimensionEnergy=nbt.getShort("DimensionEnergy");
	this.dimensionEnergyCharging=nbt.getShort("DimensionEnergyCharging");
	this.energy=nbt.getShort("Energy");

	if(nbt.hasKey("CustomName")){
		this.localizedName=nbt.getString("CustomName");
	}

}

 

 

Here could be your advertisement!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.