Search in sources :

Example 1 with ListenerIterator

use of com.builtbroken.mc.prefab.tile.listeners.ListenerIterator 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 2 with ListenerIterator

use of com.builtbroken.mc.prefab.tile.listeners.ListenerIterator in project Engine by VoltzEngine-Project.

the class BlockBase method breakBlock.

@Override
public void breakBlock(World world, int x, int y, int z, Block block, int par6) {
    ListenerIterator it = new ListenerIterator(world, x, y, z, this, "break");
    while (it.hasNext()) {
        ITileEventListener next = it.next();
        if (next instanceof IBlockListener) {
            ((IDestroyedListener) next).breakBlock(block, par6);
        }
    }
    super.breakBlock(world, x, y, z, block, par6);
}
Also used : ListenerIterator(com.builtbroken.mc.prefab.tile.listeners.ListenerIterator)

Example 3 with ListenerIterator

use of com.builtbroken.mc.prefab.tile.listeners.ListenerIterator in project Engine by VoltzEngine-Project.

the class BlockBase method onBlockActivated.

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
    try {
        boolean activated = false;
        Object tile = getTile(world, x, y, z);
        if (WrenchUtility.isUsableWrench(player, player.inventory.getCurrentItem(), x, y, z)) {
            ListenerIterator it = new ListenerIterator(world, x, y, z, this, "wrench");
            while (it.hasNext()) {
                ITileEventListener next = it.next();
                if (next instanceof IWrenchListener && ((IWrenchListener) next).handlesWrenchRightClick() && ((IWrenchListener) next).onPlayerRightClickWrench(player, side, hitX, hitY, hitZ)) {
                    activated = true;
                }
            }
            if (activated) {
                WrenchUtility.damageWrench(player, player.inventory.getCurrentItem(), x, y, z);
            }
            if (activated) {
                return true;
            }
        }
        //TODO move to listener to prevent usage of IGuiTile in special cases
        if (tile instanceof IGuiTile && ((IGuiTile) tile).shouldOpenOnRightClick(player)) {
            int id = ((IGuiTile) tile).getDefaultGuiID(player);
            if (id >= 0) {
                Object o = ((IGuiTile) tile).getServerGuiElement(id, player);
                if (o != null) {
                    player.openGui(mod, id, world, x, y, z);
                    return true;
                }
            }
        }
        ListenerIterator it = new ListenerIterator(world, x, y, z, this, "activation");
        while (it.hasNext()) {
            ITileEventListener next = it.next();
            if (next instanceof IActivationListener) {
                if (((IActivationListener) next).onPlayerActivated(player, side, hitX, hitY, hitZ)) {
                    activated = true;
                }
            }
        }
        return activated;
    } catch (Exception e) {
        outputError(world, x, y, z, "while right click block on side " + side, e);
        player.addChatComponentMessage(new ChatComponentText(Colors.RED.code + LanguageUtility.getLocal("blockTile.error.onBlockActivated")));
    }
    return false;
}
Also used : ListenerIterator(com.builtbroken.mc.prefab.tile.listeners.ListenerIterator) IGuiTile(com.builtbroken.mc.api.tile.access.IGuiTile) IJsonGenObject(com.builtbroken.mc.lib.json.imp.IJsonGenObject) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 4 with ListenerIterator

use of com.builtbroken.mc.prefab.tile.listeners.ListenerIterator in project Engine by VoltzEngine-Project.

the class BlockBase method addCollisionBoxesToList.

@Override
@SuppressWarnings("unchecked")
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB aabb, List list, Entity entity) {
    super.addCollisionBoxesToList(world, x, y, z, aabb, list, entity);
    ListenerIterator it = new ListenerIterator(world, x, y, z, this, "bounds");
    while (it.hasNext()) {
        ITileEventListener next = it.next();
        if (next instanceof IBoundListener) {
            List collect = new ArrayList();
            ((IBoundListener) next).addCollisionBoxesToList(aabb, collect, entity);
            for (Object object : list) {
                if (object instanceof AxisAlignedBB && aabb.intersectsWith((AxisAlignedBB) object)) {
                    list.add(object);
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) ListenerIterator(com.builtbroken.mc.prefab.tile.listeners.ListenerIterator) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IJsonGenObject(com.builtbroken.mc.lib.json.imp.IJsonGenObject)

Example 5 with ListenerIterator

use of com.builtbroken.mc.prefab.tile.listeners.ListenerIterator in project Engine by VoltzEngine-Project.

the class BlockBase method getDrops.

@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
    ArrayList<ItemStack> items = super.getDrops(world, x, y, z, metadata, fortune);
    ListenerIterator it = new ListenerIterator(world, x, y, z, this, "blockStack");
    while (it.hasNext()) {
        ITileEventListener next = it.next();
        if (next instanceof IBlockStackListener) {
            ((IBlockStackListener) next).collectDrops(items, metadata, fortune);
        }
    }
    return items;
}
Also used : ListenerIterator(com.builtbroken.mc.prefab.tile.listeners.ListenerIterator) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ListenerIterator (com.builtbroken.mc.prefab.tile.listeners.ListenerIterator)7 IJsonGenObject (com.builtbroken.mc.lib.json.imp.IJsonGenObject)2 IGuiTile (com.builtbroken.mc.api.tile.access.IGuiTile)1 ITileEventListener (com.builtbroken.mc.api.tile.listeners.ITileEventListener)1 IIconListener (com.builtbroken.mc.api.tile.listeners.client.IIconListener)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 BlockBase (com.builtbroken.mc.framework.block.BlockBase)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ItemStack (net.minecraft.item.ItemStack)1 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)1 ChatComponentText (net.minecraft.util.ChatComponentText)1 IIcon (net.minecraft.util.IIcon)1