Search in sources :

Example 1 with ITileEventListener

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

the class JsonBlockListenerProcessor method process.

@Override
public void process(BlockBase block, JsonElement arrayElement, List<IJsonGenObject> objectList) {
    JsonArray array = arrayElement.getAsJsonArray();
    for (JsonElement element : array) {
        String key = null;
        JsonObject data = null;
        if (element.isJsonPrimitive()) {
            key = element.getAsString().toLowerCase();
        } else if (element.isJsonObject()) {
            JsonObject object = element.getAsJsonObject();
            JsonProcessor.ensureValuesExist(object, "id");
            key = object.get("id").getAsString().toLowerCase();
            data = object;
        }
        if (builders.containsKey(key)) {
            ITileEventListener listener = builders.get(key).createListener(block);
            if (listener != null) {
                if (data != null) {
                    if (!injectionMaps.containsKey(listener.getClass())) {
                        injectionMaps.put(listener.getClass(), new JsonProcessorInjectionMap(listener.getClass()));
                    }
                    JsonProcessorInjectionMap injectionMap = injectionMaps.get(listener.getClass());
                    for (Map.Entry<String, JsonElement> entry : data.entrySet()) {
                        injectionMap.handle(listener, entry.getKey(), entry.getValue());
                    }
                }
                block.addListener(listener);
            }
        }
    }
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) ITileEventListener(com.builtbroken.mc.api.tile.listeners.ITileEventListener) JsonObject(com.google.gson.JsonObject) JsonProcessorInjectionMap(com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap) HashMap(java.util.HashMap) JsonProcessorInjectionMap(com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap) Map(java.util.Map)

Example 2 with ITileEventListener

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

the class TileRenderHandler method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float f) {
    GL11.glPushMatrix();
    try {
        GL11.glTranslated(x + 0.5, y, z + 0.5);
        RenderData data = getRenderData(tile);
        if (data != null && data.renderType.equalsIgnoreCase("tile")) {
            //Try to get tile specific state
            String key = getRenderStateKey(tile);
            //Loop default keys
            for (String de : new String[] { key, "tile", "entity", "item.entity" }) {
                if (de != null) {
                    IRenderState state = data.getState(de);
                    if (state instanceof IModelState && ((IModelState) state).render(false)) {
                        break;
                    }
                }
            }
        }
    } catch (Exception e) {
        Engine.logger().error("TileRenderHandler: Error rendering " + tile, e);
    }
    GL11.glPopMatrix();
    //If BlockBase, iterate listeners
    if (tile.getBlockType() instanceof BlockBase) {
        ListenerIterator it = new ListenerIterator(tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord, (BlockBase) tile.getBlockType(), "tilerender");
        while (it.hasNext()) {
            ITileEventListener next = it.next();
            if (next instanceof ITileRenderListener) {
                GL11.glPushMatrix();
                try {
                    ((ITileRenderListener) next).renderDynamic(tile, x, y, z, f);
                } catch (Exception e) {
                    Engine.logger().error("TileRenderHandler: Error calling listener[" + next + "] for  Tile[" + tile + "]", e);
                }
                GL11.glPopMatrix();
            }
        }
    }
}
Also used : ListenerIterator(com.builtbroken.mc.prefab.tile.listeners.ListenerIterator) BlockBase(com.builtbroken.mc.framework.block.BlockBase) RenderData(com.builtbroken.mc.client.json.render.RenderData) ITileEventListener(com.builtbroken.mc.api.tile.listeners.ITileEventListener) IRenderState(com.builtbroken.mc.client.json.imp.IRenderState) IModelState(com.builtbroken.mc.client.json.imp.IModelState) ITileRenderListener(com.builtbroken.mc.api.tile.listeners.client.ITileRenderListener)

Example 3 with ITileEventListener

use of com.builtbroken.mc.api.tile.listeners.ITileEventListener 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)

Example 4 with ITileEventListener

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

the class ClientProxy method postInit.

@Override
public void postInit() {
    super.postInit();
    //Item that uses a model for all states
    registerItemJsonRenders(new ItemJsonRenderer(), "VE-Item", "item", "tile", "block");
    List<IJsonGenObject> objects = JsonContentLoader.INSTANCE.generatedObjects.get(JsonBlockProcessor.KEY);
    if (objects != null && !objects.isEmpty()) {
        for (IJsonGenObject object : objects) {
            if (object instanceof BlockBase) {
                List<ITileEventListener> listeners = ((BlockBase) object).listeners.get("placement");
                if (listeners != null && !listeners.isEmpty()) {
                    for (ITileEventListener listener : listeners) {
                        if (listener instanceof RotatableListener) {
                            ((BlockBase) object).addListener(new RotatableIconListener((BlockBase) object));
                            break;
                        }
                    }
                }
            }
        }
    }
}
Also used : RotatableListener(com.builtbroken.mc.prefab.tile.listeners.RotatableListener) BlockBase(com.builtbroken.mc.framework.block.BlockBase) RotatableIconListener(com.builtbroken.mc.client.listeners.blocks.RotatableIconListener) IJsonGenObject(com.builtbroken.mc.lib.json.imp.IJsonGenObject) ITileEventListener(com.builtbroken.mc.api.tile.listeners.ITileEventListener) ItemJsonRenderer(com.builtbroken.mc.client.json.render.item.ItemJsonRenderer)

Aggregations

ITileEventListener (com.builtbroken.mc.api.tile.listeners.ITileEventListener)4 BlockBase (com.builtbroken.mc.framework.block.BlockBase)2 IBlockListener (com.builtbroken.mc.api.tile.listeners.IBlockListener)1 IUpdateListener (com.builtbroken.mc.api.tile.listeners.IUpdateListener)1 ITileRenderListener (com.builtbroken.mc.api.tile.listeners.client.ITileRenderListener)1 IModelState (com.builtbroken.mc.client.json.imp.IModelState)1 IRenderState (com.builtbroken.mc.client.json.imp.IRenderState)1 RenderData (com.builtbroken.mc.client.json.render.RenderData)1 ItemJsonRenderer (com.builtbroken.mc.client.json.render.item.ItemJsonRenderer)1 RotatableIconListener (com.builtbroken.mc.client.listeners.blocks.RotatableIconListener)1 IJsonGenObject (com.builtbroken.mc.lib.json.imp.IJsonGenObject)1 JsonProcessorInjectionMap (com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap)1 ListenerIterator (com.builtbroken.mc.prefab.tile.listeners.ListenerIterator)1 RotatableListener (com.builtbroken.mc.prefab.tile.listeners.RotatableListener)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1