Created
January 6, 2022 08:50
-
-
Save Teerthdev/80e8e9c5d79710f9368a166faa993561 to your computer and use it in GitHub Desktop.
gui screen code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@OnlyIn(Dist.CLIENT) | |
public class Diamond2GuiWindow extends ContainerScreen<Diamond2Gui.GuiContainerMod> { | |
private World world; | |
private int x, y, z; | |
private PlayerEntity entity; | |
private final static HashMap guistate = Diamond2Gui.guistate; | |
public Diamond2GuiWindow(Diamond2Gui.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 = 176; | |
this.ySize = 166; | |
} | |
private static final ResourceLocation texture = new ResourceLocation("car_example:textures/diamond_2.png"); | |
@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 + 71, this.guiTop + 53, 16, 16, 0, 0, 0, new ResourceLocation("car_example:textures/circle1.png"), 16, 16, (p_2130901) -> { | |
CarExampleMod.PACKET_HANDLER.sendToServer(new Diamond2Gui.ButtonPressedMessage(0, x, y, z)); | |
Diamond2Gui.handleButtonAction(entity, 0, x, y, z); | |
}, new StringTextComponent("Hello, this is a tooltip"))); | |
this.addButton(new ImageButton(this.guiLeft + 71, this.guiTop + 72, 16, 16, 0, 0, 0, new ResourceLocation("car_example:textures/circle1.png"), | |
16, 16, (p_2130901) -> { | |
CarExampleMod.PACKET_HANDLER.sendToServer(new Diamond2Gui.ButtonPressedMessage(1, x, y, z)); | |
Diamond2Gui.handleButtonAction(entity, 1, x, y, z); | |
})); | |
this.addButton(new ImageButton(this.guiLeft + 92, this.guiTop + 72, 16, 16, 0, 0, 0, | |
new ResourceLocation("car_example:textures/diamond197.png"), 16, 16, (p_2130901) -> { | |
CarExampleMod.PACKET_HANDLER.sendToServer(new Diamond2Gui.ButtonPressedMessage(1, x, y, z)); | |
Diamond2Gui.handleButtonAction(entity, 1, x, y, z); | |
})); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment