-
Notifications
You must be signed in to change notification settings - Fork 754
/
AdvDrawbridgeGui.java
115 lines (100 loc) · 4.13 KB
/
AdvDrawbridgeGui.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
110
111
112
113
114
115
package tconstruct.client.gui;
import cpw.mods.fml.common.network.PacketDispatcher;
import java.io.*;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.util.*;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import tconstruct.blocks.logic.AdvancedDrawbridgeLogic;
public class AdvDrawbridgeGui extends GuiContainer
{
public AdvancedDrawbridgeLogic logic;
public AdvDrawbridgeGui(InventoryPlayer inventoryplayer, AdvancedDrawbridgeLogic frypan, World world, int x, int y, int z)
{
super(frypan.getGuiContainer(inventoryplayer, world, x, y, z));
logic = frypan;
}
protected void drawGuiContainerForegroundLayer (int par1, int par2)
{
//fontRenderer.drawString(StatCollector.translateToLocal("aggregator.glowstone"), 60, 6, 0x404040);
fontRenderer.drawString("Drawbridge", 8, 6, 0x404040);
fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, (ySize - 96) + 2, 0x404040);
}
private static final ResourceLocation background = new ResourceLocation("tinker", "textures/gui/drawbridge.png");
protected void drawGuiContainerBackgroundLayer (float f, int i, int j)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(background);
int cornerX = (width - xSize) / 2;
int cornerY = (height - ySize) / 2;
drawTexturedModalRect(cornerX, cornerY, 0, 0, xSize, ySize);
}
public void initGui ()
{
super.initGui();
int cornerX = (this.width - this.xSize) / 2;
int cornerY = (this.height - this.ySize) / 2;
this.buttonList.clear();
GuiButton button = new DrawbridgeButton(0, cornerX + 131, cornerY + 18, 176, 0, 21, 22);
if (logic.getPlacementDirection() == 0)
button.enabled = false;
this.buttonList.add(button);
button = new DrawbridgeButton(1, cornerX + 146, cornerY + 34, 199, 23, 22, 21);
if (logic.getPlacementDirection() == 1)
button.enabled = false;
this.buttonList.add(button);
button = new DrawbridgeButton(2, cornerX + 132, cornerY + 48, 199, 0, 21, 22);
if (logic.getPlacementDirection() == 2)
button.enabled = false;
this.buttonList.add(button);
button = new DrawbridgeButton(3, cornerX + 117, cornerY + 34, 178, 23, 22, 21);
if (logic.getPlacementDirection() == 3)
button.enabled = false;
this.buttonList.add(button);
button = new DrawbridgeButton(4, cornerX + 135, cornerY + 40, 217, 0, 10, 10);
if (logic.getPlacementDirection() == 4)
button.enabled = false;
this.buttonList.add(button);
this.buttonList.add(new SlotButton(5, this.width / 2 - 13, this.height / 2 - 52, 26, 26, ""));
}
protected void actionPerformed (GuiButton button)
{
if(button.id == 5){
return;
}
for (Object o : buttonList)
{
GuiButton b = (GuiButton) o;
b.enabled = true;
}
button.enabled = false;
logic.setPlacementDirection((byte) button.id);
updateServer((byte) button.id);
}
void updateServer (byte direction)
{
ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
DataOutputStream outputStream = new DataOutputStream(bos);
try
{
outputStream.writeByte(5);
outputStream.writeInt(logic.worldObj.provider.dimensionId);
outputStream.writeInt(logic.xCoord);
outputStream.writeInt(logic.yCoord);
outputStream.writeInt(logic.zCoord);
outputStream.writeByte(direction);
}
catch (Exception ex)
{
ex.printStackTrace();
}
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = "TConstruct";
packet.data = bos.toByteArray();
packet.length = bos.size();
PacketDispatcher.sendPacketToServer(packet);
}
}