public class ShopGuiWindow extends ContainerScreen<ShopGui.GuiContainerMod> {
private World world;
private int x, y, z;
private PlayerEntity entity;
private final static HashMap guistate = ShopGui.guistate;
public ShopGuiWindow(ShopGui.GuiContainerMod container, PlayerInventory inventory, ITextComponent text) {
super(container, inventory, text);
this.world = container.world;
this.x = container.x;
this.y = container.y;
this.z = container.z;
this.entity = container.entity;
this.xSize = 190;
this.ySize = 166;
}
private static final ResourceLocation texture = new ResourceLocation("hyrabw:textures/shop.png");
private static final ResourceLocation BUTTONS = new ResourceLocation("hyrabw:textures/shop_buttons1.png");
private static final ResourceLocation BUTTONS2 = new ResourceLocation("hyrabw:textures/shop_buttons2.png");
public boolean visible = false;
@Override
public void render(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
this.renderBackground(ms);
super.render(ms, mouseX, mouseY, partialTicks);
this.renderHoveredTooltip(ms, mouseX, mouseY);
}
@Override
protected void drawGuiContainerBackgroundLayer(MatrixStack ms, float partialTicks, int gx, int gy) {
RenderSystem.color4f(1, 1, 1, 1);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
Minecraft.getInstance().getTextureManager().bindTexture(texture);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.blit(ms, k, l, 0, 0, this.xSize, this.ySize, this.xSize, this.ySize);
RenderSystem.disableBlend();
}
@Override
public boolean keyPressed(int key, int b, int c) {
if (key == 256) {
this.minecraft.player.closeScreen();
return true;
}
return super.keyPressed(key, b, c);
}
@Override
public void tick() {
super.tick();
}
@Override
protected void drawGuiContainerForegroundLayer(MatrixStack ms, int mouseX, int mouseY) {
}
@Override
public void onClose() {
super.onClose();
Minecraft.getInstance().keyboardListener.enableRepeatEvents(false);
}
@Override
public void init(Minecraft minecraft, int width, int height) {
super.init(minecraft, width, height);
minecraft.keyboardListener.enableRepeatEvents(true);
this.addButton(new ImageButton(this.guiLeft + 4, this.guiTop + 4, 32, 32, 0, 0, 128, BUTTONS2, e -> {
if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
.equals("red")) {
HyrabwMod.PACKET_HANDLER.sendToServer(new ShopGui.ButtonPressedMessage(0, x, y, z));
ShopGui.handleButtonAction(entity, 0, x, y, z);
}
}) {
@Override
public void render(MatrixStack ms, int gx, int gy, float ticks) {
if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
.equals("red"))
super.render(ms, gx, gy, ticks);
}
});
this.addButton(new ImageButton(this.guiLeft + 4, this.guiTop + 4, 32, 32, 0, 32, 128, BUTTONS2, e -> {
if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
.equals("blue")) {
HyrabwMod.PACKET_HANDLER.sendToServer(new ShopGui.ButtonPressedMessage(1, x, y, z));
ShopGui.handleButtonAction(entity, 1, x, y, z);
}
}) {
@Override
public void renderButton(MatrixStack ms, int gx, int gy, float ticks) {
if (((entity.getCapability(HyrabwModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new HyrabwModVariables.PlayerVariables())).team)
.equals("blue"))
super.renderButton(ms, gx, gy, ticks);
}
});
}
}