summaryrefslogtreecommitdiff
path: root/common/darkknight/jewelrycraft/container/GuiHandler.java
blob: 6e1a78aacfb3547eef1189d5494f093c0bf9ff43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package darkknight.jewelrycraft.container;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
import darkknight.jewelrycraft.JewelrycraftMod;
import darkknight.jewelrycraft.client.GuiGuide;
import darkknight.jewelrycraft.client.GuiRingChest;

public class GuiHandler implements IGuiHandler
{
    public static enum GuiId {
        ringChest,
        guide;

        public static final GuiId[] VALUES = GuiId.values();
    }

    public GuiHandler()
    {
        NetworkRegistry.instance().registerGuiHandler(JewelrycraftMod.instance, this);
    }

    @Override
    public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
    {
        final GuiId guiId = getGuiId(ID);
        if (guiId == null) return null;        
        switch(guiId)
        {
            case ringChest: return new ContainerRingChest(player.inventory, (TileEntityChest) world.getBlockTileEntity(x, y, z));
            case guide: return new ContainerGuide();
            default: return null;
        }
    }

    @Override
    public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
    {
        final GuiId guiId = getGuiId(ID);
        if (guiId == null) return null;        
        switch(guiId)
        {
            case ringChest: return new GuiRingChest((ContainerRingChest) getServerGuiElement(ID, player, world, x, y, z));
            case guide: return new GuiGuide((ContainerGuide) getServerGuiElement(ID, player, world, x, y, z), world);
            default: return null;
        }
    }

    private static GuiId getGuiId(int id) {
        try 
        {
            return GuiId.VALUES[id];
        } 
        catch (ArrayIndexOutOfBoundsException e) 
        {
            return null;
        }
    }
}