From 6dac2a1ce91d444355a2e0ce116f18b7413a8c12 Mon Sep 17 00:00:00 2001 From: Aesen Vismea Date: Sat, 2 Apr 2016 15:05:23 -0400 Subject: [PATCH] Ctrl+Render while hovering a slot now pre-fills the owning mod's ID Implements #6 --- .../blockrenderer/BlockRenderer.java | 45 ++++++++++--------- .../blockrenderer/GuiEnterModId.java | 8 +++- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/unascribed/blockrenderer/BlockRenderer.java b/src/main/java/com/unascribed/blockrenderer/BlockRenderer.java index 1aef611..621c5c6 100644 --- a/src/main/java/com/unascribed/blockrenderer/BlockRenderer.java +++ b/src/main/java/com/unascribed/blockrenderer/BlockRenderer.java @@ -100,31 +100,36 @@ public void onFrameStart(RenderTickEvent e) { if (!down) { down = true; Minecraft mc = Minecraft.getMinecraft(); + Slot hovered = null; + GuiScreen currentScreen = mc.currentScreen; + if (currentScreen instanceof GuiContainer) { + int w = currentScreen.width; + int h = currentScreen.height; + final int x = Mouse.getX() * w / mc.displayWidth; + // OpenGL's Y-zero is at the *bottom* of the window. + // Minecraft's Y-zero is at the top. So, we need to flip it. + final int y = h - Mouse.getY() * h / mc.displayHeight - 1; + hovered = ((GuiContainer)currentScreen).getSlotAtPosition(x, y); + } if (GuiScreen.isCtrlKeyDown()) { - mc.displayGuiScreen(new GuiEnterModId(mc.currentScreen)); - } else { - GuiScreen currentScreen = mc.currentScreen; - if (currentScreen instanceof GuiContainer) { - int w = currentScreen.width; - int h = currentScreen.height; - final int x = Mouse.getX() * w / mc.displayWidth; - // OpenGL's Y-zero is at the *bottom* of the window. - // Minecraft's Y-zero is at the top. So, we need to flip it. - final int y = h - Mouse.getY() * h / mc.displayHeight - 1; - Slot s = ((GuiContainer)currentScreen).getSlotAtPosition(x, y); - if (s != null) { - ItemStack is = s.getStack(); - if (is != null) { - mc.ingameGUI.getChatGUI().printChatMessage(new ChatComponentText(render(is, new File("renders"), 512, true))); - } else { - mc.ingameGUI.getChatGUI().printChatMessage(new ChatComponentTranslation("msg.slot.empty")); - } + String modid = null; + if (hovered != null && hovered.getHasStack()) { + modid = Item.itemRegistry.getNameForObject(hovered.getStack().getItem()).getResourceDomain(); + } + mc.displayGuiScreen(new GuiEnterModId(mc.currentScreen, modid)); + } else if (currentScreen instanceof GuiContainer) { + if (hovered != null) { + ItemStack is = hovered.getStack(); + if (is != null) { + mc.ingameGUI.getChatGUI().printChatMessage(new ChatComponentText(render(is, new File("renders"), 512, true))); } else { - mc.ingameGUI.getChatGUI().printChatMessage(new ChatComponentTranslation("msg.slot.absent")); + mc.ingameGUI.getChatGUI().printChatMessage(new ChatComponentTranslation("msg.slot.empty")); } } else { - mc.ingameGUI.getChatGUI().printChatMessage(new ChatComponentTranslation("msg.notcontainer")); + mc.ingameGUI.getChatGUI().printChatMessage(new ChatComponentTranslation("msg.slot.absent")); } + } else { + mc.ingameGUI.getChatGUI().printChatMessage(new ChatComponentTranslation("msg.notcontainer")); } } } else { diff --git a/src/main/java/com/unascribed/blockrenderer/GuiEnterModId.java b/src/main/java/com/unascribed/blockrenderer/GuiEnterModId.java index c875754..c22bf59 100644 --- a/src/main/java/com/unascribed/blockrenderer/GuiEnterModId.java +++ b/src/main/java/com/unascribed/blockrenderer/GuiEnterModId.java @@ -4,6 +4,8 @@ import org.lwjgl.input.Keyboard; +import com.google.common.base.Strings; + import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiSlider; @@ -12,18 +14,20 @@ import net.minecraft.client.resources.I18n; public class GuiEnterModId extends GuiScreen implements GuiResponder { + private String prefill; private GuiTextField text; private GuiSlider size; private GuiScreen old; - public GuiEnterModId(GuiScreen old) { + public GuiEnterModId(GuiScreen old, String prefill) { this.old = old; + this.prefill = Strings.nullToEmpty(prefill); } @Override public void initGui() { Keyboard.enableRepeatEvents(true); - String oldText = (text == null ? "" : text.getText()); + String oldText = (text == null ? prefill : text.getText()); float oldSize = (size == null ? 512 : size.func_175220_c());