Search in sources :

Example 1 with IGuiTile

use of com.builtbroken.mc.api.tile.access.IGuiTile in project Engine by VoltzEngine-Project.

the class PacketOpenGUI method handle.

@Override
public void handle(EntityPlayer player, TileEntity tile) {
    if (!player.worldObj.isRemote) {
        IGuiTile guiTile = null;
        if (tile instanceof IGuiTile) {
            guiTile = (IGuiTile) tile;
        } else if (tile instanceof ITileNodeHost && ((ITileNodeHost) tile).getTileNode() instanceof IGuiTile) {
            guiTile = (IGuiTile) ((ITileNodeHost) tile).getTileNode();
        }
        if (guiTile != null) {
            ByteBuf buf = data().slice();
            int guiID = buf.readInt();
            if (!guiTile.openGui(player, guiID)) {
                Engine.logger().error("Failed to open gui with ID(" + guiID + ") at location " + new Location(player.worldObj, x, y, z) + ", tile = " + tile);
            }
        } else if (Engine.runningAsDev) {
            Engine.logger().error("Tile at location " + new Location(player.worldObj, x, y, z) + " is not an instance of ITileGUI, tile = " + tile);
        }
    } else if (Engine.runningAsDev) {
        Engine.logger().error("Can not open GUI on client using PacketOpenGUI, tile = " + tile);
    }
}
Also used : ITileNodeHost(com.builtbroken.mc.api.tile.node.ITileNodeHost) IGuiTile(com.builtbroken.mc.api.tile.access.IGuiTile) ByteBuf(io.netty.buffer.ByteBuf) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 2 with IGuiTile

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

Aggregations

IGuiTile (com.builtbroken.mc.api.tile.access.IGuiTile)2 ITileNodeHost (com.builtbroken.mc.api.tile.node.ITileNodeHost)1 Location (com.builtbroken.mc.imp.transform.vector.Location)1 IJsonGenObject (com.builtbroken.mc.lib.json.imp.IJsonGenObject)1 ListenerIterator (com.builtbroken.mc.prefab.tile.listeners.ListenerIterator)1 ByteBuf (io.netty.buffer.ByteBuf)1 ChatComponentText (net.minecraft.util.ChatComponentText)1