Created
September 9, 2024 13:40
-
-
Save Densamisten/4c0f26fb5d808004478ab451dd1a3319 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package exonihility.client.gui; | |
| import net.minecraft.client.MinecraftClient; | |
| import net.minecraft.client.gui.DrawContext; | |
| import net.minecraft.client.gui.screen.Screen; | |
| import net.minecraft.text.Text; | |
| import net.minecraft.util.Identifier; | |
| import org.lwjgl.glfw.GLFW; | |
| public class CreeperGame extends Screen { | |
| private static final Identifier TEXTURE1 = Identifier.ofVanilla("textures/item/diamond.png"); | |
| private static final Identifier TEXTURE2 = Identifier.ofVanilla("textures/item/apple.png"); | |
| private static final Identifier TEXTURE3 = Identifier.ofVanilla("textures/item/cookie.png"); | |
| private static final Identifier EMERALD_TEXTURE = Identifier.ofVanilla("textures/item/emerald.png"); | |
| private static final Identifier VINE_TEXTURE = Identifier.ofVanilla("textures/block/vine.png"); // Added vine texture | |
| // Initial positions for the textures | |
| private int texture1X = 50, texture1Y = 50; | |
| private int texture2X = 150, texture2Y = 50; | |
| private int texture3X = 250, texture3Y = 50; | |
| private int emeraldTextureX = 350, emeraldTextureY = 50; | |
| private int vineTextureX = 450, vineTextureY = 50; // Position for the vine texture | |
| // Track which texture is selected | |
| private int selectedTexture = 1; // 1 for texture1, 2 for texture2, 3 for texture3, 4 for emerald, 5 for vine | |
| public CreeperGame(Text title) { | |
| super(title); | |
| } | |
| @Override | |
| protected void init() { | |
| super.init(); | |
| } | |
| @Override | |
| public void render(DrawContext context, int mouseX, int mouseY, float delta) { | |
| super.render(context, mouseX, mouseY, delta); | |
| context.fillGradient(0, 0, this.width, this.height, 0xFF000000, 0xFF555555); | |
| // Highlight selected texture by drawing a border around it | |
| highlightSelectedTexture(context); | |
| // Render textures at their respective positions | |
| renderTexture(context, TEXTURE1, texture1X, texture1Y); | |
| renderTexture(context, TEXTURE2, texture2X, texture2Y); | |
| renderTexture(context, TEXTURE3, texture3X, texture3Y); | |
| renderTexture(context, EMERALD_TEXTURE, emeraldTextureX, emeraldTextureY); | |
| renderTexture(context, VINE_TEXTURE, vineTextureX, vineTextureY); // Added vine texture rendering | |
| } | |
| private void renderTexture(DrawContext context, Identifier texture, int x, int y) { | |
| MinecraftClient.getInstance().getTextureManager().bindTexture(texture); | |
| context.drawTexture(texture, x, y, 0, 0, 16, 16, 16, 16); | |
| } | |
| // Highlight the selected texture by drawing a colored border around it | |
| private void highlightSelectedTexture(DrawContext context) { | |
| int borderSize = 2; // Size of the border | |
| switch (selectedTexture) { | |
| case 1: | |
| drawBorder(context, texture1X, texture1Y, borderSize); | |
| break; | |
| case 2: | |
| drawBorder(context, texture2X, texture2Y, borderSize); | |
| break; | |
| case 3: | |
| drawBorder(context, texture3X, texture3Y, borderSize); | |
| break; | |
| case 4: | |
| drawBorder(context, emeraldTextureX, emeraldTextureY, borderSize); | |
| break; | |
| case 5: | |
| drawBorder(context, vineTextureX, vineTextureY, borderSize); // Added case for vine texture | |
| break; | |
| } | |
| } | |
| // Draw a colored border around the texture | |
| private void drawBorder(DrawContext context, int x, int y, int borderSize) { | |
| int color = 0xFFFF0000; // Red color for the border | |
| context.fill(x - borderSize, y - borderSize, x + 16 + borderSize, y + 16 + borderSize, color); | |
| } | |
| @Override | |
| public boolean keyPressed(int keyCode, int scanCode, int modifiers) { | |
| switch (selectedTexture) { | |
| case 1: | |
| moveTexture(keyCode, 1); | |
| break; | |
| case 2: | |
| moveTexture(keyCode, 2); | |
| break; | |
| case 3: | |
| moveTexture(keyCode, 3); | |
| break; | |
| case 4: | |
| moveTexture(keyCode, 4); | |
| break; | |
| case 5: | |
| moveTexture(keyCode, 5); // Added movement for vine texture | |
| break; | |
| } | |
| return super.keyPressed(keyCode, scanCode, modifiers); | |
| } | |
| private void moveTexture(int keyCode, int textureNumber) { | |
| if (textureNumber == 1) { | |
| if (keyCode == GLFW.GLFW_KEY_RIGHT) texture1X += 10; | |
| if (keyCode == GLFW.GLFW_KEY_LEFT) texture1X -= 10; | |
| if (keyCode == GLFW.GLFW_KEY_UP) texture1Y -= 10; | |
| if (keyCode == GLFW.GLFW_KEY_DOWN) texture1Y += 10; | |
| } else if (textureNumber == 2) { | |
| if (keyCode == GLFW.GLFW_KEY_RIGHT) texture2X += 10; | |
| if (keyCode == GLFW.GLFW_KEY_LEFT) texture2X -= 10; | |
| if (keyCode == GLFW.GLFW_KEY_UP) texture2Y -= 10; | |
| if (keyCode == GLFW.GLFW_KEY_DOWN) texture2Y += 10; | |
| } else if (textureNumber == 3) { | |
| if (keyCode == GLFW.GLFW_KEY_RIGHT) texture3X += 10; | |
| if (keyCode == GLFW.GLFW_KEY_LEFT) texture3X -= 10; | |
| if (keyCode == GLFW.GLFW_KEY_UP) texture3Y -= 10; | |
| if (keyCode == GLFW.GLFW_KEY_DOWN) texture3Y += 10; | |
| } else if (textureNumber == 4) { | |
| if (keyCode == GLFW.GLFW_KEY_RIGHT) emeraldTextureX += 10; | |
| if (keyCode == GLFW.GLFW_KEY_LEFT) emeraldTextureX -= 10; | |
| if (keyCode == GLFW.GLFW_KEY_UP) emeraldTextureY -= 10; | |
| if (keyCode == GLFW.GLFW_KEY_DOWN) emeraldTextureY += 10; | |
| } else if (textureNumber == 5) { // Added movement for vine texture | |
| if (keyCode == GLFW.GLFW_KEY_RIGHT) vineTextureX += 10; | |
| if (keyCode == GLFW.GLFW_KEY_LEFT) vineTextureX -= 10; | |
| if (keyCode == GLFW.GLFW_KEY_UP) vineTextureY -= 10; | |
| if (keyCode == GLFW.GLFW_KEY_DOWN) vineTextureY += 10; | |
| } | |
| } | |
| @Override | |
| public boolean mouseClicked(double mouseX, double mouseY, int button) { | |
| // Select texture based on which one was clicked | |
| if (isTextureClicked(texture1X, texture1Y, mouseX, mouseY)) { | |
| selectedTexture = 1; | |
| } else if (isTextureClicked(texture2X, texture2Y, mouseX, mouseY)) { | |
| selectedTexture = 2; | |
| } else if (isTextureClicked(texture3X, texture3Y, mouseX, mouseY)) { | |
| selectedTexture = 3; | |
| } else if (isTextureClicked(emeraldTextureX, emeraldTextureY, mouseX, mouseY)) { | |
| selectedTexture = 4; | |
| } else if (isTextureClicked(vineTextureX, vineTextureY, mouseX, mouseY)) { // Added selection for vine texture | |
| selectedTexture = 5; | |
| } | |
| return super.mouseClicked(mouseX, mouseY, button); | |
| } | |
| private boolean isTextureClicked(int textureX, int textureY, double mouseX, double mouseY) { | |
| return mouseX >= textureX && mouseX <= textureX + 16 && mouseY >= textureY && mouseY <= textureY + 16; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment