feat: add tooltip

This commit is contained in:
Discreater committed 2021-04-26 22:32:54 +08:00
1 parent 4e290dde6d
commit dc1c02b035
29 files changed
+1153 -130

No files matched your search

@@ -3,21 +3,31 @@ package me.towdium.jecalculation.client.gui;
import cpw.mods.fml.client.config.GuiUtils;
import me.towdium.jecalculation.client.resource.Resource;
import me.towdium.jecalculation.client.widget.Widget;
import me.towdium.jecalculation.client.widget.widgets.WEntry;
import me.towdium.jecalculation.client.widget.widgets.WEntryGroup;
import me.towdium.jecalculation.core.entry.Entry;
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
import me.towdium.jecalculation.utils.helpers.LocalizationHelper;
import me.towdium.jecalculation.utils.wrappers.Single;
import me.towdium.jecalculation.utils.wrappers.Triple;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Keyboard;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
/**
@@ -30,24 +40,24 @@ public class JecGui extends GuiContainer {
public static final int COLOR_BLUE = 0xFFb0b9e6;
public List<GuiButton> buttonList = super.buttonList;
public WidgetManager widgetManager = new WidgetManager();
GuiScreen parent;
public WidgetManager wgtMgr = new WidgetManager();
public Entry hand = Entry.EMPTY;
protected GuiScreen parent;
protected List<Triple<Integer, Integer, List<String>>> tooltipBuffer = new ArrayList<>();
public JecGui(@Nullable GuiScreen parent) {
super(new Container() {
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
return true;
}
});
this(parent, false);
}
public JecGui(@Nullable GuiScreen parent, boolean acceptsTransfer) {
super(acceptsTransfer ? new ContainerTransfer() : new ContainerNonTransfer());
this.parent = parent;
}
@Override
public void initGui() {
super.initGui();
widgetManager.onInit();
wgtMgr.onInit();
}
public static boolean mouseIn(int xPos, int yPos, int xSize, int ySize, int xMouse, int yMouse) {
@@ -60,8 +70,10 @@ public class JecGui extends GuiContainer {
super.drawScreen(mouseX, mouseY, partialTicks);
GlStateManager.disableLighting();
GlStateManager.disableDepth();
widgetManager.onDraw(mouseX, mouseY);
wgtMgr.onDraw(mouseX, mouseY);
drawExtra();
drawItemStack(mouseX, mouseY, hand.getRepresentation(), true);
drawBufferedTooltip();
GlStateManager.enableLighting();
GlStateManager.enableDepth();
}
@@ -79,17 +91,54 @@ public class JecGui extends GuiContainer {
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
super.mouseClicked(mouseX, mouseY, mouseButton);
widgetManager.onClick(mouseX, mouseY, mouseButton);
wgtMgr.onClick(mouseX, mouseY, mouseButton);
}
// new functions
@Override
protected void keyTyped(char typedChar, int keyCode) {
super.keyTyped(typedChar, keyCode);
widgetManager.onKey(typedChar, keyCode);
if (!wgtMgr.onKey(typedChar, keyCode)) {
if (keyCode == Keyboard.KEY_ESCAPE) {
if (hand != Entry.EMPTY) hand = Entry.EMPTY;
else if (parent != null) Minecraft.getMinecraft().displayGuiScreen(parent);
else super.keyTyped(typedChar, keyCode);
}
}
}
// /**
// * @return if the event is canceled
// * This function handles click outside the normal region,
// * especially the overlap with JEI overlay. It handles
// * mouse event before JEI.
// */
// public boolean handleMouseEvent() {
// int xMouse = Mouse.getEventX() * this.width / this.mc.displayWidth;
// int yMouse = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
// if (Mouse.getEventButtonState()) {
// if (Mouse.getEventButton() == 0) {
// if (hand == Entry.EMPTY) {
// // TODO
// Entry e = JecPlugin.getEntryUnderMouse();
// if (e != Entry.EMPTY) {
// hand = e;
// return true;
// }
// } else {
// if (!mouseIn(guiLeft, guiTop, width, height, xMouse, yMouse)) {
// hand = Entry.EMPTY;
// return true;
// }
// }
// } else if (Mouse.getEventButton() == 1) {
// if (hand != Entry.EMPTY) {
// hand = Entry.EMPTY;
// return true;
// }
// }
// }
// return false;
// }
public FontRenderer getFontRenderer() {
return fontRendererObj;
}
@@ -123,6 +172,7 @@ public class JecGui extends GuiContainer {
public void drawRectangle(int xPos, int yPos, int xSize, int ySize, int color) {
drawRect(xPos, yPos, xPos + xSize, yPos + ySize, color);
// TODO Different from origin
}
public void drawText(int xPos, int yPos, Font f, String... text) {
@@ -172,13 +222,30 @@ public class JecGui extends GuiContainer {
}
public void drawTooltip(int xPos, int yPos, List<String> text) {
drawHoveringText(text, xPos, yPos);
GlStateManager.disableLighting();
GlStateManager.disableDepth();
tooltipBuffer.add(new Triple<>(xPos, yPos, text));
}
public void localize(String key) {
//LocalizationHelper.format(this.getClass(), )
protected void drawBufferedTooltip() {
tooltipBuffer.forEach(i -> {
drawHoveringText(i.three, i.one, i.two);
GlStateManager.disableLighting();
GlStateManager.disableDepth();
});
tooltipBuffer.clear();
}
public void drawItemStack(int xPos, int yPos, ItemStack is, boolean centred) {
if (centred) {
xPos -= 8;
yPos -= 8;
}
RenderHelper.enableGUIStandardItemLighting();
itemRender.renderItemIntoGUI(fontRendererObj, mc.getTextureManager(), is, xPos, yPos);
RenderHelper.disableStandardItemLighting();
}
public String localize(String key, Object... os) {
return LocalizationHelper.format(this.getClass(), "gui", key, os);
}
// function to override
@@ -216,6 +283,21 @@ public class JecGui extends GuiContainer {
}
}
public static class ContainerTransfer extends Container {
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
return true;
}
}
public static class ContainerNonTransfer extends Container {
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
return true;
}
}
public class WidgetManager {
protected List<Widget> widgets = new ArrayList<>();
@@ -248,6 +330,15 @@ public class JecGui extends GuiContainer {
return widgets.stream().filter(w -> w instanceof Widget.Advanced)
.anyMatch(w -> ((Widget.Advanced) w).onKey(JecGui.this, ch, code));
}
public Optional<WEntry> getEntryAt(int xMouse, int yMouse) {
return widgets.stream().map(w -> {
if (w instanceof WEntryGroup) return ((WEntryGroup) w).getEntryAt(JecGui.this, xMouse, yMouse);
else if (w instanceof WEntry) return Optional.ofNullable(
((WEntry) w).mouseIn(JecGui.this, xMouse, yMouse) ? ((WEntry) w) : null);
else return Optional.<WEntry>empty();
}).filter(Optional::isPresent).findFirst().orElse(Optional.empty());
}
}
public int getGuiLeft() { return guiLeft; }
@@ -16,18 +16,18 @@ import javax.annotation.ParametersAreNonnullByDefault;
@ParametersAreNonnullByDefault
public class GuiCalculator extends JecGui {
public GuiCalculator(@Nullable GuiScreen parent) {
super(parent);
widgetManager.add(new WButtonIcon(7, 7, 20, 20, Resource.BUTTON_LABEL_N, Resource.BUTTON_LABEL_F)
.setListenerLeft(() -> Minecraft.getMinecraft().displayGuiScreen(null))
.setListenerRight(() -> Minecraft.getMinecraft().displayGuiScreen(null)));
widgetManager.add(new WButtonIcon(130, 7, 20, 20, Resource.BUTTON_NEW_N, Resource.BUTTON_NEW_F));
widgetManager.add(new WButtonIcon(149, 7, 20, 20, Resource.BUTTON_SEARCH_N, Resource.BUTTON_SEARCH_F));
widgetManager.add(new WEntryGroup(7, 87, 9, 4));
widgetManager.add(new WEntryGroup(7, 31, 8, 1));
widgetManager.add(new WEntry(31, 7, 20, 20));
widgetManager.add(new WLine(52));
widgetManager.add(new WTextField(62, 7, 63));
widgetManager.add(new WIcon(151, 31, 18, 18, Resource.ICON_RECENT_N, Resource.ICON_RECENT_F));
widgetManager.add(new WPager(7, 56, 162));
super(parent, true);
wgtMgr.add(new WButtonIcon(7, 7, 20, 20, Resource.BUTTON_LABEL_N, Resource.BUTTON_LABEL_F, "new_label")
.setListenerLeft(() -> Minecraft.getMinecraft().displayGuiScreen(null))
.setListenerRight(() -> Minecraft.getMinecraft().displayGuiScreen(null)));
wgtMgr.add(new WButtonIcon(130, 7, 20, 20, Resource.BUTTON_NEW_N, Resource.BUTTON_NEW_F, "new_recipe"));
wgtMgr.add(new WButtonIcon(149, 7, 20, 20, Resource.BUTTON_SEARCH_N, Resource.BUTTON_SEARCH_F, "search"));
wgtMgr.add(new WEntryGroup(7, 87, 9, 4));
wgtMgr.add(new WEntryGroup(7, 31, 8, 1));
wgtMgr.add(new WEntry(31, 7, 20, 20));
wgtMgr.add(new WLine(52));
wgtMgr.add(new WTextField(62, 7, 63));
wgtMgr.add(new WIcon(151, 31, 18, 18, Resource.ICON_RECENT_N, Resource.ICON_RECENT_F));
wgtMgr.add(new WPager(7, 56, 162, 5));
}
}
@@ -3,10 +3,13 @@ package me.towdium.jecalculation.client.widget;
import me.towdium.jecalculation.client.gui.JecGui;
import net.minecraft.client.gui.Gui;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: towdium
* Date: 8/14/17.
*/
@ParametersAreNonnullByDefault
public class Widget extends Gui {
protected static int gl(JecGui gui) {
return gui.getGuiLeft();
@@ -35,22 +38,5 @@ public class Widget extends Gui {
}
}
public class Timer {
long time = System.currentTimeMillis();
boolean running = false;
public void setState(boolean b) {
if (!b && running)
running = false;
if (b && !running) {
running = true;
time = System.currentTimeMillis();
}
}
public long getTime() {
return running ? System.currentTimeMillis() - time : 0;
}
}
}
@@ -4,24 +4,35 @@ import cpw.mods.fml.client.config.GuiButtonExt;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.widget.Widget;
import me.towdium.jecalculation.utils.ClientUtils;
import me.towdium.jecalculation.utils.Utilities;
import net.minecraft.client.Minecraft;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: towdium
* Date: 8/14/17.
*/
@ParametersAreNonnullByDefault
public class WButton extends Widget.Advanced {
protected int xPos, yPos, xSize, ySize;
protected Runnable lsnrLeft, lsnrRight;
protected String text;
public int xPos, yPos, xSize, ySize;
public Runnable lsnrLeft, lsnrRight;
public String text, tooltip;
protected GuiButtonExt button;
protected Utilities.Timer timer = new Utilities.Timer();
public WButton(int xPos, int yPos, int xSize, int ySize, String text) {
this(xPos, yPos, xSize, ySize, text, null);
}
public WButton(int xPos, int yPos, int xSize, int ySize, String text, @Nullable String tooltip) {
this.xPos = xPos;
this.yPos = yPos;
this.xSize = xSize;
this.ySize = ySize;
this.text = text;
this.tooltip = tooltip;
}
public WButton setListenerLeft(Runnable r) {
@@ -72,4 +83,13 @@ public class WButton extends Widget.Advanced {
public void onRemoved(JecGui gui) {
gui.buttonList.remove(button);
}
@Override
public void onDraw(JecGui gui, int xMouse, int yMouse) {
if (tooltip != null) {
boolean hovered = JecGui.mouseIn(xPos + gl(gui), yPos + gt(gui), xSize, ySize, xMouse, yMouse);
timer.setState(hovered);
if (timer.getTime() > 500) gui.drawTooltip(xMouse, yMouse, gui.localize("tooltip." + tooltip));
}
}
}
@@ -5,16 +5,24 @@ import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.resource.Resource;
import net.minecraft.client.Minecraft;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: towdium
* Date: 17-8-17.
*/
@ParametersAreNonnullByDefault
public class WButtonIcon extends WButton {
protected int xPos, yPos, xSize, ySize;
protected Resource normal, focused;
public WButtonIcon(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused) {
super(xPos, yPos, xSize, ySize, "");
this(xPos, yPos, xSize, ySize, normal, focused, null);
}
public WButtonIcon(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused, @Nullable String tooltip) {
super(xPos, yPos, xSize, ySize, "", tooltip);
this.xPos = xPos;
this.yPos = yPos;
this.xSize = xSize;
@@ -44,4 +52,12 @@ public class WButtonIcon extends WButton {
};
gui.buttonList.add(button);
}
public WButtonIcon setListenerLeft(Runnable r) {
return ((WButtonIcon) super.setListenerLeft(r));
}
public WButtonIcon setListenerRight(Runnable r) {
return ((WButtonIcon) super.setListenerRight(r));
}
}
@@ -5,10 +5,13 @@ import me.towdium.jecalculation.client.resource.Resource;
import me.towdium.jecalculation.client.widget.Widget;
import me.towdium.jecalculation.core.entry.Entry;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: towdium
* Date: 17-8-17.
*/
@ParametersAreNonnullByDefault
public class WEntry extends Widget.Advanced {
public int xPos, yPos, xSize, ySize;
public Entry entry;
@@ -18,6 +21,7 @@ public class WEntry extends Widget.Advanced {
this.yPos = yPos;
this.xSize = xSize;
this.ySize = ySize;
this.entry = Entry.EMPTY;
}
public Entry getEntry() {
@@ -30,11 +34,25 @@ public class WEntry extends Widget.Advanced {
@Override
public void onDraw(JecGui gui, int xMouse, int yMouse) {
gui.drawResourceContinuous(Resource.WIDGET_SLOT, xPos + gui.getGuiLeft(), yPos + gui.getGuiTop(),
xSize, ySize, 3, 3, 3, 3);
if (mouseIn(gui, xMouse, yMouse)) drawRect(gui.getGuiLeft() + xPos + 1, gui.getGuiTop() + yPos + 1,
gui.getGuiLeft() + xPos + xSize - 1, gui.getGuiTop() + yPos + ySize - 1, 0x80FFFFFF);
// TODO draw itemStack
gui.drawResourceContinuous(Resource.WIDGET_SLOT, xPos + gui.getGuiLeft(), yPos + gui.getGuiTop(), xSize, ySize,
3, 3, 3, 3);
gui.drawItemStack(gl(gui) + xPos + xSize / 2, gt(gui) + yPos + ySize / 2, entry.getRepresentation(), true);
if (mouseIn(gui, xMouse, yMouse))
gui.drawRectangle(gui.getGuiLeft() + xPos + 1, gui.getGuiTop() + yPos + 1, xSize - 2, ySize - 2,
0x80FFFFFF);
// TODO draw amount
}
@Override
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
if (mouseIn(gui, xMouse, yMouse)) { // TODO different modes
if (gui.hand != Entry.EMPTY && button == 0) {
entry = gui.hand;
gui.hand = Entry.EMPTY;
return true;
}
}
return false;
}
public boolean mouseIn(JecGui gui, int x, int y) {
@@ -3,13 +3,16 @@ package me.towdium.jecalculation.client.widget.widgets;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.widget.Widget;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.Optional;
import java.util.stream.IntStream;
/**
* Author: towdium
* Date: 17-8-17.
*/
@ParametersAreNonnullByDefault
public class WEntryGroup extends Widget.Advanced {
ArrayList<WEntry> widgets = new ArrayList<>();
@@ -41,4 +44,8 @@ public class WEntryGroup extends Widget.Advanced {
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
return widgets.stream().anyMatch(w -> w.onClicked(gui, xMouse, yMouse, button));
}
public Optional<WEntry> getEntryAt(JecGui gui, int xMouse, int yMouse) {
return widgets.stream().filter(w -> w.mouseIn(gui, xMouse, yMouse)).findFirst();
}
}
@@ -3,24 +3,36 @@ package me.towdium.jecalculation.client.widget.widgets;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.resource.Resource;
import me.towdium.jecalculation.client.widget.Widget;
import me.towdium.jecalculation.utils.Utilities.Timer;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: towdium
* Date: 17-8-18.
*/
@ParametersAreNonnullByDefault
public class WIcon extends Widget {
public int xPos, yPos, xSize, ySize;
public Resource normal, focused;
Timer timer = new Timer();
public String tooltip;
public WIcon(int xPos, int yPos, int xSize, int ySize, Resource normal, Resource focused) {
this(xPos, yPos, xSize, ySize, normal, focused, null);
}
public WIcon(int xPos, int yPos, int xSize, int ySize,
Resource normal, Resource focused, @Nullable String tooltip) {
this.xPos = xPos;
this.yPos = yPos;
this.xSize = xSize;
this.ySize = ySize;
this.normal = normal;
this.focused = focused;
this.tooltip = tooltip;
}
@Override
@@ -30,7 +42,9 @@ public class WIcon extends Widget {
hovered ? JecGui.COLOR_BLUE : JecGui.COLOR_GREY);
Resource r = hovered ? focused : normal;
gui.drawResource(r, (xSize - r.getXSize()) / 2 + xPos + gl(gui), (ySize - r.getYSize()) / 2 + yPos + gt(gui));
timer.setState(hovered);
if (timer.getTime() > 500) gui.drawTooltip(xMouse, yMouse,"hahaa"); // TODO hover
if (tooltip != null) {
timer.setState(hovered);
if (timer.getTime() > 500) gui.drawTooltip(xMouse, yMouse, gui.localize("tooltip." + tooltip));
}
}
}
@@ -4,10 +4,13 @@ import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.resource.Resource;
import me.towdium.jecalculation.client.widget.Widget;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: towdium
* Date: 17-8-18.
*/
@ParametersAreNonnullByDefault
public class WLine extends Widget {
public int y;
@@ -3,29 +3,47 @@ package me.towdium.jecalculation.client.widget.widgets;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.resource.Resource;
import me.towdium.jecalculation.client.widget.Widget;
import me.towdium.jecalculation.utils.Utilities;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
/**
* Author: towdium
* Date: 17-8-19.
*/
@ParametersAreNonnullByDefault
public class WPager extends Widget.Advanced {
public static final int SIZE = 13;
protected int xPos, xSize, yPos;
protected WButtonIcon left, right;
protected Widget wRect, wText;
protected WRectangle wRect;
protected WText wText;
protected List<String> keys;
protected Utilities.Circulator index;
public WPager(int xPos, int yPos, int xSize) {
public WPager(int xPos, int yPos, int xSize, int total) {
this(xPos, yPos, xSize,
IntStream.rangeClosed(1, total).mapToObj(i -> i + "/" + total).collect(Collectors.toList()));
}
public WPager(int xPos, int yPos, int xSize, List<String> keys) {
this.xPos = xPos;
this.xSize = xSize;
this.yPos = yPos;
left = new WButtonIcon(xPos, yPos, SIZE, SIZE, Resource.WIDGET_ARR_L_N, Resource.WIDGET_ARR_L_F);
right = new WButtonIcon(xPos + xSize - SIZE, yPos, SIZE, SIZE,
Resource.WIDGET_ARR_R_N, Resource.WIDGET_ARR_R_F);
this.keys = keys;
left = new WButtonIcon(xPos, yPos, SIZE, SIZE, Resource.WIDGET_ARR_L_N, Resource.WIDGET_ARR_L_F)
.setListenerLeft(() -> index.prev());
right = new WButtonIcon(xPos + xSize - SIZE, yPos, SIZE, SIZE, Resource.WIDGET_ARR_R_N, Resource.WIDGET_ARR_R_F)
.setListenerLeft(() -> index.next());
wRect = new WRectangle(xPos + SIZE, yPos, xSize - 2 * SIZE, SIZE, JecGui.COLOR_GREY);
wText = new WText(xPos + SIZE, yPos, xSize - 2 * SIZE, SIZE, JecGui.Font.DEFAULT_SHADOW, "test"); // TODO input
wText = new WText(xPos + SIZE, yPos, xSize - 2 * SIZE, SIZE, JecGui.Font.DEFAULT_SHADOW,
() -> keys.get(index.index()));
index = new Utilities.Circulator(keys.size());
}
@Override
@@ -3,10 +3,13 @@ package me.towdium.jecalculation.client.widget.widgets;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.widget.Widget;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: towdium
* Date: 17-8-22.
*/
@ParametersAreNonnullByDefault
public class WRectangle extends Widget {
public int xPos, yPos, xSize, ySize, color;
@@ -3,26 +3,43 @@ package me.towdium.jecalculation.client.widget.widgets;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.widget.Widget;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.function.Supplier;
/**
* Author: towdium
* Date: 17-8-21.
*/
@ParametersAreNonnullByDefault
public class WText extends Widget {
public static final int UNDEFINED = Integer.MAX_VALUE;
int xPos, yPos, xSize, ySize;
JecGui.Font font;
String key;
public int xPos, yPos, xSize, ySize;
public JecGui.Font font;
public Supplier<String> key;
public WText(int xPos, int yPos, JecGui.Font font, String key) {
this(xPos, yPos, UNDEFINED, UNDEFINED, font, key);
}
public WText(int xPos, int yPos, JecGui.Font font, Supplier<String> key) {
this(xPos, yPos, UNDEFINED, UNDEFINED, font, key);
}
public WText(int xPos, int yPos, int xSize, JecGui.Font font, String key) {
this(xPos, yPos, xSize, UNDEFINED, font, key);
}
public WText(int xPos, int yPos, int xSize, JecGui.Font font, Supplier<String> key) {
this(xPos, yPos, xSize, UNDEFINED, font, key);
}
public WText(int xPos, int yPos, int xSize, int ySize, JecGui.Font font, String key) {
this(xPos, yPos, xSize, UNDEFINED, font, () -> key);
}
public WText(int xPos, int yPos, int xSize, int ySize, JecGui.Font font, Supplier<String> key) {
this.xPos = xPos;
this.yPos = yPos;
this.xSize = xSize;
@@ -35,7 +52,7 @@ public class WText extends Widget {
public void onDraw(JecGui gui, int xMouse, int yMouse) {
int gl = gl(gui);
int gt = gt(gui);
String[] text = key.split("\n");
String[] text = key.get().split("\n");
if (xSize == UNDEFINED) gui.drawText(xPos + gl, yPos + gt, font, text);
else if (ySize == UNDEFINED) gui.drawText(xPos + gl, yPos + gt, xSize, font, text);
else gui.drawText(xPos + gl, yPos + gt, xSize, ySize, font, text);
@@ -4,10 +4,13 @@ import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.widget.Widget;
import net.minecraft.client.gui.GuiTextField;
import javax.annotation.ParametersAreNonnullByDefault;
/**
* Author: towdium
* Date: 17-8-18.
*/
@ParametersAreNonnullByDefault
public class WTextField extends Widget.Advanced {
protected int xPos, yPos, xSize;
GuiTextField textField;
@@ -36,7 +36,7 @@ public class JecaCommand extends CommandBase {
if (cmd != null) {
cmd.execute(sender, args);
} else {
sender.addChatMessage(new ChatComponentTranslation("command.not_found", args[0]));
sender.addChatMessage(new ChatComponentTranslation("command.common.not_found", args[0]));
}
}
}
@@ -29,7 +29,7 @@ public class CommandHelp implements SubCommand {
@Override
public void execute(ICommandSender sender, String[] args) throws CommandException {
if (args.length != 0) {
sender.addChatMessage(new ChatComponentTranslation("command.unexpected_arg", String.join(" ", args)));
sender.addChatMessage(new ChatComponentTranslation("command.common.unexpected_arg", String.join(" ", args)));
return;
}
@@ -3,7 +3,9 @@ package me.towdium.jecalculation.core.entry;
import me.towdium.jecalculation.core.entry.entries.EntryItemStack;
import me.towdium.jecalculation.utils.wrappers.Pair;
import me.towdium.jecalculation.utils.wrappers.Single;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBucket;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -16,7 +18,7 @@ import java.util.function.Function;
* Date: 8/11/17.
*/
public interface Entry {
EntryMerger MERGER = EntryMerger.INSTANCE;
EntryMergerRegistry MERGER = EntryMergerRegistry.INSTANCE;
EntryRegistry REGISTRY = EntryRegistry.INSTANCE;
Entry EMPTY = new EntryItemStack(new ItemStack(new Item()), 0);
@@ -37,20 +39,20 @@ public interface Entry {
* to operate the {@link Entry}.
* For registering, see {@link EntryRegistry}.
*/
class EntryMerger {
private static final EntryMerger INSTANCE;
class EntryMergerRegistry {
public static final EntryMergerRegistry INSTANCE;
static {
INSTANCE = new EntryMerger();
INSTANCE = new EntryMergerRegistry();
// register functions here
}
private Relation<String, MergerFunction> functions = new Relation<>();
private EntryMerger() {
private EntryMergerRegistry() {
}
public void addFunction(String a, String b, MergerFunction func) {
public void register(String a, String b, MergerFunction func) {
functions.add(a, b, func);
}
@@ -83,12 +85,12 @@ public interface Entry {
/**
* This class is used to register an {@link Entry} type.
* Here you can find the identifier and deserializer of one type.
* For {@link Entry} operations, see {@link EntryMerger}
* For {@link Entry} operations, see {@link EntryMergerRegistry}
*/
class EntryRegistry {
public static final String KEY_IDENTIFIER = "identifier";
public static final String KEY_CONTENT = "content";
private static final EntryRegistry INSTANCE;
public static final EntryRegistry INSTANCE;
static {
INSTANCE = new EntryRegistry();
@@ -108,6 +110,19 @@ public interface Entry {
idToData.put(identifier, new Pair<>(clazz, deserializer));
}
/**
* @param nbt NBT to deserialize
* @return the recovered entry
* A typical NBT structure of an {@link Entry} is as follows:
* <pre>{@code
* {
* KEY_IDENTIFIER: entry_id
* KEY_CONTENT: {
* entry_content
* }
* }
* }</pre>
*/
public Entry deserialization(NBTTagCompound nbt) {
String s = nbt.getString(KEY_IDENTIFIER);
Optional<Entry> e = idToData.get(s).two.apply(nbt.getCompoundTag(KEY_CONTENT));
@@ -11,6 +11,11 @@ public class EntryItemStack implements Entry {
int amount;
ItemStack itemStack;
public EntryItemStack(ItemStack is) {
this(is, is.stackSize); // todo check
}
// I will copy it!
public EntryItemStack(ItemStack is, int amount) {
itemStack = is.copy();
@@ -6,9 +6,12 @@ import cpw.mods.fml.common.gameevent.InputEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.client.gui.guis.GuiCalculator;
import me.towdium.jecalculation.network.ProxyClient;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.client.event.GuiScreenEvent;
/**
* Author: towdium
@@ -16,11 +19,19 @@ import net.minecraft.client.Minecraft;
*/
public class InputEventHandler {
@SideOnly(Side.CLIENT)
@SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
@SubscribeEvent
public void onKey(InputEvent.KeyInputEvent event) {
if (ProxyClient.keyOpenGui.isPressed() && JustEnoughCalculation.side != JustEnoughCalculation.enumSide.SERVER) {
Minecraft.getMinecraft().displayGuiScreen(new GuiCalculator(null));
}
}
// @SubscribeEvent(priority = EventPriority.HIGH)
// public void onMouseClick(GuiScreenEvent.MouseInputEvent.Pre event) {
// if (event.getGui() instanceof JecGui) {
// GuiScreen gui = event.getGui();
// event.setCanceled(((JecGui) gui).handleMouseEvent());
// }
// }
}
@@ -3,6 +3,7 @@ package me.towdium.jecalculation.nei;
import codechicken.nei.PositionedStack;
import codechicken.nei.api.IOverlayHandler;
import codechicken.nei.recipe.IRecipeHandler;
import me.towdium.jecalculation.client.gui.JecGui;
import me.towdium.jecalculation.utils.ItemStackHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
@@ -14,36 +15,36 @@ import java.util.List;
public class JecaOverlayHandler implements IOverlayHandler {
@Override
public void overlayRecipe(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
// if(firstGui instanceof GuiEditor) {
// List<ItemStack> inputStacks = new ArrayList<>();
// LOOP:
// for (PositionedStack positionedStack : recipe.getIngredientStacks(recipeIndex)) {
// ItemStack itemStack = positionedStack.items[0];
// for (ItemStack exist : inputStacks) {
// if (ItemStackHelper.isTypeEqual(exist, itemStack)) {
// exist.stackSize += itemStack.stackSize;
// continue LOOP;
// }
// }
// inputStacks.add(itemStack.copy());
// }
// ItemStack outputStack = recipe.getResultStack(recipeIndex).items[0];
//
// Minecraft mc = Minecraft.getMinecraft();
// mc.displayGuiScreen(new GuiEditor(firstGui));
// GuiContainer myGuiContainer = (GuiContainer) mc.currentScreen;
// if (myGuiContainer != null) {
// myGuiContainer.inventorySlots.getSlot(0).putStack(outputStack);
// for (int i = 8; i <= 8 + inputStacks.size() - 1 && i <= 19; i++) {
// myGuiContainer.inventorySlots.getSlot(i).putStack(inputStacks.get(i - 8));
// }
// //crafting item, nei may not have
// // myGuiContainer.inventorySlots.getSlot(4).putStack();
// }
//
// } else {
// System.out.println(firstGui.getClass().toString());
// }
if(firstGui instanceof JecGui) {
List<ItemStack> inputStacks = new ArrayList<>();
LOOP:
for (PositionedStack positionedStack : recipe.getIngredientStacks(recipeIndex)) {
ItemStack itemStack = positionedStack.items[0];
for (ItemStack exist : inputStacks) {
if (ItemStackHelper.isTypeEqual(exist, itemStack)) {
exist.stackSize += itemStack.stackSize;
continue LOOP;
}
}
inputStacks.add(itemStack.copy());
}
ItemStack outputStack = recipe.getResultStack(recipeIndex).items[0];
Minecraft mc = Minecraft.getMinecraft();
mc.displayGuiScreen(new JecGui(firstGui));
GuiContainer myGuiContainer = (GuiContainer) mc.currentScreen;
if (myGuiContainer != null) {
myGuiContainer.inventorySlots.getSlot(0).putStack(outputStack);
for (int i = 8; i <= 8 + inputStacks.size() - 1 && i <= 19; i++) {
myGuiContainer.inventorySlots.getSlot(i).putStack(inputStacks.get(i - 8));
}
//crafting item, nei may not have
// myGuiContainer.inventorySlots.getSlot(4).putStack();
}
} else {
System.out.println(firstGui.getClass().toString());
}
}
}
@@ -1,6 +1,7 @@
package me.towdium.jecalculation.nei;
import codechicken.nei.guihook.IContainerTooltipHandler;
import me.towdium.jecalculation.client.gui.JecGui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
@@ -14,8 +15,8 @@ public class JecaTooltipHandler implements IContainerTooltipHandler {
@Override
public List<String> handleItemDisplayName(GuiContainer gui, ItemStack itemstack, List<String> currenttip) {
// if (gui instanceof JecaGuiContainer) {
// ((JecaGuiContainer)gui).handleMouseOverNEIItemPanel(itemstack);
// if (gui instanceof JecGui) {
// ((JecGui)gui).handleMouseOverNEIItemPanel(itemstack);
// }
return currenttip;
}
@@ -3,6 +3,7 @@ package me.towdium.jecalculation.nei;
import codechicken.nei.api.API;
import codechicken.nei.api.IConfigureNEI;
import me.towdium.jecalculation.JustEnoughCalculation;
import me.towdium.jecalculation.client.gui.JecGui;
public class NEICalculatorConfig implements IConfigureNEI {
@@ -10,10 +11,10 @@ public class NEICalculatorConfig implements IConfigureNEI {
public void loadConfig() {
System.out.println("loaded nei config");
String [] recipeType = new String[]{ "crafting", "crafting2x2", "smelting", "fuel", "brewing"};
// for (String ident : recipeType) {
// API.registerGuiOverlay(GuiEditor.class, ident);
// API.registerGuiOverlayHandler(GuiEditor.class, new JecaOverlayHandler(), ident);
// }
for (String ident : recipeType) {
API.registerGuiOverlay(JecGui.class, ident);
API.registerGuiOverlayHandler(JecGui.class, new JecaOverlayHandler(), ident);
}
}
@Override
@@ -1,4 +1,4 @@
package me.towdium.jecalculation.utils.polyfill;
package me.towdium.jecalculation.polyfill;
import cpw.mods.fml.relauncher.Side;
@@ -1,4 +1,4 @@
package me.towdium.jecalculation.utils.polyfill;
package me.towdium.jecalculation.polyfill;
import cpw.mods.fml.common.eventhandler.EventBus;
@@ -0,0 +1,569 @@
package me.towdium.jecalculation.polyfill.mc.util.math;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Random;
import java.util.UUID;
public class MathHelper
{
public static final float SQRT_2 = sqrt(2.0F);
private static final float[] SIN_TABLE = new float[65536];
private static final Random RANDOM = new Random();
private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION;
private static final double FRAC_BIAS;
private static final double[] ASINE_TAB;
private static final double[] COS_TAB;
public static float sin(float value)
{
return SIN_TABLE[(int)(value * 10430.378F) & 65535];
}
public static float cos(float value)
{
return SIN_TABLE[(int)(value * 10430.378F + 16384.0F) & 65535];
}
public static float sqrt(float value)
{
return (float)Math.sqrt((double)value);
}
public static float sqrt(double value)
{
return (float)Math.sqrt(value);
}
public static int floor(float value)
{
int i = (int)value;
return value < (float)i ? i - 1 : i;
}
@SideOnly(Side.CLIENT)
public static int fastFloor(double value)
{
return (int)(value + 1024.0D) - 1024;
}
public static int floor(double value)
{
int i = (int)value;
return value < (double)i ? i - 1 : i;
}
public static long lfloor(double value)
{
long i = (long)value;
return value < (double)i ? i - 1L : i;
}
@SideOnly(Side.CLIENT)
public static int absFloor(double value)
{
return (int)(value >= 0.0D ? value : -value + 1.0D);
}
public static float abs(float value)
{
return value >= 0.0F ? value : -value;
}
public static int abs(int value)
{
return value >= 0 ? value : -value;
}
public static int ceil(float value)
{
int i = (int)value;
return value > (float)i ? i + 1 : i;
}
public static int ceil(double value)
{
int i = (int)value;
return value > (double)i ? i + 1 : i;
}
public static int clamp(int num, int min, int max)
{
if (num < min)
{
return min;
}
else
{
return num > max ? max : num;
}
}
public static float clamp(float num, float min, float max)
{
if (num < min)
{
return min;
}
else
{
return num > max ? max : num;
}
}
public static double clamp(double num, double min, double max)
{
if (num < min)
{
return min;
}
else
{
return num > max ? max : num;
}
}
public static double clampedLerp(double lowerBnd, double upperBnd, double slide)
{
if (slide < 0.0D)
{
return lowerBnd;
}
else
{
return slide > 1.0D ? upperBnd : lowerBnd + (upperBnd - lowerBnd) * slide;
}
}
public static double absMax(double p_76132_0_, double p_76132_2_)
{
if (p_76132_0_ < 0.0D)
{
p_76132_0_ = -p_76132_0_;
}
if (p_76132_2_ < 0.0D)
{
p_76132_2_ = -p_76132_2_;
}
return p_76132_0_ > p_76132_2_ ? p_76132_0_ : p_76132_2_;
}
@SideOnly(Side.CLIENT)
public static int intFloorDiv(int p_76137_0_, int p_76137_1_)
{
return p_76137_0_ < 0 ? -((-p_76137_0_ - 1) / p_76137_1_) - 1 : p_76137_0_ / p_76137_1_;
}
public static int getInt(Random random, int minimum, int maximum)
{
return minimum >= maximum ? minimum : random.nextInt(maximum - minimum + 1) + minimum;
}
public static float nextFloat(Random random, float minimum, float maximum)
{
return minimum >= maximum ? minimum : random.nextFloat() * (maximum - minimum) + minimum;
}
public static double nextDouble(Random random, double minimum, double maximum)
{
return minimum >= maximum ? minimum : random.nextDouble() * (maximum - minimum) + minimum;
}
public static double average(long[] values)
{
long i = 0L;
for (long j : values)
{
i += j;
}
return (double)i / (double)values.length;
}
@SideOnly(Side.CLIENT)
public static boolean epsilonEquals(float p_180185_0_, float p_180185_1_)
{
return abs(p_180185_1_ - p_180185_0_) < 1.0E-5F;
}
@SideOnly(Side.CLIENT)
public static int normalizeAngle(int p_180184_0_, int p_180184_1_)
{
return (p_180184_0_ % p_180184_1_ + p_180184_1_) % p_180184_1_;
}
@SideOnly(Side.CLIENT)
public static float positiveModulo(float numerator, float denominator)
{
return (numerator % denominator + denominator) % denominator;
}
@SideOnly(Side.CLIENT)
public static double positiveModulo(double numerator, double denominator)
{
return (numerator % denominator + denominator) % denominator;
}
public static float wrapDegrees(float value)
{
value = value % 360.0F;
if (value >= 180.0F)
{
value -= 360.0F;
}
if (value < -180.0F)
{
value += 360.0F;
}
return value;
}
public static double wrapDegrees(double value)
{
value = value % 360.0D;
if (value >= 180.0D)
{
value -= 360.0D;
}
if (value < -180.0D)
{
value += 360.0D;
}
return value;
}
public static int wrapDegrees(int angle)
{
angle = angle % 360;
if (angle >= 180)
{
angle -= 360;
}
if (angle < -180)
{
angle += 360;
}
return angle;
}
public static int getInt(String value, int defaultValue)
{
try
{
return Integer.parseInt(value);
}
catch (Throwable var3)
{
return defaultValue;
}
}
public static int getInt(String value, int defaultValue, int max)
{
return Math.max(max, getInt(value, defaultValue));
}
public static double getDouble(String value, double defaultValue)
{
try
{
return Double.parseDouble(value);
}
catch (Throwable var4)
{
return defaultValue;
}
}
public static double getDouble(String value, double defaultValue, double max)
{
return Math.max(max, getDouble(value, defaultValue));
}
public static int smallestEncompassingPowerOfTwo(int value)
{
int i = value - 1;
i = i | i >> 1;
i = i | i >> 2;
i = i | i >> 4;
i = i | i >> 8;
i = i | i >> 16;
return i + 1;
}
private static boolean isPowerOfTwo(int value)
{
return value != 0 && (value & value - 1) == 0;
}
public static int log2DeBruijn(int value)
{
value = isPowerOfTwo(value) ? value : smallestEncompassingPowerOfTwo(value);
return MULTIPLY_DE_BRUIJN_BIT_POSITION[(int)((long)value * 125613361L >> 27) & 31];
}
public static int log2(int value)
{
return log2DeBruijn(value) - (isPowerOfTwo(value) ? 0 : 1);
}
public static int roundUp(int number, int interval)
{
if (interval == 0)
{
return 0;
}
else if (number == 0)
{
return interval;
}
else
{
if (number < 0)
{
interval *= -1;
}
int i = number % interval;
return i == 0 ? number : number + interval - i;
}
}
public static long getCoordinateRandom(int x, int y, int z)
{
long i = (long)(x * 3129871) ^ (long)z * 116129781L ^ (long)y;
i = i * i * 42317861L + i * 11L;
return i;
}
@SideOnly(Side.CLIENT)
public static int rgb(float rIn, float gIn, float bIn)
{
return rgb(floor(rIn * 255.0F), floor(gIn * 255.0F), floor(bIn * 255.0F));
}
@SideOnly(Side.CLIENT)
public static int rgb(int rIn, int gIn, int bIn)
{
int lvt_3_1_ = (rIn << 8) + gIn;
lvt_3_1_ = (lvt_3_1_ << 8) + bIn;
return lvt_3_1_;
}
@SideOnly(Side.CLIENT)
public static int multiplyColor(int p_180188_0_, int p_180188_1_)
{
int i = (p_180188_0_ & 16711680) >> 16;
int j = (p_180188_1_ & 16711680) >> 16;
int k = (p_180188_0_ & 65280) >> 8;
int l = (p_180188_1_ & 65280) >> 8;
int i1 = (p_180188_0_ & 255) >> 0;
int j1 = (p_180188_1_ & 255) >> 0;
int k1 = (int)((float)i * (float)j / 255.0F);
int l1 = (int)((float)k * (float)l / 255.0F);
int i2 = (int)((float)i1 * (float)j1 / 255.0F);
return p_180188_0_ & -16777216 | k1 << 16 | l1 << 8 | i2;
}
@SideOnly(Side.CLIENT)
public static double frac(double number)
{
return number - Math.floor(number);
}
@SideOnly(Side.CLIENT)
public static long getPositionRandom(Vec3i pos)
{
return getCoordinateRandom(pos.getX(), pos.getY(), pos.getZ());
}
public static UUID getRandomUUID(Random rand)
{
long i = rand.nextLong() & -61441L | 16384L;
long j = rand.nextLong() & 4611686018427387903L | Long.MIN_VALUE;
return new UUID(i, j);
}
public static UUID getRandomUUID()
{
return getRandomUUID(RANDOM);
}
public static double pct(double p_181160_0_, double p_181160_2_, double p_181160_4_)
{
return (p_181160_0_ - p_181160_2_) / (p_181160_4_ - p_181160_2_);
}
public static double atan2(double p_181159_0_, double p_181159_2_)
{
double d0 = p_181159_2_ * p_181159_2_ + p_181159_0_ * p_181159_0_;
if (Double.isNaN(d0))
{
return Double.NaN;
}
else
{
boolean flag = p_181159_0_ < 0.0D;
if (flag)
{
p_181159_0_ = -p_181159_0_;
}
boolean flag1 = p_181159_2_ < 0.0D;
if (flag1)
{
p_181159_2_ = -p_181159_2_;
}
boolean flag2 = p_181159_0_ > p_181159_2_;
if (flag2)
{
double d1 = p_181159_2_;
p_181159_2_ = p_181159_0_;
p_181159_0_ = d1;
}
double d9 = fastInvSqrt(d0);
p_181159_2_ = p_181159_2_ * d9;
p_181159_0_ = p_181159_0_ * d9;
double d2 = FRAC_BIAS + p_181159_0_;
int i = (int)Double.doubleToRawLongBits(d2);
double d3 = ASINE_TAB[i];
double d4 = COS_TAB[i];
double d5 = d2 - FRAC_BIAS;
double d6 = p_181159_0_ * d4 - p_181159_2_ * d5;
double d7 = (6.0D + d6 * d6) * d6 * 0.16666666666666666D;
double d8 = d3 + d7;
if (flag2)
{
d8 = (Math.PI / 2D) - d8;
}
if (flag1)
{
d8 = Math.PI - d8;
}
if (flag)
{
d8 = -d8;
}
return d8;
}
}
public static double fastInvSqrt(double p_181161_0_)
{
double d0 = 0.5D * p_181161_0_;
long i = Double.doubleToRawLongBits(p_181161_0_);
i = 6910469410427058090L - (i >> 1);
p_181161_0_ = Double.longBitsToDouble(i);
p_181161_0_ = p_181161_0_ * (1.5D - d0 * p_181161_0_ * p_181161_0_);
return p_181161_0_;
}
@SideOnly(Side.CLIENT)
public static int hsvToRGB(float hue, float saturation, float value)
{
int i = (int)(hue * 6.0F) % 6;
float f = hue * 6.0F - (float)i;
float f1 = value * (1.0F - saturation);
float f2 = value * (1.0F - f * saturation);
float f3 = value * (1.0F - (1.0F - f) * saturation);
float f4;
float f5;
float f6;
switch (i)
{
case 0:
f4 = value;
f5 = f3;
f6 = f1;
break;
case 1:
f4 = f2;
f5 = value;
f6 = f1;
break;
case 2:
f4 = f1;
f5 = value;
f6 = f3;
break;
case 3:
f4 = f1;
f5 = f2;
f6 = value;
break;
case 4:
f4 = f3;
f5 = f1;
f6 = value;
break;
case 5:
f4 = value;
f5 = f1;
f6 = f2;
break;
default:
throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + hue + ", " + saturation + ", " + value);
}
int j = clamp((int)(f4 * 255.0F), 0, 255);
int k = clamp((int)(f5 * 255.0F), 0, 255);
int l = clamp((int)(f6 * 255.0F), 0, 255);
return j << 16 | k << 8 | l;
}
public static int hash(int p_188208_0_)
{
p_188208_0_ = p_188208_0_ ^ p_188208_0_ >>> 16;
p_188208_0_ = p_188208_0_ * -2048144789;
p_188208_0_ = p_188208_0_ ^ p_188208_0_ >>> 13;
p_188208_0_ = p_188208_0_ * -1028477387;
p_188208_0_ = p_188208_0_ ^ p_188208_0_ >>> 16;
return p_188208_0_;
}
static
{
for (int i = 0; i < 65536; ++i)
{
SIN_TABLE[i] = (float)Math.sin((double)i * Math.PI * 2.0D / 65536.0D);
}
MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[] {0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9};
FRAC_BIAS = Double.longBitsToDouble(4805340802404319232L);
ASINE_TAB = new double[257];
COS_TAB = new double[257];
for (int j = 0; j < 257; ++j)
{
double d0 = (double)j / 256.0D;
double d1 = Math.asin(d0);
COS_TAB[j] = Math.cos(d1);
ASINE_TAB[j] = d1;
}
}
}
@@ -0,0 +1,126 @@
package me.towdium.jecalculation.polyfill.mc.util.math;
import com.google.common.base.Objects;
import javax.annotation.concurrent.Immutable;
@Immutable
public class Vec3i implements Comparable<Vec3i>
{
public static final Vec3i NULL_VECTOR = new Vec3i(0, 0, 0);
private final int x;
private final int y;
private final int z;
public Vec3i(int xIn, int yIn, int zIn)
{
this.x = xIn;
this.y = yIn;
this.z = zIn;
}
public Vec3i(double xIn, double yIn, double zIn)
{
this(MathHelper.floor(xIn), MathHelper.floor(yIn), MathHelper.floor(zIn));
}
public boolean equals(Object p_equals_1_)
{
if (this == p_equals_1_)
{
return true;
}
else if (!(p_equals_1_ instanceof Vec3i))
{
return false;
}
else
{
Vec3i vec3i = (Vec3i)p_equals_1_;
if (this.getX() != vec3i.getX())
{
return false;
}
else if (this.getY() != vec3i.getY())
{
return false;
}
else
{
return this.getZ() == vec3i.getZ();
}
}
}
public int hashCode()
{
return (this.getY() + this.getZ() * 31) * 31 + this.getX();
}
public int compareTo(Vec3i p_compareTo_1_)
{
if (this.getY() == p_compareTo_1_.getY())
{
return this.getZ() == p_compareTo_1_.getZ() ? this.getX() - p_compareTo_1_.getX() : this.getZ() - p_compareTo_1_.getZ();
}
else
{
return this.getY() - p_compareTo_1_.getY();
}
}
public int getX()
{
return this.x;
}
public int getY()
{
return this.y;
}
public int getZ()
{
return this.z;
}
public Vec3i crossProduct(Vec3i vec)
{
return new Vec3i(this.getY() * vec.getZ() - this.getZ() * vec.getY(), this.getZ() * vec.getX() - this.getX() * vec.getZ(), this.getX() * vec.getY() - this.getY() * vec.getX());
}
public double getDistance(int xIn, int yIn, int zIn)
{
double d0 = (double)(this.getX() - xIn);
double d1 = (double)(this.getY() - yIn);
double d2 = (double)(this.getZ() - zIn);
return Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
}
public double distanceSq(double toX, double toY, double toZ)
{
double d0 = (double)this.getX() - toX;
double d1 = (double)this.getY() - toY;
double d2 = (double)this.getZ() - toZ;
return d0 * d0 + d1 * d1 + d2 * d2;
}
public double distanceSqToCenter(double xIn, double yIn, double zIn)
{
double d0 = (double)this.getX() + 0.5D - xIn;
double d1 = (double)this.getY() + 0.5D - yIn;
double d2 = (double)this.getZ() + 0.5D - zIn;
return d0 * d0 + d1 * d1 + d2 * d2;
}
public double distanceSq(Vec3i to)
{
return this.distanceSq((double)to.getX(), (double)to.getY(), (double)to.getZ());
}
public String toString()
{
return Objects.toStringHelper(this).add("x", this.getX()).add("y", this.getY()).add("z", this.getZ()).toString();
}
}
@@ -39,4 +39,28 @@ public class ReflectionHelper {
}
}
public static <T, C> T get(C o, String name) {
T res;
try {
Field field = o.getClass().getDeclaredField(name);
field.setAccessible(true);
res = (T) field.get(o);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
throw new RuntimeException();
}
return res;
}
public static <T, C> void set(C o, String name, T value) {
try {
Field field = o.getClass().getDeclaredField(name);
field.setAccessible(true);
field.set(o, value);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
throw new RuntimeException();
}
}
}
@@ -7,10 +7,10 @@ import me.towdium.jecalculation.JustEnoughCalculation;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.*;
import java.util.function.BiFunction;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
/**
* Author: Towdium
@@ -90,4 +90,77 @@ public class Utilities {
// TODO check
return name;
}
public static class Timer {
long time = System.currentTimeMillis();
boolean running = false;
public void setState(boolean b) {
if (!b && running)
running = false;
if (b && !running) {
running = true;
time = System.currentTimeMillis();
}
}
public long getTime() {
return running ? System.currentTimeMillis() - time : 0;
}
}
public static class Circulator {
int total, current;
public Circulator(int total) {
this(total, 0);
}
public Circulator(int total, int current) {
this.total = total;
this.current = current;
}
public int next() {
current = current + 1 == total ? 0 : current + 1;
return current;
}
public int prev() {
current = current == 0 ? total - 1 : current - 1;
return current;
}
public int index() {
return current;
}
}
public static class ReversedIterator<T> implements Iterator<T> {
ListIterator<T> i;
public ReversedIterator(List<T> l) {
i = l.listIterator(l.size());
}
public ReversedIterator(ListIterator<T> i) {
while (i.hasNext()) i.next();
this.i = i;
}
@Override
public boolean hasNext() {
return i.hasPrevious();
}
@Override
public T next() {
return i.previous();
}
public Stream<T> stream() {
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(this, Spliterator.ORDERED), false);
}
}
}
@@ -1,5 +1,6 @@
package me.towdium.jecalculation.utils.helpers;
import com.google.common.base.CaseFormat;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import me.towdium.jecalculation.utils.wrappers.Pair;
@@ -32,10 +33,8 @@ public class LocalizationHelper {
* It will search all the super classes.
*/
public static Pair<String, Boolean> search(Class c, String prefix, String translateKey, Object... parameters) {
StringBuilder builder = new StringBuilder(c.getName());
builder.delete(0, builder.lastIndexOf(".") + 1).setCharAt(0, Character.toLowerCase(builder.charAt(0)));
builder.insert(0, prefix).append('.').append(translateKey); // TODO simplify and change underscore
String key = builder.toString();
String clazz = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, c.getSimpleName());
String key = String.join(".", prefix, clazz, translateKey);
Pair<String, Boolean> ret = LocalizationHelper.search(key, parameters);
if (ret.two || c.equals(Object.class))
return ret;