Items
From SemanticLab
The following snippet shows the creation of a custom Item, which is also visible in the player's inventory.
public class Beer extends Item { static String hname; static Image himage; /** * initialize Object Beer */ public void init(Manager m, ConfigValue v) { // general data for Object taken from plugin.xml hname = v.getStringValue("name"); try { himage = ImageIO.read(getClass().getResource(v.getStringValue("image"))); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** Constructor - sets the Image and Name */ public Beer (){ setImage (himage); setName (hname); } }
The init method reads the Item's image and description which is stored in static variables. Every time a new instance of the item is created its constructor sets the item image and name to these static values.
You may use such an object as demonstrated in the example below:
Beer ale = new Beer(); Manager.getActiveCharacter().getInventory().take(ale);

