Skip to content

Commit

Permalink
Ctrl+Render while hovering a slot now pre-fills the owning mod's ID
Browse files Browse the repository at this point in the history
Implements #6
  • Loading branch information
unascribed committed Apr 2, 2016
1 parent f74eaaa commit 6dac2a1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
45 changes: 25 additions & 20 deletions src/main/java/com/unascribed/blockrenderer/BlockRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/unascribed/blockrenderer/GuiEnterModId.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());

Expand Down

0 comments on commit 6dac2a1

Please sign in to comment.