mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-12 00:17:51 +00:00
Improve image exporter data dumper (#902)
This commit is contained in:
1 parent
6bc899769f
commit
b60769864f
2 files changed
+82
-21
No files matched your search
@@ -5,6 +5,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -23,7 +24,11 @@ import codechicken.nei.guihook.GuiContainerManager;
|
||||
|
||||
public class ItemPanelDumper extends DataDumper {
|
||||
|
||||
private static final int[] resolutions = new int[] { 16, 32, 48, 64, 128, 256 };
|
||||
public static final int CSV = 0;
|
||||
public static final int NBT = 1;
|
||||
public static final int JSON = 2;
|
||||
public static final int PNG = 3;
|
||||
private static final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
public ItemPanelDumper(String name) {
|
||||
super(name);
|
||||
@@ -54,19 +59,29 @@ public class ItemPanelDumper extends DataDumper {
|
||||
|
||||
public int getRes() {
|
||||
int i = renderTag(name + ".res").getIntValue(0);
|
||||
if (i >= resolutions.length || i < 0) renderTag().setIntValue(i = 0);
|
||||
return resolutions[i];
|
||||
int size = 16 << i;
|
||||
if (size >= getSmallerScreenAxisSize() || i < 0) {
|
||||
getTag(name + ".res").setIntValue(0);
|
||||
size = 16;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
private int getSmallerScreenAxisSize() {
|
||||
int width = mc.displayWidth;
|
||||
int height = mc.displayHeight;
|
||||
return Math.min(width, height);
|
||||
}
|
||||
|
||||
public Rectangle4i resButtonSize() {
|
||||
int width = 50;
|
||||
int width = 60;
|
||||
return new Rectangle4i(modeButtonSize().x - width - 6, 0, width, 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int mousex, int mousey, float frame) {
|
||||
super.draw(mousex, mousey, frame);
|
||||
if (getMode() == 3) {
|
||||
if (getMode() == PNG) {
|
||||
int res = getRes();
|
||||
drawButton(mousex, mousey, resButtonSize(), res + "x" + res);
|
||||
}
|
||||
@@ -74,23 +89,35 @@ public class ItemPanelDumper extends DataDumper {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mousex, int mousey, int button) {
|
||||
if (getMode() == 3 && resButtonSize().contains(mousex, mousey)) {
|
||||
if (getMode() != PNG) {
|
||||
super.mouseClicked(mousex, mousey, button);
|
||||
return;
|
||||
}
|
||||
if (resButtonSize().contains(mousex, mousey)) {
|
||||
NEIClientUtils.playClickSound();
|
||||
getTag(name + ".res").setIntValue((renderTag(name + ".res").getIntValue(0) + 1) % resolutions.length);
|
||||
} else super.mouseClicked(mousex, mousey, button);
|
||||
int current = renderTag(name + ".res").getIntValue(0);
|
||||
int next;
|
||||
// 31 - numberOfLeadingZeros(x) = floor(log2(x))
|
||||
int max = 31 - Integer.numberOfLeadingZeros(getSmallerScreenAxisSize()) - 3;
|
||||
if (button == 1) { // Right click to cycle backward
|
||||
next = (current - 1 + max) % max;
|
||||
} else { // Left click to cycle forward
|
||||
next = (current + 1) % max;
|
||||
}
|
||||
getTag(name + ".res").setIntValue(next);
|
||||
} else if (!dumpButtonSize().contains(mousex, mousey) || acknowledgedItemSizeWarning()) {
|
||||
super.mouseClicked(mousex, mousey, button);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileExtension() {
|
||||
switch (getMode()) {
|
||||
case 0:
|
||||
return ".csv";
|
||||
case 1:
|
||||
return ".nbt";
|
||||
case 2:
|
||||
return ".json";
|
||||
}
|
||||
return null;
|
||||
return switch (getMode()) {
|
||||
case CSV -> ".csv";
|
||||
case NBT -> ".nbt";
|
||||
case JSON -> ".json";
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,15 +132,29 @@ public class ItemPanelDumper extends DataDumper {
|
||||
|
||||
@Override
|
||||
public void dumpFile() {
|
||||
if (getMode() == 3) Minecraft.getMinecraft().displayGuiScreen(new GuiItemIconDumper(this, getRes()));
|
||||
if (getMode() == PNG && acknowledgedItemSizeWarning())
|
||||
mc.displayGuiScreen(new GuiItemIconDumper(this, getRes()));
|
||||
else super.dumpFile();
|
||||
}
|
||||
|
||||
private boolean acknowledgedItemSizeWarning() {
|
||||
return !showItemSizeWarning() || NEIClientUtils.shiftKey();
|
||||
}
|
||||
|
||||
private boolean showItemSizeWarning() {
|
||||
int res = getRes();
|
||||
// More than 4 items at 2048x2048, 16 items at 1024x1024, 64 at 512x512, etc.
|
||||
int WARNING_SIZE = 16_777_216;
|
||||
return ItemPanels.itemPanel.getItems().size() * res * res > WARNING_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dumpTo(File file) throws IOException {
|
||||
if (getMode() == 0) super.dumpTo(file);
|
||||
else if (getMode() == 1) dumpNBT(file);
|
||||
else dumpJson(file);
|
||||
switch (getMode()) {
|
||||
case CSV -> super.dumpTo(file);
|
||||
case NBT -> dumpNBT(file);
|
||||
default -> dumpJson(file);
|
||||
}
|
||||
}
|
||||
|
||||
public void dumpNBT(File file) throws IOException {
|
||||
@@ -141,4 +182,22 @@ public class ItemPanelDumper extends DataDumper {
|
||||
public int modeCount() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleTooltip(int mousex, int mousey, List<String> currenttip) {
|
||||
if (getMode() == PNG && dumpButtonSize().contains(mousex, mousey) && showItemSizeWarning()) {
|
||||
int res = getRes();
|
||||
currenttip.add(
|
||||
NEIClientUtils.translate(
|
||||
"options.tools.dump.itempanel.icon.warning.1",
|
||||
ItemPanels.itemPanel.getItems().size(),
|
||||
res,
|
||||
res));
|
||||
currenttip.add(
|
||||
NEIClientUtils.translate(
|
||||
"options.tools.dump.itempanel.icon.warning.2",
|
||||
NEIClientUtils.translate("key.shift")));
|
||||
}
|
||||
return currenttip;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user