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);
}
}
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;
}
Aggregations