Hello everyone!
I've been in the process of creating a 2D dungeon crawler for a little while now. I've been able to get entities working, and have started on implementing items/tools. However, i am encountering a small bug that i cannot seem to figure out. For some reason, my metadata variable (used to store damage for tools) is applying to ALL tools vs. just one.
Some code:
The actual "use" statment.
public void onUse(EntityPlayer ent)
{
System.out.println("DID SOMEONE CALL ME?");
//if(ent.inventory.pInv[ent.inventory.selection].item.metadeta < toolMaterial.durability)
//{
ent.inventory.pInv[ent.inventory.selection].item.metadeta++;
System.out.println(ent.inventory.pInv[ent.inventory.selection].item.metadeta);
if(ent.inventory.pInv[ent.inventory.selection].item.metadeta == toolMaterial.durability)
{
onBreak();
}
//}
//else {
//onBreak();
//}
}
}
The supertype for Items (first deceleration of metadata variable)
package main;
import java.awt.Image;
public class Item {
//public static Item[] itemL = new Item[256];
public static Item emptyBottle = new ItemBottle(1,"Glass Bottle",0);
public static Item healthPotion = new ItemBottle(2, "Health Potion", 1);
public static Item manaPotion = new ItemBottle(3, "Mana Potion", 2);
public static Item woodSword = new ItemSword(4, "Wood Sword",5,EnumToolMaterials.WOOD);
public static Item stoneSword = new ItemSword(5, "Stone Sword",5,EnumToolMaterials.STONE);
public static Item ironSword = new ItemSword(6, "Iron Sword",5,EnumToolMaterials.IRON);
public static Item gemSword = new ItemSword(7, "Gem Sword",5,EnumToolMaterials.GEM);
public static Item soulSword = new ItemSword(8, "Soul Sword",5,EnumToolMaterials.SOUL);
public static Item testSword = new ItemSword(9, "TEST", 0, EnumToolMaterials.TEST);
public String name;
public int ID;
int metadeta = 0;
public int force;
public int r,b,g;
public static String prefix;
public int damage;
public boolean disposable;
public int maxStack;
public boolean destroy;
public Item(int index,String name, String Prefix, int damage,int maxStack)
{
this.name = name;
ID = index;
force = 1;
if(prefix == "")
{
prefix = "used";
}
else prefix = Prefix;
destroy = false;
/*itemL[1] = emptyBottle;
itemL[2] = healthPotion;
itemL[3] = manaPotion;*/
}
public Item(int index,String name,String Prefix) {
this(index, name, Prefix, 0,64);
}
public Item(int index,String name) {
this(index, name, "",0,64);
}
public void onUse(EntityPlayer ent) {
}
}
Any other code can be provided upon request. Sorry if this isn't clear enough.
TL;DR: Having problems with variables carrying over to independent instances of declared entities!
Thank you very much!
-EB5473