From 4109c9575dd6d8a89f03e1242493dca228255570 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 29 Apr 2019 12:55:19 +1000 Subject: + Added Framework for Thermal power based upon the code used for RF. > This is more effective than trying to use the GT EU code for the exact same thing. --- .../api/thermal/energy/IThermalConnection.java | 7 ++ .../api/thermal/energy/IThermalContainerItem.java | 15 +++ .../api/thermal/energy/IThermalHandler.java | 15 +++ .../api/thermal/energy/IThermalProvider.java | 13 +++ .../api/thermal/energy/IThermalReceiver.java | 13 +++ .../api/thermal/energy/IThermalStorage.java | 13 +++ .../api/thermal/energy/ThermalStorage.java | 116 +++++++++++++++++++++ .../api/thermal/energy/ThermalStorageAdv.java | 34 ++++++ 8 files changed, 226 insertions(+) create mode 100644 src/Java/gtPlusPlus/api/thermal/energy/IThermalConnection.java create mode 100644 src/Java/gtPlusPlus/api/thermal/energy/IThermalContainerItem.java create mode 100644 src/Java/gtPlusPlus/api/thermal/energy/IThermalHandler.java create mode 100644 src/Java/gtPlusPlus/api/thermal/energy/IThermalProvider.java create mode 100644 src/Java/gtPlusPlus/api/thermal/energy/IThermalReceiver.java create mode 100644 src/Java/gtPlusPlus/api/thermal/energy/IThermalStorage.java create mode 100644 src/Java/gtPlusPlus/api/thermal/energy/ThermalStorage.java create mode 100644 src/Java/gtPlusPlus/api/thermal/energy/ThermalStorageAdv.java (limited to 'src/Java/gtPlusPlus/api/thermal/energy') diff --git a/src/Java/gtPlusPlus/api/thermal/energy/IThermalConnection.java b/src/Java/gtPlusPlus/api/thermal/energy/IThermalConnection.java new file mode 100644 index 0000000000..d8573000fc --- /dev/null +++ b/src/Java/gtPlusPlus/api/thermal/energy/IThermalConnection.java @@ -0,0 +1,7 @@ +package gtPlusPlus.api.thermal.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IThermalConnection { + boolean canConnectThermalEnergy(ForgeDirection arg0); +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/thermal/energy/IThermalContainerItem.java b/src/Java/gtPlusPlus/api/thermal/energy/IThermalContainerItem.java new file mode 100644 index 0000000000..072695bd76 --- /dev/null +++ b/src/Java/gtPlusPlus/api/thermal/energy/IThermalContainerItem.java @@ -0,0 +1,15 @@ +package gtPlusPlus.api.thermal.energy; + +import net.minecraft.item.ItemStack; + +public interface IThermalContainerItem { + + int receiveThermalEnergy(ItemStack arg0, int arg1, boolean arg2); + + int extractThermalEnergy(ItemStack arg0, int arg1, boolean arg2); + + int getThermalEnergyStored(ItemStack arg0); + + int getMaxThermalEnergyStored(ItemStack arg0); + +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/thermal/energy/IThermalHandler.java b/src/Java/gtPlusPlus/api/thermal/energy/IThermalHandler.java new file mode 100644 index 0000000000..3ab7127757 --- /dev/null +++ b/src/Java/gtPlusPlus/api/thermal/energy/IThermalHandler.java @@ -0,0 +1,15 @@ +package gtPlusPlus.api.thermal.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IThermalHandler extends IThermalProvider, IThermalReceiver { + + int receiveThermalEnergy(ForgeDirection arg0, int arg1, boolean arg2); + + int extractThermalEnergy(ForgeDirection arg0, int arg1, boolean arg2); + + int getThermalEnergyStored(ForgeDirection arg0); + + int getMaxThermalEnergyStored(ForgeDirection arg0); + +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/thermal/energy/IThermalProvider.java b/src/Java/gtPlusPlus/api/thermal/energy/IThermalProvider.java new file mode 100644 index 0000000000..0e4a060b23 --- /dev/null +++ b/src/Java/gtPlusPlus/api/thermal/energy/IThermalProvider.java @@ -0,0 +1,13 @@ +package gtPlusPlus.api.thermal.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IThermalProvider extends IThermalConnection { + + int extractThermalEnergy(ForgeDirection arg0, int arg1, boolean arg2); + + int getThermalEnergyStored(ForgeDirection arg0); + + int getMaxThermalEnergyStored(ForgeDirection arg0); + +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/thermal/energy/IThermalReceiver.java b/src/Java/gtPlusPlus/api/thermal/energy/IThermalReceiver.java new file mode 100644 index 0000000000..e08ce48a06 --- /dev/null +++ b/src/Java/gtPlusPlus/api/thermal/energy/IThermalReceiver.java @@ -0,0 +1,13 @@ +package gtPlusPlus.api.thermal.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IThermalReceiver extends IThermalConnection { + + int receiveThermalEnergy(ForgeDirection arg0, int arg1, boolean arg2); + + int getThermalEnergyStored(ForgeDirection arg0); + + int getMaxThermalEnergyStored(ForgeDirection arg0); + +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/thermal/energy/IThermalStorage.java b/src/Java/gtPlusPlus/api/thermal/energy/IThermalStorage.java new file mode 100644 index 0000000000..db3e6c8966 --- /dev/null +++ b/src/Java/gtPlusPlus/api/thermal/energy/IThermalStorage.java @@ -0,0 +1,13 @@ +package gtPlusPlus.api.thermal.energy; + +public interface IThermalStorage { + + int receiveThermalEnergy(int arg0, boolean arg1); + + int extractThermalEnergy(int arg0, boolean arg1); + + int getThermalEnergyStored(); + + int getMaxThermalEnergyStored(); + +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/thermal/energy/ThermalStorage.java b/src/Java/gtPlusPlus/api/thermal/energy/ThermalStorage.java new file mode 100644 index 0000000000..22a47b2807 --- /dev/null +++ b/src/Java/gtPlusPlus/api/thermal/energy/ThermalStorage.java @@ -0,0 +1,116 @@ +package gtPlusPlus.api.thermal.energy; + +import net.minecraft.nbt.NBTTagCompound; + +public class ThermalStorage implements IThermalStorage { + + protected int thermal_energy; + protected int capacity; + protected int maxReceive; + protected int maxExtract; + + public ThermalStorage(int arg0) { + this(arg0, arg0, arg0); + } + + public ThermalStorage(int arg0, int arg1) { + this(arg0, arg1, arg1); + } + + public ThermalStorage(int arg0, int arg1, int arg2) { + this.capacity = arg0; + this.maxReceive = arg1; + this.maxExtract = arg2; + } + + public ThermalStorage readFromNBT(NBTTagCompound arg0) { + this.thermal_energy = arg0.getInteger("Energy"); + if (this.thermal_energy > this.capacity) { + this.thermal_energy = this.capacity; + } + return this; + } + + public NBTTagCompound writeToNBT(NBTTagCompound arg0) { + if (this.thermal_energy < 0) { + this.thermal_energy = 0; + } + arg0.setInteger("Energy", this.thermal_energy); + return arg0; + } + + public void setCapacity(int arg0) { + this.capacity = arg0; + if (this.thermal_energy > arg0) { + this.thermal_energy = arg0; + } + + } + + public void setMaxTransfer(int arg0) { + this.setMaxReceive(arg0); + this.setMaxExtract(arg0); + } + + public void setMaxReceive(int arg0) { + this.maxReceive = arg0; + } + + public void setMaxExtract(int arg0) { + this.maxExtract = arg0; + } + + public int getMaxReceive() { + return this.maxReceive; + } + + public int getMaxExtract() { + return this.maxExtract; + } + + public void setEnergyStored(int arg0) { + this.thermal_energy = arg0; + if (this.thermal_energy > this.capacity) { + this.thermal_energy = this.capacity; + } else if (this.thermal_energy < 0) { + this.thermal_energy = 0; + } + + } + + public void modifyEnergyStored(int arg0) { + this.thermal_energy += arg0; + if (this.thermal_energy > this.capacity) { + this.thermal_energy = this.capacity; + } else if (this.thermal_energy < 0) { + this.thermal_energy = 0; + } + + } + + public int receiveThermalEnergy(int arg0, boolean arg1) { + int arg2 = Math.min(this.capacity - this.thermal_energy, Math.min(this.maxReceive, arg0)); + if (!arg1) { + this.thermal_energy += arg2; + } + + return arg2; + } + + public int extractThermalEnergy(int arg0, boolean arg1) { + int arg2 = Math.min(this.thermal_energy, Math.min(this.maxExtract, arg0)); + if (!arg1) { + this.thermal_energy -= arg2; + } + + return arg2; + } + + public int getThermalEnergyStored() { + return this.thermal_energy; + } + + public int getMaxThermalEnergyStored() { + return this.capacity; + } +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/thermal/energy/ThermalStorageAdv.java b/src/Java/gtPlusPlus/api/thermal/energy/ThermalStorageAdv.java new file mode 100644 index 0000000000..47af7e79a6 --- /dev/null +++ b/src/Java/gtPlusPlus/api/thermal/energy/ThermalStorageAdv.java @@ -0,0 +1,34 @@ +package gtPlusPlus.api.thermal.energy; + +public class ThermalStorageAdv extends ThermalStorage { + + public ThermalStorageAdv(int arg0) { + this(arg0, arg0, arg0); + } + + public ThermalStorageAdv(int arg0, int arg1) { + this(arg0, arg1, arg1); + } + + public ThermalStorageAdv(int arg0, int arg1, int arg2) { + super(arg0, arg1, arg2); + } + + public int receiveEnergyNoLimit(int arg0, boolean arg1) { + int arg2 = Math.min(super.capacity - super.thermal_energy, arg0); + if (!arg1) { + super.thermal_energy += arg2; + } + + return arg2; + } + + public int extractEnergyNoLimit(int arg0, boolean arg1) { + int arg2 = Math.min(super.thermal_energy, arg0); + if (!arg1) { + super.thermal_energy -= arg2; + } + + return arg2; + } +} \ No newline at end of file -- cgit From e5193543b16561e0f6b13ba0a347d94092d8a9b4 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Sun, 12 May 2019 11:09:03 +1000 Subject: + Thermal Boiler now pulls lava filters from an input bus. + Added some minor GUI functions to GregtechMeta_MultiBlockBase. + Added some new Reflection functions. --- .../api/thermal/energy/ThermalStorage.java | 4 +- .../api/thermal/sample/ItemThermalContainer.java | 16 +- .../core/util/reflect/ReflectionUtils.java | 202 ++++++++++++++++++--- .../base/GregtechMeta_MultiBlockBase.java | 52 +++++- .../multi/production/GT4Entity_ThermalBoiler.java | 29 ++- 5 files changed, 261 insertions(+), 42 deletions(-) (limited to 'src/Java/gtPlusPlus/api/thermal/energy') 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 + * + */ + + + //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 typeMap = new HashMap(); + 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 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> nestedOuterTypes = new LinkedList>(); + 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 outerTypeMap = new HashMap(); + extractTypeArguments(outerTypeMap, outerClass); + for (Map.Entry 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; -- cgit