mirror of
https://github.com/GTNewHorizons/JustEnoughCalculation.git
synced 2026-11-19 19:49:38 +00:00
feat: ore
This commit is contained in:
1 parent
3881b3eaf8
commit
d7d4135528
26 files changed
+428
-179
No files matched your search
@@ -2,10 +2,11 @@ package me.towdium.jecalculation.client.gui;
|
||||
|
||||
import cpw.mods.fml.client.config.GuiUtils;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
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.client.gui.resource.Resource;
|
||||
import me.towdium.jecalculation.client.gui.widget.IDrawable;
|
||||
import me.towdium.jecalculation.client.gui.widget.Widget;
|
||||
import me.towdium.jecalculation.client.gui.widget.widgets.WEntry;
|
||||
import me.towdium.jecalculation.client.gui.widget.widgets.WEntryGroup;
|
||||
import me.towdium.jecalculation.core.entry.Entry;
|
||||
import me.towdium.jecalculation.nei.NEIPlugin;
|
||||
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
|
||||
@@ -19,10 +20,14 @@ 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.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
@@ -76,7 +81,10 @@ public class JecGui extends GuiContainer {
|
||||
GlStateManager.disableDepth();
|
||||
wgtMgr.onDraw(mouseX, mouseY);
|
||||
drawExtra();
|
||||
drawItemStack(mouseX, mouseY, hand.getRepresentation(), true);
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(mouseX - 8, mouseY - 8, 0);
|
||||
hand.drawEntry(this);
|
||||
GlStateManager.popMatrix();
|
||||
drawBufferedTooltip();
|
||||
GlStateManager.enableLighting();
|
||||
GlStateManager.enableDepth();
|
||||
@@ -184,8 +192,14 @@ public class JecGui extends GuiContainer {
|
||||
int sourceXSize,
|
||||
int sourceYSize) {
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.mc.getTextureManager().bindTexture(l);
|
||||
this.drawTexturedModalRect(destXPos, destYPos, sourceXPos, sourceYPos, sourceXSize, sourceYSize);
|
||||
mc.getTextureManager().bindTexture(l);
|
||||
drawTexturedModalRect(destXPos, destYPos, sourceXPos, sourceYPos, sourceXSize, sourceYSize);
|
||||
}
|
||||
|
||||
public void drawFluid(Fluid f, int xPos, int yPos, int xSize, int ySize) {
|
||||
IIcon fluidStillIcon = f.getStillIcon();
|
||||
mc.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
|
||||
if (fluidStillIcon != null) drawTexturedModelRectFromIcon(xPos, yPos, fluidStillIcon, xSize, ySize);
|
||||
}
|
||||
|
||||
public void drawTextureContinuous(ResourceLocation l,
|
||||
@@ -208,7 +222,22 @@ 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
|
||||
float f3 = (float) (color >> 24 & 255) / 255.0F;
|
||||
float f = (float) (color >> 16 & 255) / 255.0F;
|
||||
float f1 = (float) (color >> 8 & 255) / 255.0F;
|
||||
float f2 = (float) (color & 255) / 255.0F;
|
||||
int right = xPos + xSize;
|
||||
int bottom = yPos + ySize;
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
GlStateManager.disableTexture2D();
|
||||
GlStateManager.color(f, f1, f2, f3);
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.addVertex((double) xPos, (double) bottom, 0.0D);
|
||||
tessellator.addVertex((double) right, (double) bottom, 0.0D);
|
||||
tessellator.addVertex((double) right, (double) yPos, 0.0D);
|
||||
tessellator.addVertex((double) xPos, (double) yPos, 0.0D);
|
||||
tessellator.draw();
|
||||
GlStateManager.enableTexture2D();
|
||||
}
|
||||
|
||||
|
||||
@@ -374,8 +403,8 @@ public class JecGui extends GuiContainer {
|
||||
|
||||
public void add(Widget w) {
|
||||
widgets.add(w);
|
||||
if (initialized && w instanceof Widget.Advanced)
|
||||
((Widget.Advanced) w).onGuiInit(JecGui.this);
|
||||
if (initialized && w instanceof IDrawable)
|
||||
((IDrawable) w).onGuiInit(JecGui.this);
|
||||
}
|
||||
|
||||
public void addAll(Widget... w) {
|
||||
@@ -384,7 +413,7 @@ public class JecGui extends GuiContainer {
|
||||
}
|
||||
|
||||
public void remove(Widget w) {
|
||||
if (widgets.remove(w) && w instanceof Widget.Advanced) ((Widget.Advanced) w).onRemoved(JecGui.this);
|
||||
if (widgets.remove(w) && w instanceof IDrawable) ((IDrawable) w).onRemoved(JecGui.this);
|
||||
}
|
||||
|
||||
public void removeAll(Widget... w) {
|
||||
@@ -393,8 +422,8 @@ public class JecGui extends GuiContainer {
|
||||
}
|
||||
|
||||
public void onInit() {
|
||||
widgets.stream().filter(w -> w instanceof Widget.Advanced)
|
||||
.forEach(w -> ((Widget.Advanced) w).onGuiInit(JecGui.this));
|
||||
widgets.stream().filter(w -> w instanceof IDrawable)
|
||||
.forEach(w -> ((IDrawable) w).onGuiInit(JecGui.this));
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
@@ -405,8 +434,8 @@ public class JecGui extends GuiContainer {
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public boolean onClick(int xMouse, int yMouse, int button) {
|
||||
for (Widget w : widgets) {
|
||||
if (w instanceof Widget.Advanced &&
|
||||
((Widget.Advanced) w).onClicked(JecGui.this, xMouse, yMouse, button))
|
||||
if (w instanceof IDrawable &&
|
||||
((IDrawable) w).onClicked(JecGui.this, xMouse, yMouse, button))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -414,8 +443,8 @@ public class JecGui extends GuiContainer {
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public boolean onKey(char ch, int code) {
|
||||
return widgets.stream().filter(w -> w instanceof Widget.Advanced)
|
||||
.anyMatch(w -> ((Widget.Advanced) w).onKey(JecGui.this, ch, code));
|
||||
return widgets.stream().filter(w -> w instanceof IDrawable)
|
||||
.anyMatch(w -> ((IDrawable) w).onKey(JecGui.this, ch, code));
|
||||
}
|
||||
|
||||
public Optional<WEntry> getEntryAt(int xMouse, int yMouse) {
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package me.towdium.jecalculation.client.gui.guis;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.resource.Resource;
|
||||
import me.towdium.jecalculation.client.widget.widgets.*;
|
||||
import me.towdium.jecalculation.client.gui.resource.Resource;
|
||||
import me.towdium.jecalculation.client.gui.widget.widgets.*;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import static me.towdium.jecalculation.client.widget.widgets.WEntry.enumMode.*;
|
||||
import static me.towdium.jecalculation.client.gui.widget.widgets.WEntry.enumMode.*;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package me.towdium.jecalculation.client.gui.guis;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.resource.Resource;
|
||||
import me.towdium.jecalculation.client.widget.widgets.*;
|
||||
import me.towdium.jecalculation.client.gui.resource.Resource;
|
||||
import me.towdium.jecalculation.client.gui.widget.widgets.*;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static me.towdium.jecalculation.client.widget.widgets.WEntry.enumMode.EDITOR;
|
||||
import static me.towdium.jecalculation.client.gui.widget.widgets.WEntry.enumMode.EDITOR;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package me.towdium.jecalculation.client.resource;
|
||||
package me.towdium.jecalculation.client.gui.resource;
|
||||
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.towdium.jecalculation.client.gui.widget;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
|
||||
public class IDrawable extends Widget {
|
||||
public void onRemoved(JecGui gui) {
|
||||
}
|
||||
|
||||
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean onKey(JecGui gui, char ch, int code) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onGuiInit(JecGui gui) {
|
||||
}
|
||||
}
|
||||
+1
-17
@@ -1,4 +1,4 @@
|
||||
package me.towdium.jecalculation.client.widget;
|
||||
package me.towdium.jecalculation.client.gui.widget;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
@@ -22,21 +22,5 @@ public class Widget extends Gui {
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
}
|
||||
|
||||
public static class Advanced extends Widget {
|
||||
public void onRemoved(JecGui gui) {
|
||||
}
|
||||
|
||||
public boolean onClicked(JecGui gui, int xMouse, int yMouse, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean onKey(JecGui gui, char ch, int code) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onGuiInit(JecGui gui) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
package me.towdium.jecalculation.client.widget.widgets;
|
||||
package me.towdium.jecalculation.client.gui.widget.widgets;
|
||||
|
||||
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.client.gui.widget.IDrawable;
|
||||
import me.towdium.jecalculation.utils.ClientUtils;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -15,7 +15,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
* Date: 8/14/17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class WButton extends Widget.Advanced {
|
||||
public class WButton extends IDrawable {
|
||||
protected int xPos, yPos, xSize, ySize;
|
||||
public Runnable lsnrLeft, lsnrRight;
|
||||
public String text, tooltip;
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package me.towdium.jecalculation.client.widget.widgets;
|
||||
package me.towdium.jecalculation.client.gui.widget.widgets;
|
||||
|
||||
import cpw.mods.fml.client.config.GuiButtonExt;
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.resource.Resource;
|
||||
import me.towdium.jecalculation.client.gui.resource.Resource;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
+9
-5
@@ -1,9 +1,10 @@
|
||||
package me.towdium.jecalculation.client.widget.widgets;
|
||||
package me.towdium.jecalculation.client.gui.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.client.gui.resource.Resource;
|
||||
import me.towdium.jecalculation.client.gui.widget.IDrawable;
|
||||
import me.towdium.jecalculation.core.entry.Entry;
|
||||
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
|
||||
import me.towdium.jecalculation.utils.IllegalPositionException;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -13,7 +14,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
* Date: 17-8-17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class WEntry extends Widget.Advanced {
|
||||
public class WEntry extends IDrawable {
|
||||
static JecGui.Font font;
|
||||
|
||||
static {
|
||||
@@ -47,7 +48,10 @@ public class WEntry extends Widget.Advanced {
|
||||
public void onDraw(JecGui gui, int xMouse, int yMouse) {
|
||||
gui.drawResourceContinuous(Resource.WGT_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);
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(xPos + gl(gui) + xSize / 2 - 8, yPos + gt(gui) + ySize / 2 - 8, 0);
|
||||
entry.drawEntry(gui);
|
||||
GlStateManager.popMatrix();
|
||||
if (mode == enumMode.RESULT || mode == enumMode.EDITOR)
|
||||
gui.drawText(gl(gui) + xPos + xSize / 2 + 7.5f, gt(gui) + yPos + ySize / 2 + 7 -
|
||||
(int) (font.size * gui.getFontRenderer().FONT_HEIGHT), font, entry.getAmountString());
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
package me.towdium.jecalculation.client.widget.widgets;
|
||||
package me.towdium.jecalculation.client.gui.widget.widgets;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.widget.Widget;
|
||||
import me.towdium.jecalculation.client.gui.widget.IDrawable;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.ArrayList;
|
||||
@@ -13,7 +13,7 @@ import java.util.stream.IntStream;
|
||||
* Date: 17-8-17.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class WEntryGroup extends Widget.Advanced {
|
||||
public class WEntryGroup extends IDrawable {
|
||||
ArrayList<WEntry> widgets = new ArrayList<>();
|
||||
|
||||
public WEntryGroup(int xPos, int yPos, int column, int row, WEntry.enumMode mode) {
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
package me.towdium.jecalculation.client.widget.widgets;
|
||||
package me.towdium.jecalculation.client.gui.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.client.gui.resource.Resource;
|
||||
import me.towdium.jecalculation.client.gui.widget.Widget;
|
||||
import me.towdium.jecalculation.utils.Utilities.Timer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
package me.towdium.jecalculation.client.widget.widgets;
|
||||
package me.towdium.jecalculation.client.gui.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.client.gui.resource.Resource;
|
||||
import me.towdium.jecalculation.client.gui.widget.Widget;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
+4
-4
@@ -1,8 +1,8 @@
|
||||
package me.towdium.jecalculation.client.widget.widgets;
|
||||
package me.towdium.jecalculation.client.gui.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.client.gui.resource.Resource;
|
||||
import me.towdium.jecalculation.client.gui.widget.IDrawable;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -16,7 +16,7 @@ import java.util.stream.Stream;
|
||||
* Date: 17-8-19.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class WPager extends Widget.Advanced {
|
||||
public class WPager extends IDrawable {
|
||||
public static final int SIZE = 13;
|
||||
|
||||
protected int xPos, xSize, yPos;
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package me.towdium.jecalculation.client.widget.widgets;
|
||||
package me.towdium.jecalculation.client.gui.widget.widgets;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.widget.Widget;
|
||||
import me.towdium.jecalculation.client.gui.widget.Widget;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package me.towdium.jecalculation.client.widget.widgets;
|
||||
package me.towdium.jecalculation.client.gui.widget.widgets;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.widget.Widget;
|
||||
import me.towdium.jecalculation.client.gui.widget.Widget;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.function.Supplier;
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
package me.towdium.jecalculation.client.widget.widgets;
|
||||
package me.towdium.jecalculation.client.gui.widget.widgets;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.client.widget.Widget;
|
||||
import me.towdium.jecalculation.client.gui.widget.IDrawable;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -11,7 +11,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
||||
* Date: 17-8-18.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class WTextField extends Widget.Advanced {
|
||||
public class WTextField extends IDrawable {
|
||||
protected int xPos, yPos, xSize;
|
||||
GuiTextField textField;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.towdium.jecalculation.command;
|
||||
|
||||
import me.towdium.jecalculation.command.commands.CommandHelp;
|
||||
import me.towdium.jecalculation.command.commands.CommandOreDict;
|
||||
import me.towdium.jecalculation.command.commands.CommandState;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -16,12 +17,14 @@ public class Commands {
|
||||
|
||||
public static final CommandHelp commandHelp = new CommandHelp();
|
||||
public static final CommandState commandState = new CommandState();
|
||||
public static final CommandOreDict commandOreDict = new CommandOreDict();
|
||||
|
||||
static {
|
||||
commands = new HashMap<>();
|
||||
|
||||
add(commandHelp);
|
||||
add(commandState);
|
||||
add(commandOreDict);
|
||||
}
|
||||
|
||||
static void add(SubCommand c) {
|
||||
|
||||
@@ -34,7 +34,7 @@ public class JecaCommand extends CommandBase {
|
||||
} else {
|
||||
SubCommand cmd = Commands.commands.get(args[0].toLowerCase());
|
||||
if (cmd != null) {
|
||||
cmd.execute(sender, args);
|
||||
cmd.execute(sender, cut(args));
|
||||
} else {
|
||||
sender.addChatMessage(new ChatComponentTranslation("command.common.not_found", args[0]));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package me.towdium.jecalculation.command.commands;
|
||||
|
||||
import me.towdium.jecalculation.command.SubCommand;
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-11.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public class CommandOreDict implements SubCommand {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ore";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage(ICommandSender sender) {
|
||||
return "/jec ore";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(ICommandSender sender, String[] args) throws CommandException {
|
||||
if (args.length == 0) {
|
||||
Arrays.stream(OreDictionary.getOreNames()).forEach(s -> sender.addChatMessage(new ChatComponentText(s)));
|
||||
} // TODO error handling
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,18 @@
|
||||
package me.towdium.jecalculation.core.entry;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.core.entry.entries.EntryItemStack;
|
||||
import me.towdium.jecalculation.utils.Utilities.Relation;
|
||||
import me.towdium.jecalculation.utils.Utilities.ReversedIterator;
|
||||
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;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
@@ -21,7 +22,7 @@ public interface Entry {
|
||||
ItemStack EMPTY_ITEM_STACK = new ItemStack((Item)null);
|
||||
|
||||
EntryMergerRegistry MERGER = EntryMergerRegistry.INSTANCE;
|
||||
EntryRegistry REGISTRY = EntryRegistry.INSTANCE;
|
||||
Registry REGISTRY = Registry.INSTANCE;
|
||||
Entry EMPTY = new EntryItemStack(Entry.EMPTY_ITEM_STACK, 0);
|
||||
|
||||
Entry increaseAmount();
|
||||
@@ -32,12 +33,13 @@ public interface Entry {
|
||||
|
||||
Entry decreaseAmountLarge();
|
||||
|
||||
ItemStack getRepresentation();
|
||||
|
||||
String getAmountString();
|
||||
|
||||
Entry copy();
|
||||
|
||||
void drawEntry(JecGui gui);
|
||||
|
||||
|
||||
/**
|
||||
* Since {@link Entry} merging is bidirectional, it is redundant to
|
||||
* implement on both side. So this class is created for merging
|
||||
@@ -45,7 +47,7 @@ public interface Entry {
|
||||
* It uses singleton mode. First register merge functions, then use
|
||||
* {@link #test(Entry, Entry)} and {@link #merge(Entry, Entry, boolean)}
|
||||
* to operate the {@link Entry}.
|
||||
* For registering, see {@link EntryRegistry}.
|
||||
* For registering, see {@link Registry}.
|
||||
*/
|
||||
class EntryMergerRegistry {
|
||||
public static final EntryMergerRegistry INSTANCE;
|
||||
@@ -95,13 +97,13 @@ public interface Entry {
|
||||
* Here you can find the identifier and deserializer of one type.
|
||||
* For {@link Entry} operations, see {@link EntryMergerRegistry}
|
||||
*/
|
||||
class EntryRegistry {
|
||||
class Registry {
|
||||
public static final String KEY_IDENTIFIER = "identifier";
|
||||
public static final String KEY_CONTENT = "content";
|
||||
public static final EntryRegistry INSTANCE;
|
||||
public static final Registry INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE = new EntryRegistry();
|
||||
INSTANCE = new Registry();
|
||||
}
|
||||
|
||||
private HashMap<Class<? extends Entry>, Pair<String,
|
||||
@@ -109,7 +111,7 @@ public interface Entry {
|
||||
private HashMap<String, Pair<Class<? extends Entry>,
|
||||
Function<NBTTagCompound, Optional<Entry>>>> idToData = new HashMap<>();
|
||||
|
||||
private EntryRegistry() {
|
||||
private Registry() {
|
||||
}
|
||||
|
||||
public <T extends Entry> void register(
|
||||
@@ -145,22 +147,52 @@ public interface Entry {
|
||||
}
|
||||
}
|
||||
|
||||
class Relation<T, R> {
|
||||
HashMap<Pair<T, T>, R> data = new HashMap<>();
|
||||
class ConverterRegistry<T> {
|
||||
List<Function<List<T>, List<Entry>>> handlers = new ArrayList<>();
|
||||
|
||||
public void add(T a, T b, R relation) {
|
||||
data.put(a.hashCode() < b.hashCode() ? new Pair<>(a, b) : new Pair<>(b, a), relation);
|
||||
private ConverterRegistry() {
|
||||
}
|
||||
|
||||
public Optional<R> get(T a, T b) {
|
||||
int ah = a.hashCode();
|
||||
int bh = b.hashCode();
|
||||
Single<R> ret = new Single<>(null);
|
||||
if (ah == bh)
|
||||
ret.push(data.get(new Pair<>(a, b))).push(data.get(new Pair<>(b, a)));
|
||||
else
|
||||
ret.push(data.get(ah < bh ? new Pair<>(a, b) : new Pair<>(b, a)));
|
||||
return Optional.ofNullable(ret.value);
|
||||
public Entry toEntry(T ingredient) {
|
||||
return handlers.stream().map(h -> h.apply(Collections.singletonList(ingredient)))
|
||||
.filter(l -> !l.isEmpty()).findFirst().orElse(Collections.singletonList(Entry.EMPTY)).get(0);
|
||||
}
|
||||
|
||||
public List<Entry> toEntry(List<T> ingredients) {
|
||||
return new ReversedIterator<>(handlers).stream().flatMap(h -> h.apply(ingredients).stream())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
void register(Function<List<T>, List<Entry>> handler) {
|
||||
handlers.add(handler);
|
||||
}
|
||||
}
|
||||
|
||||
class ConverterRegistryItem extends ConverterRegistry<ItemStack> {
|
||||
public static final ConverterRegistryItem INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE = new ConverterRegistryItem();
|
||||
|
||||
INSTANCE.register(ConverterRegistryItem::convertRawItemStack);
|
||||
}
|
||||
|
||||
private ConverterRegistryItem() {
|
||||
}
|
||||
|
||||
public static List<Entry> convertRawItemStack(List<ItemStack> iss) {
|
||||
return iss.stream().map(EntryItemStack::new).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
class ConverterRegistryFluid extends ConverterRegistry<FluidStack> {
|
||||
public static final ConverterRegistryFluid INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE = new ConverterRegistryFluid();
|
||||
}
|
||||
|
||||
private ConverterRegistryFluid() {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
package me.towdium.jecalculation.core.entry.entries;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.core.entry.Entry;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 8/11/17.
|
||||
*/
|
||||
public class EntryItemStack implements Entry {
|
||||
public class EntryItemStack extends EntrySimpleAmount {
|
||||
int amount;
|
||||
ItemStack itemStack;
|
||||
|
||||
@@ -28,48 +28,13 @@ public class EntryItemStack implements Entry {
|
||||
itemStack = eis.itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry increaseAmount() {
|
||||
amount++;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry increaseAmountLarge() {
|
||||
amount += 10;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry decreaseAmount() {
|
||||
if (amount <= 1) return Entry.EMPTY;
|
||||
else {
|
||||
amount--;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry decreaseAmountLarge() {
|
||||
if (amount <= 10) return Entry.EMPTY;
|
||||
else {
|
||||
amount -= 10;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getRepresentation() {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAmountString() {
|
||||
return amount == 0 ? "" : Utilities.cutLong(amount, 5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry copy() {
|
||||
return new EntryItemStack(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(JecGui gui) {
|
||||
gui.drawItemStack(0, 0, itemStack, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package me.towdium.jecalculation.core.entry.entries;
|
||||
|
||||
import me.towdium.jecalculation.client.gui.JecGui;
|
||||
import me.towdium.jecalculation.polyfill.mc.client.renderer.GlStateManager;
|
||||
import me.towdium.jecalculation.polyfill.mc.util.NonNullList;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-10.
|
||||
*/
|
||||
public class EntryOreDict extends EntrySimpleAmount {
|
||||
public static final String IDENTIFIER = "ore";
|
||||
|
||||
protected String name;
|
||||
|
||||
public EntryOreDict(String name) {
|
||||
this(name, 1);
|
||||
}
|
||||
|
||||
public EntryOreDict(String name, int amount) {
|
||||
this.name = name;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public EntryOreDict(EntryOreDict eod) {
|
||||
this.name = eod.name;
|
||||
this.amount = eod.amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntryOreDict copy() {
|
||||
return new EntryOreDict(this);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(JecGui gui) {
|
||||
NonNullList<ItemStack> list = NonNullList.create();
|
||||
OreDictionary.getOres(name).forEach(is -> {
|
||||
if (is.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||
is.getItem().getSubItems(is.getItem(), CreativeTabs.tabAllSearch, list);
|
||||
} else list.add(is);
|
||||
});
|
||||
long index = System.currentTimeMillis() / 1500;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(1, 1, 0);
|
||||
GlStateManager.scale(14f / 16, 14f / 16, 1);
|
||||
gui.drawItemStack(0, 0, list.get((int) (index % list.size())), false);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package me.towdium.jecalculation.core.entry.entries;
|
||||
|
||||
import me.towdium.jecalculation.core.entry.Entry;
|
||||
import me.towdium.jecalculation.utils.Utilities;
|
||||
|
||||
/**
|
||||
* Author: towdium
|
||||
* Date: 17-9-11.
|
||||
*/
|
||||
public abstract class EntrySimpleAmount implements Entry {
|
||||
protected int amount;
|
||||
|
||||
@Override
|
||||
public Entry increaseAmount() {
|
||||
amount++;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry increaseAmountLarge() {
|
||||
amount += 10;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry decreaseAmount() {
|
||||
if (amount <= 1) return Entry.EMPTY;
|
||||
else {
|
||||
amount--;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry decreaseAmountLarge() {
|
||||
if (amount <= 10) return Entry.EMPTY;
|
||||
else {
|
||||
amount -= 10;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAmountString() {
|
||||
return amount == 0 ? "" : Utilities.cutLong(amount, 5);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,8 @@ import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class NEIPlugin {
|
||||
public static final TransferRegistryItem registryItem = TransferRegistryItem.INSTANCE;
|
||||
public static final Entry.ConverterRegistryItem registryItem = Entry.ConverterRegistryItem.INSTANCE;
|
||||
public static final Entry.ConverterRegistryFluid registryFluid = Entry.ConverterRegistryFluid.INSTANCE;
|
||||
|
||||
public static void init() {
|
||||
GuiContainerManager.addTooltipHandler(new JecaTooltipHandler());
|
||||
@@ -30,42 +31,4 @@ public class NEIPlugin {
|
||||
public static void setEntryUnderMouse(ItemStack itemStack) {
|
||||
NEIPlugin.currentItemStack = itemStack;
|
||||
}
|
||||
|
||||
public static List<Entry> transferRawItemStack(List<ItemStack> iss) {
|
||||
return iss.stream().map(EntryItemStack::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static class TransferRegistryItem extends TransferHandlerRegistry<ItemStack> {
|
||||
public static final TransferRegistryItem INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE = new TransferRegistryItem();
|
||||
|
||||
INSTANCE.register(NEIPlugin::transferRawItemStack);
|
||||
}
|
||||
|
||||
private TransferRegistryItem() {
|
||||
}
|
||||
}
|
||||
|
||||
public static class TransferHandlerRegistry<T> {
|
||||
List<Function<List<T>, List<Entry>>> handlers = new ArrayList<>();
|
||||
|
||||
private TransferHandlerRegistry() {
|
||||
}
|
||||
|
||||
Entry toEntry(T ingredient) {
|
||||
return handlers.isEmpty() ? Entry.EMPTY :
|
||||
handlers.get(0).apply(Collections.singletonList(ingredient)).get(0);
|
||||
}
|
||||
|
||||
List<Entry> toEntry(List<T> ingredients) {
|
||||
return new Utilities.ReversedIterator<>(handlers).stream().flatMap(h -> h.apply(ingredients).stream())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
void register(Function<List<T>, List<Entry>> handler) {
|
||||
handlers.add(handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package me.towdium.jecalculation.polyfill.mc.util;
|
||||
|
||||
|
||||
import java.util.AbstractList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
public class NonNullList<E> extends AbstractList<E>
|
||||
{
|
||||
private final List<E> delegate;
|
||||
private final E defaultElement;
|
||||
|
||||
public static <E> NonNullList<E> create()
|
||||
{
|
||||
return new NonNullList<E>();
|
||||
}
|
||||
|
||||
public static <E> NonNullList<E> withSize(int size, E fill)
|
||||
{
|
||||
Validate.notNull(fill);
|
||||
Object[] aobject = new Object[size];
|
||||
Arrays.fill(aobject, fill);
|
||||
return new NonNullList<E>(Arrays.asList((E[])aobject), fill);
|
||||
}
|
||||
|
||||
public static <E> NonNullList<E> from(E defaultElementIn, E... elements)
|
||||
{
|
||||
return new NonNullList<E>(Arrays.asList(elements), defaultElementIn);
|
||||
}
|
||||
|
||||
protected NonNullList()
|
||||
{
|
||||
this(new ArrayList(), null);
|
||||
}
|
||||
|
||||
protected NonNullList(List<E> delegateIn, @Nullable E listType)
|
||||
{
|
||||
this.delegate = delegateIn;
|
||||
this.defaultElement = listType;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public E get(int p_get_1_)
|
||||
{
|
||||
return this.delegate.get(p_get_1_);
|
||||
}
|
||||
|
||||
public E set(int p_set_1_, E p_set_2_)
|
||||
{
|
||||
Validate.notNull(p_set_2_);
|
||||
return this.delegate.set(p_set_1_, p_set_2_);
|
||||
}
|
||||
|
||||
public void add(int p_add_1_, E p_add_2_)
|
||||
{
|
||||
Validate.notNull(p_add_2_);
|
||||
this.delegate.add(p_add_1_, p_add_2_);
|
||||
}
|
||||
|
||||
public E remove(int p_remove_1_)
|
||||
{
|
||||
return this.delegate.remove(p_remove_1_);
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return this.delegate.size();
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
if (this.defaultElement == null)
|
||||
{
|
||||
super.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < this.size(); ++i)
|
||||
{
|
||||
this.set(i, this.defaultElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
import me.towdium.jecalculation.JustEnoughCalculation;
|
||||
import me.towdium.jecalculation.utils.wrappers.Pair;
|
||||
import me.towdium.jecalculation.utils.wrappers.Single;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
@@ -163,4 +165,23 @@ public class Utilities {
|
||||
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(this, Spliterator.ORDERED), false);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Relation<T, R> {
|
||||
HashMap<Pair<T, T>, R> data = new HashMap<>();
|
||||
|
||||
public void add(T a, T b, R relation) {
|
||||
data.put(a.hashCode() < b.hashCode() ? new Pair<>(a, b) : new Pair<>(b, a), relation);
|
||||
}
|
||||
|
||||
public Optional<R> get(T a, T b) {
|
||||
int ah = a.hashCode();
|
||||
int bh = b.hashCode();
|
||||
Single<R> ret = new Single<>(null);
|
||||
if (ah == bh)
|
||||
ret.push(data.get(new Pair<>(a, b))).push(data.get(new Pair<>(b, a)));
|
||||
else
|
||||
ret.push(data.get(ah < bh ? new Pair<>(a, b) : new Pair<>(b, a)));
|
||||
return Optional.ofNullable(ret.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user