From 6aba7870ea223dd26bf126b6723879c08d0b577a Mon Sep 17 00:00:00 2001 From: Jared Date: Thu, 20 Oct 2016 00:09:28 +0200 Subject: [PATCH] Close #5 --- .../java/com/blamejared/ctgui/MTRecipe.java | 40 +++ .../com/blamejared/ctgui/api/CheckButton.java | 99 +++++ .../ctgui/api/CheckButtonRecipe.java | 106 ++++++ .../blamejared/ctgui/api/ContainerBase.java | 88 +++++ .../com/blamejared/ctgui/api/GuiBase.java | 339 ++++++++++++++++++ .../com/blamejared/ctgui/api/GuiRegistry.java | 32 ++ .../java/com/blamejared/ctgui/api/Slider.java | 20 ++ .../com/blamejared/ctgui/api/SlotRecipe.java | 107 ++++++ .../ctgui/api/SlotRecipeOutput.java | 13 + .../blamejared/ctgui/client/GuiHandler.java | 34 ++ .../ctgui/client/GuiHandlerVanilla.java | 37 ++ .../ctgui/client/InventoryFake.java | 119 ++++++ .../blamejared/ctgui/client/gui/GuiMenu.java | 217 +++++++++++ .../craftingtable/ContainerCraftingTable.java | 48 +++ .../gui/craftingtable/GuiCraftingTable.java | 103 ++++++ .../client/gui/furnace/ContainerFurnace.java | 46 +++ .../ctgui/client/gui/furnace/GuiFurnace.java | 50 +++ .../ctgui/commands/CommandCTGUI.java | 44 +++ .../blamejared/ctgui/proxy/ClientProxy.java | 18 + .../blamejared/ctgui/proxy/CommonProxy.java | 17 + .../blamejared/ctgui/reference/Reference.java | 9 + 21 files changed, 1586 insertions(+) create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/MTRecipe.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/CheckButton.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/CheckButtonRecipe.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/ContainerBase.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/GuiBase.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/GuiRegistry.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/Slider.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/SlotRecipe.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/SlotRecipeOutput.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/GuiHandler.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/GuiHandlerVanilla.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/InventoryFake.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/GuiMenu.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/craftingtable/ContainerCraftingTable.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/craftingtable/GuiCraftingTable.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/furnace/ContainerFurnace.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/furnace/GuiFurnace.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/commands/CommandCTGUI.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/proxy/ClientProxy.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/proxy/CommonProxy.java create mode 100644 MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/reference/Reference.java diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/MTRecipe.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/MTRecipe.java new file mode 100644 index 0000000..5e177b1 --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/MTRecipe.java @@ -0,0 +1,40 @@ +package com.blamejared.ctgui; + +import com.blamejared.ctgui.api.GuiRegistry; +import com.blamejared.ctgui.client.GuiHandlerVanilla; +import com.blamejared.ctgui.commands.CommandCTGUI; +import com.blamejared.ctgui.proxy.CommonProxy; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.SidedProxy; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.event.FMLServerStartingEvent; + +import java.util.ArrayList; +import java.util.List; + +import static com.blamejared.ctgui.reference.Reference.*; + +@Mod(modid = MOD_ID, name = MOD_NAME, version = VERSION, clientSideOnly = true, dependencies = "required-after:MineTweaker3;") +public class MTRecipe { + + @Mod.Instance(MOD_ID) + public static MTRecipe INSTANCE; + + @SidedProxy(clientSide = "com.blamejared.ctgui.proxy.ClientProxy", serverSide = "com.blamejared.ctgui.proxy.CommonProxy") + public static CommonProxy PROXY; + + @Mod.EventHandler + public void preInit(FMLPreInitializationEvent event) { + List idrange = new ArrayList(); + idrange.add(1); + idrange.add(2); + GuiRegistry.registerGui(idrange, new GuiHandlerVanilla()); + PROXY.registerGuis(); + } + + @Mod.EventHandler + public void serverStarting(FMLServerStartingEvent e) { + e.registerServerCommand(new CommandCTGUI()); + } + +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/CheckButton.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/CheckButton.java new file mode 100644 index 0000000..bc6fcc5 --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/CheckButton.java @@ -0,0 +1,99 @@ +package com.blamejared.ctgui.api; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraftforge.fml.client.config.GuiCheckBox; +import net.minecraftforge.fml.client.config.GuiUtils; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.util.List; + +/** + * Created by Jared. + */ +public class CheckButton extends GuiCheckBox { + + protected GuiBase parent; + protected List incompatible; + + protected int backgroundSize = 100; + + public CheckButton(GuiBase parent, int id, int xPos, int yPos, String displayString, boolean isChecked) { + super(id, xPos, yPos, displayString, isChecked); + this.parent = parent; + } + + + public int getBackgroundSize() { + return backgroundSize; + } + + public void setBackgroundSize(int backgroundSize) { + this.backgroundSize = backgroundSize; + } + + public void setIncompatible(List incompatible) { + this.incompatible = incompatible; + } + + public List getIncompatible() { + return incompatible; + } + + /** + * Draws this button to the screen. + */ + public void drawButton(Minecraft mc, int mouseX, int mouseY) { + if (this.visible) { + this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + getButtonWidth() && mouseY < this.yPosition + this.height; + GlStateManager.enableAlpha(); + GL11.glColor4d(1, 1, 1, 0); + GuiUtils.drawGradientRect(30, this.xPosition - 2, this.yPosition - 2, this.xPosition + getBackgroundSize(), this.yPosition + height + 2, 0x9F100010, 0x9F100010); + GlStateManager.disableAlpha(); + GuiUtils.drawContinuousTexturedBox(BUTTON_TEXTURES, this.xPosition, this.yPosition, 0, 46, 11, this.height, 200, 20, 2, 3, 2, 2, this.zLevel); + this.mouseDragged(mc, mouseX, mouseY); + int color = 14737632; + + if (packedFGColour != 0) { + color = packedFGColour; + } else if (!this.enabled) { + color = 10526880; + } + + if (this.isChecked()) { + this.drawGradientRect(this.xPosition + 2, this.yPosition + 2, this.xPosition + 11 - 2, this.yPosition + height - 2, Color.cyan.darker().getRGB(), Color.cyan.darker().getRGB()); + } + + this.drawString(mc.fontRendererObj, displayString, xPosition + 11 + 2, yPosition + 2, color); + } + } + + @Override + public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) { + if (this.enabled && this.visible && mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height) { + setIsChecked(!isChecked()); + return true; + } + return false; + } + + + public void setIsChecked(boolean isChecked) { + super.setIsChecked(isChecked); + if (isChecked()) { + for (GuiButton but : incompatible) { + but.enabled = false; + if (but instanceof CheckButton) { + ((CheckButton) but).setIsChecked(false); + } + } + } else { + for (GuiButton but : incompatible) { + but.enabled = true; + } + } + } + +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/CheckButtonRecipe.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/CheckButtonRecipe.java new file mode 100644 index 0000000..f0cb500 --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/CheckButtonRecipe.java @@ -0,0 +1,106 @@ +package com.blamejared.ctgui.api; + +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.ItemStack; + +import java.util.ArrayList; + +/** + * Created by Jared. + */ +public class CheckButtonRecipe extends CheckButton { + + private String propertyKey; + + public CheckButtonRecipe(GuiBase parent, int id, int xPos, int yPos, String displayString, boolean isChecked, String propertyKey) { + super(parent, id, xPos, yPos, displayString, isChecked); + this.propertyKey = propertyKey; + } + + + @Override + public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) { + if (this.enabled && this.visible && mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height) { + setIsChecked(!isChecked()); + parent.selectedSlot.getPropertyMap().put(getPropertyKey(), isChecked()); + if (isChecked()) { + for (Slider slider : parent.getMenu().getSliders(this)) { + if (parent.isBlock(parent.selectedSlot.getStack())) { + Block b = Block.getBlockFromItem(parent.selectedSlot.getStack().getItem()); + ArrayList list = new ArrayList(); + b.getSubBlocks(parent.selectedSlot.getStack().getItem(), CreativeTabs.SEARCH, list); + slider.setValue(parent.selectedSlot.getProperty(slider.getPropertyKey())); + slider.maxValue = list.size() - 1; + slider.updateSlider(); + } else { + if (parent.selectedSlot.getStack().getItem().getHasSubtypes()) { + ArrayList list = new ArrayList(); + parent.selectedSlot.getStack().getItem().getSubItems(parent.selectedSlot.getStack().getItem(), CreativeTabs.SEARCH, list); + slider.setValue(parent.selectedSlot.getProperty(slider.getPropertyKey())); + slider.maxValue = list.size() - 1; + slider.updateSlider(); + } else { + slider.setValue(parent.selectedSlot.getProperty(slider.getPropertyKey())); + slider.maxValue = parent.selectedSlot.getStack().getMaxDamage(); + slider.updateSlider(); + } + } + parent.getButtonList().add(slider); + } + } else { + for (Slider slider : parent.getMenu().getSliders(this)) { + parent.getButtonList().remove(slider); + } + } + return true; + } + return false; + } + + + public void setIsChecked(boolean isChecked) { + super.setIsChecked(isChecked); + if (isChecked()) { + for (Slider slider : parent.getMenu().getSliders(this)) { + if (GuiBase.isBlock(parent.selectedSlot.getStack())) { + Block b = Block.getBlockFromItem(parent.selectedSlot.getStack().getItem()); + ArrayList list = new ArrayList(); + b.getSubBlocks(parent.selectedSlot.getStack().getItem(), CreativeTabs.SEARCH, list); + slider.setValue(parent.selectedSlot.getProperty(slider.getPropertyKey())); + slider.maxValue = list.size() - 1; + slider.updateSlider(); + } else { + if (parent.selectedSlot.getStack().getItem().getHasSubtypes()) { + ArrayList list = new ArrayList(); + parent.selectedSlot.getStack().getItem().getSubItems(parent.selectedSlot.getStack().getItem(), CreativeTabs.SEARCH, list); + slider.setValue(parent.selectedSlot.getProperty(slider.getPropertyKey())); + slider.maxValue = list.size() - 1; + slider.updateSlider(); + } else { + slider.setValue(parent.selectedSlot.getProperty(slider.getPropertyKey())); + slider.maxValue = parent.selectedSlot.getStack().getMaxDamage(); + slider.updateSlider(); + } + } + parent.getButtonList().add(slider); + } + for (GuiButton but : incompatible) { + but.enabled = false; + } + } else { + for (Slider slider : parent.getMenu().getSliders(this)) { + parent.getButtonList().remove(slider); + } + for (GuiButton but : incompatible) { + but.enabled = true; + } + } + } + + public String getPropertyKey() { + return propertyKey; + } +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/ContainerBase.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/ContainerBase.java new file mode 100644 index 0000000..e6c2a96 --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/ContainerBase.java @@ -0,0 +1,88 @@ +package com.blamejared.ctgui.api; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.ClickType; +import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; + +import javax.annotation.Nullable; +import java.util.LinkedList; +import java.util.List; + +/** + * Created by Jared on 5/29/2016. + */ +public class ContainerBase extends Container { + + protected List recipeSlots = new LinkedList(); + + @Override + public boolean canInteractWith(EntityPlayer player) { + return true; + } + + + @Nullable + @Override + public ItemStack slotClick(int i, int mousebtn, ClickType clickTypeIn, EntityPlayer player) { + ItemStack stack = null; + + if (i >= 0 && getSlot(i) != null && getSlot(i) instanceof SlotRecipe) // Fake slots + { + if (mousebtn == 2) { + getSlot(i).putStack(null); + } else if (mousebtn == 0) { + InventoryPlayer playerInv = player.inventory; + getSlot(i).onSlotChanged(); + ItemStack stackSlot = getSlot(i).getStack(); + ItemStack stackHeld = playerInv.getItemStack(); + + if (stackSlot != null) stack = stackSlot.copy(); + + if (stackHeld != null) { + ItemStack newStack = stackHeld.copy(); + if (!(getSlot(i) instanceof SlotRecipeOutput)) newStack.stackSize = 1; + getSlot(i).putStack(newStack); + } else getSlot(i).putStack(null); + } else if (mousebtn == 1) { + InventoryPlayer playerInv = player.inventory; + getSlot(i).onSlotChanged(); + ItemStack stackSlot = getSlot(i).getStack(); + ItemStack stackHeld = playerInv.getItemStack(); + + if (stackSlot != null) stack = stackSlot.copy(); + + if (stackHeld != null) { + stackHeld = stackHeld.copy(); + if (stackSlot != null && stackHeld.isItemEqual(stackSlot) && (i == 0 || i == 0)) { + int max = stackSlot.getMaxStackSize(); + if (++stackSlot.stackSize > max) stackSlot.stackSize = max; + getSlot(i).putStack(stackSlot); + } else { + stackHeld.stackSize = 1; + getSlot(i).putStack(stackHeld); + } + } else { + if (stackSlot != null) { + stackSlot.stackSize--; + if (stackSlot.stackSize == 0) getSlot(i).putStack(null); + } + } + } + } else { + stack = super.slotClick(i, mousebtn, clickTypeIn, player); + } + return stack; + } + + @Nullable + @Override + public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { + return null; + } + + public List getRecipeSlots() { + return recipeSlots; + } +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/GuiBase.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/GuiBase.java new file mode 100644 index 0000000..84baf8c --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/GuiBase.java @@ -0,0 +1,339 @@ +package com.blamejared.ctgui.api; + +import com.blamejared.ctgui.client.gui.GuiMenu; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import org.apache.commons.lang3.tuple.Pair; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.io.*; +import java.util.LinkedList; +import java.util.List; + +public abstract class GuiBase extends GuiContainer { + + protected ContainerBase container; + public SlotRecipe selectedSlot; + protected GuiMenu menu = new GuiMenu(); + public GuiTextField editingField; + + public GuiButton add; + public GuiButton remove; + + private boolean shouldOpenMenu; + + public GuiBase(ContainerBase container, int xSize, int ySize, boolean shouldOpenMenu) { + super(container); + this.container = container; + this.xSize = xSize; + this.ySize = ySize; + this.shouldOpenMenu = shouldOpenMenu; + } + + @Override + public void initGui() { + super.initGui(); + buttonList.clear(); + if (shouldOpenMenu) + menu.open(this, guiLeft - 102, guiTop); + editingField = new GuiTextField(2906, fontRendererObj, guiLeft - 104, guiTop - 26, xSize + 102, 20); + editingField.setMaxStringLength(Integer.MAX_VALUE); + editingField.setEnabled(true); + add = new GuiButton(2906, getGuiLeft() + 86, getGuiTop() + 8, fontRendererObj.getStringWidth("Add") + 4, 20, "Add"); + getButtonList().add(add); + remove = new GuiButton(2907, getGuiLeft() + 86 + 2 + fontRendererObj.getStringWidth("Add") + 4, getGuiTop() + 8, fontRendererObj.getStringWidth("Remove") + 4, 20, "Remove"); + getButtonList().add(remove); + + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + super.drawScreen(mouseX, mouseY, partialTicks); + editingField.drawTextBox(); + } + + @Override + public void updateScreen() { + super.updateScreen(); + if (selectedSlot != null) { + if (!selectedSlot.getHasStack()) { + selectedSlot = null; + editingField.setText(""); + if (shouldOpenMenu) { + menu.setState(false); + menu.toggle(false); + for (Pair but : menu.getButtons()) { + for (Slider slider : but.getValue()) { + slider.setValue(0); + slider.maxValue = 0; + slider.updateSlider(); + buttonList.remove(slider); + } + } + } + } else { + editingField.setText(selectedSlot.getItemString()); + } + } else { + editingField.setText(""); + if (shouldOpenMenu) { + menu.setState(false); + menu.toggle(false); + for (Pair but : menu.getButtons()) { + for (Slider slider : but.getValue()) { + slider.setValue(0); + slider.maxValue = 0; + slider.updateSlider(); + buttonList.remove(slider); + } + } + ; + } + + } + editingField.updateCursorCounter(); + final boolean[] canCreate = {true}; + for (SlotRecipe slot : container.getRecipeSlots()) { + if (slot instanceof SlotRecipeOutput) { + if (!slot.getHasStack()) { + canCreate[0] = false; + } + } + } + if (!canCreate[0]) { + add.enabled = false; + remove.enabled = false; + } else { + add.enabled = true; + remove.enabled = true; + } + if (shouldOpenMenu) { + if (selectedSlot != null) { + if (selectedSlot.getHasStack() && !selectedSlot.getStack().hasTagCompound()) { + menu.nbt.getLeft().enabled = false; + } + } + } + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + final boolean[] clickedSlot = new boolean[]{false}; + container.getRecipeSlots().stream().filter(slot -> { + Rectangle rectangle = new Rectangle(guiLeft + slot.xDisplayPosition, guiTop + slot.yDisplayPosition, 18, 18); + if (rectangle.contains(mouseX, mouseY)) { + switch (mouseButton) { + case 0: + return false; + case 1: + if (slot.getHasStack()) { + clickedSlot[0] = true; + return true; + } + return false; + case 2: + clickedSlot[0] = true; + return true; + } + } + return false; + }).forEach(slot -> { + switch (mouseButton) { + case 0: + break; + case 1: + selectedSlot = slot; + editingField.setText(slot.getItemString()); + if (shouldOpenMenu) { + menu.toggle(true); + menu.getButtons().forEach(but -> { + for (Slider slider : but.getValue()) { + buttonList.remove(slider); + } + }); + menu.getFromMap(slot.getPropertyMap(), slot.getProperties()); + } + break; + case 2: + selectedSlot = null; + if (shouldOpenMenu) { + menu.toggle(false); + menu.getButtons().forEach(but -> { + for (Slider slider : but.getValue()) { + slider.updateSlider(); + buttonList.remove(slider); + } + }); + } + if (editingField != null) + editingField.setText(""); + break; + } + + }); + if (!clickedSlot[0]) { + super.mouseClicked(mouseX, mouseY, mouseButton); + } + } + + public abstract String getOutputAdd(); + + public abstract String getOutputRemove(); + + + protected void actionPerformed(GuiButton btn) { + if (btn.equals(add)) { + File scriptFile = new File(new File("scripts"), "/recipes.zs"); + if (!scriptFile.exists()) { + generateFile(scriptFile); + } + try { + List lines = new LinkedList<>(); + BufferedReader reader = new BufferedReader(new FileReader(scriptFile)); + reader.lines().forEach(line -> lines.add(line)); + if (lines.isEmpty()) { + generateFile(scriptFile); + reader.lines().forEach(line -> lines.add(line)); + } + reader.close(); + PrintWriter writer = new PrintWriter(new FileWriter(scriptFile)); + for (int i = 0; i < lines.size(); i++) { + String beforeLine = ""; + if (i > 0) + beforeLine = lines.get(i - 1); + + String line = lines.get(i); + if (beforeLine.trim().equals("//#Remove")) { + } + if (beforeLine.trim().equals("//#Add")) { + writer.println(getOutputAdd()); + } + if (!line.isEmpty()) { + writer.println(line); + } + + } + writer.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (btn.equals(remove)) { + File scriptFile = new File(new File("scripts"), "/recipes.zs"); + if (!scriptFile.exists()) { + generateFile(scriptFile); + } + + try { + List lines = new LinkedList<>(); + BufferedReader reader = new BufferedReader(new FileReader(scriptFile)); + reader.lines().forEach(line -> lines.add(line)); + if (lines.isEmpty()) { + generateFile(scriptFile); + reader.lines().forEach(line -> lines.add(line)); + } + reader.close(); + PrintWriter writer = new PrintWriter(new FileWriter(scriptFile)); + for (int i = 0; i < lines.size(); i++) { + String beforeLine = ""; + if (i > 0) + beforeLine = lines.get(i - 1); + + String line = lines.get(i); + if (beforeLine.trim().equals("//#Remove")) { + writer.println(getOutputRemove()); + } + if (beforeLine.trim().equals("//#Add")) { + } + if (!line.isEmpty()) { + writer.println(line); + } + } + writer.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + + public abstract ResourceLocation getTexture(); + + protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { + GlStateManager.pushAttrib(); + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + Minecraft.getMinecraft().renderEngine.bindTexture(getTexture()); + drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); + GlStateManager.popAttrib(); + if (selectedSlot != null) { + GlStateManager.colorMask(true, true, true, false); + this.drawGradientRect(guiLeft + selectedSlot.xDisplayPosition, guiTop + selectedSlot.yDisplayPosition, guiLeft + selectedSlot.xDisplayPosition + 16, guiTop + selectedSlot.yDisplayPosition + 16, Color.cyan.darker().getRGB(), Color.cyan.darker().getRGB()); + GlStateManager.colorMask(true, true, true, true); + } + } + + public List getButtonList() { + return this.buttonList; + } + + + public int getGuiLeft() { + return guiLeft; + } + + public int getGuiTop() { + return guiTop; + } + + + public int getXSize() { + return xSize; + } + + public int getYSize() { + return ySize; + } + + public static boolean isBlock(ItemStack stack) { + ResourceLocation name = Block.REGISTRY.getNameForObject(Block.getBlockFromItem(stack.getItem())); + if (name != null && name.toString().equals("minecraft:air")) { + return false; + } + return Block.REGISTRY.containsKey(name); + } + + public GuiMenu getMenu() { + return menu; + } + + + public void generateFile(File f) { + try { + f.createNewFile(); + PrintWriter writer = new PrintWriter(new FileWriter(f)); + writer.println("//This file was created via CT-GUI! Editing it is not advised!"); + writer.println("//Don't touch me!"); + writer.println("//#Remove"); + writer.println(); + writer.println("//Don't touch me!"); + writer.println("//#Add"); + writer.println(); + writer.println("//File End"); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/GuiRegistry.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/GuiRegistry.java new file mode 100644 index 0000000..f51f41b --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/GuiRegistry.java @@ -0,0 +1,32 @@ +package com.blamejared.ctgui.api; + +import net.minecraftforge.fml.common.network.IGuiHandler; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Created by Jared. + */ +public class GuiRegistry { + + public static Map, IGuiHandler> guiMap = new HashMap<>(); + + public static void registerGui(List idRange, IGuiHandler handler) { + getGuiMap().put(idRange, handler); + } + + public static IGuiHandler getHandlerForID(int id) { + for (Map.Entry, IGuiHandler> entry : getGuiMap().entrySet()) { + if (entry.getKey().contains(id)) { + return entry.getValue(); + } + } + return null; + } + + public static Map, IGuiHandler> getGuiMap() { + return guiMap; + } +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/Slider.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/Slider.java new file mode 100644 index 0000000..503e82b --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/Slider.java @@ -0,0 +1,20 @@ +package com.blamejared.ctgui.api; + +import net.minecraftforge.fml.client.config.GuiSlider; + +/** + * Created by Jared. + */ +public class Slider extends GuiSlider { + private String propertyKey; + + public Slider(String propertyKey, int id, int xPos, int yPos, int width, int height, String prefix, String suf, double minVal, double maxVal, double currentVal, boolean showDec, boolean drawStr, ISlider par) { + super(id, xPos, yPos, width, height, prefix, suf, minVal, maxVal, currentVal, showDec, drawStr, par); + this.propertyKey = propertyKey; + } + + + public String getPropertyKey() { + return propertyKey; + } +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/SlotRecipe.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/SlotRecipe.java new file mode 100644 index 0000000..3e59de2 --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/SlotRecipe.java @@ -0,0 +1,107 @@ +package com.blamejared.ctgui.api; + +import minetweaker.mc1102.data.NBTConverter; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; + +import javax.annotation.Nullable; +import java.util.HashMap; +import java.util.Map; + +/** + * Created by Jared. + */ +public class SlotRecipe extends Slot { + + //key is the operation, value is the values, for more than 1 value, seperate using ยง + private Map propertyMap = new HashMap<>(); + private Map properties = new HashMap<>(); + + + public SlotRecipe(IInventory inventoryIn, int index, int xPosition, int yPosition) { + super(inventoryIn, index, xPosition, yPosition); + } + + @Override + public void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack) { + super.onPickupFromSlot(playerIn, stack); + this.propertyMap.clear(); + this.properties.clear(); + } + + @Override + public int getSlotStackLimit() { + return 1; + } + + @Override + public boolean isItemValid(@Nullable ItemStack stack) { + return true; + } + + public String getItemString() { + boolean matchAny = getPropertyFromMap("matchNotEmpty"); + boolean metaWildcard = getPropertyFromMap("anyMetadata"); + boolean oreDict = getPropertyFromMap("oreDictionary"); + if (getStack() == null) return "null"; + String stackName = Item.REGISTRY.getNameForObject(getStack().getItem()).toString(); + StringBuilder builder = new StringBuilder("<"); + if (oreDict) { + int[] ids = OreDictionary.getOreIDs(getStack()); + if (ids.length != 0) { + stackName = "ore:" + OreDictionary.getOreName(ids[0]); + } else oreDict = false; + } + if (matchAny) { + stackName = "*"; + } + builder.append(stackName); + if (!oreDict && !matchAny && (metaWildcard || getStack().getItemDamage() != 0)) + builder.append(':').append(metaWildcard || getStack().getItemDamage() == OreDictionary.WILDCARD_VALUE ? "*" : getStack().getItemDamage()); + builder.append('>'); + if (getStack().stackSize > 1) builder.append(" * ").append(getStack().stackSize); + if (getPropertyFromMap("anyDamage")) builder.append(".anyDamage()"); + if (getPropertyFromMap("onlyDamage")) builder.append(".onlyDamaged()"); + if (getPropertyFromMap("gted")) + builder.append(".onlyDamageAtLeast(").append("" + getProperty("gted")).append(')'); + if (getPropertyFromMap("ltd")) + builder.append(".onlyDamageAtMost(").append("" + getProperty("ltd")).append(')'); + if (getPropertyFromMap("betweenDamage")) + builder.append(".onlyDamageBetween(").append("" + getProperty("betweenDamageX")).append(", ").append("" + getProperty("betweenDamageY")).append(')'); + if (getPropertyFromMap("reuse")) builder.append(".reuse()"); + if (getPropertyFromMap("noreturn")) builder.append(".noReturn()"); + if (getPropertyFromMap("nbt")) { + if (this instanceof SlotRecipeOutput) + builder.append(String.format(".withTag(%s)", NBTConverter.from(getStack().getTagCompound(), false).toString())); + else + builder.append(String.format(".onlyWithTag(%s)", NBTConverter.from(getStack().getTagCompound(), false).toString())); + } + return builder.toString(); + } + + boolean getPropertyFromMap(String key) { + if (propertyMap.containsKey(key)) { + return propertyMap.get(key); + } + return false; + } + + int getProperty(String key) { + if (properties.containsKey(key)) { + return properties.get(key); + } + return 0; + } + + public Map getPropertyMap() { + return propertyMap; + } + + public Map getProperties() { + return properties; + } +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/SlotRecipeOutput.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/SlotRecipeOutput.java new file mode 100644 index 0000000..cd6c58c --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/api/SlotRecipeOutput.java @@ -0,0 +1,13 @@ +package com.blamejared.ctgui.api; + +import net.minecraft.inventory.IInventory; + +/** + * Created by Jared. + */ +public class SlotRecipeOutput extends SlotRecipe { + + public SlotRecipeOutput(IInventory inventoryIn, int index, int xPosition, int yPosition) { + super(inventoryIn, index, xPosition, yPosition); + } +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/GuiHandler.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/GuiHandler.java new file mode 100644 index 0000000..6d56a86 --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/GuiHandler.java @@ -0,0 +1,34 @@ +package com.blamejared.ctgui.client; + +import com.blamejared.ctgui.MTRecipe; +import com.blamejared.ctgui.api.GuiRegistry; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.network.IGuiHandler; +import net.minecraftforge.fml.common.network.NetworkRegistry; + +/** + * Created by Jared. + */ +public class GuiHandler implements IGuiHandler { + + public GuiHandler() { + NetworkRegistry.INSTANCE.registerGuiHandler(MTRecipe.INSTANCE, this); + } + + @Override + public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + if (GuiRegistry.getHandlerForID(ID) == null) { + return null; + } + return GuiRegistry.getHandlerForID(ID).getServerGuiElement(ID, player, world, x, y, z); + } + + @Override + public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + if (GuiRegistry.getHandlerForID(ID) == null) { + return null; + } + return GuiRegistry.getHandlerForID(ID).getClientGuiElement(ID, player, world, x, y, z); + } +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/GuiHandlerVanilla.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/GuiHandlerVanilla.java new file mode 100644 index 0000000..d483691 --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/GuiHandlerVanilla.java @@ -0,0 +1,37 @@ +package com.blamejared.ctgui.client; + +import com.blamejared.ctgui.client.gui.craftingtable.ContainerCraftingTable; +import com.blamejared.ctgui.client.gui.craftingtable.GuiCraftingTable; +import com.blamejared.ctgui.client.gui.furnace.ContainerFurnace; +import com.blamejared.ctgui.client.gui.furnace.GuiFurnace; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.network.IGuiHandler; + +/** + * Created by Jared. + */ +public class GuiHandlerVanilla implements IGuiHandler { + + @Override + public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + switch (ID) { + case 1: + return new ContainerCraftingTable(player.inventory); + case 2: + return new ContainerFurnace(player.inventory); + } + return null; + } + + @Override + public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + switch (ID) { + case 1: + return new GuiCraftingTable(new ContainerCraftingTable(player.inventory)); + case 2: + return new GuiFurnace(new ContainerFurnace(player.inventory)); + } + return null; + } +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/InventoryFake.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/InventoryFake.java new file mode 100644 index 0000000..1445000 --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/InventoryFake.java @@ -0,0 +1,119 @@ +package com.blamejared.ctgui.client; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ItemStackHelper; +import net.minecraft.item.ItemStack; +import net.minecraft.util.text.ITextComponent; + +import javax.annotation.Nullable; + +/** + * Created by Jared. + */ +public class InventoryFake implements IInventory { + + private final int size; + private ItemStack[] items; + + public InventoryFake(int size) { + this.size = size; + items = new ItemStack[size]; + } + + @Override + public int getSizeInventory() { + return items.length; + } + + @Nullable + @Override + public ItemStack getStackInSlot(int index) { + return index >= this.getSizeInventory() ? null : items[index]; + } + + @Nullable + @Override + public ItemStack decrStackSize(int index, int count) { + ItemStack itemstack = ItemStackHelper.getAndSplit(items, index, count); + return itemstack; + } + + @Nullable + @Override + public ItemStack removeStackFromSlot(int index) { + return ItemStackHelper.getAndRemove(items, index); + } + + @Override + public void setInventorySlotContents(int index, @Nullable ItemStack stack) { + this.items[index] = stack; + } + + @Override + public int getInventoryStackLimit() { + return 64; + } + + @Override + public void markDirty() { + + } + + @Override + public boolean isUseableByPlayer(EntityPlayer player) { + return true; + } + + @Override + public void openInventory(EntityPlayer player) { + + } + + @Override + public void closeInventory(EntityPlayer player) { + + } + + @Override + public boolean isItemValidForSlot(int index, ItemStack stack) { + return true; + } + + @Override + public int getField(int id) { + return 0; + } + + @Override + public void setField(int id, int value) { + + } + + @Override + public int getFieldCount() { + return 0; + } + + @Override + public void clear() { + for (int i = 0; i < this.items.length; ++i) { + this.items[i] = null; + } + } + + @Override + public String getName() { + return "Fake Inventory"; + } + + @Override + public boolean hasCustomName() { + return false; + } + + @Override + public ITextComponent getDisplayName() { + return null; + } +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/GuiMenu.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/GuiMenu.java new file mode 100644 index 0000000..8f1e9f7 --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/GuiMenu.java @@ -0,0 +1,217 @@ +package com.blamejared.ctgui.client.gui; + +import com.blamejared.ctgui.api.CheckButtonRecipe; +import com.blamejared.ctgui.api.GuiBase; +import com.blamejared.ctgui.api.Slider; +import org.apache.commons.lang3.tuple.MutablePair; +import org.apache.commons.lang3.tuple.Pair; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * Created by Jared. + */ +public class GuiMenu { + private GuiBase parent; + private int x; + private int y; + private List> buttons = new ArrayList<>(); + // public Pair matchNotEmpty; + public Pair useOreDict; + public Pair matchAnyMetadata; + public Pair anyDamage; + public Pair onlyDamage; + + // public Pair damage; + public Pair greaterThanEqualDamage; + public Pair lessThanDamage; + public Pair betweenDamage; + + public Pair nbt; + + // public Pair transformDamage; +// public Pair transformReplace; + public Pair reuse; + public Pair noReturn; +// public Pair giveBack; + + + public GuiMenu() { + } + + public void open(GuiBase parent, int x, int y) { + this.parent = parent; + this.x = x; + this.y = y; + int buttonCount = 0; +// matchNotEmpty = new MutablePair<>(new CheckButtonRecipe(parent, 0, x, y + (15 * buttonCount++), "Match Not Empty", false, "matchNotEmpty"), new Slider[]{}); + useOreDict = new MutablePair<>(new CheckButtonRecipe(parent, 1, x, y + (15 * buttonCount++), "Ore Dictionary", false, "oreDictionary"), new Slider[]{}); + matchAnyMetadata = new MutablePair<>(new CheckButtonRecipe(parent, 2, x, y + (15 * buttonCount++), "Any Metadata", false, "anyMetadata"), new Slider[]{}); + anyDamage = new MutablePair<>(new CheckButtonRecipe(parent, 3, x, y + (15 * buttonCount++), "Any Damage", false, "anyDamage"), new Slider[]{}); + onlyDamage = new MutablePair<>(new CheckButtonRecipe(parent, 4, x, y + (15 * buttonCount++), "Only Damage", false, "onlyDamage"), new Slider[]{}); + greaterThanEqualDamage = new MutablePair<>(new CheckButtonRecipe(parent, 6, x, y + (15 * buttonCount++), "X>=Damage", false, "gted"), new Slider[]{new Slider("gted", 10, x - 2, parent.getGuiTop() + parent.getYSize() + 20, parent.getXSize() + 102, 20, "X= ", "", 0, 0, 0, false, true, slider -> { + if (parent.selectedSlot != null && parent.selectedSlot.getStack() != null) { + parent.selectedSlot.getProperties().put(((Slider) slider).getPropertyKey(), slider.getValueInt()); + } + })}); + lessThanDamage = new MutablePair<>(new CheckButtonRecipe(parent, 7, x, y + (15 * buttonCount++), "Damage { + if (parent.selectedSlot != null && parent.selectedSlot.getStack() != null) { + parent.selectedSlot.getProperties().put(((Slider) slider).getPropertyKey(), slider.getValueInt()); + } + })}); + betweenDamage = new MutablePair<>(new CheckButtonRecipe(parent, 8, x, y + (15 * buttonCount++), "X { + if (parent.selectedSlot != null && parent.selectedSlot.getStack() != null) { + parent.selectedSlot.getProperties().put(((Slider) slider).getPropertyKey(), slider.getValueInt()); + } + }), new Slider("betweenDamageY", 13, x - 2, parent.getGuiTop() + parent.getYSize() + 44, parent.getXSize() + 102, 20, "Y= ", "", 0, 0, 0, false, true, slider -> { + if (parent.selectedSlot != null && parent.selectedSlot.getStack() != null) { + parent.selectedSlot.getProperties().put(((Slider) slider).getPropertyKey(), slider.getValueInt()); + } + })}); + + nbt = new MutablePair<>(new CheckButtonRecipe(parent, 8, x, y + (15 * buttonCount++), "NBT", false, "nbt"), new Slider[]{}); + + reuse = new MutablePair<>(new CheckButtonRecipe(parent, 0, x, y + (15 * buttonCount++), "Reuse", false, "reuse"), new Slider[]{}); + noReturn = new MutablePair<>(new CheckButtonRecipe(parent, 0, x, y + (15 * buttonCount++), "No Return", false, "noreturn"), new Slider[]{}); + + + this.buttons.add(useOreDict); + this.buttons.add(matchAnyMetadata); + this.buttons.add(anyDamage); + this.buttons.add(onlyDamage); + + this.buttons.add(greaterThanEqualDamage); + this.buttons.add(lessThanDamage); + this.buttons.add(betweenDamage); + this.buttons.add(nbt); + + + this.buttons.add(reuse); + this.buttons.add(noReturn); + + this.buttons.forEach(but -> parent.getButtonList().add(but.getLeft())); + + useOreDict.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft(), nbt.getLeft()})); + matchAnyMetadata.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()})); + anyDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()})); + onlyDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()})); + + greaterThanEqualDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), lessThanDamage.getLeft(), betweenDamage.getLeft()})); + lessThanDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), betweenDamage.getLeft()})); + betweenDamage.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft(), matchAnyMetadata.getLeft(), anyDamage.getLeft(), onlyDamage.getLeft(), greaterThanEqualDamage.getLeft(), lessThanDamage.getLeft()})); + + nbt.getLeft().setIncompatible(Arrays.asList(new CheckButtonRecipe[]{useOreDict.getLeft()})); + noReturn.getLeft().setIncompatible(Arrays.asList(reuse.getLeft())); + reuse.getLeft().setIncompatible(Arrays.asList(noReturn.getLeft())); + + + } + + public void close(GuiBase parent) { + this.parent = parent; + if (!parent.getButtonList().isEmpty()) { + this.parent.getButtonList().remove(useOreDict.getLeft()); + this.parent.getButtonList().remove(matchAnyMetadata.getLeft()); + this.parent.getButtonList().remove(anyDamage.getLeft()); + this.parent.getButtonList().remove(onlyDamage.getLeft()); + this.parent.getButtonList().remove(greaterThanEqualDamage.getLeft()); + this.parent.getButtonList().remove(lessThanDamage.getLeft()); + this.parent.getButtonList().remove(betweenDamage.getLeft()); + + this.parent.getButtonList().remove(reuse.getLeft()); + this.parent.getButtonList().remove(noReturn.getLeft()); + + } + } + + + public void setState(boolean active) { + useOreDict.getLeft().setIsChecked(active); + matchAnyMetadata.getLeft().setIsChecked(active); + anyDamage.getLeft().setIsChecked(active); + onlyDamage.getLeft().setIsChecked(active); + + greaterThanEqualDamage.getLeft().setIsChecked(active); + lessThanDamage.getLeft().setIsChecked(active); + betweenDamage.getLeft().setIsChecked(active); + reuse.getLeft().setIsChecked(active); + noReturn.getLeft().setIsChecked(active); + nbt.getLeft().setIsChecked(active); + + } + + public void toggle(boolean active) { + useOreDict.getLeft().enabled = active; + matchAnyMetadata.getLeft().enabled = active; + anyDamage.getLeft().enabled = active; + onlyDamage.getLeft().enabled = active; + greaterThanEqualDamage.getLeft().enabled = active; + lessThanDamage.getLeft().enabled = active; + betweenDamage.getLeft().enabled = active; + reuse.getLeft().enabled = active; + noReturn.getLeft().enabled = active; + nbt.getLeft().enabled = active; + + + } + + public void getFromMap(Map propertyMap, Map properties) { + useOreDict.getLeft().setIsChecked(getPropertyFromMap(propertyMap, useOreDict.getLeft().getPropertyKey())); + matchAnyMetadata.getLeft().setIsChecked(getPropertyFromMap(propertyMap, matchAnyMetadata.getLeft().getPropertyKey())); + anyDamage.getLeft().setIsChecked(getPropertyFromMap(propertyMap, anyDamage.getLeft().getPropertyKey())); + onlyDamage.getLeft().setIsChecked(getPropertyFromMap(propertyMap, onlyDamage.getLeft().getPropertyKey())); + greaterThanEqualDamage.getLeft().setIsChecked(getPropertyFromMap(propertyMap, greaterThanEqualDamage.getLeft().getPropertyKey())); + lessThanDamage.getLeft().setIsChecked(getPropertyFromMap(propertyMap, lessThanDamage.getLeft().getPropertyKey())); + betweenDamage.getLeft().setIsChecked(getPropertyFromMap(propertyMap, betweenDamage.getLeft().getPropertyKey())); + reuse.getLeft().setIsChecked(getPropertyFromMap(propertyMap, reuse.getLeft().getPropertyKey())); + noReturn.getLeft().setIsChecked(getPropertyFromMap(propertyMap, noReturn.getLeft().getPropertyKey())); + nbt.getLeft().setIsChecked(getPropertyFromMap(propertyMap, nbt.getLeft().getPropertyKey())); + } + + boolean getPropertyFromMap(Map propertyMap, String key) { + if (propertyMap.containsKey(key)) { + return propertyMap.get(key); + } + return false; + } + + Object getProperty(Map propertyMap, String key) { + if (propertyMap.containsKey(key)) { + return propertyMap.get(key); + } + return false; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public int getWidth() { + return 11; + } + + public int getHeight() { + return 55; + } + + + public Slider[] getSliders(CheckButtonRecipe check) { + for (Pair pair : this.buttons) { + if (pair.getLeft().getPropertyKey().equals(check.getPropertyKey())) { + return pair.getValue(); + } + } + return new Slider[0]; + } + + public List> getButtons() { + return buttons; + } +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/craftingtable/ContainerCraftingTable.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/craftingtable/ContainerCraftingTable.java new file mode 100644 index 0000000..01c12f3 --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/craftingtable/ContainerCraftingTable.java @@ -0,0 +1,48 @@ +package com.blamejared.ctgui.client.gui.craftingtable; + +import com.blamejared.ctgui.api.ContainerBase; +import com.blamejared.ctgui.api.SlotRecipe; +import com.blamejared.ctgui.api.SlotRecipeOutput; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.InventoryCraftResult; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.inventory.Slot; + +/** + * Created by Jared. + */ +public class ContainerCraftingTable extends ContainerBase { + + public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3); + public IInventory craftResult = new InventoryCraftResult(); + + public ContainerCraftingTable(InventoryPlayer invPlayer) { + //output + this.addSlotToContainer(new SlotRecipeOutput(craftResult, 0, 124, 35)); + //Slots + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j) { + this.addSlotToContainer(new SlotRecipe(craftMatrix, j + i * 3, 30 + j * 18, 17 + i * 18)); + } + } + //Player + for (int x = 0; x < 9; x++) { + addSlotToContainer(new Slot(invPlayer, x, 8 + 18 * x, 142)); + } + + for (int y = 0; y < 3; y++) { + for (int x = 0; x < 9; x++) { + addSlotToContainer(new Slot(invPlayer, x + y * 9 + 9, 8 + 18 * x, 84 + y * 18)); + } + } + } + + @Override + protected Slot addSlotToContainer(Slot slotIn) { + if (slotIn instanceof SlotRecipe) { + getRecipeSlots().add((SlotRecipe) slotIn); + } + return super.addSlotToContainer(slotIn); + } +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/craftingtable/GuiCraftingTable.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/craftingtable/GuiCraftingTable.java new file mode 100644 index 0000000..cd2cd86 --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/craftingtable/GuiCraftingTable.java @@ -0,0 +1,103 @@ +package com.blamejared.ctgui.client.gui.craftingtable; + +import com.blamejared.ctgui.api.CheckButton; +import com.blamejared.ctgui.api.ContainerBase; +import com.blamejared.ctgui.api.GuiBase; +import com.blamejared.ctgui.api.SlotRecipe; +import net.minecraft.util.ResourceLocation; + +import java.util.Arrays; + +/** + * Created by Jared. + */ +public class GuiCraftingTable extends GuiBase { + + + public GuiCraftingTable(ContainerBase container) { + super(container, 176, 166, true); + } + + private CheckButton shaped; + private CheckButton shapeless; + private CheckButton mirror; + + @Override + public void initGui() { + super.initGui(); + shaped = new CheckButton(this, 2910, getGuiLeft(), getGuiTop() + getYSize() + 4, "Shaped", true); + shapeless = new CheckButton(this, 2911, getGuiLeft() + 54, getGuiTop() + getYSize() + 4, "Shapeless", false); + mirror = new CheckButton(this, 2912, getGuiLeft() + 54 + 74, getGuiTop() + getYSize() + 4, "Mirror", false); + shaped.setBackgroundSize(50); + shapeless.setBackgroundSize(70); + mirror.setBackgroundSize(50); + + getButtonList().add(shapeless); + getButtonList().add(shaped); + getButtonList().add(mirror); + shaped.setIncompatible(Arrays.asList(shapeless)); + shapeless.setIncompatible(Arrays.asList(shaped, mirror)); + mirror.setIncompatible(Arrays.asList(remove)); + shaped.setIsChecked(true); + + } + + @Override + public String getOutputAdd() { + String type = "add"; + boolean shapel = false; + if (shapeless.isChecked()) { + type += "Shapeless"; + shapel = true; + } else if (shaped.isChecked()) { + type += "Shaped"; + } + if (mirror.isChecked()) { + type += "Mirrored"; + } + if (shapel) { + return String.format("recipes.%s(%s, [%s%s%s%s%s%s%s%s%s]);", type, container.getRecipeSlots().get(0).getItemString(), getShapelessItem(container.getRecipeSlots().get(1)), getShapelessItem(container.getRecipeSlots().get(2)), getShapelessItem(container.getRecipeSlots().get(3)), getShapelessItem(container.getRecipeSlots().get(4)), getShapelessItem(container.getRecipeSlots().get(5)), getShapelessItem(container.getRecipeSlots().get(6)), getShapelessItem(container.getRecipeSlots().get(7)), getShapelessItem(container.getRecipeSlots().get(8)), getShapelessItem(container.getRecipeSlots().get(9))); + } + return String.format("recipes.%s(%s, [[%s, %s, %s],[%s, %s, %s], [%s, %s, %s]]);", type, container.getRecipeSlots().get(0).getItemString(), container.getRecipeSlots().get(1).getItemString(), container.getRecipeSlots().get(2).getItemString(), container.getRecipeSlots().get(3).getItemString(), container.getRecipeSlots().get(4).getItemString(), container.getRecipeSlots().get(5).getItemString(), container.getRecipeSlots().get(6).getItemString(), container.getRecipeSlots().get(7).getItemString(), container.getRecipeSlots().get(8).getItemString(), container.getRecipeSlots().get(9).getItemString()); + } + + private String getShapelessItem(SlotRecipe slot) { + String ret = ""; + if (slot.getHasStack()) { + ret += "," + slot.getItemString(); + } + return ret.isEmpty() ? ret : ret.substring(1); + } + + @Override + public String getOutputRemove() { + boolean hasrecipe = false; + for (int i = 1; i < container.getRecipeSlots().size(); i++) { + SlotRecipe slot = container.getRecipeSlots().get(i); + if (slot.getHasStack()) { + hasrecipe = true; + } + } + + String type = "remove"; + boolean shapel = false; + if (hasrecipe) + if (shapeless.isChecked()) { + type += "Shapeless"; + shapel = true; + } else if (shaped.isChecked()) { + type += "Shaped"; + } + if (shapel) { + return String.format("recipes.%s(%s, [%s%s%s%s%s%s%s%s%s]);", type, container.getRecipeSlots().get(0).getItemString(), getShapelessItem(container.getRecipeSlots().get(1)), getShapelessItem(container.getRecipeSlots().get(2)), getShapelessItem(container.getRecipeSlots().get(3)), getShapelessItem(container.getRecipeSlots().get(4)), getShapelessItem(container.getRecipeSlots().get(5)), getShapelessItem(container.getRecipeSlots().get(6)), getShapelessItem(container.getRecipeSlots().get(7)), getShapelessItem(container.getRecipeSlots().get(8)), getShapelessItem(container.getRecipeSlots().get(9))); + } + return hasrecipe ? String.format("recipes.%s(%s, [[%s, %s, %s],[%s, %s, %s], [%s, %s, %s]]);", type, container.getRecipeSlots().get(0).getItemString(), container.getRecipeSlots().get(1).getItemString(), container.getRecipeSlots().get(2).getItemString(), container.getRecipeSlots().get(3).getItemString(), container.getRecipeSlots().get(4).getItemString(), container.getRecipeSlots().get(5).getItemString(), container.getRecipeSlots().get(6).getItemString(), container.getRecipeSlots().get(7).getItemString(), container.getRecipeSlots().get(8).getItemString(), container.getRecipeSlots().get(9).getItemString()) : String.format("recipes.removeShaped(%s);", container.getRecipeSlots().get(0).getItemString()); + } + + @Override + public ResourceLocation getTexture() { + return new ResourceLocation("textures/gui/container/crafting_table.png"); + } + + +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/furnace/ContainerFurnace.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/furnace/ContainerFurnace.java new file mode 100644 index 0000000..1eae450 --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/furnace/ContainerFurnace.java @@ -0,0 +1,46 @@ +package com.blamejared.ctgui.client.gui.furnace; + +import com.blamejared.ctgui.api.ContainerBase; +import com.blamejared.ctgui.api.SlotRecipe; +import com.blamejared.ctgui.api.SlotRecipeOutput; +import com.blamejared.ctgui.client.InventoryFake; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.InventoryCraftResult; +import net.minecraft.inventory.Slot; + +/** + * Created by Jared. + */ +public class ContainerFurnace extends ContainerBase { + + public IInventory inventory = new InventoryFake(1); + public IInventory craftResult = new InventoryCraftResult(); + + public ContainerFurnace(InventoryPlayer invPlayer) { + //output + this.addSlotToContainer(new SlotRecipeOutput(craftResult, 0, 116, 35)); + + //Slots + this.addSlotToContainer(new SlotRecipe(inventory, 0, 56, 17)); + + //Player + for (int x = 0; x < 9; x++) { + addSlotToContainer(new Slot(invPlayer, x, 8 + 18 * x, 142)); + } + + for (int y = 0; y < 3; y++) { + for (int x = 0; x < 9; x++) { + addSlotToContainer(new Slot(invPlayer, x + y * 9 + 9, 8 + 18 * x, 84 + y * 18)); + } + } + } + + @Override + protected Slot addSlotToContainer(Slot slotIn) { + if (slotIn instanceof SlotRecipe) { + getRecipeSlots().add((SlotRecipe) slotIn); + } + return super.addSlotToContainer(slotIn); + } +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/furnace/GuiFurnace.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/furnace/GuiFurnace.java new file mode 100644 index 0000000..4edb18e --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/client/gui/furnace/GuiFurnace.java @@ -0,0 +1,50 @@ +package com.blamejared.ctgui.client.gui.furnace; + +import com.blamejared.ctgui.api.ContainerBase; +import com.blamejared.ctgui.api.GuiBase; +import com.blamejared.ctgui.api.Slider; +import net.minecraft.util.ResourceLocation; + +/** + * Created by Jared. + */ +public class GuiFurnace extends GuiBase { + private Slider xpSlider; + + public GuiFurnace(ContainerBase container) { + super(container, 176, 166, false); + } + + @Override + public void initGui() { + super.initGui(); + xpSlider = new Slider("slider", 10, getGuiLeft() - 102 - 2, getGuiTop() + getYSize() + 20, getXSize()+102, 20, "XP= ", "", 0, 50, 0, true, true, slider -> { + }); + getButtonList().add(xpSlider); + } + + @Override + public void updateScreen() { + super.updateScreen(); + if (!container.getRecipeSlots().get(1).getHasStack()) { + add.enabled = false; + remove.enabled = false; + } + } + + @Override + public String getOutputAdd() { + return String.format("furnace.addRecipe(%s, %s, %s);", container.getRecipeSlots().get(0).getItemString(), container.getRecipeSlots().get(1).getItemString(), xpSlider.getValue() + 0f); + } + + @Override + public String getOutputRemove() { + return String.format("furnace.remove(%s%s);", container.getRecipeSlots().get(0).getItemString(), container.getRecipeSlots().get(1).getHasStack() ? ", " + container.getRecipeSlots().get(1).getItemString() : ""); + } + + @Override + public ResourceLocation getTexture() { + return new ResourceLocation("textures/gui/container/furnace.png"); + } + +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/commands/CommandCTGUI.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/commands/CommandCTGUI.java new file mode 100644 index 0000000..5906d07 --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/commands/CommandCTGUI.java @@ -0,0 +1,44 @@ +package com.blamejared.ctgui.commands; + +import com.blamejared.ctgui.MTRecipe; +import com.blamejared.ctgui.api.GuiRegistry; +import net.minecraft.command.CommandBase; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.text.TextComponentString; + +/** + * Created by Jared. + */ +public class CommandCTGUI extends CommandBase { + + @Override + public String getCommandName() { + return "CTGUI"; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "CTGUI "; + } + + @Override + public int getRequiredPermissionLevel() { + return 0; + } + + @Override + public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { + if (args.length == 0 || Integer.parseInt(args[0]) < 1 || GuiRegistry.getHandlerForID(Integer.parseInt(args[0])) == null) { + sender.addChatMessage(new TextComponentString("Invalid ID!")); + return; + } + + if (sender instanceof EntityPlayer) { + EntityPlayer player = (EntityPlayer) sender; + player.openGui(MTRecipe.INSTANCE, Integer.parseInt(args[0]), sender.getEntityWorld(), 0, 0, 0); + } + } +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/proxy/ClientProxy.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/proxy/ClientProxy.java new file mode 100644 index 0000000..b15330e --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/proxy/ClientProxy.java @@ -0,0 +1,18 @@ +package com.blamejared.ctgui.proxy; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; + +public class ClientProxy extends CommonProxy { + + @Override + public void registerGuis() { + super.registerGuis(); + } + + @Override + public EntityPlayer getPlayer() { + return Minecraft.getMinecraft().thePlayer; + } + +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/proxy/CommonProxy.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/proxy/CommonProxy.java new file mode 100644 index 0000000..11c6762 --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/proxy/CommonProxy.java @@ -0,0 +1,17 @@ +package com.blamejared.ctgui.proxy; + +import com.blamejared.ctgui.client.GuiHandler; +import net.minecraft.entity.player.EntityPlayer; + +public class CommonProxy { + + public void registerGuis() { + new GuiHandler(); + } + + + public EntityPlayer getPlayer() { + return null; + } + +} diff --git a/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/reference/Reference.java b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/reference/Reference.java new file mode 100644 index 0000000..fa8f5ac --- /dev/null +++ b/MineTweaker3-MC1102-Main/src/main/java/com/blamejared/ctgui/reference/Reference.java @@ -0,0 +1,9 @@ +package com.blamejared.ctgui.reference; + +public class Reference { + + public static final String MOD_ID = "mtrecipe"; + public static final String MOD_NAME = "MTRecipe"; + public static final String VERSION = "1.0.0"; + +}