mirror of
https://github.com/GTNewHorizons/Avaritia.git
synced 2026-11-20 12:19:39 +00:00
MineTweaker
This commit is contained in:
1 parent
00306fcc07
commit
b52cf82049
6 files changed
+319
-2
No files matched your search
@@ -5,6 +5,7 @@ import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import fox.spiteful.avaritia.Lumberjack;
|
||||
import fox.spiteful.avaritia.compat.bloodmagic.Bloody;
|
||||
import fox.spiteful.avaritia.compat.botania.Tsundere;
|
||||
import fox.spiteful.avaritia.compat.modtweaker.Tweak;
|
||||
import fox.spiteful.avaritia.compat.thaumcraft.Lucrum;
|
||||
import fox.spiteful.avaritia.crafting.Grinder;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -27,6 +28,7 @@ public class Compat {
|
||||
public static boolean bigReactors = false;
|
||||
public static boolean ticon = false;
|
||||
public static boolean pe = false;
|
||||
public static boolean tweak = false;
|
||||
public static boolean mfr = false;
|
||||
|
||||
public static void census(){
|
||||
@@ -43,6 +45,7 @@ public class Compat {
|
||||
bigReactors = Loader.isModLoaded("BigReactors");
|
||||
ticon = Loader.isModLoaded("TConstruct");
|
||||
pe = Loader.isModLoaded("ProjectE");
|
||||
tweak = Loader.isModLoaded("MineTweaker3");
|
||||
mfr = Loader.isModLoaded("MineFactoryReloaded");
|
||||
}
|
||||
|
||||
@@ -64,6 +67,17 @@ public class Compat {
|
||||
}
|
||||
}
|
||||
|
||||
if(tweak){
|
||||
try
|
||||
{
|
||||
Tweak.registrate();
|
||||
}
|
||||
catch(Throwable e){
|
||||
Lumberjack.log(Level.INFO, "Avaritia is too good for tweaking, apparently.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if(thaumic){
|
||||
try
|
||||
{
|
||||
@@ -221,7 +235,7 @@ public class Compat {
|
||||
pe = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(mfr){
|
||||
try {
|
||||
Item ponk = getItem("MineFactoryReloaded", "mfr.pinkslime");
|
||||
@@ -234,6 +248,7 @@ public class Compat {
|
||||
mfr = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Block getBlock(String mod, String block) throws ItemNotFoundException {
|
||||
|
||||
@@ -0,0 +1,285 @@
|
||||
package fox.spiteful.avaritia.compat.modtweaker;
|
||||
|
||||
import fox.spiteful.avaritia.crafting.ExtremeCraftingManager;
|
||||
import fox.spiteful.avaritia.crafting.ExtremeShapedOreRecipe;
|
||||
import fox.spiteful.avaritia.crafting.Grinder;
|
||||
import minetweaker.IUndoableAction;
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
import stanhebben.zenscript.annotations.ZenClass;
|
||||
import stanhebben.zenscript.annotations.ZenMethod;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ZenClass("mods.avaritia.ExtremeCrafting")
|
||||
public class ExtremeCrafting {
|
||||
|
||||
@ZenMethod
|
||||
public static void addShapeless(IItemStack output, IIngredient[] ingredients){
|
||||
|
||||
MineTweakerAPI.apply(new Add(new ShapelessOreRecipe(toStack(output), toObjects(ingredients))));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public static void addShaped(IItemStack output, IIngredient[][] ingredients){
|
||||
int height = ingredients.length;
|
||||
int width = 0;
|
||||
for(IIngredient[] row : ingredients){
|
||||
if(width < row.length)
|
||||
width = row.length;
|
||||
}
|
||||
Object[] input = new Object[width * height];
|
||||
int x = 0;
|
||||
for(IIngredient[] row : ingredients){
|
||||
for(IIngredient ingredient : row){
|
||||
input[x++] = toActualObject(ingredient);
|
||||
}
|
||||
}
|
||||
|
||||
MineTweakerAPI.apply(new Add(new ExtremeShapedOreRecipe(toStack(output), input, width, height)));
|
||||
}
|
||||
|
||||
@ZenMethod
|
||||
public void remove(IItemStack target){
|
||||
MineTweakerAPI.apply(new Remove(toStack(target)));
|
||||
}
|
||||
|
||||
private static class Add implements IUndoableAction {
|
||||
IRecipe recipe;
|
||||
|
||||
public Add(IRecipe add){
|
||||
recipe = add;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
|
||||
ExtremeCraftingManager.getInstance().getRecipeList().add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo(){
|
||||
ExtremeCraftingManager.getInstance().getRecipeList().remove(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe(){
|
||||
return "Adding Xtreme Crafting Recipe for " + recipe.getRecipeOutput().getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo(){
|
||||
return "Un-adding Xtreme Crafting Recipe for " + recipe.getRecipeOutput().getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class Remove implements IUndoableAction {
|
||||
IRecipe recipe = null;
|
||||
ItemStack remove;
|
||||
|
||||
public Remove(ItemStack rem){
|
||||
remove = rem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
|
||||
ExtremeCraftingManager.getInstance().getRecipeList().add(recipe);
|
||||
for(Object obj : ExtremeCraftingManager.getInstance().getRecipeList()){
|
||||
if(obj instanceof IRecipe){
|
||||
IRecipe craft = (IRecipe)obj;
|
||||
if(craft.getRecipeOutput().isItemEqual(remove)) {
|
||||
recipe = craft;
|
||||
ExtremeCraftingManager.getInstance().getRecipeList().remove(obj);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo(){
|
||||
return recipe != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo(){
|
||||
ExtremeCraftingManager.getInstance().getRecipeList().add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe(){
|
||||
return "Removing Xtreme Crafting Recipe for " + recipe.getRecipeOutput().getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo(){
|
||||
return "Un-removing Xtreme Crafting Recipe for " + recipe.getRecipeOutput().getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class AddCatalyst implements IUndoableAction {
|
||||
Object ingredient;
|
||||
|
||||
public AddCatalyst(Object add){
|
||||
ingredient = add;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
|
||||
Grinder.catalyst.getInput().add(ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo(){
|
||||
Grinder.catalyst.getInput().remove(ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe(){
|
||||
if(ingredient instanceof ItemStack)
|
||||
return "Adding " + ((ItemStack)ingredient).getDisplayName() + " to Infinity Catalyst recipe.";
|
||||
else if(ingredient instanceof List)
|
||||
return "Adding " + ((ItemStack)(((List)ingredient).get(0))).getDisplayName() + " to Infinity Catalyst recipe.";
|
||||
else
|
||||
return "Adding something to Infinity Catalyst recipe.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo(){
|
||||
if(ingredient instanceof ItemStack)
|
||||
return "Removing " + ((ItemStack)ingredient).getDisplayName() + " from Infinity Catalyst recipe.";
|
||||
else if(ingredient instanceof List)
|
||||
return "Removing " + ((ItemStack)(((List)ingredient).get(0))).getDisplayName() + " from Infinity Catalyst recipe.";
|
||||
else
|
||||
return "Removing something from Infinity Catalyst recipe.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class RemoveCatalyst implements IUndoableAction {
|
||||
IIngredient ingredient;
|
||||
|
||||
public RemoveCatalyst(IIngredient rem){
|
||||
ingredient = rem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
|
||||
Grinder.catalyst.getInput().add(ingredient);
|
||||
for(Object ingredient : Grinder.catalyst.getInput()){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUndo(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo(){
|
||||
Grinder.catalyst.getInput().remove(ingredient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describe(){
|
||||
return "Adding something to Infinity Catalyst recipe.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String describeUndo(){
|
||||
return "Removing something from Infinity Catalyst recipe.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getOverrideKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static ItemStack toStack(IItemStack item){
|
||||
if (item == null) return null;
|
||||
else {
|
||||
Object internal = item.getInternal();
|
||||
if (internal == null || !(internal instanceof ItemStack)) {
|
||||
MineTweakerAPI.getLogger().logError("Not a valid item stack: " + item);
|
||||
}
|
||||
return (ItemStack) internal;
|
||||
}
|
||||
}
|
||||
|
||||
private static Object toObject(IIngredient ingredient){
|
||||
if (ingredient == null) return null;
|
||||
else {
|
||||
if (ingredient instanceof IOreDictEntry) {
|
||||
return toString((IOreDictEntry)ingredient);
|
||||
} else if (ingredient instanceof IItemStack) {
|
||||
return toStack((IItemStack) ingredient);
|
||||
} else return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Object[] toObjects(IIngredient[] list){
|
||||
if(list == null)
|
||||
return null;
|
||||
Object[] ingredients = new Object[list.length];
|
||||
for(int x = 0;x < list.length;x++){
|
||||
ingredients[x] = toObject(list[x]);
|
||||
}
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
private static Object toActualObject(IIngredient ingredient){
|
||||
if (ingredient == null) return null;
|
||||
else {
|
||||
if (ingredient instanceof IOreDictEntry) {
|
||||
return OreDictionary.getOres(toString((IOreDictEntry) ingredient));
|
||||
} else if (ingredient instanceof IItemStack) {
|
||||
return toStack((IItemStack) ingredient);
|
||||
} else return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String toString(IOreDictEntry entry) {
|
||||
return ((IOreDictEntry) entry).getName();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package fox.spiteful.avaritia.compat.modtweaker;
|
||||
|
||||
import minetweaker.MineTweakerAPI;
|
||||
|
||||
public class Tweak {
|
||||
|
||||
public static void registrate(){
|
||||
MineTweakerAPI.registerClass(ExtremeCrafting.class);
|
||||
}
|
||||
}
|
||||
@@ -150,6 +150,13 @@ public class ExtremeShapedOreRecipe implements IRecipe {
|
||||
}
|
||||
}
|
||||
|
||||
public ExtremeShapedOreRecipe(ItemStack result, Object[] ingredients, int wid, int hei){
|
||||
width = wid;
|
||||
height = hei;
|
||||
output = result;
|
||||
input = ingredients;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an Item that is the result of this recipe
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user