Jump to content

[1.11] ItemStack.loadItemStackFromNBT


Keks

Recommended Posts

In 1.10.2 => ItemStack.loadItemStackFromNBT

and in 1.11?

 

Here is my Code. Error in Red below.

 

Thanks ;)

 

 

package ...

 

import ...

 

public class InventoryBackpack extends InventoryBasic {

 

private final ItemStack stack;

 

public InventoryBackpack(ItemStack stack) {

//super(I18n.format("lang.backpack1", new Object[0]), false, 9);

super("Level 1", false, 9);

this.stack = stack;

}

 

@Override

public void openInventory(EntityPlayer player){

readFromNBT();

super.openInventory(player);

}

 

@Override

public void closeInventory(EntityPlayer player){

writeToNBT();

super.closeInventory(player);

}

 

@Override

public void markDirty(){

writeToNBT();

super.markDirty();

}

 

public void writeToNBT() {

NBTTagCompound tag = stack.getTagCompound();

if(tag == null){

tag = new NBTTagCompound();

stack.setTagCompound(tag);

}

 

NBTTagList list = new NBTTagList();

 

for(int i = 0; i < getSizeInventory(); i++){

ItemStack stack = getStackInSlot(i);

 

if(stack != null){

NBTTagCompound slottag = new NBTTagCompound();

slottag.setInteger("slotindex", i);

stack.writeToNBT(slottag);

list.appendTag(slottag);

}

}

 

tag.setTag("inventory", list);

}

 

public void readFromNBT() {

NBTTagCompound tag = stack.getTagCompound();

if(tag == null){

writeToNBT();

return;

}

 

NBTTagList list = tag.getTagList("inventory", Constants.NBT.TAG_COMPOUND);//10

if(list == null){

writeToNBT();

return;

}

 

for(int i = 0; i < list.tagCount(); i++){

NBTTagCompound slottag = list.getCompoundTagAt(i);

int index = slottag.getInteger("slotindex");

ItemStack stack = ItemStack.loadItemStackFromNBT(slottag);

setInventorySlotContents(index, stack);

}

}

}

 

Link to comment
Share on other sites

  • 2 years later...
On 11/16/2016 at 8:48 PM, Keks said:

In 1.10.2 => ItemStack.loadItemStackFromNBT

and in 1.11?

 

Here is my Code. Error in Red below.

 

Thanks ;)

 

 

  Reveal hidden contents

package ...

 

import ...

 

public class InventoryBackpack extends InventoryBasic {

 

private final ItemStack stack;

 

public InventoryBackpack(ItemStack stack) {

//super(I18n.format("lang.backpack1", new Object[0]), false, 9);

super("Level 1", false, 9);

this.stack = stack;

}

 

@Override

public void openInventory(EntityPlayer player){

readFromNBT();

super.openInventory(player);

}

 

@Override

public void closeInventory(EntityPlayer player){

writeToNBT();

super.closeInventory(player);

}

 

@Override

public void markDirty(){

writeToNBT();

super.markDirty();

}

 

public void writeToNBT() {

NBTTagCompound tag = stack.getTagCompound();

if(tag == null){

tag = new NBTTagCompound();

stack.setTagCompound(tag);

}

 

NBTTagList list = new NBTTagList();

 

for(int i = 0; i < getSizeInventory(); i++){

ItemStack stack = getStackInSlot(i);

 

if(stack != null){

NBTTagCompound slottag = new NBTTagCompound();

slottag.setInteger("slotindex", i);

stack.writeToNBT(slottag);

list.appendTag(slottag);

}

}

 

tag.setTag("inventory", list);

}

 

public void readFromNBT() {

NBTTagCompound tag = stack.getTagCompound();

if(tag == null){

writeToNBT();

return;

}

 

NBTTagList list = tag.getTagList("inventory", Constants.NBT.TAG_COMPOUND);//10

if(list == null){

writeToNBT();

return;

}

 

for(int i = 0; i < list.tagCount(); i++){

NBTTagCompound slottag = list.getCompoundTagAt(i);

int index = slottag.getInteger("slotindex");

ItemStack stack = ItemStack.loadItemStackFromNBT(slottag);

setInventorySlotContents(index, stack);

}

}

}

 

What´s about 1.12? How can I replace loadItemStackFromNBT there?

Link to comment
Share on other sites

20 hours ago, Screamer said:

So I recently wrote a code for a custom backpack, but noticed that the function: loadItemStackFromNBT doesn´t exist anymore.

Can anyone tell me with which code I have to replace this?

Thanks

ItemStack(NBTTagCompound)
Link to comment
Share on other sites

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
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.



×
×
  • Create New...

Important Information

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