Hmmmm when running you exact code, for testing purposes, I get these 6 errors
== ERRORS FOUND ==
src/minecraft/net/minecraft/src/InventoryBackpack.java:5: net.minecraft.src.InventoryBackpack is not abstract and does not override abstract method canInteractWith(net.minecraft.src.EntityPlayer) in net.minecraft.src.IInventory
public class InventoryBackpack implements IInventory
^
src/minecraft/net/minecraft/src/InventoryBackpack.java:31: cannot find symbol
symbol : method onInventoryChanged()
location: class net.minecraft.src.InventoryBackpack
onInventoryChanged();
^
src/minecraft/net/minecraft/src/InventoryBackpack.java:39: cannot find symbol
symbol : method onInventoryChanged()
location: class net.minecraft.src.InventoryBackpack
onInventoryChanged();
^
src/minecraft/net/minecraft/src/InventoryBackpack.java:54: cannot find symbol
symbol : method onInventoryChanged()
location: class net.minecraft.src.InventoryBackpack
onInventoryChanged();
^
src/minecraft/net/minecraft/src/InventoryBackpack.java:64: cannot find symbol
symbol : method readFromNBT(net.minecraft.src.NBTTagCompound)
location: class java.lang.Object
super.readFromNBT(nbttagcompound);
^
src/minecraft/net/minecraft/src/InventoryBackpack.java:81: cannot find symbol
symbol : method writeToNBT(net.minecraft.src.NBTTagCompound)
location: class java.lang.Object
super.writeToNBT(nbttagcompound);
^
6 errors
==================
Rollback Post to RevisionRollBack
Check out my minecraft tools, mods, or maybe my website! I've got tons of applications (both minecraft related and not) which some of you may find useful. Thanks!
Hmmmm when running you exact code, for testing purposes, I get these 6 errors
It looks as if you're missing something (probably syntax) relating to canInteractWith(...) method. Posting your exact source code for InventoryBackpack would help in debugging.
To OP, good tutorial. It was easy to follow along and everything was explained in efficient detail. I'm curious though, is it possible to make it so that when you right click on the backpack, only the backpack inventory will come up? Because currently (and i'm assuming this is purposefully) it brings up the normal inventory underneath the backpack.
EDIT: I realize now that that is the whole GUI for chests. So if I wanted it customized, i'd have to look into creating ContainerBackpack and GuiBackpack classes (as far as I can tell so far).
Hmmmm when running you exact code, for testing purposes, I get these 6 errors
== ERRORS FOUND ==
src/minecraft/net/minecraft/src/InventoryBackpack.java:5: net.minecraft.src.InventoryBackpack is not abstract and does not override abstract method canInteractWith(net.minecraft.src.EntityPlayer) in net.minecraft.src.IInventory
public class InventoryBackpack implements IInventory
^
src/minecraft/net/minecraft/src/InventoryBackpack.java:31: cannot find symbol
symbol : method onInventoryChanged()
location: class net.minecraft.src.InventoryBackpack
onInventoryChanged();
^
src/minecraft/net/minecraft/src/InventoryBackpack.java:39: cannot find symbol
symbol : method onInventoryChanged()
location: class net.minecraft.src.InventoryBackpack
onInventoryChanged();
^
src/minecraft/net/minecraft/src/InventoryBackpack.java:54: cannot find symbol
symbol : method onInventoryChanged()
location: class net.minecraft.src.InventoryBackpack
onInventoryChanged();
^
src/minecraft/net/minecraft/src/InventoryBackpack.java:64: cannot find symbol
symbol : method readFromNBT(net.minecraft.src.NBTTagCompound)
location: class java.lang.Object
super.readFromNBT(nbttagcompound);
^
src/minecraft/net/minecraft/src/InventoryBackpack.java:81: cannot find symbol
symbol : method writeToNBT(net.minecraft.src.NBTTagCompound)
location: class java.lang.Object
super.writeToNBT(nbttagcompound);
^
6 errors
==================
I can tel from the bottom two errors that you have not looked recently at t he tutorial, because in the tutorial I fixed these errors. the super.read/writeFrom/ToNBT should be deleted, look at the updated code. Also a method was missing. Please look at the tutorial again.
I can tel from the bottom two errors that you have not looked recently at t he tutorial, because in the tutorial I fixed these errors. the super.read/writeFrom/ToNBT should be deleted, look at the updated code. Also a method was missing. Please look at the tutorial again.
Yep, you fixed it. Thanks!
Rollback Post to RevisionRollBack
Check out my minecraft tools, mods, or maybe my website! I've got tons of applications (both minecraft related and not) which some of you may find useful. Thanks!
does it work then? I have tested it and it works for me, however I realized a problem. you can have 2 backpacks and they will have the same inventory, and even if you lose your backpack the item itself keeps the inventory. I'm working on a way to give the ItemStack itself an inventory, maybe make a new ItemStack class.
hey checked this out tried it but when I right click I get this error heres the error:
Mods loaded: 2
ModLoader Beta 1.7.3
net.minecraft.src.mod_Backpack Backpack test
Minecraft has crashed!
----------------------
Minecraft has stopped running because it encountered a problem.
If you wish to report this, please copy this entire text and email it to [email protected].
Please include a description of what you did when the error occured.
--- BEGIN ERROR REPORT b2cff7f --------
Generated 7/12/11 7:38 PM
Minecraft: Minecraft Beta 1.7.3
OS: Windows Vista (x86) version 6.0
Java: 1.6.0_24, Sun Microsystems Inc.
VM: Java HotSpot(TM) Client VM (mixed mode), Sun Microsystems Inc.
LWJGL: 2.4.2
OpenGL: GeForce 9800M GS/PCI/SSE2 version 3.0.0, NVIDIA Corporation
java.lang.NullPointerException
at net.minecraft.src.ContainerChest.<init>(ContainerChest.java:19)
at net.minecraft.src.GuiChest.<init>(GuiChest.java:19)
at net.minecraft.src.EntityPlayerSP.displayGUIChest(EntityPlayerSP.java:145)
at net.minecraft.src.ItemBackpack.onItemRightClick(ItemBackpack.java:13)
at net.minecraft.src.ItemStack.useItemRightClick(ItemStack.java:92)
at net.minecraft.src.PlayerController.sendUseItem(PlayerController.java:67)
at net.minecraft.client.Minecraft.clickMouse(Minecraft.java:847)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1052)
at net.minecraft.client.Minecraft.run(Minecraft.java:480)
at java.lang.Thread.run(Unknown Source)
--- END ERROR REPORT bc681dd7 ----------
public void readFromNBT(NBTTagCompound nbttagcompound)
{
NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
packContents = new ItemStack[getSizeInventory()];
for(int i = 0; i < nbttaglist.tagCount(); i++)
{
NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
int j = nbttagcompound1.getByte("Slot") & 0xff;
if(j >= 0 && j < packContents.length)
{
packContents[j] = new ItemStack(nbttagcompound1);
}
}
}
public void writeToNBT(NBTTagCompound nbttagcompound)
{
NBTTagList nbttaglist = new NBTTagList();
for(int i = 0; i < packContents.length; i++)
{
if(packContents[i] != null)
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte)i);
packContents[i].writeToNBT(nbttagcompound1);
nbttaglist.setTag(nbttagcompound1);
}
}
nbttagcompound.setTag("Items", nbttaglist);
}
public int getInventoryStackLimit()
{
return 64;
}
private ItemStack packContents[];
}
I need ItemBackpack.java not InventoryBackpack.java. The error is coming from the ItemBackpack at line 13 NullPointerException.
@StrongJoshua I can definatly make one, but I'm still working on figuring out the GUI's and stuff. So far I know you'd need to edit at least 4 classes and make 2-3. So it may be a while. I will however take tutorial requests even during this time period.
I followed all of the steps, but I still can't seem to open the backpack on right-click. :sad.gif: I looked everything over again and again and I don't get any errors either.
It looks as if you're missing something (probably syntax) relating to canInteractWith(...) method. Posting your exact source code for InventoryBackpack would help in debugging.
To OP, good tutorial. It was easy to follow along and everything was explained in efficient detail. I'm curious though, is it possible to make it so that when you right click on the backpack, only the backpack inventory will come up? Because currently (and i'm assuming this is purposefully) it brings up the normal inventory underneath the backpack.
EDIT: I realize now that that is the whole GUI for chests. So if I wanted it customized, i'd have to look into creating ContainerBackpack and GuiBackpack classes (as far as I can tell so far).
I can tel from the bottom two errors that you have not looked recently at t he tutorial, because in the tutorial I fixed these errors. the super.read/writeFrom/ToNBT should be deleted, look at the updated code. Also a method was missing. Please look at the tutorial again.
Yep, you fixed it. Thanks!
ModLoader Beta 1.7.3
net.minecraft.src.mod_Backpack Backpack test
Minecraft has crashed!
----------------------
Minecraft has stopped running because it encountered a problem.
If you wish to report this, please copy this entire text and email it to [email protected].
Please include a description of what you did when the error occured.
--- BEGIN ERROR REPORT b2cff7f --------
Generated 7/12/11 7:38 PM
Minecraft: Minecraft Beta 1.7.3
OS: Windows Vista (x86) version 6.0
Java: 1.6.0_24, Sun Microsystems Inc.
VM: Java HotSpot(TM) Client VM (mixed mode), Sun Microsystems Inc.
LWJGL: 2.4.2
OpenGL: GeForce 9800M GS/PCI/SSE2 version 3.0.0, NVIDIA Corporation
java.lang.NullPointerException
at net.minecraft.src.ContainerChest.<init>(ContainerChest.java:19)
at net.minecraft.src.GuiChest.<init>(GuiChest.java:19)
at net.minecraft.src.EntityPlayerSP.displayGUIChest(EntityPlayerSP.java:145)
at net.minecraft.src.ItemBackpack.onItemRightClick(ItemBackpack.java:13)
at net.minecraft.src.ItemStack.useItemRightClick(ItemStack.java:92)
at net.minecraft.src.PlayerController.sendUseItem(PlayerController.java:67)
at net.minecraft.client.Minecraft.clickMouse(Minecraft.java:847)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1052)
at net.minecraft.client.Minecraft.run(Minecraft.java:480)
at java.lang.Thread.run(Unknown Source)
--- END ERROR REPORT bc681dd7 ----------
public class InventoryBackpack implements IInventory
{
public InventoryBackpack()
{
packContents = new ItemStack[36];
}
public int getSizeInventory()
{
return 27;
}
public boolean canInteractWith(EntityPlayer entityplayer)
{
return !entityplayer.isDead;
}
public void onInventoryChanged()
{
}
public ItemStack getStackInSlot(int i)
{
return packContents[i];
}
public ItemStack decrStackSize(int i, int j)
{
if(packContents[i] != null)
{
if(packContents[i].stackSize <= j)
{
ItemStack itemstack = packContents[i];
packContents[i] = null;
onInventoryChanged();
return itemstack;
}
ItemStack itemstack1 = packContents[i].splitStack(j);
if(packContents[i].stackSize == 0)
{
packContents[i] = null;
}
onInventoryChanged();
return itemstack1;
} else
{
return null;
}
}
public void setInventorySlotContents(int i, ItemStack itemstack)
{
packContents[i] = itemstack;
if(itemstack != null && itemstack.stackSize > getInventoryStackLimit())
{
itemstack.stackSize = getInventoryStackLimit();
}
onInventoryChanged();
}
public String getInvName()
{
return "Backpack";
}
public void readFromNBT(NBTTagCompound nbttagcompound)
{
NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
packContents = new ItemStack[getSizeInventory()];
for(int i = 0; i < nbttaglist.tagCount(); i++)
{
NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
int j = nbttagcompound1.getByte("Slot") & 0xff;
if(j >= 0 && j < packContents.length)
{
packContents[j] = new ItemStack(nbttagcompound1);
}
}
}
public void writeToNBT(NBTTagCompound nbttagcompound)
{
NBTTagList nbttaglist = new NBTTagList();
for(int i = 0; i < packContents.length; i++)
{
if(packContents[i] != null)
{
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte)i);
packContents[i].writeToNBT(nbttagcompound1);
nbttaglist.setTag(nbttagcompound1);
}
}
nbttagcompound.setTag("Items", nbttaglist);
}
public int getInventoryStackLimit()
{
return 64;
}
private ItemStack packContents[];
}
Also, check out my YouTube channel: www.YouTube.com/StrongJoshua
I need ItemBackpack.java not InventoryBackpack.java. The error is coming from the ItemBackpack at line 13 NullPointerException.
@StrongJoshua I can definatly make one, but I'm still working on figuring out the GUI's and stuff. So far I know you'd need to edit at least 4 classes and make 2-3. So it may be a while. I will however take tutorial requests even during this time period.
public class ItemBackpack extends Item{
private IInventory inv;
protected ItemBackpack(int ID) {
super(ID);
maxStackSize=1;
}
public ItemStack onItemRightClick(ItemStack itemstack, World world,EntityPlayer entityplayer){
entityplayer.displayGUIChest(inv);
return itemstack;
}
}
Check out my Minecraft Modding Tutorials!
Okay, I will try that. :smile.gif:
Check out my Minecraft Modding Tutorials!