Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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);

}

}

}

 

  • 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?

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

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)

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.