aboutsummaryrefslogtreecommitdiff
path: root/src/Java/binnie/core/gui/BinnieGUIHandler.java
blob: c146d914e08ef6d7d06060ff9d76cb07e220bf74 (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
package binnie.core.gui;

import binnie.core.AbstractMod;
import binnie.core.BinnieCore;
import binnie.core.proxy.BinnieProxy;
import binnie.craftgui.minecraft.Window;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;

public final class BinnieGUIHandler
  implements IGuiHandler
{
  private AbstractMod mod;
  
  public BinnieGUIHandler(AbstractMod mod)
  {
    this.mod = mod;
  }
  
  public final Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
  {
    Window window = getWindow(id, player, world, x, y, z, Side.SERVER);
    if (window == null) {
      return null;
    }
    window.initialiseServer();
    
    return window.getContainer();
  }
  
  public final Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
  {
    if (BinnieCore.proxy.isSimulating(world)) {
      return getServerGuiElement(id, player, world, x, y, z);
    }
    Window window = getWindow(id, player, world, x, y, z, Side.CLIENT);
    if (window == null) {
      return null;
    }
    return window.getGui();
  }
  
  public Window getWindow(int id, EntityPlayer player, World world, int x, int y, int z, Side side)
  {
    for (IBinnieGUID guid : this.mod.getGUIDs()) {
      if (guid.ordinal() == id) {
        return guid.getWindow(player, world, x, y, z, side);
      }
    }
    return null;
  }
}