From 9a955245cb03442da3f81a505e8412cca956eacd Mon Sep 17 00:00:00 2001 From: Bob Date: Fri, 12 Jan 2024 20:58:03 +0100 Subject: [PATCH] preview render thing --- changelog | 2 + .../hbm/inventory/gui/GUIScreenPreview.java | 110 ++++++++++++++++++ .../com/hbm/main/ModEventHandlerClient.java | 79 ++++++++----- 3 files changed, 162 insertions(+), 29 deletions(-) create mode 100644 src/main/java/com/hbm/inventory/gui/GUIScreenPreview.java diff --git a/changelog b/changelog index 6fb4ecbcd..15939683f 100644 --- a/changelog +++ b/changelog @@ -13,6 +13,8 @@ * The nuclear flash now bypasses radiation resistance, being only affected by blocks and distance * Mushroom clouds' initial scale is now based on the total scale instead of all spawning roughly at the same size, causing fireballs to be comically small for huge bombs * Removed the old mining drill, combustion generator, old watz core, structure marker, all old large reactor parts and CMB furnace for good +* Chemical plants will now eject all their outputs within a single tick if possible, increasing the throughput of fast recipes with many outputs, like asphalt +* Hitting CTRL + ALT when hovering over an item now displays a preview of that item. Useful if you want to get authentic renders for a wiki, or just like staring at things. ## Fixed * Fixed a rare crash caused by radars force-loading chunks conflicting with certain mods' chunk loading changes diff --git a/src/main/java/com/hbm/inventory/gui/GUIScreenPreview.java b/src/main/java/com/hbm/inventory/gui/GUIScreenPreview.java new file mode 100644 index 000000000..56e50ee60 --- /dev/null +++ b/src/main/java/com/hbm/inventory/gui/GUIScreenPreview.java @@ -0,0 +1,110 @@ +package com.hbm.inventory.gui; + +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +import com.hbm.lib.RefStrings; + +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +public class GUIScreenPreview extends GuiScreen { + + protected static final ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/nei/gui_nei.png"); + protected ItemStack preview; + protected int zoom = 1; + + public GUIScreenPreview(ItemStack stack) { + this.preview = stack; + } + + public void drawScreen(int mouseX, int mouseY, float f) { + + if(this.mc.theWorld != null) { + this.drawRect(0, 0, this.width, this.height, 0xFFC6C6C6); + } else { + this.drawBackground(0); + } + + if(!Mouse.isButtonDown(0) && !Mouse.isButtonDown(1) && Mouse.next()) { + int scroll = Mouse.getEventDWheel(); + + if(scroll < 0 && this.zoom > 1) this.zoom--; + if(scroll > 0 && this.zoom < 15) this.zoom++; + } + + this.drawGuiContainerBackgroundLayer(f, mouseX, mouseY); + GL11.glDisable(GL11.GL_LIGHTING); + this.drawGuiContainerForegroundLayer(mouseX, mouseY); + GL11.glEnable(GL11.GL_LIGHTING); + } + + protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) { + GL11.glPushMatrix(); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.getTextureManager().bindTexture(texture); + ScaledResolution res = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight); + GL11.glScaled(zoom, zoom, zoom); + this.drawTexturedModalRect(res.getScaledWidth_double() / 2D / zoom - 9D, res.getScaledHeight_double() / 2D / zoom - 9D, 5, 87, 18, 18); + GL11.glPopMatrix(); + + this.fontRendererObj.drawString("Zoom: " + zoom, 2, this.height - 20, 0xff0000); + this.fontRendererObj.drawString("Windows Scale: " + res.getScaleFactor(), 2, this.height - 10, 0xff0000); + } + + public void drawTexturedModalRect(double x, double y, int sourceX, int sourceY, int sizeX, int sizeY) { + double f = 0.00390625D; + double f1 = 0.00390625D; + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV((double) (x + 0), (double) (y + sizeY), (double) this.zLevel, (double) ((float) (sourceX + 0) * f), (double) ((float) (sourceY + sizeY) * f1)); + tessellator.addVertexWithUV((double) (x + sizeX), (double) (y + sizeY), (double) this.zLevel, (double) ((float) (sourceX + sizeX) * f), (double) ((float) (sourceY + sizeY) * f1)); + tessellator.addVertexWithUV((double) (x + sizeX), (double) (y + 0), (double) this.zLevel, (double) ((float) (sourceX + sizeX) * f), (double) ((float) (sourceY + 0) * f1)); + tessellator.addVertexWithUV((double) (x + 0), (double) (y + 0), (double) this.zLevel, (double) ((float) (sourceX + 0) * f), (double) ((float) (sourceY + 0) * f1)); + tessellator.draw(); + } + + protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + + if(preview == null) return; + + GL11.glPushMatrix(); + RenderHelper.enableGUIStandardItemLighting(); + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240F, 240F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_DEPTH_TEST); + + GL11.glScaled(zoom, zoom, zoom); + + ScaledResolution res = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight); + GL11.glTranslated(res.getScaledWidth_double() / 2D / zoom, res.getScaledHeight_double() / 2D / zoom, -200); + + this.zLevel = 200.0F; + itemRender.zLevel = 200.0F; + + GL11.glEnable(GL11.GL_DEPTH_TEST); + itemRender.renderItemAndEffectIntoGUI(this.fontRendererObj, this.mc.getTextureManager(), preview, -8, -8); + itemRender.renderItemOverlayIntoGUI(this.fontRendererObj, this.mc.getTextureManager(), preview, -8, -8, null); + + itemRender.zLevel = 0.0F; + this.zLevel = 0.0F; + + GL11.glPopMatrix(); + } + + @Override + protected void keyTyped(char c, int key) { + if(key == 1 || key == this.mc.gameSettings.keyBindInventory.getKeyCode()) { + this.mc.thePlayer.closeScreen(); + } + } +} diff --git a/src/main/java/com/hbm/main/ModEventHandlerClient.java b/src/main/java/com/hbm/main/ModEventHandlerClient.java index 72e07c9b8..2aa380413 100644 --- a/src/main/java/com/hbm/main/ModEventHandlerClient.java +++ b/src/main/java/com/hbm/main/ModEventHandlerClient.java @@ -34,6 +34,7 @@ import com.hbm.interfaces.IItemHUD; import com.hbm.interfaces.Spaghetti; import com.hbm.inventory.RecipesCommon.ComparableStack; import com.hbm.inventory.gui.GUIArmorTable; +import com.hbm.inventory.gui.GUIScreenPreview; import com.hbm.items.ISyncButtons; import com.hbm.items.ModItems; import com.hbm.items.armor.ArmorFSB; @@ -931,40 +932,28 @@ public class ModEventHandlerClient { } } - if(mc.currentScreen instanceof GuiContainer && Keyboard.isKeyDown(Keyboard.KEY_F1)) { - - ScaledResolution scaledresolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); - int width = scaledresolution.getScaledWidth(); - int height = scaledresolution.getScaledHeight(); - int mouseX = Mouse.getX() * width / mc.displayWidth; - int mouseY = height - Mouse.getY() * height / mc.displayHeight - 1; + if(Keyboard.isKeyDown(Keyboard.KEY_F1)) { - GuiContainer container = (GuiContainer) mc.currentScreen; - - for(Object o : container.inventorySlots.inventorySlots) { - Slot slot = (Slot) o; - - if(slot.getHasStack()) { - try { - Method isMouseOverSlot = ReflectionHelper.findMethod(GuiContainer.class, container, new String[] {"func_146981_a", "isMouseOverSlot"}, Slot.class, int.class, int.class); - - if((boolean) isMouseOverSlot.invoke(container, slot, mouseX, mouseY)) { - - ComparableStack comp = new ComparableStack(slot.getStack()).makeSingular(); - CanneryBase cannery = Jars.canneries.get(comp); - - if(cannery != null) { - FMLCommonHandler.instance().showGuiScreen(new GuiWorldInAJar(cannery.createScript(), cannery.getName(), cannery.getIcon(), cannery.seeAlso())); - } - - break; - } - - } catch(Exception ex) { } + ItemStack stack = getMouseOverStack(); + if(stack != null) { + ComparableStack comp = new ComparableStack(stack).makeSingular(); + CanneryBase cannery = Jars.canneries.get(comp); + if(cannery != null) { + FMLCommonHandler.instance().showGuiScreen(new GuiWorldInAJar(cannery.createScript(), cannery.getName(), cannery.getIcon(), cannery.seeAlso())); } } } + if(Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) && Keyboard.isKeyDown(Keyboard.KEY_LMENU)) { + + ItemStack stack = getMouseOverStack(); + if(stack != null) { + stack = stack.copy(); + stack.stackSize = 1; + FMLCommonHandler.instance().showGuiScreen(new GUIScreenPreview(stack)); + } + } + if(event.phase == Phase.START) { EntityPlayer player = mc.thePlayer; @@ -985,6 +974,38 @@ public class ModEventHandlerClient { } } + public static ItemStack getMouseOverStack() { + + Minecraft mc = Minecraft.getMinecraft(); + if(mc.currentScreen instanceof GuiContainer) { + + ScaledResolution scaledresolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + int width = scaledresolution.getScaledWidth(); + int height = scaledresolution.getScaledHeight(); + int mouseX = Mouse.getX() * width / mc.displayWidth; + int mouseY = height - Mouse.getY() * height / mc.displayHeight - 1; + + GuiContainer container = (GuiContainer) mc.currentScreen; + + for(Object o : container.inventorySlots.inventorySlots) { + Slot slot = (Slot) o; + + if(slot.getHasStack()) { + try { + Method isMouseOverSlot = ReflectionHelper.findMethod(GuiContainer.class, container, new String[] {"func_146981_a", "isMouseOverSlot"}, Slot.class, int.class, int.class); + + if((boolean) isMouseOverSlot.invoke(container, slot, mouseX, mouseY)) { + return slot.getStack(); + } + + } catch(Exception ex) { } + } + } + } + + return null; + } + @SideOnly(Side.CLIENT) @SubscribeEvent(priority = EventPriority.LOWEST) public void onClientTickLast(ClientTickEvent event) {