2014-03-16 22:26:43 +01:00
|
|
|
package info.jbcs.minecraft.utilities;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
import cpw.mods.fml.common.network.IGuiHandler;
|
|
|
|
|
import cpw.mods.fml.common.network.NetworkRegistry;
|
|
|
|
|
|
2014-04-21 19:13:15 +01:00
|
|
|
public abstract class GuiHandler implements Comparable
|
|
|
|
|
{
|
|
|
|
|
static ArrayList<GuiHandler> items = new ArrayList<GuiHandler>();
|
2014-03-16 22:26:43 +01:00
|
|
|
|
2014-04-21 19:13:15 +01:00
|
|
|
int index;
|
|
|
|
|
Object mod;
|
|
|
|
|
String name;
|
2014-03-16 22:26:43 +01:00
|
|
|
|
2014-04-21 19:13:15 +01:00
|
|
|
public GuiHandler(String n)
|
|
|
|
|
{
|
|
|
|
|
items.add(this);
|
|
|
|
|
name = n;
|
|
|
|
|
}
|
2014-03-16 22:26:43 +01:00
|
|
|
|
2014-04-21 19:13:15 +01:00
|
|
|
public void open(EntityPlayer player, World world, int x, int y, int z)
|
|
|
|
|
{
|
|
|
|
|
player.openGui(mod, index, world, x, y, z);
|
|
|
|
|
}
|
2014-03-16 22:26:43 +01:00
|
|
|
|
2014-04-21 19:13:15 +01:00
|
|
|
@Override
|
|
|
|
|
public int compareTo(Object a)
|
|
|
|
|
{
|
|
|
|
|
return name.compareTo(((GuiHandler) a).name);
|
|
|
|
|
}
|
2014-03-16 22:26:43 +01:00
|
|
|
|
2014-04-21 19:13:15 +01:00
|
|
|
public static void register(Object mod)
|
|
|
|
|
{
|
|
|
|
|
Collections.sort(items);
|
|
|
|
|
int index = 0;
|
2014-03-16 22:26:43 +01:00
|
|
|
|
2014-04-21 19:13:15 +01:00
|
|
|
for(GuiHandler h : items)
|
|
|
|
|
{
|
|
|
|
|
h.mod = mod;
|
|
|
|
|
h.index = index++;
|
|
|
|
|
}
|
2014-03-16 22:26:43 +01:00
|
|
|
|
2014-04-21 19:13:15 +01:00
|
|
|
NetworkRegistry.INSTANCE.registerGuiHandler(mod, new IGuiHandler()
|
|
|
|
|
{
|
|
|
|
|
@Override
|
|
|
|
|
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
|
|
|
|
|
{
|
|
|
|
|
if(id < 0 || id >= items.size())
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2014-03-16 22:26:43 +01:00
|
|
|
|
2014-04-21 19:13:15 +01:00
|
|
|
return items.get(id).getServerGuiElement(id, player, world, x, y, z);
|
|
|
|
|
}
|
2014-03-16 22:26:43 +01:00
|
|
|
|
2014-04-21 19:13:15 +01:00
|
|
|
@Override
|
|
|
|
|
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
|
|
|
|
|
{
|
|
|
|
|
if(id < 0 || id >= items.size())
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2014-03-16 22:26:43 +01:00
|
|
|
|
2014-04-21 19:13:15 +01:00
|
|
|
return items.get(id).getClientGuiElement(id, player, world, x, y, z);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-03-16 22:26:43 +01:00
|
|
|
|
2014-04-21 19:13:15 +01:00
|
|
|
public abstract Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z);
|
2014-03-16 22:26:43 +01:00
|
|
|
|
2014-04-21 19:13:15 +01:00
|
|
|
public abstract Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z);
|
2014-03-16 22:26:43 +01:00
|
|
|
}
|