-
Notifications
You must be signed in to change notification settings - Fork 497
/
GuiRedstoneBoard.java
executable file
·109 lines (87 loc) · 3.04 KB
/
GuiRedstoneBoard.java
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.silicon.gui;
import org.lwjgl.opengl.GL11;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import buildcraft.api.boards.IBoardParameter;
import buildcraft.api.boards.IBoardParameterStack;
import buildcraft.api.boards.RedstoneBoardNBT;
import buildcraft.api.boards.RedstoneBoardRegistry;
import buildcraft.core.DefaultProps;
import buildcraft.core.gui.AdvancedSlot;
import buildcraft.core.gui.GuiAdvancedInterface;
import buildcraft.core.gui.ItemSlot;
import buildcraft.core.network.RPCHandler;
import buildcraft.core.utils.NBTUtils;
public class GuiRedstoneBoard extends GuiAdvancedInterface {
private static final ResourceLocation TEXTURE = new ResourceLocation(
"buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/generic_ui.png");
private World world;
private int x, y, z;
private RedstoneBoardNBT<?> board;
private IBoardParameter[] params;
public GuiRedstoneBoard(EntityPlayer player, int ix, int iy, int iz) {
super(new ContainerRedstoneBoard(player, ix, iy, iz), player.inventory, TEXTURE);
x = ix;
y = iy;
z = iz;
xSize = 175;
ySize = 222;
world = player.worldObj;
NBTTagCompound boardNBT = NBTUtils.getItemData(player.getHeldItem());
board = RedstoneBoardRegistry.instance.getRedstoneBoard(boardNBT);
params = board.getParameters(boardNBT);
for (int i = 0; i < params.length; ++i) {
ItemSlot s = new ItemSlot(this, 10, 10 + i * 20);
slots.add(s);
s.drawBackround = true;
s.stack = ((IBoardParameterStack) params[i]).getStack();
}
}
@Override
public void initGui() {
super.initGui();
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(TEXTURE);
int j = (width - xSize) / 2;
int k = (height - ySize) / 2;
drawTexturedModalRect(j, k, 0, 0, xSize, ySize);
drawBackgroundSlots();
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
super.drawGuiContainerForegroundLayer(par1, par2);
drawTooltipForSlotAt(par1, par2);
}
@Override
protected void mouseClicked(int i, int j, int k) {
super.mouseClicked(i, j, k);
int cornerX = (width - xSize) / 2;
int cornerY = (height - ySize) / 2;
int position = getSlotIndexAtLocation(i - cornerX, j - cornerY);
AdvancedSlot slot = null;
if (position < 0) {
return;
}
slot = slots.get(position);
if (slot instanceof ItemSlot) {
ItemStack stackCopy = mc.thePlayer.inventory.getItemStack().copy();
stackCopy.stackSize = 1;
((ItemSlot) slot).stack = stackCopy;
RPCHandler.rpcServer(container, "setParameterStack", position, stackCopy);
}
}
}