HowToAddItemsStendhal: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>Hendrik Brummermann
imported>Kymara
Line 108: Line 108:


= Register the class =
= Register the class =
So far we have defined what the item is like to the server. Registering the class tells the client what to do with it. (Is it stackable and should have numbers displayed, is it useable and should have a Use displayed?) '''Most classes are already registered and you may be able to ignore this section... read on to find out.'''
Usually you need to register your item class unless it really does nothing. If you're adding an item which is like what we already have (i.e. just a new shield) it's done for you, the shield class is registered. Add your item with type (item), class and subclass to the rest in ''src/games/stendhal/client/entity/factory/EntityMap.java''


Items will default to behave as a non stackable, non useable Item to the client. This covers armor, weapons, most items that don't change. Stackable but non useable classes get registered by class i.e. money, missiles, herbs etc. And most Useable items like food, drink, are registered as a whole class. So if you are adding to any existing class you very likely can ignore all this following stuff. Just come back if something doesn't work... like you expected to be able to use your new item and can't. Or if you are adding a totally new class.
register("item",null,Item.class);

register("item","book",Book.class);
So, if you have a new class and you want it to be stackable or useable <small>or is a totally new client side object, extending Item,</small> then add your class with type (item), class and your chosen behaviour to the rest in ''src/games/stendhal/client/entity/factory/EntityMap.java'', e.g.
register("item","food",StackableItem.class);

register("item","drink",StackableItem.class);
<source lang = "java">
register("item","money",StackableItem.class);
// flower was a new class of stackables
register("item","projectiles",StackableItem.class);
register("item", "flower", null, StackableItem.class);
// drink was a new class of Useables
register("item", "drink", null, UseableItem.class);
// Box is a new client side object
register("item", "box", null, Box.class);
</source>

What if your item is part of a class which has a mixture of stackable and non stackable or useable and non useable? Remember the default is non stackable and non useable. So then you need to register the special ones individually. This is done by type (item), class, as before, and also subclass (same as in the xml) to specify which exact item you meant.

<source lang = "java">
// most tools don't have a Use but the sugar mill should. the subclass in xml is sugarmill
register("item", "tool", "sugarmill", UseableItem.class);
</source>

Finally, go to ''src/games/stendhal/client/gui/j2d/entity/EntityViewFactory.java'' and configure item in the same way only if you needed to add to EntityMap above. The examples are

<source lang = "java">
// flower was a new class of stackables
register("item", "flower", null, StackableItem2DView.class);
// drink was a new class of Useables
register("item", "drink", null, UseableItem2DView.class);
// Box is a new client side object
register("item", "box", null, Box2DView.class);

// most tools don't have a Use but the sugar mill should. the subclass in xml is sugarmill
register("item", "tool", "sugarmill", UseableItem2DView.class);
</source>


= Add to game=
= Add to game=