Search in sources :

Example 1 with BlockBase

use of com.builtbroken.mc.framework.block.BlockBase in project Engine by VoltzEngine-Project.

the class JsonBlockProcessor method process.

@Override
public boolean process(JsonElement element, List<IJsonGenObject> objectList) {
    debugPrinter.start("BlockProcessor", "Processing entry", Engine.runningAsDev);
    //Get object and ensure minimal keys exist
    JsonObject blockData = element.getAsJsonObject();
    ensureValuesExist(blockData, "name", "id", "mod");
    //Load default data
    String mod = blockData.getAsJsonPrimitive("mod").getAsString();
    String id = blockData.getAsJsonPrimitive("id").getAsString();
    String name = blockData.get("name").getAsString();
    debugPrinter.log("Name: " + name);
    debugPrinter.log("Mod: " + mod);
    debugPrinter.log("ID: " + id);
    //Generate object
    BlockPropertyData blockPropertyData = new BlockPropertyData(this, id, mod, name);
    //Load blocks
    BlockBase block;
    //Meta data loading
    if (blockData.has("subtypes")) {
        blockPropertyData.localization += "." + BlockMeta.META_LOCAL_KEY;
        block = new BlockMeta(blockPropertyData);
        //Call to load metadata
        readMeta((BlockMeta) block, blockData.get("subtypes").getAsJsonArray(), objectList);
    } else //No meta data
    {
        block = new BlockBase(blockPropertyData);
    }
    processAdditionalKeys(blockPropertyData, blockData, block, objectList);
    //Add block to object list
    objectList.add(block);
    debugPrinter.end("Done...");
    return true;
}
Also used : BlockPropertyData(com.builtbroken.mc.framework.block.BlockPropertyData) BlockBase(com.builtbroken.mc.framework.block.BlockBase) JsonObject(com.google.gson.JsonObject) BlockMeta(com.builtbroken.mc.framework.block.meta.BlockMeta)

Example 2 with BlockBase

use of com.builtbroken.mc.framework.block.BlockBase 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 BlockBase

use of com.builtbroken.mc.framework.block.BlockBase 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

BlockBase (com.builtbroken.mc.framework.block.BlockBase)3 ITileEventListener (com.builtbroken.mc.api.tile.listeners.ITileEventListener)2 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 BlockPropertyData (com.builtbroken.mc.framework.block.BlockPropertyData)1 BlockMeta (com.builtbroken.mc.framework.block.meta.BlockMeta)1 IJsonGenObject (com.builtbroken.mc.lib.json.imp.IJsonGenObject)1 ListenerIterator (com.builtbroken.mc.prefab.tile.listeners.ListenerIterator)1 RotatableListener (com.builtbroken.mc.prefab.tile.listeners.RotatableListener)1 JsonObject (com.google.gson.JsonObject)1