fixed 1.7.10 version

This commit is contained in:
Dries007 committed 2017-02-13 20:22:04 +01:00
commit 9d4ccd1915
12 files changed
+1273

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
.gradle
build
jars
out
*.iml
*.ipr
*.iws
.idea
*.txt
*.json
gradlew
gradlew.bat
gradle
eclipse
+27
View File
@@ -0,0 +1,27 @@
MineTweakerRecipeMaker
======================
Oh god, its is finally here!<br>
The one and only **MineTweakerRecipeMaker**!
This mod creates the .zs file on the server's side, that is why you need the mod on the server too (and need to be op).
(Although you can join a server that does not have the mod, you just won't be able to use it.)
This mod has no relation with MineTweaker itself, and MineTweaker is not a dependency. Although this mod is utterly useless without it :p
**Warning**, this mod is not idiot proof, but it tries to be. :p Please post bugreports, so we can make it more idiot proof!
How to use
----------
Command: "/mtrm" or "/MineTweakerRecipeMaker"
Download
--------
We have downloads on [curseforge](http://minecraft.curseforge.com/mc-mods/226294-minetweaker-recipemaker) and on [our website](http://doubledoordev.net/) (more up to date).
Modpacks & license
------------------
As per usual this mod is open-source, you can see the license [here](LICENSE.txt)
+82
View File
@@ -0,0 +1,82 @@
buildscript {
repositories {
mavenCentral()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
}
}
import groovy.json.*
configurations {
compile
deployJars
}
apply plugin: "forge"
apply plugin: "maven"
group = "net.doubledoordev.mtrm"
version = "1.1.1"
targetCompatibility = 1.7
sourceCompatibility = 1.7
archivesBaseName = 'MineTweakerRecipeMaker'
def githuborg = 'DoubleDoorDevelopment'
def description = 'MineTweaker Recipe Maker'
minecraft {
version = "1.7.10-10.13.1.1224"
runDir = "jars"
}
if (System.getenv().BUILD_NUMBER != null) version += "." + System.getenv().BUILD_NUMBER
processResources {
from(sourceSets.main.resources.srcDirs) {
include '**/*.info'
expand 'version':project.version, 'mcversion':project.minecraft.version, 'modid':project.archivesBaseName, 'githuborg':githuborg, 'description':description
}
from(sourceSets.main.resources.srcDirs) {
exclude '**/*.info'
}
}
task sourcesJar(type: Jar) {
from "LICENSE.txt"
from sourceSets.main.allSource
classifier = 'src'
appendix = project.minecraft.version
}
task deobfJar(type: Jar) {
from "LICENSE.txt"
from sourceSets.main.output
from (sourceSets.main.allSource.srcDirs) {
include '**/*.java'
}
classifier = 'dev'
appendix = project.minecraft.version
}
jar {
from "LICENSE.txt"
appendix = project.minecraft.version
}
artifacts {
archives jar
archives sourcesJar
archives deobfJar
}
@@ -0,0 +1,45 @@
package net.doubledoordev.mtrm;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import java.util.Arrays;
import java.util.List;
/**
* @author Dries007
*/
public class MTRMCommand extends CommandBase
{
@Override
public String getCommandName()
{
return "minetweakerrecipemaker";
}
@Override
public List getCommandAliases()
{
return Arrays.asList("mtrm");
}
@Override
public String getCommandUsage(ICommandSender p_71518_1_)
{
return "Step 4: PROFIT?";
}
@Override
public boolean canCommandSenderUseCommand(ICommandSender p_71519_1_)
{
return MinecraftServer.getServer().isSinglePlayer() || super.canCommandSenderUseCommand(p_71519_1_);
}
@Override
public void processCommand(ICommandSender sender, String[] args)
{
if (sender instanceof EntityPlayer) ((EntityPlayer) sender).openGui(MineTweakerRecipeMaker.instance, 0, sender.getEntityWorld(), 0, 0, 0);
}
}
@@ -0,0 +1,57 @@
package net.doubledoordev.mtrm;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.network.NetworkCheckHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;
import net.doubledoordev.mtrm.gui.MTRMGuiHandler;
import net.doubledoordev.mtrm.network.MessageResponse;
import net.doubledoordev.mtrm.network.MessageSend;
import java.util.Map;
/**
* @author Dries007
*/
@Mod(modid = MineTweakerRecipeMaker.MODID, name = MineTweakerRecipeMaker.NAME)
public class MineTweakerRecipeMaker
{
public static final String MODID = "MTRM";
public static final String NAME = "MineTweakerRecipeMaker";
@Mod.Instance(MODID)
public static MineTweakerRecipeMaker instance;
private SimpleNetworkWrapper snw;
public static SimpleNetworkWrapper getSnw()
{
return instance.snw;
}
@Mod.EventHandler
public void init(FMLPreInitializationEvent event)
{
NetworkRegistry.INSTANCE.registerGuiHandler(this, new MTRMGuiHandler());
int id = 0;
snw = NetworkRegistry.INSTANCE.newSimpleChannel(MODID);
snw.registerMessage(MessageSend.Handler.class, MessageSend.class, id++, Side.SERVER);
snw.registerMessage(MessageResponse.Handler.class, MessageResponse.class, id++, Side.CLIENT);
}
@Mod.EventHandler
public void serverStarting(FMLServerStartingEvent event)
{
event.registerServerCommand(new MTRMCommand());
}
@NetworkCheckHandler
public boolean networkCheckHandler(Map<String, String> map, Side side)
{
return side.isClient() || map.containsKey(MODID);
}
}
@@ -0,0 +1,132 @@
package net.doubledoordev.mtrm.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.*;
import net.minecraft.item.ItemStack;
/**
* @author Dries007
*/
public class MTRMContainer extends Container
{
public static final int RETURN_SLOT_ID = 1 + (3 * 3) + (3 * 9) + 9;
/**
* The crafting matrix inventory (3x3).
*/
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);
public IInventory craftResult = new InventoryCraftResult();
public IInventory returnSlot = new InventoryCraftResult();
public MTRMContainer(InventoryPlayer p_i1808_1_)
{
this.addSlotToContainer(new Slot(this.craftResult, 0, 138, 48));
for (int y = 0; y < 3; ++y) for (int x = 0; x < 3; ++x) this.addSlotToContainer(new Slot(this.craftMatrix, x + y * 3, 22 + x * 26, 21 + y * 26));
for (int y = 0; y < 3; ++y) for (int x = 0; x < 9; ++x) this.addSlotToContainer(new Slot(p_i1808_1_, x + y * 9 + 9, 8 + x * 18, 99 + y * 18));
for (int x = 0; x < 9; ++x) this.addSlotToContainer(new Slot(p_i1808_1_, x, 8 + x * 18, 157));
this.addSlotToContainer(new Slot(returnSlot, 0, -109, 143));
this.onCraftMatrixChanged(this.craftMatrix);
}
/**
* Callback for when the crafting matrix is changed.
*/
public void onCraftMatrixChanged(IInventory p_75130_1_)
{
super.onCraftMatrixChanged(p_75130_1_);
}
public boolean canInteractWith(EntityPlayer p_75145_1_)
{
return true;
}
@Override
protected void retrySlotClick(int p_75133_1_, int p_75133_2_, boolean p_75133_3_, EntityPlayer p_75133_4_)
{
}
@Override
public ItemStack slotClick(int i, int mousebtn, int modifier, EntityPlayer player)
{
ItemStack stack = null;
if ((i >= 0 && i <= 9) || i == RETURN_SLOT_ID) // 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 (!(i == 0 || i == RETURN_SLOT_ID)) 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 == RETURN_SLOT_ID))
{
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, modifier, player);
}
return stack;
}
/**
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
*/
public ItemStack transferStackInSlot(EntityPlayer player, int slots)
{
if (slots < 10 || slots == RETURN_SLOT_ID) ((Slot) inventorySlots.get(slots)).putStack(null);
return null;
}
public boolean func_94530_a(ItemStack p_94530_1_, Slot p_94530_2_)
{
return p_94530_2_.inventory != craftResult && p_94530_2_.inventory != returnSlot && super.func_94530_a(p_94530_1_, p_94530_2_);
}
}
@@ -0,0 +1,582 @@
package net.doubledoordev.mtrm.gui;
import cpw.mods.fml.client.config.GuiButtonExt;
import cpw.mods.fml.client.config.GuiCheckBox;
import cpw.mods.fml.client.config.GuiSlider;
import cpw.mods.fml.common.registry.GameData;
import cpw.mods.fml.common.registry.GameRegistry;
import net.doubledoordev.mtrm.MineTweakerRecipeMaker;
import net.doubledoordev.mtrm.network.MessageSend;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.oredict.OreDictionary;
import org.lwjgl.opengl.GL11;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static net.doubledoordev.mtrm.gui.MTRMContainer.RETURN_SLOT_ID;
/**
* @author Dries007
*/
public class MTRMGui extends GuiContainer
{
private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation("mtrm:gui/mtrm.png");
private static final Pattern MATCH_ALL = Pattern.compile("<\\*>");
private static final Pattern META_WILDCARD = Pattern.compile(":\\*>");
private static final Pattern ORE_DICT = Pattern.compile("<ore:.*>");
private static final Pattern REUSE = Pattern.compile("\\.reuse\\(\\)");
private static final Pattern NO_RETURN = Pattern.compile("\\.noReturn\\(\\)");
private static final Pattern ANY_DAMAGE = Pattern.compile("\\.anyDamage\\(\\)");
private static final Pattern ONLY_DAMAGE = Pattern.compile("\\.onlyDamaged\\(\\)");
private static final Pattern ONLY_DAMAGE_AT_MOST = Pattern.compile("\\.onlyDamageAtMost\\((\\d+)\\)");
private static final Pattern ONLY_DAMAGE_AT_LEAST = Pattern.compile("\\.onlyDamageAtLeast\\((\\d+)\\)");
private static final Pattern ONLY_DAMAGE_BETWEEN = Pattern.compile("\\.onlyDamageBetween\\((\\d+), ?(\\d+)\\)");
private static final Pattern WITH_DAMAGE = Pattern.compile("\\.withDamage\\((\\d+)\\)");
private static final Pattern TRANSFORM_DAMAGE = Pattern.compile("\\.transformDamage\\((\\d+)\\)");
private static final Pattern GIVE_BACK = Pattern.compile("\\.giveBack\\(<(.*):(.*)(:\\d+)?>(?: ?\\* ?(\\d+))\\)");
private static final Pattern TRANSFORM_REPLACE = Pattern.compile("\\.transformReplace\\(<(.*):(.*)(:\\d+)?>(?: ?\\* ?(\\d+))\\)");
private static final int ID_SEND = 10;
private static final int ID_REMOVE = 11;
private static final int ID_SHAPELESS = 12;
private static final int ID_MIRRORED = 13;
private static final int ID_OPTION_OK = 14;
private static final int ID_OPTION_MATCHALL = 15;
private static final int ID_OPTION_OREDICT = 16;
private static final int ID_OPTION_META_WILDCARD = 17;
private static final int ID_OPTION_NEXT_OREDICT = 18;
private static final int ID_OPTION_ANY_DAMAGE = 19;
private static final int ID_OPTION_WITH_DAMAGE = 20;
private static final int ID_OPTION_ONLY_DAMAGED = 21;
private static final int ID_CLOSE = 22;
private static final int ID_OPTION_ONLY_DAMAGE_AT_LEAST = 23;
private static final int ID_OPTION_ONLY_DAMAGE_AT_MOST = 24;
private static final int ID_OPTION_ONLY_DAMAGE_BETWEEN = 25;
private static final int ID_OPTION_REUSE = 26;
private static final int ID_OPTION_ID_OPTION_TRANSFORM_DAMAGE = 27;
private static final int ID_OPTION_NO_RETURN = 28;
private static final int ID_OPTION_RETURN_OK = 29;
private static final int ID_OPTION_ID_OPTION_TRANSFORM_REPLACE = 30;
private static final int ID_OPTION_GIVE_BACK = 31;
private final GuiSlider.ISlider iSlider = new GuiSlider.ISlider()
{
@Override
public void onChangeSliderValue(GuiSlider slider)
{
tokenTxt.setText(getStackToken(false, inventorySlots.getSlot(editing).getStack()));
}
};
private final MTRMContainer container;
private GuiCheckBox remove;
private GuiCheckBox shapeless;
private GuiCheckBox mirrored;
private GuiCheckBox matchAll;
private GuiCheckBox oreDict;
private GuiCheckBox metaWildcard;
private GuiCheckBox anyDamage;
private GuiButtonExt optionsOk;
private GuiButtonExt nextOreDict;
private GuiTextField tokenTxt;
private GuiCheckBox onlyDamaged;
private GuiCheckBox withDamage;
private GuiCheckBox onlyDamageAtLeast;
private GuiCheckBox onlyDamageAtMost;
private GuiCheckBox onlyDamageBetween;
private GuiCheckBox reuse;
private GuiCheckBox noReturn;
private GuiCheckBox transformDamage;
private GuiCheckBox transformReplace;
private GuiCheckBox giveBack;
private GuiButtonExt returnOk;
private Map<GuiCheckBox, GuiSlider[]> sliders = new HashMap<>();
private Map<GuiCheckBox, Pattern> patterns = new HashMap<>();
private Map<GuiCheckBox, GuiCustomLabel[]> labels = new HashMap<>();
private GuiCheckBox[] allDamage;
private GuiCheckBox[] allTransform;
private GuiCheckBox[][] allGroups;
private MessageSend messageSend = new MessageSend();
private int editing = -1;
private int lastOreId = 0;
private String errorMessage;
public MTRMGui(MTRMContainer container)
{
super(container);
ySize = 181;
this.container = container;
}
public String getStackToken(boolean nextOreDict, ItemStack stack)
{
boolean metaWildcard = this.metaWildcard.isChecked();
boolean oreDict = this.oreDict.isChecked();
if (stack == null) return "null";
String stackName = GameData.getItemRegistry().getNameForObject(stack.getItem());
StringBuilder builder = new StringBuilder("<");
if (oreDict)
{
int[] ids = OreDictionary.getOreIDs(stack);
if (ids.length != 0)
{
stackName = "ore:" + OreDictionary.getOreName(ids[lastOreId]);
if (nextOreDict) lastOreId++;
if (lastOreId >= ids.length) lastOreId = 0;
}
else oreDict = false;
}
builder.append(stackName);
if (!oreDict && (metaWildcard || stack.getItemDamage() != 0)) builder.append(':').append(metaWildcard || stack.getItemDamage() == OreDictionary.WILDCARD_VALUE ? "*" : stack.getItemDamage());
builder.append('>');
if (stack.stackSize > 1) builder.append(" * ").append(stack.stackSize);
if (anyDamage.isChecked()) builder.append(".anyDamage()");
if (onlyDamaged.isChecked()) builder.append(".onlyDamaged()");
if (withDamage.isChecked()) builder.append(".withDamage(").append(sliders.get(withDamage)[0].getValueInt()).append(')');
if (onlyDamageAtLeast.isChecked()) builder.append(".onlyDamageAtLeast(").append(sliders.get(onlyDamageAtLeast)[0].getValueInt()).append(')');
if (onlyDamageAtMost.isChecked()) builder.append(".onlyDamageAtMost(").append(sliders.get(onlyDamageAtMost)[0].getValueInt()).append(')');
if (onlyDamageBetween.isChecked()) builder.append(".onlyDamageBetween(").append(sliders.get(onlyDamageBetween)[0].getValueInt()).append(", ").append(sliders.get(onlyDamageBetween)[1].getValueInt()).append(')');
if (reuse.isChecked()) builder.append(".reuse()");
if (noReturn.isChecked()) builder.append(".noReturn()");
if (transformDamage.isChecked()) builder.append(".transformDamage(").append(sliders.get(transformDamage)[0].getValueInt()).append(')');
if (container.getSlot(RETURN_SLOT_ID).getHasStack() && (giveBack.isChecked() || transformReplace.isChecked()))
{
ItemStack returnStack = container.getSlot(RETURN_SLOT_ID).getStack();
if (giveBack.isChecked()) builder.append(".giveBack(<");
else if (transformReplace.isChecked()) builder.append(".transformReplace(<");
builder.append(GameData.getItemRegistry().getNameForObject(returnStack.getItem()));
if (returnStack.getItemDamage() != 0) builder.append(':').append(returnStack.getItemDamage());
builder.append('>');
if (returnStack.stackSize > 1) builder.append(" * ").append(returnStack.stackSize);
builder.append(')');
}
return builder.toString();
}
@Override
public void initGui()
{
super.initGui();
int id = 0;
this.buttonList.add(new GuiButtonExt(id++, this.width / 2 + 65, this.height / 2 - 50, 10, 10, "*"));
for (int y = 0; y < 3; ++y) for (int x = 0; x < 3; ++x) this.buttonList.add(new GuiButtonExt(id++, this.width / 2 - 52 + x * 26, this.height / 2 - 78 + y * 26, 10, 10, "*"));
this.buttonList.add(remove = new GuiCheckBox(ID_REMOVE, this.width / 2 + 90, this.height / 2 - 80, "Remove", false));
this.buttonList.add(shapeless = new GuiCheckBox(ID_SHAPELESS, this.width / 2 + 90, this.height / 2 - 70, "Shapeless", false));
this.buttonList.add(mirrored = new GuiCheckBox(ID_MIRRORED, this.width / 2 + 90, this.height / 2 - 60, "Mirrored", true));
this.buttonList.add(new GuiButtonExt(ID_SEND, this.width / 2 + 90, this.height / 2 - 45, 110, 20, "Ok!"));
this.buttonList.add(new GuiButtonExt(ID_CLOSE, this.width / 2 + 90, this.height / 2 - 25, 110, 20, "Close"));
int wOffset = this.width / 2 - 200;
int hOffset = this.height / 2 - 110;
tokenTxt = new GuiTextField(this.fontRendererObj, wOffset, hOffset - 25, 220 + this.xSize, 20);
tokenTxt.setMaxStringLength(Integer.MAX_VALUE);
this.buttonList.add(matchAll = new GuiCheckBox(ID_OPTION_MATCHALL, wOffset, hOffset += 10, "Match not empty (*)", false));
this.buttonList.add(oreDict = new GuiCheckBox(ID_OPTION_OREDICT, wOffset, hOffset += 10, "Use ore dictionary", true));
this.buttonList.add(metaWildcard = new GuiCheckBox(ID_OPTION_META_WILDCARD, wOffset, hOffset += 10, "Match any metadata", false));
this.buttonList.add(anyDamage = new GuiCheckBox(ID_OPTION_ANY_DAMAGE, wOffset, hOffset += 10, "Any Damage", false));
this.buttonList.add(onlyDamaged = new GuiCheckBox(ID_OPTION_ONLY_DAMAGED, wOffset, hOffset += 10, "Only Damaged", false));
this.buttonList.add(withDamage = new GuiCheckBox(ID_OPTION_WITH_DAMAGE, wOffset, hOffset += 10, "With Damage X", false));
this.buttonList.add(onlyDamageAtLeast = new GuiCheckBox(ID_OPTION_ONLY_DAMAGE_AT_LEAST, wOffset, hOffset += 10, "With Damage >= X", false));
this.buttonList.add(onlyDamageAtMost = new GuiCheckBox(ID_OPTION_ONLY_DAMAGE_AT_MOST, wOffset, hOffset += 10, "With Damage < X", false));
this.buttonList.add(onlyDamageBetween = new GuiCheckBox(ID_OPTION_ONLY_DAMAGE_BETWEEN, wOffset, hOffset += 10, "With X > Damage > Y", false));
this.buttonList.add(transformDamage = new GuiCheckBox(ID_OPTION_ID_OPTION_TRANSFORM_DAMAGE, wOffset, hOffset += 10, "Transform Damage", false));
this.buttonList.add(transformReplace = new GuiCheckBox(ID_OPTION_ID_OPTION_TRANSFORM_REPLACE, wOffset, hOffset += 10, "Transform Replace", false));
this.buttonList.add(reuse = new GuiCheckBox(ID_OPTION_REUSE, wOffset, hOffset += 10, "Reuse", false));
this.buttonList.add(noReturn = new GuiCheckBox(ID_OPTION_NO_RETURN, wOffset, hOffset += 10, "No Return", false));
this.buttonList.add(giveBack = new GuiCheckBox(ID_OPTION_GIVE_BACK, wOffset, hOffset += 10, "GiveBack", false));
this.buttonList.add(nextOreDict = new GuiButtonExt(ID_OPTION_NEXT_OREDICT, wOffset, hOffset += 40, 110, 20, "Next oredict value"));
this.buttonList.add(optionsOk = new GuiButtonExt(ID_OPTION_OK, wOffset, hOffset += 20, 110, 20, "Save changes!"));
// Buttongroups
allDamage = new GuiCheckBox[]{matchAll, metaWildcard, anyDamage, onlyDamaged, withDamage, onlyDamageAtLeast, onlyDamageAtMost, onlyDamageBetween};
allTransform = new GuiCheckBox[]{transformDamage, transformReplace, reuse, noReturn, giveBack};
allGroups = new GuiCheckBox[][]{allDamage, allTransform};
addPatterns(matchAll, MATCH_ALL);
addPatterns(metaWildcard, META_WILDCARD);
addPatterns(anyDamage, ANY_DAMAGE);
addPatterns(onlyDamaged, ONLY_DAMAGE);
addPatterns(reuse, REUSE);
addPatterns(noReturn, NO_RETURN);
id = 100;
hOffset += 30;
int hOffsetText = hOffset - this.guiTop - 10;
GuiCustomLabel returnSlot = new GuiCustomLabel()
{
@Override
public void draw(boolean b)
{
if (!b) drawTexturedModalRect(((width - xSize) / 2) - 110, ((height - ySize) / 2) + 142, 21, 20, 18, 18);
}
};
addLabels(transformReplace, returnSlot, new GuiCustomLabelText("Transform Replace:", -110, hOffsetText - 68));
addPatterns(transformReplace, TRANSFORM_REPLACE);
returnSlot = new GuiCustomLabel()
{
@Override
public void draw(boolean b)
{
if (!b) drawTexturedModalRect(((width - xSize) / 2) - 110, ((height - ySize) / 2) + 142, 21, 20, 18, 18);
}
};
addLabels(giveBack, returnSlot, new GuiCustomLabelText("Give Back:", -110, hOffsetText - 68));
addPatterns(giveBack, GIVE_BACK);
this.buttonList.add(returnOk = new GuiButtonExt(ID_OPTION_RETURN_OK, wOffset + 20, hOffset - 68, 20, 18, "OK"));
addSliders(withDamage, new GuiSlider(id++, wOffset, hOffset, 220 + this.xSize, 20, "X = ", "", 0, 0, 0, false, true, iSlider));
addLabels(withDamage, new GuiCustomLabelText("With Damage X", -110, hOffsetText));
addPatterns(withDamage, WITH_DAMAGE);
addSliders(onlyDamageAtLeast, new GuiSlider(id++, wOffset, hOffset, 220 + this.xSize, 20, "X = ", "", 0, 0, 0, false, true, iSlider));
addLabels(onlyDamageAtLeast, new GuiCustomLabelText("With Damage >= X", -110, hOffsetText));
addPatterns(onlyDamageAtLeast, ONLY_DAMAGE_AT_LEAST);
addSliders(onlyDamageAtMost, new GuiSlider(id++, wOffset, hOffset, 220 + this.xSize, 20, "X = ", "", 0, 0, 0, false, true, iSlider));
addLabels(onlyDamageAtMost, new GuiCustomLabelText("With Damage < X", -110, hOffsetText));
addPatterns(onlyDamageAtMost, ONLY_DAMAGE_AT_MOST);
addSliders(onlyDamageBetween, new GuiSlider(id++, wOffset, hOffset, 220 + this.xSize, 20, "X = ", "", 0, 0, 0, false, true, iSlider), new GuiSlider(id++, wOffset, hOffset + 20, 220 + this.xSize, 20, "Y = ", "", 0, 0, 0, false, true, iSlider));
addLabels(onlyDamageBetween, new GuiCustomLabelText("With X > Damage > Y", -110, hOffsetText));
addPatterns(onlyDamageBetween, ONLY_DAMAGE_BETWEEN);
hOffset += 50;
hOffsetText += 50;
addSliders(transformDamage, new GuiSlider(id++, wOffset, hOffset, 220 + this.xSize, 20, "X = ", "", 0, 0, 0, false, true, iSlider));
addLabels(transformDamage, new GuiCustomLabelText("Transform with X damage", -110, hOffsetText));
addPatterns(transformDamage, TRANSFORM_DAMAGE);
setOptionsVisible(false);
}
private void addPatterns(GuiCheckBox key, Pattern values)
{
patterns.put(key, values);
}
private void addSliders(GuiCheckBox key, GuiSlider... values)
{
for (GuiSlider value : values) this.buttonList.add(value);
sliders.put(key, values);
}
private void addLabels(GuiCheckBox key, GuiCustomLabel... values)
{
labels.put(key, values);
}
protected void handleMouseClick(Slot slot, int slotNumber, int mouseBtn, int modifier)
{
super.handleMouseClick(slot, slotNumber, mouseBtn, modifier);
if (slot != null && slotNumber >= 0 && slotNumber <= 9)
{
showOptionsFor(slotNumber);
messageSend.data[slotNumber] = getStackToken(false, slot.getStack());
showOptionsFor(slotNumber);
}
if (slotNumber == RETURN_SLOT_ID)
{
tokenTxt.setText(getStackToken(true, inventorySlots.getSlot(editing).getStack()));
}
}
protected void actionPerformed(GuiButton btn)
{
switch (btn.id)
{
case ID_CLOSE:
this.mc.thePlayer.closeScreen();
break;
case ID_SEND:
messageSend.remove = remove.isChecked();
messageSend.shapeless = shapeless.isChecked();
messageSend.mirrored = mirrored.isChecked();
MineTweakerRecipeMaker.getSnw().sendToServer(messageSend);
break;
case ID_REMOVE:
case ID_SHAPELESS:
mirrored.enabled = !(shapeless.isChecked() || remove.isChecked());
if (!mirrored.enabled) mirrored.setIsChecked(false);
break;
case ID_OPTION_OK:
saveOptions();
break;
case ID_OPTION_MATCHALL:
radioBoxToggle(matchAll, allDamage);
oreDict.setIsChecked(!matchAll.isChecked());
oreDict.enabled = !matchAll.isChecked();
nextOreDict.enabled = oreDict.isChecked();
if (matchAll.isChecked()) tokenTxt.setText("<*>");
else tokenTxt.setText(getStackToken(false, inventorySlots.getSlot(editing).getStack()));
break;
case ID_OPTION_META_WILDCARD:
case ID_OPTION_ONLY_DAMAGED:
case ID_OPTION_ANY_DAMAGE:
case ID_OPTION_WITH_DAMAGE:
case ID_OPTION_ONLY_DAMAGE_AT_LEAST:
case ID_OPTION_ONLY_DAMAGE_AT_MOST:
case ID_OPTION_ONLY_DAMAGE_BETWEEN:
radioBoxToggle((GuiCheckBox) btn, allDamage);
tokenTxt.setText(getStackToken(false, inventorySlots.getSlot(editing).getStack()));
break;
case ID_OPTION_ID_OPTION_TRANSFORM_DAMAGE:
case ID_OPTION_ID_OPTION_TRANSFORM_REPLACE:
case ID_OPTION_REUSE:
case ID_OPTION_NO_RETURN:
case ID_OPTION_GIVE_BACK:
radioBoxToggle((GuiCheckBox) btn, allTransform);
tokenTxt.setText(getStackToken(false, inventorySlots.getSlot(editing).getStack()));
break;
case ID_OPTION_OREDICT:
nextOreDict.enabled = oreDict.isChecked();
case ID_OPTION_NEXT_OREDICT:
case ID_OPTION_RETURN_OK:
tokenTxt.setText(getStackToken(true, inventorySlots.getSlot(editing).getStack()));
break;
default:
if (btn.id >= 0 && btn.id <= 10) showOptionsFor(btn.id);
}
}
private void radioBoxToggle(GuiCheckBox clicked, GuiCheckBox... others)
{
for (GuiCheckBox checkBox : others)
{
if (sliders.containsKey(checkBox)) for (GuiSlider s : sliders.get(checkBox)) s.visible = checkBox.isChecked();
if (labels.containsKey(checkBox)) for (GuiCustomLabel s : labels.get(checkBox)) s.draw = checkBox.isChecked();
if (checkBox == clicked) continue;
if (clicked.isChecked()) checkBox.setIsChecked(false);
checkBox.enabled = !clicked.isChecked();
}
}
private void saveOptions()
{
messageSend.data[editing] = tokenTxt.getText();
if (messageSend.data[editing].equalsIgnoreCase("null")) messageSend.data[editing] = null;
editing = -1;
setOptionsVisible(false);
}
private void showOptionsFor(int id)
{
if (editing != id) lastOreId = 0;
editing = id;
String token = messageSend.data[id];
if (token == null)
{
tokenTxt.setText("null");
oreDict.enabled = id != 0;
oreDict.setIsChecked(id != 0);
nextOreDict.enabled = id != 0;
for (GuiCheckBox[] group : allGroups)
{
for (GuiCheckBox checkBox : group)
{
checkBox.setIsChecked(false);
if (sliders.containsKey(checkBox))
{
for (GuiSlider slider : sliders.get(checkBox))
{
slider.minValue = 0;
slider.maxValue = 0;
slider.setValue(0);
}
}
if (labels.containsKey(checkBox)) for (GuiCustomLabel l : labels.get(checkBox)) l.draw = false;
}
}
container.getSlot(RETURN_SLOT_ID).putStack(null);
}
else
{
tokenTxt.setText(token);
oreDict.enabled = id != 0;
oreDict.setIsChecked(ORE_DICT.matcher(token).find() && id != 0);
nextOreDict.enabled = oreDict.isChecked() && id != 0;
for (GuiCheckBox[] group : allGroups)
{
for (GuiCheckBox checkBox : group)
{
if (patterns.containsKey(checkBox))
{
checkBox.setIsChecked(patterns.get(checkBox).matcher(token).find());
radioBoxToggle(checkBox, group);
}
}
}
Matcher m = GIVE_BACK.matcher(token);
if (m.find())
{
int meta = m.group(3) != null ? Integer.parseInt(m.group(3)) : 0;
int size = m.group(4) != null ? Integer.parseInt(m.group(4)) : 1;
container.getSlot(RETURN_SLOT_ID).putStack(new ItemStack(GameRegistry.findItem(m.group(1), m.group(2)), size, meta));
}
}
for (GuiCheckBox[] group : allGroups)
{
for (GuiCheckBox checkBox : group)
{
checkBox.enabled = id != 0;
if (!sliders.containsKey(checkBox)) continue;
GuiSlider[] sliderA = sliders.get(checkBox);
for (GuiSlider slider : sliderA)
{
slider.minValue = 0;
slider.maxValue = Integer.MAX_VALUE;
slider.setValue(0);
if (!oreDict.isChecked())
{
ItemStack stack = container.getSlot(editing).getStack();
if (stack != null) slider.maxValue = stack.getItem().getMaxDamage();
}
}
if (token != null && patterns.containsKey(checkBox))
{
Matcher matcher = patterns.get(checkBox).matcher(token);
if (matcher.find())
{
for (int i = 0; i < matcher.groupCount() && i < sliderA.length; i++)
{
sliderA[i].setValue(Integer.parseInt(matcher.group(i + 1)));
}
}
}
}
}
setOptionsVisible(true);
}
private void setOptionsVisible(boolean visible)
{
matchAll.visible = visible;
metaWildcard.visible = visible;
optionsOk.visible = visible;
oreDict.visible = visible;
nextOreDict.visible = visible;
anyDamage.visible = visible;
withDamage.visible = visible;
onlyDamaged.visible = visible;
reuse.visible = visible;
returnOk.visible = visible;
for (GuiCheckBox[] group : allGroups)
{
for (GuiCheckBox gui : group)
{
gui.visible = visible;
if (sliders.containsKey(gui)) for (GuiSlider s : sliders.get(gui)) s.visible = visible && gui.isChecked();
if (labels.containsKey(gui)) for (GuiCustomLabel l : labels.get(gui)) l.draw = visible && gui.isChecked();
}
}
tokenTxt.setVisible(visible);
if (!visible) container.putStackInSlot(RETURN_SLOT_ID, null);
}
protected void keyTyped(char p_73869_1_, int p_73869_2_)
{
if (!this.tokenTxt.textboxKeyTyped(p_73869_1_, p_73869_2_))
{
super.keyTyped(p_73869_1_, p_73869_2_);
}
}
protected void mouseClicked(int p_73864_1_, int p_73864_2_, int p_73864_3_)
{
super.mouseClicked(p_73864_1_, p_73864_2_, p_73864_3_);
this.tokenTxt.mouseClicked(p_73864_1_, p_73864_2_, p_73864_3_);
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
*/
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_)
{
if (editing != -1)
{
this.fontRendererObj.drawString("Editing slot " + editing, -110, -55, 0xFFFFFF);
this.fontRendererObj.drawString("Slot Options", -100, -20, 0xFFFFFF);
}
this.fontRendererObj.drawString("Recipe Options", this.xSize + 15, 0, 0xFFFFFF);
this.fontRendererObj.drawString("MineTweaker Recipe Maker", 28, 4, 4210752);
this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 5, 4210752);
if (errorMessage != null) this.drawCenteredString(this.fontRendererObj, errorMessage, this.xSize / 2, -15, 0xFF0000);
this.fontRendererObj.drawString("0", 144, 53, 0xFFFFFF);
for (int y = 0; y < 3; ++y) for (int x = 0; x < 3; ++x) this.fontRendererObj.drawString(String.valueOf(1 + y * 3 + x), 28 + x * 26, 25 + y * 26, 0xFFFFFF);
for (GuiCustomLabel[] labela : labels.values()) for (GuiCustomLabel label : labela) if (label.draw) label.draw(true);
}
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(craftingTableGuiTextures);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
for (GuiCustomLabel[] labela : labels.values()) for (GuiCustomLabel label : labela) if (label.draw) label.draw(false);
tokenTxt.drawTextBox();
}
public void showMessage(String message)
{
this.errorMessage = message;
}
private abstract class GuiCustomLabel
{
boolean draw = false;
public abstract void draw(boolean b);
}
private class GuiCustomLabelText extends GuiCustomLabel
{
String text;
int color = 0xFFFFFF;
int x, y;
public GuiCustomLabelText(String s, int x, int y)
{
this.x = x;
this.y = y;
this.text = s;
}
public void draw(boolean b)
{
if (b) fontRendererObj.drawString(text, x, y, color);
}
}
}
@@ -0,0 +1,23 @@
package net.doubledoordev.mtrm.gui;
import cpw.mods.fml.common.network.IGuiHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
/**
* @author Dries007
*/
public class MTRMGuiHandler implements IGuiHandler
{
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
return new MTRMContainer(player.inventory);
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
return new MTRMGui(new MTRMContainer(player.inventory));
}
}
@@ -0,0 +1,64 @@
package net.doubledoordev.mtrm.network;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.doubledoordev.mtrm.gui.MTRMGui;
import net.minecraft.client.Minecraft;
/**
* @author Dries007
*/
public class MessageResponse implements IMessage
{
private String message;
public MessageResponse()
{
}
public MessageResponse(Status status, Object... args)
{
this.message = status.message == null ? null : String.format(status.message, args);
}
@Override
public void fromBytes(ByteBuf buf)
{
if (buf.readBoolean()) message = ByteBufUtils.readUTF8String(buf);
}
@Override
public void toBytes(ByteBuf buf)
{
buf.writeBoolean(message != null);
if (message != null) ByteBufUtils.writeUTF8String(buf, message);
}
public static class Handler implements IMessageHandler<MessageResponse, IMessage>
{
@Override
public IMessage onMessage(MessageResponse message, MessageContext ctx)
{
if (Minecraft.getMinecraft().currentScreen instanceof MTRMGui)
{
MTRMGui gui = ((MTRMGui) Minecraft.getMinecraft().currentScreen);
gui.showMessage(message.message);
}
return null;
}
}
public static enum Status
{
OK(null), NO_OUT("There is no output specified."), NO_IN("There is no input specified."), WRITE_ERROR("IOError: %s");
private final String message;
Status(String message)
{
this.message = message;
}
}
}
@@ -0,0 +1,226 @@
package net.doubledoordev.mtrm.network;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.doubledoordev.mtrm.MineTweakerRecipeMaker;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
/**
* @author Dries007
*/
public class MessageSend implements IMessage
{
public boolean remove;
public boolean shapeless;
public boolean mirrored;
public String[] data = new String[10];
public MessageSend()
{
}
@Override
public void fromBytes(ByteBuf buf)
{
remove = buf.readBoolean();
shapeless = buf.readBoolean();
mirrored = buf.readBoolean();
data = new String[buf.readInt()];
for (int i = 0; i < data.length; i++)
{
if (buf.readBoolean()) data[i] = ByteBufUtils.readUTF8String(buf);
}
}
@Override
public void toBytes(ByteBuf buf)
{
buf.writeBoolean(remove);
buf.writeBoolean(shapeless);
buf.writeBoolean(mirrored);
buf.writeInt(data.length);
for (String item : data)
{
boolean tag = item != null && !item.equals("null");
buf.writeBoolean(tag);
if (tag) ByteBufUtils.writeUTF8String(buf, item);
}
}
private String getMarker(boolean noIngredients)
{
StringBuilder marker = new StringBuilder(25);
marker.append("//#MARKER ");
marker.append(remove ? "REMOVE" : "ADD");
if (!noIngredients) marker.append(shapeless ? " SHAPELESS" : " SHAPED");
return marker.toString();
}
private String getScript(boolean noIngredients, ArrayList<ArrayList<String>> ingredients)
{
StringBuilder script = new StringBuilder(100);
script.append("recipes.").append(remove ? "remove" : "add");
if (!noIngredients) script.append(shapeless ? "Shapeless" : "Shaped");
script.append('(').append(data[0]);
if (!noIngredients)
{
script.append(", ");
if (shapeless) script.append(ingredients.get(0).toString());
else script.append(ingredients.toString());
}
return script.append(");").toString();
}
private MessageResponse makeScript()
{
ArrayList<ArrayList<String>> ingredients = new ArrayList<>();
boolean noIngredients = true;
if (shapeless)
{
ArrayList<String> lst = new ArrayList<>();
for (int i = 1; i < data.length; i++)
{
if (data[i] != null) lst.add(data[i]);
}
noIngredients = lst.isEmpty();
ingredients.add(lst);
}
else
{
String[][] rawIngredients = new String[][]{new String[3], new String[3], new String[3]};
boolean rowsNull[] = new boolean[]{true, true, true};
boolean colsNull[] = new boolean[]{true, true, true};
for (int i = 1; i < data.length; i++)
{
if (data[i] != null)
{
int row = (i - 1) / 3;
int col = (i - 1) % 3;
noIngredients = false;
rowsNull[row] = false;
colsNull[col] = false;
rawIngredients[row][col] = data[i];
}
}
for (int i = 0; i < rowsNull.length; i++)
{
if (!rowsNull[i])
{
ArrayList<String> row = new ArrayList<>();
for (int j = 0; j < colsNull.length; j++)
{
if (!colsNull[j]) row.add(rawIngredients[i][j]);
}
ingredients.add(row);
}
}
}
if (data[0] == null) return new MessageResponse(MessageResponse.Status.NO_OUT);
if (!remove && noIngredients) return new MessageResponse(MessageResponse.Status.NO_IN);
File oldFile = new File("scripts/MineTweakerRecipeMaker/scripts/", "Crafting.zs");
File file = new File("scripts", MineTweakerRecipeMaker.NAME + ".zs");
if (!file.getParentFile().exists()) file.getParentFile().mkdirs();
try
{
if (oldFile.exists()) FileUtils.moveFile(oldFile, file);
}
catch (IOException e)
{
e.printStackTrace();
}
if (!file.exists())
{
try
{
file.createNewFile();
PrintWriter printWriter = new PrintWriter(file);
printWriter.println("// File generated by MineTweakerRecipeMaker");
printWriter.println("// READ THIS HEADER BEFORE EDITING ANYTHING");
printWriter.println("// ================================================================================");
printWriter.println("// This file is read and changed by the mod.");
printWriter.println("// If you remove/edit any of the markers, IT WILL STOP WORKING!");
printWriter.println("// If you want to make manual edits, make a backup of this file!");
printWriter.println("// Markers look like this: \"//#MARKER something\"");
printWriter.println("// They indicate where calls should be placed, so that MineTweaker does them in the correct order.");
printWriter.println("// Removes come first, then stuff is added.");
printWriter.println("// ================================================================================");
printWriter.println("//");
printWriter.println();
printWriter.println("// ================================================================================");
printWriter.println("//#MARKER REMOVE");
printWriter.println();
printWriter.println("// ================================================================================");
printWriter.println("//#MARKER REMOVE SHAPELESS");
printWriter.println();
printWriter.println("// ================================================================================");
printWriter.println("//#MARKER REMOVE SHAPED");
printWriter.println();
printWriter.println("// ================================================================================");
printWriter.println("//#MARKER ADD");
printWriter.println();
printWriter.println("// ================================================================================");
printWriter.println("//#MARKER ADD SHAPELESS");
printWriter.println();
printWriter.println("// ================================================================================");
printWriter.println("//#MARKER ADD SHAPED");
printWriter.println();
printWriter.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
try
{
final String marker = getMarker(noIngredients);
List<String> lines = FileUtils.readLines(file);
ListIterator<String> i = lines.listIterator();
while (i.hasNext())
{
String line = i.next();
if (line.equals(marker))
{
i.add(getScript(noIngredients, ingredients));
break;
}
}
if (!i.hasNext()) return new MessageResponse(MessageResponse.Status.WRITE_ERROR, "Cannot find " + marker + " . Did you edit the file manually?");
FileUtils.writeLines(file, lines);
try
{
Class.forName("minetweaker.MineTweakerImplementationAPI").getDeclaredMethod("reload").invoke(null);
}
catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException ignored)
{
}
}
catch (IOException e)
{
e.printStackTrace();
return new MessageResponse(MessageResponse.Status.WRITE_ERROR, e.toString());
}
return new MessageResponse(MessageResponse.Status.OK);
}
public static class Handler implements IMessageHandler<MessageSend, IMessage>
{
@Override
public IMessage onMessage(MessageSend message, MessageContext ctx)
{
return message.makeScript();
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

+21
View File
@@ -0,0 +1,21 @@
{
"modListVersion": 2,
"modList": [{
"modid": "${modid}",
"name": "${modid}",
"description": "${description}",
"version": "${version}",
"mcversion": "${mcversion}",
"url": "https://github.com/${githuborg}/${modid}",
"updateUrl": "",
"authorList": [ "Dries007", "Doubledoor team" ],
"credits": "",
"logoFile": "",
"screenshots": [],
"parent": "",
"requiredMods": [ "Forge" ],
"dependencies": [ ],
"dependants": [ ],
"useDependencyInformation": true
}]
}