* @param player
*/
public void addToWorld(Entity entity, final Player player) {
if (parent != null) {
// drop the entity into a slot
final RPSlot rpslot = ((EntitySlot) parent.getSlot(slot)).getWriteableSlot();
// check if the item can be merged with one already in the slot
if (entity instanceof StackableItem) {
final StackableItem stackEntity = (StackableItem) entity;
// find a stackable item of the same type
final Iterator<RPObject> it = rpslot.iterator();
while (it.hasNext()) {
final RPObject object = it.next();
if (object instanceof StackableItem) {
// found another stackable
final StackableItem other = (StackableItem) object;
if (other.isStackable(stackEntity)) {
new ItemLogger().merge(player, stackEntity, other);
// other is the same type...merge them
other.add(stackEntity);
entity = null;
// do not process the entity further
break;
}
}
}
}
// entity still there?
if (entity != null) {
// Set position to 0,0 (relative to container)
entity.setPosition(0, 0);
// yep, so it is not stacked. simply add it
rpslot.add(entity);
}
SingletonRepository.getRPWorld().modify(parent.getBaseContainer());
} else {
// drop the entity to the ground. Do this always in the player's
// zone.