Search in sources :

Example 1 with IUpdateListener

use of com.builtbroken.mc.api.tile.listeners.IUpdateListener in project Engine by VoltzEngine-Project.

the class TileEntityWrapper method updateEntity.

/**
     * TILE, Called by the world to update the tile. Never
     * call this from your owner code. Use Update() method
     * as this is set final to ensure base functionality.
     */
@Override
public final void updateEntity() {
    //Ticks listeners that require updates
    for (List<ITileEventListener> list : new List[] { getListeners("multiblock"), ((BlockBase) getBlockType()).listeners.get("multiblock") }) {
        if (list != null && !list.isEmpty()) {
            for (ITileEventListener listener : list) {
                if (listener instanceof IUpdateListener) {
                    try {
                        if (listener instanceof IBlockListener) {
                            ((IBlockListener) listener).inject(world(), xi(), yi(), zi());
                        }
                        ((IUpdateListener) listener).update(ticks);
                    } catch (Exception e) {
                        Engine.logger().error("Unexpected exception while calling first tick on " + tile + "\nWrapper:" + this, e);
                    }
                }
            }
        }
    }
    //Ticks node
    if (ticks == 0) {
        try {
            tile.firstTick();
        } catch (Exception e) {
            Engine.logger().error("Unexpected exception while calling first tick on " + tile + "\nWrapper:" + this, e);
        }
    } else {
        try {
            tile.update(ticks);
        } catch (Exception e) {
            Engine.logger().error("Unexpected exception while ticking " + tile + "\nTick:" + ticks + "\nWrapper:" + this, e);
        }
    }
    //Increase tick
    if (ticks >= Long.MAX_VALUE) {
        ticks = 0;
    }
    ticks += 1;
    if (ticks % nextCleanupTick == 0) {
        tile.doCleanupCheck();
        nextCleanupTick = tile.getNextCleanupTick();
    }
    if (playersUsing.size() > 0) {
    //tile.doUpdateGuiUsers();
    }
}
Also used : IBlockListener(com.builtbroken.mc.api.tile.listeners.IBlockListener) IUpdateListener(com.builtbroken.mc.api.tile.listeners.IUpdateListener) ITileEventListener(com.builtbroken.mc.api.tile.listeners.ITileEventListener)

Aggregations

IBlockListener (com.builtbroken.mc.api.tile.listeners.IBlockListener)1 ITileEventListener (com.builtbroken.mc.api.tile.listeners.ITileEventListener)1 IUpdateListener (com.builtbroken.mc.api.tile.listeners.IUpdateListener)1