mirror of
https://github.com/GTNewHorizons/ModTweaker.git
synced 2026-11-18 19:49:08 +00:00
ModTweaker2 Rework
- Revised base classes for IUndoableAction - Reordered lots of code, so stuck actions should be less frequent - Added wildcard support to many "remove" methods - Started working on exist & duplicate checks
This commit is contained in:
1 parent
f5034b04d8
commit
da33cc6fab
112 files changed
+4596
-3522
No files matched your search
@@ -1,11 +1,12 @@
|
||||
package modtweaker2.helpers;
|
||||
|
||||
import static modtweaker2.helpers.ReflectionHelper.getFinalObject;
|
||||
import static modtweaker2.helpers.ReflectionHelper.getStaticObject;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import static modtweaker2.helpers.ReflectionHelper.*;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
@@ -2,13 +2,16 @@ package modtweaker2.helpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.api.entity.IEntity;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import minetweaker.api.oredict.IOreDictEntry;
|
||||
import minetweaker.mc1710.data.NBTConverter;
|
||||
import minetweaker.mc1710.item.MCItemStack;
|
||||
import minetweaker.mc1710.liquid.MCLiquidStack;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
@@ -18,11 +21,55 @@ import net.minecraftforge.fluids.FluidStack;
|
||||
public class InputHelper {
|
||||
public static boolean isABlock(IItemStack block) {
|
||||
if (!(isABlock(toStack(block)))) {
|
||||
MineTweakerAPI.getLogger().logError("Item must be a block, or you must specify a block to render as when adding a TConstruct Melting recipe");
|
||||
LogHelper.logError("Item must be a block, or you must specify a block to render as when adding a TConstruct Melting recipe");
|
||||
return false;
|
||||
} else
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the item which can also be used in scripts
|
||||
*/
|
||||
public static String getStackDescription(ItemStack stack) {
|
||||
if(stack != null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
// Creates a name like <minecraft:piston> or <appliedenergistics2:item.ItemMultiMaterial:156>
|
||||
sb.append('<');
|
||||
sb.append(Item.itemRegistry.getNameForObject(stack.getItem()));
|
||||
if(stack.getItemDamage() == 32767) {
|
||||
sb.append(":*");
|
||||
} else if (stack.getItemDamage() > 0) {
|
||||
sb.append(":").append(stack.getItemDamage());
|
||||
}
|
||||
sb.append('>');
|
||||
|
||||
// Do we have a tag? (e.g. <Botania:specialFlower>.withTag({}) )
|
||||
if(stack.getTagCompound() != null)
|
||||
{
|
||||
sb.append(".withTag(");
|
||||
sb.append(NBTConverter.from(stack.getTagCompound(), true));
|
||||
sb.append(')');
|
||||
}
|
||||
|
||||
// Do we have a stack size > 1?
|
||||
if(stack.stackSize > 1) {
|
||||
sb.append(" * ").append(stack.stackSize);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
} else {
|
||||
return "null object";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getStackDescription(FluidStack stack) {
|
||||
if(stack != null) {
|
||||
return "<liquid:" + stack.getFluid().getName() + ">";
|
||||
} else {
|
||||
return "null object";
|
||||
}
|
||||
}
|
||||
|
||||
public static IItemStack[] toStacks(IIngredient[] iIngredient) {
|
||||
ArrayList<IItemStack> stacks = new ArrayList<IItemStack>();
|
||||
@@ -52,12 +99,39 @@ public class InputHelper {
|
||||
else {
|
||||
Object internal = iStack.getInternal();
|
||||
if (internal == null || !(internal instanceof ItemStack)) {
|
||||
MineTweakerAPI.getLogger().logError("Not a valid item stack: " + iStack);
|
||||
LogHelper.logError("Not a valid item stack: " + iStack);
|
||||
}
|
||||
|
||||
return (ItemStack) internal;
|
||||
}
|
||||
}
|
||||
|
||||
public static IIngredient toIngredient(ItemStack stack) {
|
||||
return toIItemStack(stack);
|
||||
}
|
||||
|
||||
public static IIngredient toIngredient(FluidStack stack) {
|
||||
if(stack == null)
|
||||
return null;
|
||||
|
||||
return new MCLiquidStack(stack);
|
||||
}
|
||||
|
||||
public static IItemStack toIItemStack(ItemStack stack) {
|
||||
if(stack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new MCItemStack(stack);
|
||||
}
|
||||
|
||||
public static ILiquidStack toILiquidStack(FluidStack stack) {
|
||||
if(stack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new MCLiquidStack(stack);
|
||||
}
|
||||
|
||||
public static ItemStack[] toStacks(IItemStack[] iStack) {
|
||||
if (iStack == null)
|
||||
|
||||
@@ -21,4 +21,20 @@ public class LogHelper {
|
||||
System.out.println(string);
|
||||
MineTweakerAPI.logCommand(string);
|
||||
}
|
||||
|
||||
public static void logError(String message) {
|
||||
MineTweakerAPI.logError("[ModTweaker2] " + message);
|
||||
}
|
||||
|
||||
public static void logError(String message, Throwable exception) {
|
||||
MineTweakerAPI.logError("[ModTweaker2] " + message, exception);
|
||||
}
|
||||
|
||||
public static void logWarning(String message) {
|
||||
MineTweakerAPI.logWarning("[ModTweaker2] " + message);
|
||||
}
|
||||
|
||||
public static void logInfo(String message) {
|
||||
MineTweakerAPI.logInfo("[ModTweaker2] " + message);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,90 @@
|
||||
package modtweaker2.helpers;
|
||||
|
||||
//import modtweaker2.mods.botania.Botania;
|
||||
import static modtweaker2.helpers.InputHelper.toStack;
|
||||
import minetweaker.api.item.IIngredient;
|
||||
import minetweaker.api.item.IItemStack;
|
||||
import minetweaker.api.liquid.ILiquidStack;
|
||||
import modtweaker2.mods.botania.Botania;
|
||||
import modtweaker2.utils.TweakerPlugin;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class StackHelper {
|
||||
// Stack is the stack that is part of a recipe, stack2 is the one input
|
||||
// trying to match
|
||||
public static boolean areEqual(ItemStack stack, ItemStack stack2) {
|
||||
if (stack == null || stack2 == null)
|
||||
/**
|
||||
* Compares two ItemStack instances, trying to match the referenced item.
|
||||
*/
|
||||
public static boolean areEqual(ItemStack stack1, ItemStack stack2) {
|
||||
if (stack1 == null || stack2 == null) {
|
||||
return false;
|
||||
else if (TweakerPlugin.isLoaded("Botania") && Botania.isSubtile(stack) && Botania.isSubtile(stack2)) {
|
||||
return Botania.subtileMatches(stack, stack2);
|
||||
} else
|
||||
return stack.isItemEqual(stack2);
|
||||
} else if (TweakerPlugin.isLoaded("Botania") && Botania.isSubtile(stack1) && Botania.isSubtile(stack2)) {
|
||||
return Botania.subtileMatches(stack1, stack2);
|
||||
} else {
|
||||
return stack1.isItemEqual(stack2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two ItemStack instances if they reference the same object or
|
||||
* are both null. If false, the method areEqual() is called to check if the
|
||||
* two instances reference the same item.
|
||||
*/
|
||||
public static boolean areEqualOrNull(ItemStack stack1, ItemStack stack2) {
|
||||
// Check if they reference the same object or are are both null
|
||||
if(stack1 == stack2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return(areEqual(stack1, stack2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds extra check to IIngredient matches() for Botania special flowers
|
||||
*/
|
||||
public static boolean matches(IIngredient ingredient, IItemStack itemStack) {
|
||||
if(ingredient == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!ingredient.matches(itemStack)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Do we have a wildcard (<*>) or an actual item?
|
||||
if(ingredient.getItems() != null) {
|
||||
for(IItemStack item : ingredient.getItems()) {
|
||||
if(areEqual(toStack(item), toStack(itemStack))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function compares an ingredient with a fluid. MCLiquidStack.matches() function
|
||||
* is currently broken in MineTweaker3, thus this function is only a workaround.
|
||||
*/
|
||||
public static boolean matches(IIngredient ingredient, ILiquidStack liquidStack) {
|
||||
if(ingredient == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Do we have a wildcard (<*>) ?
|
||||
if(ingredient.matches(liquidStack)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Does ingredient reference liquids?
|
||||
if(ingredient.getLiquids() != null) {
|
||||
for (ILiquidStack liquid : ingredient.getLiquids()) {
|
||||
if(InputHelper.toFluid(liquid).isFluidEqual(InputHelper.toFluid(liquidStack))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user