Posted April 13, 201411 yr 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?
April 13, 201411 yr 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!
April 13, 201411 yr Author We want to save the Block or Item that the variable holds, and it's not an ItemStack. These Tile Entities are also not IInventories or ISidedInventories.
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.