mirror of
https://github.com/GTNewHorizons/Avaritia.git
synced 2026-11-27 23:45:44 +00:00
magic
This commit is contained in:
3 files changed
+162
-1
No files matched your search
@@ -1,6 +1,6 @@
|
||||
package fox.spiteful.avaritia.compat.minetweaker;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
@@ -33,14 +33,55 @@ public class ExtremeCrafting {
|
||||
for (IIngredient[] row : ingredients) {
|
||||
if (width < row.length) width = row.length;
|
||||
}
|
||||
|
||||
String letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
int nextletter = 0;
|
||||
// ExtremeShapedOreRecipe r = (ExtremeShapedOreRecipe)recipe;
|
||||
HashMap<Character, Object> itemMap = new HashMap<>();
|
||||
HashMap<Object, Character> reverseItemMap = new HashMap<>();
|
||||
|
||||
Object[] input = new Object[width * height];
|
||||
String[] shapes = new String[height];
|
||||
int x = 0;
|
||||
int xx = 0;
|
||||
for (IIngredient[] row : ingredients) {
|
||||
Object[] objects = toObjects(row);
|
||||
StringBuilder shape = new StringBuilder();
|
||||
for (Object o : objects) {
|
||||
Object o2 = o;
|
||||
if (o2 instanceof ItemStack) o2 = new ItemMetaNBTWrapper((ItemStack) o2);
|
||||
Character chr = null;
|
||||
if (o == null) chr = '-';
|
||||
else if (reverseItemMap.containsKey(o2)) {
|
||||
chr = reverseItemMap.get(o2);
|
||||
} else {
|
||||
chr = letters.charAt(nextletter);
|
||||
nextletter++;
|
||||
itemMap.put(chr, o);
|
||||
reverseItemMap.put(o2, chr);
|
||||
}
|
||||
shape.append(chr);
|
||||
}
|
||||
shapes[xx++] = shape.toString();
|
||||
|
||||
for (IIngredient ingredient : row) {
|
||||
input[x++] = toActualObject(ingredient);
|
||||
}
|
||||
}
|
||||
|
||||
List<Object> ready = new ArrayList<>(Arrays.asList(shapes));
|
||||
|
||||
for (Map.Entry<Character, Object> entry : itemMap.entrySet()) {
|
||||
ready.add(entry.getKey());
|
||||
ready.add(entry.getValue());
|
||||
}
|
||||
|
||||
Tweak.info(
|
||||
"ExtremeCraftingManager.getInstance().addExtremeShapedOreRecipe(" + Tweak.convertStack(toStack(output))
|
||||
+ ", "
|
||||
+ Tweak.convertArrayInLine(ready.toArray())
|
||||
+ ");");
|
||||
|
||||
MineTweakerAPI.apply(new Add(new ExtremeShapedOreRecipe(toStack(output), input, width, height)));
|
||||
}
|
||||
|
||||
@@ -61,6 +102,7 @@ public class ExtremeCrafting {
|
||||
public void apply() {
|
||||
|
||||
ExtremeCraftingManager.getInstance().getRecipeList().add(recipe);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,6 +144,8 @@ public class ExtremeCrafting {
|
||||
@Override
|
||||
public void apply() {
|
||||
|
||||
Tweak.info("AvaritiaHelper.removeExtremeCraftingRecipe(" + Tweak.convertStack(remove) + ");");
|
||||
|
||||
for (Object obj : ExtremeCraftingManager.getInstance().getRecipeList()) {
|
||||
if (obj instanceof IRecipe) {
|
||||
IRecipe craft = (IRecipe) obj;
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package fox.spiteful.avaritia.compat.minetweaker;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import mantle.utils.ItemMetaWrapper;
|
||||
|
||||
public class ItemMetaNBTWrapper extends ItemMetaWrapper {
|
||||
|
||||
public final NBTTagCompound nbt;
|
||||
|
||||
public ItemMetaNBTWrapper(Item item, Integer meta, NBTTagCompound nbt) {
|
||||
super(item, meta);
|
||||
this.nbt = nbt;
|
||||
}
|
||||
|
||||
public ItemMetaNBTWrapper(ItemStack stack) {
|
||||
super(stack);
|
||||
this.nbt = stack.stackTagCompound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
|
||||
ItemMetaNBTWrapper that = (ItemMetaNBTWrapper) o;
|
||||
|
||||
if (nbt != null ? !nbt.equals(that.nbt) : that.nbt != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + (nbt != null ? nbt.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,85 @@
|
||||
package fox.spiteful.avaritia.compat.minetweaker;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import fox.spiteful.avaritia.Config;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.item.IngredientItem;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import minetweaker.api.oredict.IngredientOreDict;
|
||||
|
||||
public class Tweak {
|
||||
|
||||
private static final org.apache.logging.log4j.Logger TRANSLATORLOGGER = LogManager
|
||||
.getLogger("[SCRIPTS TO CODE TRANSLATOR]");
|
||||
|
||||
public static void info(String log) {
|
||||
TRANSLATORLOGGER.info(log);
|
||||
}
|
||||
|
||||
public static String convertStack(ItemStack stack) {
|
||||
if (stack == null) return "null";
|
||||
GameRegistry.UniqueIdentifier itemIdentifier = GameRegistry.findUniqueIdentifierFor(stack.getItem());
|
||||
int meta = stack.getItemDamage();
|
||||
int size = stack.stackSize;
|
||||
NBTTagCompound tagCompound = stack.stackTagCompound;
|
||||
if (tagCompound == null || tagCompound.hasNoTags()) {
|
||||
return "getModItem(\"" + itemIdentifier.modId
|
||||
+ "\", \""
|
||||
+ itemIdentifier.name
|
||||
+ "\", "
|
||||
+ size
|
||||
+ ", "
|
||||
+ meta
|
||||
+ ", missing)";
|
||||
} else {
|
||||
return "createItemStack(\"" + itemIdentifier.modId
|
||||
+ "\", \""
|
||||
+ itemIdentifier.name
|
||||
+ "\", "
|
||||
+ size
|
||||
+ ", "
|
||||
+ meta
|
||||
+ ", "
|
||||
+ "\""
|
||||
+ tagCompound.toString().replace("\"", "\\\"")
|
||||
+ "\""
|
||||
+ ", missing)";
|
||||
}
|
||||
}
|
||||
|
||||
public static String convertStack(IIngredient ingredient) {
|
||||
Object internal = ingredient.getInternal();
|
||||
if (internal instanceof ItemStack) return convertStack((ItemStack) internal);
|
||||
else return "ERRORSTACK";
|
||||
}
|
||||
|
||||
public static String convertArrayInLine(Object[] arr) {
|
||||
StringBuilder arrayString = new StringBuilder();
|
||||
for (int i = 0, arrLength = arr.length; i < arrLength; i++) {
|
||||
Object o = arr[i];
|
||||
if (o instanceof String) arrayString.append("\"").append((String) o).append("\"");
|
||||
else if (o instanceof Character) arrayString.append("'").append((char) o).append("'");
|
||||
else if (o instanceof ItemStack) arrayString.append(convertStack((ItemStack) o));
|
||||
else if (o instanceof IItemStack || o instanceof IngredientItem)
|
||||
arrayString.append(convertStack((IIngredient) o));
|
||||
else if (o instanceof IOreDictEntry)
|
||||
arrayString.append("\"").append((String) ((IOreDictEntry) o).getInternal()).append("\"");
|
||||
else if (o instanceof IngredientOreDict)
|
||||
arrayString.append("\"").append((String) ((IngredientOreDict) o).getInternal()).append("\"");
|
||||
else if (o == null) arrayString.append("null");
|
||||
else arrayString.append(o);
|
||||
if (i + 1 < arrLength) arrayString.append(", ");
|
||||
}
|
||||
return arrayString.toString();
|
||||
}
|
||||
|
||||
public static void registrate() {
|
||||
MineTweakerAPI.registerClass(ExtremeCrafting.class);
|
||||
if (Config.craftingOnly) return;
|
||||
|
||||
Reference in new issue
Block a user