mirror of
https://github.com/GTNewHorizons/ModTweaker.git
synced 2026-11-18 11:39:07 +00:00
Also changes like all packages inb4 "jared changes a package name in ModTweaker2 breaking compatability with everything" drama tweet.
This commit is contained in:
1 parent
4fd2551072
commit
ec562b62ea
187 files changed
+977
-991
No files matched your search
@@ -0,0 +1,47 @@
|
||||
package modtweaker2.helpers;
|
||||
|
||||
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;
|
||||
import net.minecraftforge.common.ChestGenHooks;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
public class ForgeHelper {
|
||||
public static Map translate = null;
|
||||
public static List seeds = null;
|
||||
public static HashMap<String, ChestGenHooks> loot = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
seeds = getStaticObject(ForgeHooks.class, "seedList");
|
||||
loot = getStaticObject(ChestGenHooks.class, "chestInfo");
|
||||
translate = getFinalObject(getStaticObject(StatCollector.class, "localizedName", "field_74839_a"), "languageList", "field_74816_c");
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
private ForgeHelper() {}
|
||||
|
||||
public static Object getSeedEntry(ItemStack stack, int weight) {
|
||||
try {
|
||||
Class clazz = Class.forName("net.minecraftforge.common.ForgeHooks$SeedEntry");
|
||||
Constructor constructor = clazz.getDeclaredConstructor(ItemStack.class, int.class);
|
||||
constructor.setAccessible(true);
|
||||
return constructor.newInstance(stack, weight);
|
||||
} catch (Exception e) {
|
||||
throw new NullPointerException("Failed to instantiate SeedEntry");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isLangActive(String lang) {
|
||||
return FMLCommonHandler.instance().getSide() == Side.SERVER ? null : FMLClientHandler.instance().getCurrentLanguage().equals(lang);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
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 net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.IEntityLivingData;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
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");
|
||||
return false;
|
||||
} else
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isABlock(ItemStack block) {
|
||||
return block.getItem() instanceof ItemBlock;
|
||||
}
|
||||
|
||||
public static Entity toEntity(){
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack toStack(IItemStack iStack) {
|
||||
if (iStack == null)
|
||||
return null;
|
||||
else {
|
||||
Object internal = iStack.getInternal();
|
||||
if (internal == null || !(internal instanceof ItemStack)) {
|
||||
MineTweakerAPI.getLogger().logError("Not a valid item stack: " + iStack);
|
||||
}
|
||||
|
||||
return (ItemStack) internal;
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack[] toStacks(IItemStack[] iStack) {
|
||||
if (iStack == null)
|
||||
return null;
|
||||
else {
|
||||
ItemStack[] output = new ItemStack[iStack.length];
|
||||
for (int i = 0; i < iStack.length; i++) {
|
||||
output[i] = toStack(iStack[i]);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object toObject(IIngredient iStack) {
|
||||
if (iStack == null)
|
||||
return null;
|
||||
else {
|
||||
if (iStack instanceof IOreDictEntry) {
|
||||
return toString((IOreDictEntry) iStack);
|
||||
} else if (iStack instanceof IItemStack) {
|
||||
return toStack((IItemStack) iStack);
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object[] toObjects(IIngredient[] ingredient) {
|
||||
if (ingredient == null)
|
||||
return null;
|
||||
else {
|
||||
Object[] output = new Object[ingredient.length];
|
||||
for (int i = 0; i < ingredient.length; i++) {
|
||||
if (ingredient[i] != null) {
|
||||
output[i] = toObject(ingredient[i]);
|
||||
} else
|
||||
output[i] = "";
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object[] toShapedObjects(IIngredient[][] ingredients) {
|
||||
if (ingredients == null)
|
||||
return null;
|
||||
else {
|
||||
ArrayList prep = new ArrayList();
|
||||
prep.add("abc");
|
||||
prep.add("def");
|
||||
prep.add("ghi");
|
||||
char[][] map = new char[][] { { 'a', 'b', 'c' }, { 'd', 'e', 'f' }, { 'g', 'h', 'i' } };
|
||||
for (int x = 0; x < ingredients.length; x++) {
|
||||
if (ingredients[x] != null) {
|
||||
for (int y = 0; y < ingredients[x].length; y++) {
|
||||
if (ingredients[x][y] != null && x < map.length && y < map[x].length) {
|
||||
prep.add(map[x][y]);
|
||||
prep.add(toObject(ingredients[x][y]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return prep.toArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static String toString(IOreDictEntry entry) {
|
||||
return ((IOreDictEntry) entry).getName();
|
||||
}
|
||||
|
||||
public static FluidStack toFluid(ILiquidStack iStack) {
|
||||
if (iStack == null) {
|
||||
return null;
|
||||
} else
|
||||
return FluidRegistry.getFluidStack(iStack.getName(), iStack.getAmount());
|
||||
}
|
||||
|
||||
public static Fluid getFluid(ILiquidStack iStack) {
|
||||
if (iStack == null) {
|
||||
return null;
|
||||
} else
|
||||
return FluidRegistry.getFluid(iStack.getName());
|
||||
|
||||
}
|
||||
|
||||
public static FluidStack[] toFluids(IIngredient[] input) {
|
||||
return toFluids((IItemStack[]) input);
|
||||
}
|
||||
|
||||
public static FluidStack[] toFluids(ILiquidStack[] iStack) {
|
||||
FluidStack[] stack = new FluidStack[iStack.length];
|
||||
for (int i = 0; i < stack.length; i++)
|
||||
stack[i] = toFluid(iStack[i]);
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package modtweaker2.helpers;
|
||||
|
||||
import minetweaker.MineTweakerAPI;
|
||||
import minetweaker.MineTweakerImplementationAPI;
|
||||
import minetweaker.api.player.IPlayer;
|
||||
|
||||
public class LogHelper {
|
||||
public static void logPrinted(IPlayer player) {
|
||||
if (player != null) {
|
||||
player.sendChat(MineTweakerImplementationAPI.platform.getMessage("List generated; see minetweaker.log in your minecraft dir"));
|
||||
}
|
||||
}
|
||||
|
||||
public static void log(IPlayer player, String message) {
|
||||
if (player != null) {
|
||||
player.sendChat(MineTweakerImplementationAPI.platform.getMessage(message));
|
||||
}
|
||||
}
|
||||
|
||||
public static void print(String string) {
|
||||
System.out.println(string);
|
||||
MineTweakerAPI.logCommand(string);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package modtweaker2.helpers;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public class ReflectionHelper {
|
||||
public static Constructor getConstructor(String string, Class... types) {
|
||||
try {
|
||||
Class clazz = Class.forName(string);
|
||||
Constructor constructor = clazz.getDeclaredConstructor(types);
|
||||
constructor.setAccessible(true);
|
||||
return constructor;
|
||||
} catch (Exception ex) {}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T> T getObject(Object o, String... fieldName) {
|
||||
Class cls = o.getClass();
|
||||
for (String field : fieldName) {
|
||||
try {
|
||||
Field result = cls.getDeclaredField(field);
|
||||
result.setAccessible(true);
|
||||
return (T) result.get(o);
|
||||
} catch (Exception ex) {}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T> T getFinalObject(Object o, String... fieldName) {
|
||||
Class cls = o.getClass();
|
||||
for (String field : fieldName) {
|
||||
try {
|
||||
Field result = cls.getDeclaredField(field);
|
||||
result.setAccessible(true);
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
modifiersField.setInt(result, result.getModifiers() & ~Modifier.FINAL);
|
||||
return (T) result.get(o);
|
||||
} catch (Exception ex) {}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T> T getStaticObject(Class cls, String... fieldName) {
|
||||
for (String field : fieldName) {
|
||||
try {
|
||||
Field result = cls.getDeclaredField(field);
|
||||
result.setAccessible(true);
|
||||
return (T) result.get(null);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setPrivateValue(Class cls, String field, int var) {
|
||||
try {
|
||||
Field f = cls.getDeclaredField(field);
|
||||
f.setAccessible(true);
|
||||
f.setInt(null, var);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
public static void setPrivateValue(Class cls, Object o, String field, Object var) {
|
||||
cpw.mods.fml.relauncher.ReflectionHelper.setPrivateValue(cls, o, var, field);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package modtweaker2.helpers;
|
||||
|
||||
import modtweaker2.mods.botania.Botania;
|
||||
import modtweaker2.util.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) return false;
|
||||
else if (TweakerPlugin.isLoaded("Botania") && Botania.isSubtile(stack) && Botania.isSubtile(stack2)) {
|
||||
return Botania.subtileMatches(stack, stack2);
|
||||
} else return stack.isItemEqual(stack2);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user