aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2019-05-12 11:09:03 +1000
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2019-05-12 11:09:03 +1000
commite5193543b16561e0f6b13ba0a347d94092d8a9b4 (patch)
tree3eb027829664acf287f4338e0023d416606296b4
parent4109c9575dd6d8a89f03e1242493dca228255570 (diff)
downloadGT5-Unofficial-e5193543b16561e0f6b13ba0a347d94092d8a9b4.tar.gz
GT5-Unofficial-e5193543b16561e0f6b13ba0a347d94092d8a9b4.tar.bz2
GT5-Unofficial-e5193543b16561e0f6b13ba0a347d94092d8a9b4.zip
+ Thermal Boiler now pulls lava filters from an input bus.
+ Added some minor GUI functions to GregtechMeta_MultiBlockBase. + Added some new Reflection functions.
-rw-r--r--src/Java/gtPlusPlus/api/thermal/energy/ThermalStorage.java4
-rw-r--r--src/Java/gtPlusPlus/api/thermal/sample/ItemThermalContainer.java16
-rw-r--r--src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java202
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java52
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_ThermalBoiler.java29
5 files changed, 261 insertions, 42 deletions
diff --git a/src/Java/gtPlusPlus/api/thermal/energy/ThermalStorage.java b/src/Java/gtPlusPlus/api/thermal/energy/ThermalStorage.java
index 22a47b2807..9c7bb0066c 100644
--- a/src/Java/gtPlusPlus/api/thermal/energy/ThermalStorage.java
+++ b/src/Java/gtPlusPlus/api/thermal/energy/ThermalStorage.java
@@ -24,7 +24,7 @@ public class ThermalStorage implements IThermalStorage {
}
public ThermalStorage readFromNBT(NBTTagCompound arg0) {
- this.thermal_energy = arg0.getInteger("Energy");
+ this.thermal_energy = arg0.getInteger("ThermalEnergy");
if (this.thermal_energy > this.capacity) {
this.thermal_energy = this.capacity;
}
@@ -35,7 +35,7 @@ public class ThermalStorage implements IThermalStorage {
if (this.thermal_energy < 0) {
this.thermal_energy = 0;
}
- arg0.setInteger("Energy", this.thermal_energy);
+ arg0.setInteger("ThermalEnergy", this.thermal_energy);
return arg0;
}
diff --git a/src/Java/gtPlusPlus/api/thermal/sample/ItemThermalContainer.java b/src/Java/gtPlusPlus/api/thermal/sample/ItemThermalContainer.java
index e33a47d220..015e5fd5f3 100644
--- a/src/Java/gtPlusPlus/api/thermal/sample/ItemThermalContainer.java
+++ b/src/Java/gtPlusPlus/api/thermal/sample/ItemThermalContainer.java
@@ -49,22 +49,22 @@ public class ItemThermalContainer extends Item implements IThermalContainerItem
if (arg0.getTagCompound() == null) {
arg0.stackTagCompound = new NBTTagCompound();
}
- int arg3 = arg0.stackTagCompound.getInteger("Energy");
+ int arg3 = arg0.stackTagCompound.getInteger("ThermalEnergy");
int arg4 = Math.min(this.capacity - arg3, Math.min(this.maxReceive, arg1));
if (!arg2) {
arg3 += arg4;
- arg0.stackTagCompound.setInteger("Energy", arg3);
+ arg0.stackTagCompound.setInteger("ThermalEnergy", arg3);
}
return arg4;
}
public int extractThermalEnergy(ItemStack arg0, int arg1, boolean arg2) {
- if (arg0.stackTagCompound != null && arg0.stackTagCompound.hasKey("Energy")) {
- int arg3 = arg0.stackTagCompound.getInteger("Energy");
+ if (arg0.stackTagCompound != null && arg0.stackTagCompound.hasKey("ThermalEnergy")) {
+ int arg3 = arg0.stackTagCompound.getInteger("ThermalEnergy");
int arg4 = Math.min(arg3, Math.min(this.maxExtract, arg1));
if (!arg2) {
arg3 -= arg4;
- arg0.stackTagCompound.setInteger("Energy", arg3);
+ arg0.stackTagCompound.setInteger("ThermalEnergy", arg3);
}
return arg4;
} else {
@@ -72,9 +72,9 @@ public class ItemThermalContainer extends Item implements IThermalContainerItem
}
}
- public int getEnergyStored(ItemStack arg0) {
- return arg0.stackTagCompound != null && arg0.stackTagCompound.hasKey("Energy")
- ? arg0.stackTagCompound.getInteger("Energy")
+ public int getThermalEnergyStored(ItemStack arg0) {
+ return arg0.stackTagCompound != null && arg0.stackTagCompound.hasKey("ThermalEnergy")
+ ? arg0.stackTagCompound.getInteger("ThermalEnergy")
: 0;
}
diff --git a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
index 722a4f3ff7..c86d6ccb83 100644
--- a/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
+++ b/src/Java/gtPlusPlus/core/util/reflect/ReflectionUtils.java
@@ -3,10 +3,17 @@ package gtPlusPlus.core.util.reflect;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
+import java.lang.reflect.GenericDeclaration;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.util.HashMap;
import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.ArrayUtils;
@@ -133,8 +140,8 @@ public class ReflectionUtils {
public static Method getMethod(Object aObject, String aMethodName, Class[] aTypes) {
return getMethod(aObject.getClass(), aMethodName, aTypes);
}
-
-
+
+
/**
* Returns a cached {@link Method} object.
* @param aClass - Class containing the Method.
@@ -193,7 +200,7 @@ public class ReflectionUtils {
return y.get();
}
}
-
+
/**
* Returns a cached {@link Field} object.
* @param aInstance - {@link Object} to get the field instance from.
@@ -219,6 +226,20 @@ public class ReflectionUtils {
return isClassPresent(classname);
}
+
+ /**
+ * Returns the class of the objects type parameter
+ * @param o - Object to examine paramters on
+ * @return - a Class<?> or null
+ */
+ public static Class<?> getTypeOfGenericObject(Object o) {
+ Class<?> aTypeParam = findSuperClassParameterType(o, o.getClass(), 0);
+ if (aTypeParam == null) {
+ aTypeParam = findSubClassParameterType(o, o.getClass(), 0);
+ }
+ return aTypeParam;
+ }
+
public static void makeFieldAccessible(final Field field) {
if (!Modifier.isPublic(field.getModifiers()) ||
!Modifier.isPublic(field.getDeclaringClass().getModifiers()))
@@ -271,7 +292,7 @@ public class ReflectionUtils {
return loaded > 0;
}
-
+
public static boolean setField(final Object object, final String fieldName, final Object fieldValue) {
Class<?> clazz = object.getClass();
@@ -414,13 +435,27 @@ public class ReflectionUtils {
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /*
+ * Internal Magic that probably should not get exposed.
+ */
+
@@ -429,11 +464,126 @@ public class ReflectionUtils {
+ /*
+ *
+ * Below Code block is used for determining generic types associated with type<E>
+ *
+ */
+
+
+ //https://xebia.com/blog/acessing-generic-types-at-runtime-in-java/
+ //https://www.javacodegeeks.com/2013/12/advanced-java-generics-retreiving-generic-type-arguments.html
+ public static Class<?> findSuperClassParameterType(Object instance, Class<?> classOfInterest, int parameterIndex) {
+ Class<?> subClass = instance.getClass();
+ while (classOfInterest != subClass.getSuperclass()) {
+ // instance.getClass() is no subclass of classOfInterest or instance is a direct instance of classOfInterest
+ subClass = subClass.getSuperclass();
+ if (subClass == null) {
+ return null;
+ }
+ }
+ ParameterizedType parameterizedType = (ParameterizedType) subClass.getGenericSuperclass();
+ Class<?> aReturn;
+ aReturn = (Class<?>) parameterizedType.getActualTypeArguments()[parameterIndex];
+ return aReturn;
+ }
+
+ public static Class<?> findSubClassParameterType(Object instance, Class<?> classOfInterest, int parameterIndex) {
+ Map<Type, Type> typeMap = new HashMap<Type, Type>();
+ Class<?> instanceClass = instance.getClass();
+ while (classOfInterest != instanceClass.getSuperclass()) {
+ extractTypeArguments(typeMap, instanceClass);
+ instanceClass = instanceClass.getSuperclass();
+ if (instanceClass == null) {
+ return null;
+ }
+ }
+
+ ParameterizedType parameterizedType = (ParameterizedType) instanceClass.getGenericSuperclass();
+ Type actualType = parameterizedType.getActualTypeArguments()[parameterIndex];
+ if (typeMap.containsKey(actualType)) {
+ actualType = typeMap.get(actualType);
+ }
+ if (actualType instanceof Class) {
+ return (Class<?>) actualType;
+ } else if (actualType instanceof TypeVariable) {
+ return browseNestedTypes(instance, (TypeVariable<?>) actualType);
+ } else {
+ return null;
+ }
+ }
+
+ private static void extractTypeArguments(Map<Type, Type> typeMap, Class<?> clazz) {
+ Type genericSuperclass = clazz.getGenericSuperclass();
+ if (!(genericSuperclass instanceof ParameterizedType)) {
+ return;
+ }
+
+ ParameterizedType parameterizedType = (ParameterizedType) genericSuperclass;
+ Type[] typeParameter = ((Class<?>) parameterizedType.getRawType()).getTypeParameters();
+ Type[] actualTypeArgument = parameterizedType.getActualTypeArguments();
+ for (int i = 0; i < typeParameter.length; i++) {
+ if(typeMap.containsKey(actualTypeArgument[i])) {
+ actualTypeArgument[i] = typeMap.get(actualTypeArgument[i]);
+ }
+ typeMap.put(typeParameter[i], actualTypeArgument[i]);
+ }
+ }
+
+ private static Class<?> browseNestedTypes(Object instance, TypeVariable<?> actualType) {
+ Class<?> instanceClass = instance.getClass();
+ List<Class<?>> nestedOuterTypes = new LinkedList<Class<?>>();
+ for (Class<?> enclosingClass = instanceClass
+ .getEnclosingClass(); enclosingClass != null; enclosingClass = enclosingClass.getEnclosingClass()) {
+ try {
+ Field this$0 = instanceClass.getDeclaredField("this$0");
+ Object outerInstance = this$0.get(instance);
+ Class<?> outerClass = outerInstance.getClass();
+ nestedOuterTypes.add(outerClass);
+ Map<Type, Type> outerTypeMap = new HashMap<Type, Type>();
+ extractTypeArguments(outerTypeMap, outerClass);
+ for (Map.Entry<Type, Type> entry : outerTypeMap.entrySet()) {
+ if (!(entry.getKey() instanceof TypeVariable)) {
+ continue;
+ }
+ TypeVariable<?> foundType = (TypeVariable<?>) entry.getKey();
+ if (foundType.getName().equals(actualType.getName())
+ && isInnerClass(foundType.getGenericDeclaration(), actualType.getGenericDeclaration())) {
+ if (entry.getValue() instanceof Class) {
+ return (Class<?>) entry.getValue();
+ }
+ actualType = (TypeVariable<?>) entry.getValue();
+ }
+ }
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+
+ }
+
+ }
+ return null;
+ }
+
+ private static boolean isInnerClass(GenericDeclaration outerDeclaration, GenericDeclaration innerDeclaration) {
+ if (!(outerDeclaration instanceof Class) || !(innerDeclaration instanceof Class)) {
+ return false;
+ }
+ Class<?> outerClass = (Class<?>) outerDeclaration;
+ Class<?> innerClass = (Class<?>) innerDeclaration;
+ while ((innerClass = innerClass.getEnclosingClass()) != null) {
+ if (innerClass == outerClass) {
+ return true;
+ }
+ }
+ return false;
+ }
/*
- * Internal Magic that probably should not get exposed.
- */
+ *
+ * End of Generics Block
+ *
+ */
+
private static Field getField_Internal(final Class<?> clazz, final String fieldName) throws NoSuchFieldException {
@@ -525,26 +675,26 @@ public class ReflectionUtils {
return getMethod_Internal(superClass, aMethodName);
}
}
-
+
private static void dumpClassInfo(Class aClass) {
Logger.INFO("We ran into an error processing reflection in "+aClass.getName()+", dumping all data for debugging.");
// Get the methods
- Method[] methods = aClass.getDeclaredMethods();
- Field[] fields = aClass.getDeclaredFields();
- Constructor[] consts = aClass.getDeclaredConstructors();
+ Method[] methods = aClass.getDeclaredMethods();
+ Field[] fields = aClass.getDeclaredFields();
+ Constructor[] consts = aClass.getDeclaredConstructors();
Logger.INFO("Dumping all Methods.");
- for (Method method : methods) {
- System.out.println(method.getName()+" | "+StringUtils.getDataStringFromArray(method.getParameterTypes()));
- }
+ for (Method method : methods) {
+ System.out.println(method.getName()+" | "+StringUtils.getDataStringFromArray(method.getParameterTypes()));
+ }
Logger.INFO("Dumping all Fields.");
- for (Field f : fields) {
- System.out.println(f.getName());
- }
+ for (Field f : fields) {
+ System.out.println(f.getName());
+ }
Logger.INFO("Dumping all Constructors.");
- for (Constructor c : consts) {
- System.out.println(c.getName()+" | "+c.getParameterCount()+" | "+StringUtils.getDataStringFromArray(c.getParameterTypes()));
- }
+ for (Constructor c : consts) {
+ System.out.println(c.getName()+" | "+c.getParameterCount()+" | "+StringUtils.getDataStringFromArray(c.getParameterTypes()));
+ }
}
private static Class<?> getNonPublicClass(final String className) {
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java
index e352712138..e0f768830d 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java
@@ -1,10 +1,10 @@
package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base;
-import static gtPlusPlus.core.lib.CORE.ConfigSwitches.requireControlCores;
import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -48,6 +48,7 @@ import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.lib.LoadedMods;
import gtPlusPlus.core.recipe.common.CI;
import gtPlusPlus.core.util.math.MathUtils;
+import gtPlusPlus.core.util.minecraft.ItemUtils;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_MultiMachine;
import gtPlusPlus.xmod.gregtech.api.gui.GUI_MultiMachine;
@@ -1136,6 +1137,47 @@ GT_MetaTileEntity_MultiBlockBase {
ItemStack guiSlot = this.mInventory[1];
return guiSlot;
}
+
+ protected boolean setGUIItemStack(ItemStack aNewGuiSlotContents) {
+ boolean result = false;
+ if (this.mInventory[1] == null) {
+ this.mInventory[1] = aNewGuiSlotContents != null ? aNewGuiSlotContents.copy() : null;
+ aNewGuiSlotContents = null;
+ this.updateSlots();
+ result = true;
+ }
+ return result;
+ }
+
+ protected boolean clearGUIItemSlot() {
+ return setGUIItemStack(null);
+ }
+
+
+ public ItemStack findItemInInventory(Item aSearchStack) {
+ return findItemInInventory(aSearchStack, 0);
+ }
+
+ public ItemStack findItemInInventory(Item aSearchStack, int aMeta) {
+ return findItemInInventory(ItemUtils.simpleMetaStack(aSearchStack, aMeta, 1));
+ }
+
+ public ItemStack findItemInInventory(ItemStack aSearchStack) {
+ if (aSearchStack != null && this.mInputBusses.size() > 0) {
+ for (GT_MetaTileEntity_Hatch_InputBus bus : this.mInputBusses) {
+ if (bus != null) {
+ for (ItemStack uStack : bus.mInventory) {
+ if (uStack != null) {
+ if (aSearchStack.getClass().isInstance(uStack.getItem())) {
+ return uStack;
+ }
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
@Override
public void updateSlots() {
@@ -1208,6 +1250,14 @@ GT_MetaTileEntity_MultiBlockBase {
if (aTileEntity == null) {
return false;
}
+
+ //Check type
+ Class <?> aHatchType = ReflectionUtils.getTypeOfGenericObject(aList);
+ if (!aHatchType.isInstance(aTileEntity)) {
+ return false;
+ }
+
+
if (aList.isEmpty()) {
if (aTileEntity instanceof GT_MetaTileEntity_Hatch) {
if (GTplusplus.CURRENT_LOAD_PHASE == INIT_PHASE.STARTED) {
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_ThermalBoiler.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_ThermalBoiler.java
index 5ab9cd9795..c55fe10829 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_ThermalBoiler.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_ThermalBoiler.java
@@ -7,6 +7,7 @@ import gregtech.api.enums.Textures;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
+import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus;
import gregtech.api.objects.GT_RenderedTexture;
import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_Recipe;
@@ -19,6 +20,7 @@ import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.Gregtech
import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
@@ -68,13 +70,29 @@ extends GregtechMeta_MultiBlockBase
@Override
public int getDamageToComponent(ItemStack aStack){
- Logger.INFO("Trying to damage component.");
+ //log("Trying to damage component.");
return ItemList.Component_LavaFilter.get(1L).getClass().isInstance(aStack) ? 1 : 0;
}
+
+ private static Item mLavaFilter;
@Override
- public boolean checkRecipe(final ItemStack aStack) {
+ public boolean checkRecipe(ItemStack aStack) {
this.mSuperEfficencyIncrease=0;
+
+ if (mLavaFilter == null) {
+ mLavaFilter = ItemList.Component_LavaFilter.getItem();
+ }
+
+ //Try reload new Lava Filter
+ if (aStack == null) {
+ ItemStack uStack = this.findItemInInventory(mLavaFilter);
+ if (uStack != null) {
+ this.setGUIItemStack(uStack);
+ aStack = this.getGUIItemStack();
+ }
+ }
+
for (GT_Recipe tRecipe : Recipe_GT.Gregtech_Recipe_Map.sThermalFuels.mRecipeList) {
FluidStack tFluid = tRecipe.mFluidInputs[0];
@@ -85,7 +103,7 @@ extends GregtechMeta_MultiBlockBase
this.mEfficiencyIncrease = (this.mMaxProgresstime * getEfficiencyIncrease());
int loot_MAXCHANCE = 100000;
- if (ItemList.Component_LavaFilter.get(1L).getClass().isInstance(aStack)) {
+ if (mLavaFilter.getClass().isInstance(aStack.getItem())) {
if ((tRecipe.getOutput(0) != null) && (getBaseMetaTileEntity().getRandomNumber(loot_MAXCHANCE) < tRecipe.getOutputChance(0))) {
this.mOutputItems = new ItemStack[] { GT_Utility.copy(new Object[] { tRecipe.getOutput(0) }) };
@@ -199,8 +217,9 @@ extends GregtechMeta_MultiBlockBase
"Size: 3x3x3 (Hollow)",
"Thermal Containment Casings (10 at least!)",
"Controller (front middle)",
- "2x Input Hatch",
+ "2x Input Hatch (Water/Thermal Fluid)",
"1x Output Hatch (Steam)",
+ "1x Input Bus (Supplies controller with Lava Filters, optional)",
"1x Output Bus (Filter results, optional)",
};
}
@@ -234,7 +253,7 @@ extends GregtechMeta_MultiBlockBase
if (!isValidBlockForStructure(tTileEntity, 1, true, aBlock, aMeta,
ModBlocks.blockCasings2Misc, 11)) {
- Logger.INFO("Bad Thermal Boiler casing");
+ log("Bad Thermal Boiler casing");
return false;
}
++tAmount;