diff options
| author | Unknown <shekwancheung0528@gmail.com> | 2018-12-22 13:17:31 +0800 |
|---|---|---|
| committer | Unknown <shekwancheung0528@gmail.com> | 2018-12-22 13:17:31 +0800 |
| commit | d1e292ca25b7987bc4ddf334205238d75f7f29b7 (patch) | |
| tree | 3c2911284faccd10f97e3aa307719ec12efd4b53 /src/main/java | |
| parent | 7bcd4d2e868210a842ad7e4e4fc34240de40a121 (diff) | |
| download | RoughlyEnoughItems-d1e292ca25b7987bc4ddf334205238d75f7f29b7.tar.gz RoughlyEnoughItems-d1e292ca25b7987bc4ddf334205238d75f7f29b7.tar.bz2 RoughlyEnoughItems-d1e292ca25b7987bc4ddf334205238d75f7f29b7.zip | |
from aei but like jei now
Diffstat (limited to 'src/main/java')
52 files changed, 2642 insertions, 0 deletions
diff --git a/src/main/java/me/shedaniel/ClientListener.java b/src/main/java/me/shedaniel/ClientListener.java new file mode 100755 index 000000000..9d52addd5 --- /dev/null +++ b/src/main/java/me/shedaniel/ClientListener.java @@ -0,0 +1,66 @@ +package me.shedaniel; + +import me.shedaniel.api.IAEIPlugin; +import me.shedaniel.gui.AEIRenderHelper; +import me.shedaniel.impl.AEIRecipeManager; +import me.shedaniel.library.KeyBindManager; +import me.shedaniel.listenerdefinitions.DoneLoading; +import me.shedaniel.listenerdefinitions.RecipeLoadListener; +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; +import net.minecraft.util.registry.IRegistry; + +import java.awt.event.KeyEvent; +import java.util.ArrayList; +import java.util.List; + +public class ClientListener implements DoneLoading, RecipeLoadListener { + public static KeyBinding recipeKeybind; + public static KeyBinding hideKeybind; + public static KeyBinding useKeybind; + + private List<IAEIPlugin> plugins; + public static List<ItemStack> stackList; + + @Override + public void onDoneLoading() { + + plugins = new ArrayList<>(); + stackList = new ArrayList<>(); + + recipeKeybind = KeyBindManager.createKeybinding("key.aei.recipe", KeyEvent.VK_R, "key.aei.category", AEIRenderHelper::recipeKeybind); + hideKeybind = KeyBindManager.createKeybinding("key.aei.hide", KeyEvent.VK_O, "key.aei.category", AEIRenderHelper::hideKeybind); + useKeybind = KeyBindManager.createKeybinding("key.aei.use", KeyEvent.VK_U, "key.aei.category", AEIRenderHelper::useKeybind); + + buildItemList(); + } + + private void buildItemList() { + if (!IRegistry.ITEM.isEmpty()) { + IRegistry.ITEM.forEach(item -> processItem((Item) item)); + } + + } + + private void processItem(Item item) { + NonNullList<ItemStack> items = NonNullList.create(); + try { + item.fillItemGroup(item.getGroup(), items); + items.forEach(stackList::add); + } catch (NullPointerException e) { + if (item == Items.ENCHANTED_BOOK) { + item.fillItemGroup(ItemGroup.TOOLS, items); + items.forEach(stackList::add); + } + } + } + + @Override + public void recipesLoaded(net.minecraft.item.crafting.RecipeManager recipeManager) { + AEIRecipeManager.instance().RecipesLoaded(recipeManager); + } +} diff --git a/src/main/java/me/shedaniel/Core.java b/src/main/java/me/shedaniel/Core.java new file mode 100755 index 000000000..61f985db1 --- /dev/null +++ b/src/main/java/me/shedaniel/Core.java @@ -0,0 +1,33 @@ +package me.shedaniel; + +import me.shedaniel.network.CheatPacket; +import me.shedaniel.network.DeletePacket; +import net.minecraft.network.EnumPacketDirection; +import org.dimdev.rift.listener.PacketAdder; + +/** + * Created by James on 7/27/2018. + */ +public class Core implements PacketAdder { + @Override + public void registerHandshakingPackets(PacketRegistrationReceiver receiver) { + } + + @Override + public void registerPlayPackets(PacketRegistrationReceiver receiver) { + receiver.registerPacket(EnumPacketDirection.SERVERBOUND, CheatPacket.class); + receiver.registerPacket(EnumPacketDirection.SERVERBOUND, DeletePacket.class); + } + + @Override + public void registerStatusPackets(PacketRegistrationReceiver receiver) { + + } + + @Override + public void registerLoginPackets(PacketRegistrationReceiver receiver) { + + } + + +} diff --git a/src/main/java/me/shedaniel/api/IAEIPlugin.java b/src/main/java/me/shedaniel/api/IAEIPlugin.java new file mode 100755 index 000000000..9f5b5da6e --- /dev/null +++ b/src/main/java/me/shedaniel/api/IAEIPlugin.java @@ -0,0 +1,9 @@ +package me.shedaniel.api; + +/** + * Created by James on 7/27/2018. + */ +public interface IAEIPlugin { + + public void register(); +} diff --git a/src/main/java/me/shedaniel/api/IDisplayCategory.java b/src/main/java/me/shedaniel/api/IDisplayCategory.java new file mode 100755 index 000000000..f5cb02a4d --- /dev/null +++ b/src/main/java/me/shedaniel/api/IDisplayCategory.java @@ -0,0 +1,27 @@ +package me.shedaniel.api; + +import me.shedaniel.gui.widget.AEISlot; +import me.shedaniel.gui.widget.Control; + +import java.util.List; + +/** + * Created by James on 8/7/2018. + */ +public interface IDisplayCategory<T extends IRecipe> { + public String getId(); + + public String getDisplayName(); + + public void addRecipe(T recipe); + + public void resetRecipes(); + + public List<AEISlot> setupDisplay(int number); + + public boolean canDisplay(T recipe); + + public void drawExtras(); + + public void addWidget(List<Control> controls, int number); +} diff --git a/src/main/java/me/shedaniel/api/IDisplayHelper.java b/src/main/java/me/shedaniel/api/IDisplayHelper.java new file mode 100755 index 000000000..6f230d3b5 --- /dev/null +++ b/src/main/java/me/shedaniel/api/IDisplayHelper.java @@ -0,0 +1,7 @@ +package me.shedaniel.api; + +/** + * Created by James on 8/7/2018. + */ +public interface IDisplayHelper { +} diff --git a/src/main/java/me/shedaniel/api/IDrawable.java b/src/main/java/me/shedaniel/api/IDrawable.java new file mode 100755 index 000000000..102b7e1c5 --- /dev/null +++ b/src/main/java/me/shedaniel/api/IDrawable.java @@ -0,0 +1,10 @@ +package me.shedaniel.api; + +/** + * Created by James on 8/7/2018. + */ +public interface IDrawable { + public void draw(); + + public boolean isHighlighted(); +} diff --git a/src/main/java/me/shedaniel/api/IRecipe.java b/src/main/java/me/shedaniel/api/IRecipe.java new file mode 100755 index 000000000..6359c351a --- /dev/null +++ b/src/main/java/me/shedaniel/api/IRecipe.java @@ -0,0 +1,15 @@ +package me.shedaniel.api; + +import java.util.List; + +/** + * Created by James on 7/27/2018. + */ +public interface IRecipe<T> { + + public String getId(); + + public List<T> getOutput(); + + public List<List<T>> getInput(); +} diff --git a/src/main/java/me/shedaniel/api/IRecipeManager.java b/src/main/java/me/shedaniel/api/IRecipeManager.java new file mode 100755 index 000000000..355a1cd4d --- /dev/null +++ b/src/main/java/me/shedaniel/api/IRecipeManager.java @@ -0,0 +1,20 @@ +package me.shedaniel.api; + +import net.minecraft.item.ItemStack; + +import java.util.List; +import java.util.Map; + +/** + * Created by James on 8/5/2018. + */ +public interface IRecipeManager { + + public void addRecipe(String id, IRecipe recipe); + + public void addRecipe(String id, List<? extends IRecipe> recipes); + + public void addDisplayAdapter(IDisplayCategory adapter); + + public Map<IDisplayCategory, List<IRecipe>> getRecipesFor(ItemStack stack); +} diff --git a/src/main/java/me/shedaniel/api/TriBooleanProducer.java b/src/main/java/me/shedaniel/api/TriBooleanProducer.java new file mode 100755 index 000000000..0925fee75 --- /dev/null +++ b/src/main/java/me/shedaniel/api/TriBooleanProducer.java @@ -0,0 +1,8 @@ +package me.shedaniel.api; + +/** + * Created by James on 8/4/2018. + */ +public interface TriBooleanProducer { + public boolean accept(int first, int second, int third); +} diff --git a/src/main/java/me/shedaniel/gui/AEIRenderHelper.java b/src/main/java/me/shedaniel/gui/AEIRenderHelper.java new file mode 100755 index 000000000..3ffbc7d82 --- /dev/null +++ b/src/main/java/me/shedaniel/gui/AEIRenderHelper.java @@ -0,0 +1,235 @@ +package me.shedaniel.gui; + +import me.shedaniel.gui.widget.AEISlot; +import me.shedaniel.gui.widget.Control; +import me.shedaniel.gui.widget.IFocusable; +import me.shedaniel.impl.AEIRecipeManager; +import me.shedaniel.library.KeyBindManager; +import me.shedaniel.listenerdefinitions.IMixinGuiContainer; +import net.minecraft.client.MainWindow; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.item.ItemStack; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + + +/** + * Created by James on 7/28/2018. + */ +public class AEIRenderHelper { + static Point mouseLoc; + static public GuiItemList aeiGui; + static GuiContainer overlayedGui; + static List<TooltipData> tooltipsToRender = new ArrayList<>(); + + public static void setMouseLoc(int x, int y) { + mouseLoc = new Point(x, y); + } + + static public IFocusable focusedControl; + + public static Point getMouseLoc() { + return mouseLoc; + } + + public static MainWindow getResolution() { + + return Minecraft.getInstance().mainWindow; + } + + public static void drawAEI(GuiContainer overlayedGui) { + AEIRenderHelper.overlayedGui = overlayedGui; + if (aeiGui == null) { + aeiGui = new GuiItemList(overlayedGui); + } + aeiGui.draw(); + renderTooltips(); + } + + public static void resize() { + if (aeiGui != null) { + aeiGui.resize(); + } + if (overlayedGui instanceof RecipeGui) { + overlayedGui.onResize(Minecraft.getInstance(), 0, 0); + } + } + + public static ItemRenderer getItemRender() { + return Minecraft.getInstance().getItemRenderer(); + } + + public static FontRenderer getFontRenderer() { + return Minecraft.getInstance().fontRenderer; + } + + public static GuiContainer getOverlayedGui() { + if (overlayedGui instanceof GuiContainer) + return overlayedGui; + return null; + } + + public static void addToolTip(List<String> text, int x, int y) { + tooltipsToRender.add(new TooltipData(text, x, y)); + } + + + private static void renderTooltips() { + GlStateManager.pushMatrix(); + GlStateManager.enableLighting(); + for(TooltipData tooltipData : tooltipsToRender) { + getOverlayedGui().drawHoveringText(tooltipData.text, tooltipData.x, tooltipData.y); + } + GlStateManager.disableLighting(); + tooltipsToRender.clear(); + GlStateManager.popMatrix(); + + } + + public static boolean mouseClick(int x, int y, int button) { + if (aeiGui.visible) { + for(Control control : aeiGui.controls) { + if (control.isHighlighted() && control.isEnabled() && control.onClick != null) { + if (focusedControl != null) + focusedControl.setFocused(false); + if (control instanceof IFocusable) { + focusedControl = (IFocusable) control; + ((IFocusable) control).setFocused(true); + } + return control.onClick.apply(button); + } + } + if (focusedControl != null) { + focusedControl.setFocused(false); + focusedControl = null; + } + } + if (overlayedGui instanceof RecipeGui) { + List<Control> controls = ((RecipeGui) overlayedGui).controls; + Optional<Control> ctrl = controls.stream().filter(Control::isHighlighted).filter(Control::isEnabled).findFirst(); + if (ctrl.isPresent()) { + try { + return ctrl.get().onClick.apply(button); + } catch (Exception e) { + } + } + } + return false; + } + + public static boolean keyDown(int typedChar, int keyCode, int unknown) { + boolean handled = false; + if (focusedControl != null && focusedControl instanceof Control) { + Control control = (Control) focusedControl; + if (control.onKeyDown != null) { + handled = control.onKeyDown.accept(typedChar, keyCode, unknown); + } + if (control.charPressed != null) + if (typedChar == 256) { + ((IFocusable) control).setFocused(false); + focusedControl = null; + } + handled = true; + } + if (!handled) { + return KeyBindManager.processGuiKeybinds(typedChar); + } + return handled; + } + + public static boolean charInput(long num, int keyCode, int unknown) { + if (focusedControl != null && focusedControl instanceof Control) { + Control control = (Control) focusedControl; + if (control.charPressed != null) { + int numChars = Character.charCount(keyCode); + if (num == numChars) + control.charPressed.accept((char) keyCode, unknown); + else { + char[] chars = Character.toChars(keyCode); + for(int x = 0; x < chars.length; x++) { + control.charPressed.accept(chars[x], unknown); + } + } + return true; + } + } + return false; + } + + public static boolean mouseScrolled(double direction) { + if (!aeiGui.visible) + return false; + if (direction > 0 && aeiGui.buttonLeft.isEnabled()) + aeiGui.buttonLeft.onClick.apply(0); + else if (direction < 0 && aeiGui.buttonRight.isEnabled()) + aeiGui.buttonRight.onClick.apply(0); + return true; + } + + private static class TooltipData { + + private final List<String> text; + private final int x; + private final int y; + + public TooltipData(List<String> text, int x, int y) { + this.text = text; + this.x = x; + this.y = y; + } + } + + public static void updateSearch() { + aeiGui.updateView(); + } + + public static void tick() { + if (aeiGui != null && Minecraft.getInstance().currentScreen == overlayedGui) + aeiGui.tick(); + } + + public static void recipeKeybind() { + if (!(Minecraft.getInstance().currentScreen instanceof GuiContainer)) + return; + Control control = aeiGui.getLastHovered(); + if (control != null && control.isHighlighted() && control instanceof AEISlot) { + AEISlot slot = (AEISlot) control; + AEIRecipeManager.instance().displayRecipesFor(slot.getStack()); + return; + } + if (((IMixinGuiContainer) overlayedGui).getHoveredSlot() != null) { + ItemStack stack = ((IMixinGuiContainer) overlayedGui).getHoveredSlot().getStack(); + AEIRecipeManager.instance().displayRecipesFor(stack); + } + + } + + public static void useKeybind() { + if (!(Minecraft.getInstance().currentScreen instanceof GuiContainer)) + return; + Control control = aeiGui.getLastHovered(); + if (control != null && control.isHighlighted() && control instanceof AEISlot) { + AEISlot slot = (AEISlot) control; + AEIRecipeManager.instance().displayUsesFor(slot.getStack()); + return; + } + if (((IMixinGuiContainer) overlayedGui).getHoveredSlot() != null) { + ItemStack stack = ((IMixinGuiContainer) overlayedGui).getHoveredSlot().getStack(); + AEIRecipeManager.instance().displayUsesFor(stack); + } + + } + + public static void hideKeybind() { + if (Minecraft.getInstance().currentScreen == overlayedGui && aeiGui != null) { + aeiGui.visible = !aeiGui.visible; + } + } +} diff --git a/src/main/java/me/shedaniel/gui/Drawable.java b/src/main/java/me/shedaniel/gui/Drawable.java new file mode 100755 index 000000000..8fffc17af --- /dev/null +++ b/src/main/java/me/shedaniel/gui/Drawable.java @@ -0,0 +1,33 @@ +package me.shedaniel.gui; + +import me.shedaniel.api.IDrawable; +import me.shedaniel.gui.widget.Control; + +import java.awt.*; + +/** + * Created by James on 7/28/2018. + */ +public abstract class Drawable implements IDrawable { + protected Rectangle rect; + + public Drawable(int x, int y, int width, int height) { + rect = new Rectangle(x, y, width, height); + } + + public Drawable(Rectangle rect) { + this.rect = rect; + } + + public abstract void draw(); + + public boolean isHighlighted() { + Point mousePoint = AEIRenderHelper.getMouseLoc(); + if (rect.contains(mousePoint.x, mousePoint.y)) { + if (this instanceof Control) + AEIRenderHelper.aeiGui.setLastHovered((Control) this); + return true; + } + return false; + } +} |
