I have used IHasGui for my addon. It is a very user-friendly interface, that make gui handling much easier. But i have noticed, that IHasGui is not applicable for Entities. Digging in IC2 source i learned, that code checks object, that launch gui, and it should be item or tileentity. I hope, that with minor code changes it can be applied to entities as well. Can you do it, please?
Suggestion: Addon development: interface IHasGui compatibility with Entities
-
-
You should use the Forge IGuiHandler Interface instead. That is much easier than implementing the IC² Variant.
-
Yes, i know how use it:
Java
Display Morepackage ihl; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.List; import ic2.core.IC2; import ic2.core.IHasGui; import ic2.core.network.DataEncoder; import ihl.servitor.ServitorContainer; import ihl.servitor.ServitorEntity; import ihl.servitor.ServitorGui; import io.netty.buffer.Unpooled; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.ChatComponentText; import net.minecraft.world.World; import cpw.mods.fml.common.network.FMLEventChannel; import cpw.mods.fml.common.network.IGuiHandler; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.internal.FMLProxyPacket; public class IHLGuiHandler implements IGuiHandler { //returns an instance of the Container @Override public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { AxisAlignedBB aabb = AxisAlignedBB.getAABBPool().getAABB(player.posX-range,player.posY-range,player.posZ-range,player.posX+range,player.posY+range,player.posZ+range); List<ServitorEntity> sList = world.getEntitiesWithinAABB(ServitorEntity.class, aabb); if(sList.size()>0) { return new ServitorContainer(player, sList.get(0)); } return null; } //returns an instance of the Gui @Override public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { AxisAlignedBB aabb = AxisAlignedBB.getAABBPool().getAABB(player.posX-range,player.posY-range,player.posZ-range,player.posX+range,player.posY+range,player.posZ+range); List<ServitorEntity> sList = world.getEntitiesWithinAABB(ServitorEntity.class, aabb); if(sList.size()>0) { return new ServitorGui(player, sList.get(0)); } return null; } }
It means making switch-case for every gui i made. GregoriusT, you mean making IHasGui interface applicable for entities is too much work?
-
Why don't you just use the GuiHandler to open the GUI for the Interface yourself? Also instead of sending a GUI ID you could just make it dependant on the found Entity. I personally don't even use the GUI ID anymore for my own Blocks, and let the Block itself decide which Client GUI to open depending on the Coords (TileEntity).
And in general even though it might be more Efficient in some cases (and inefficient in rare other cases), I would not use any of the IC² Networking Code for my own Stuff.
Not to mention that Interfaces can work on everything per definition of Java.
-
Ok, i got it. "No" means no.