aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2019-12-30 01:48:09 +0000
committerGitHub <noreply@github.com>2019-12-30 01:48:09 +0000
commit5af823e80a611090216375fecd3794d345446830 (patch)
treec54a19977b4a25cb86f54394eb9711aaf268efe3 /src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base
parenta731e939c6b9a70ac9fd444dbf06243f63f29c06 (diff)
parentcc825179dce70a5f2c4a13730639e3300243e21a (diff)
downloadGT5-Unofficial-5af823e80a611090216375fecd3794d345446830.tar.gz
GT5-Unofficial-5af823e80a611090216375fecd3794d345446830.tar.bz2
GT5-Unofficial-5af823e80a611090216375fecd3794d345446830.zip
Merge pull request #525 from alkcorp/DevTop
+ 6 Months of work, let's get the ball rolling.
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base')
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GT_MetaTileEntity_Hatch_CustomFluidBase.java2
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaPipeEntityBase_Cable.java13
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java786
3 files changed, 632 insertions, 169 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GT_MetaTileEntity_Hatch_CustomFluidBase.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GT_MetaTileEntity_Hatch_CustomFluidBase.java
index 839fb3a14a..c9b98a6a64 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GT_MetaTileEntity_Hatch_CustomFluidBase.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GT_MetaTileEntity_Hatch_CustomFluidBase.java
@@ -102,7 +102,7 @@ public class GT_MetaTileEntity_Hatch_CustomFluidBase extends GT_MetaTileEntity_H
String[] s2 = new String[]{
"Fluid Input for Multiblocks",
"Capacity: " + getCapacity()+"L",
- "Accepted Fluid: " + mTempMod + mLockedStack.getLocalizedName()
+ "Accepted Fluid: " + mTempMod + mLockedStack != null ? mLockedStack.getLocalizedName() : "Empty"
};
return s2;
}
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaPipeEntityBase_Cable.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaPipeEntityBase_Cable.java
index d17c820699..4dd5bf25d6 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaPipeEntityBase_Cable.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaPipeEntityBase_Cable.java
@@ -5,6 +5,7 @@ import static gregtech.api.enums.GT_Values.VN;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashSet;
import cofh.api.energy.IEnergyReceiver;
import net.minecraft.entity.Entity;
@@ -219,6 +220,18 @@ public class GregtechMetaPipeEntityBase_Cable extends MetaPipeEntity implements
return this.transferElectricity(aSide, aVoltage, aAmperage,
new ArrayList<>(Arrays.asList((TileEntity) this.getBaseMetaTileEntity())));
}
+
+
+ /**
+ * Adds support for the newer function added by https://github.com/Blood-Asp/GT5-Unofficial/commit/73ee102b63efd92c0f164a7ed7a79ebcd2619617#diff-3051838621d8ae87aa5ccd1345e1f07d
+ */
+ public long transferElectricity(byte arg0, long arg1, long arg2, HashSet<TileEntity> arg3) {
+ ArrayList<TileEntity> aTiles = new ArrayList<TileEntity>();
+ for (TileEntity y : arg3) {
+ aTiles.add(y);
+ }
+ return transferElectricity(arg0, arg1, arg2, aTiles);
+ }
@Override
public long transferElectricity(final byte aSide, long aVoltage, final long aAmperage,
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 0e1ef0e47e..3869adb7ab 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
@@ -4,9 +4,9 @@ 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.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -41,18 +41,28 @@ import gregtech.api.util.GT_Recipe.GT_Recipe_Map;
import gregtech.api.util.GT_Utility;
import gtPlusPlus.GTplusplus;
import gtPlusPlus.GTplusplus.INIT_PHASE;
+import gtPlusPlus.api.helpers.GregtechPlusPlus_API.Multiblock_API;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.AutoMap;
+import gtPlusPlus.api.objects.data.ConcurrentHashSet;
+import gtPlusPlus.api.objects.data.ConcurrentSet;
+import gtPlusPlus.api.objects.data.FlexiblePair;
+import gtPlusPlus.api.objects.data.Triplet;
import gtPlusPlus.api.objects.minecraft.BlockPos;
+import gtPlusPlus.api.objects.minecraft.multi.SpecialMultiBehaviour;
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.preloader.asm.AsmConfig;
import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_MultiMachine;
+import gtPlusPlus.xmod.gregtech.api.gui.CONTAINER_MultiMachine_NoPlayerInventory;
import gtPlusPlus.xmod.gregtech.api.gui.GUI_MultiMachine;
+import gtPlusPlus.xmod.gregtech.api.gui.GUI_MultiMachine_Default;
import gtPlusPlus.xmod.gregtech.api.gui.GUI_Multi_Basic_Slotted;
+import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_AirIntake;
import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_ControlCore;
import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBattery;
import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_OutputBattery;
@@ -66,16 +76,13 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
+import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
-public abstract class GregtechMeta_MultiBlockBase
-extends
-GT_MetaTileEntity_MultiBlockBase {
-
+public abstract class GregtechMeta_MultiBlockBase extends GT_MetaTileEntity_MultiBlockBase {
public static final boolean DEBUG_DISABLE_CORES_TEMPORARILY = true;
-
static {
Method a08 = findRecipe08 = ReflectionUtils.getMethod(GT_Recipe_Map.class, "findRecipe", IHasWorldObjectAndCoords.class, GT_Recipe.class, boolean.class, long.class, FluidStack[].class, ItemStack.class, ItemStack[].class);
@@ -83,8 +90,19 @@ GT_MetaTileEntity_MultiBlockBase {
Logger.MACHINE_INFO("Found .08 findRecipe method? "+(a08 != null));
Logger.MACHINE_INFO("Found .09 findRecipe method? "+(a09 != null));
- //gregtech.api.util.GT_Recipe.GT_Recipe_Map.findRecipe(IHasWorldObjectAndCoords, GT_Recipe, boolean, long, FluidStack[], ItemStack, ItemStack...)
+ if (CORE.DEBUG) {
+ aLogger = ReflectionUtils.getMethod(Logger.class, "INFO", String.class);
+ }
+ else {
+ aLogger = ReflectionUtils.getMethod(Logger.class, "MACHINE_INFO", String.class);
+ }
+ try {
+ calculatePollutionReduction = GT_MetaTileEntity_Hatch_Muffler.class.getDeclaredMethod("calculatePollutionReduction", int.class);
+ } catch (NoSuchMethodException | SecurityException e) {}
+
+ mCustomBehviours = new HashMap<String, SpecialMultiBehaviour>();
+
}
//Find Recipe Methods
@@ -98,9 +116,14 @@ GT_MetaTileEntity_MultiBlockBase {
//Control Core Hatch
public ArrayList<GT_MetaTileEntity_Hatch_ControlCore> mControlCoreBus = new ArrayList<GT_MetaTileEntity_Hatch_ControlCore>();
+ public ArrayList<GT_MetaTileEntity_Hatch_AirIntake> mAirIntakes = new ArrayList<GT_MetaTileEntity_Hatch_AirIntake>();
public ArrayList<GT_MetaTileEntity_Hatch_InputBattery> mChargeHatches = new ArrayList<GT_MetaTileEntity_Hatch_InputBattery>();
public ArrayList<GT_MetaTileEntity_Hatch_OutputBattery> mDischargeHatches = new ArrayList<GT_MetaTileEntity_Hatch_OutputBattery>();
+ // Custom Behaviour Map
+ private static final HashMap<String, SpecialMultiBehaviour> mCustomBehviours;
+
+
public GregtechMeta_MultiBlockBase(final int aID, final String aName,
final String aNameRegional) {
super(aID, aName, aNameRegional);
@@ -120,13 +143,23 @@ GT_MetaTileEntity_MultiBlockBase {
public abstract boolean hasSlotInGUI();
+ public long getTotalRuntimeInTicks() {
+ return this.mTotalRunTime;
+ }
+
@Override
public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) {
if (hasSlotInGUI()) {
return new GT_Container_MultiMachine(aPlayerInventory, aBaseMetaTileEntity);
}
- else {
- return new CONTAINER_MultiMachine(aPlayerInventory, aBaseMetaTileEntity);
+ else {
+ String aCustomGUI = getCustomGUIResourceName();
+ if (aCustomGUI == null) {
+ return new CONTAINER_MultiMachine_NoPlayerInventory(aPlayerInventory, aBaseMetaTileEntity);
+ }
+ else {
+ return new CONTAINER_MultiMachine(aPlayerInventory, aBaseMetaTileEntity);
+ }
}
}
@@ -139,7 +172,7 @@ GT_MetaTileEntity_MultiBlockBase {
@Override
public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, final IGregTechTileEntity aBaseMetaTileEntity) {
String aCustomGUI = getCustomGUIResourceName();
- aCustomGUI = aCustomGUI != null ? aCustomGUI : "MultiblockDisplay";
+ aCustomGUI = aCustomGUI != null ? aCustomGUI : hasSlotInGUI() ? "MultiblockDisplay" : "MultiblockDisplay_Generic";
aCustomGUI = aCustomGUI + ".png";
if (hasSlotInGUI()) {
if (!requiresVanillaGtGUI()) {
@@ -150,7 +183,12 @@ GT_MetaTileEntity_MultiBlockBase {
}
}
else {
- return new GUI_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), aCustomGUI);
+ if (getCustomGUIResourceName() == null && !hasSlotInGUI()) {
+ return new GUI_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), aCustomGUI);
+ }
+ else {
+ return new GUI_MultiMachine_Default(aPlayerInventory, aBaseMetaTileEntity, this.getLocalName(), aCustomGUI);
+ }
}
}
@@ -189,31 +227,17 @@ GT_MetaTileEntity_MultiBlockBase {
long minutes = TimeUnit.SECONDS.toMinutes(seconds) - (TimeUnit.SECONDS.toHours(seconds) * 60);
long second = TimeUnit.SECONDS.toSeconds(seconds) - (TimeUnit.SECONDS.toMinutes(seconds) *60);
- int mPollutionReduction=0;
- for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) {
- if (isValidMetaTileEntity(tHatch)) {
- mPollutionReduction=Math.max(calculatePollutionReductionForHatch(tHatch, 100),mPollutionReduction);
- }
- }
-
- long storedEnergy=0;
- long maxEnergy=0;
- for(GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) {
- if (isValidMetaTileEntity(tHatch)) {
- storedEnergy+=tHatch.getBaseMetaTileEntity().getStoredEU();
- maxEnergy+=tHatch.getBaseMetaTileEntity().getEUCapacity();
- }
- }
-
+ int mPollutionReduction = getPollutionReductionForAllMufflers();
+ long storedEnergy = getStoredEnergyInAllEnergyHatches();
+ long maxEnergy = getMaxEnergyStorageOfAllEnergyHatches();
int tTier = this.getControlCoreTier();
-
mInfo.add(getMachineTooltip());
//Lets borrow the GTNH handling
- mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.Progress")+": "+
+ mInfo.add(StatCollector.translateToLocal("GTPP.multiblock.progress")+": "+
EnumChatFormatting.GREEN + Integer.toString(mProgresstime/20) + EnumChatFormatting.RESET +" s / "+
EnumChatFormatting.YELLOW + Integer.toString(mMaxProgresstime/20) + EnumChatFormatting.RESET +" s");
@@ -260,6 +284,36 @@ GT_MetaTileEntity_MultiBlockBase {
}
+ public int getPollutionReductionForAllMufflers() {
+ int mPollutionReduction=0;
+ for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) {
+ if (isValidMetaTileEntity(tHatch)) {
+ mPollutionReduction=Math.max(calculatePollutionReductionForHatch(tHatch, 100),mPollutionReduction);
+ }
+ }
+ return mPollutionReduction;
+ }
+
+ public long getStoredEnergyInAllEnergyHatches() {
+ long storedEnergy=0;
+ for(GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) {
+ if (isValidMetaTileEntity(tHatch)) {
+ storedEnergy+=tHatch.getBaseMetaTileEntity().getStoredEU();
+ }
+ }
+ return storedEnergy;
+ }
+
+ public long getMaxEnergyStorageOfAllEnergyHatches() {
+ long maxEnergy=0;
+ for(GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) {
+ if (isValidMetaTileEntity(tHatch)) {
+ maxEnergy+=tHatch.getBaseMetaTileEntity().getEUCapacity();
+ }
+ }
+ return maxEnergy;
+ }
+
@Override
public boolean isGivingInformation() {
return true;
@@ -294,7 +348,7 @@ GT_MetaTileEntity_MultiBlockBase {
}*/
String aRequiresMuffler = "1x Muffler Hatch";
- String aRequiresCoreModule = "1x Core Module";
+ //String aRequiresCoreModule = "1x Core Module";
String aRequiresMaint = "1x Maintanence Hatch";
String[] x = getTooltip();
@@ -330,7 +384,7 @@ GT_MetaTileEntity_MultiBlockBase {
AutoMap<String> aOrderedMap = new AutoMap<String>();
if (showHatches) {
aOrderedMap.put(aRequiresMaint);
- aOrderedMap.put(aRequiresCoreModule);
+ //aOrderedMap.put(aRequiresCoreModule);
if (showPollution) {
aOrderedMap.put(aRequiresMuffler);
}
@@ -361,8 +415,11 @@ GT_MetaTileEntity_MultiBlockBase {
String[] aToolTip = new String[(a2 + a3)];
aToolTip = ArrayUtils.addAll(aToolTip, x);
aToolTip = ArrayUtils.addAll(aToolTip, z);
- aCachedToolTip = aToolTip;
- return aToolTip;
+
+ if (aCachedToolTip == null || aCachedToolTip.length <= 0) {
+ aCachedToolTip = aToolTip;
+ }
+ return aCachedToolTip;
}
public abstract String[] getTooltip();
@@ -414,67 +471,316 @@ GT_MetaTileEntity_MultiBlockBase {
public String getSound() { return ""; }
+
public boolean canBufferOutputs(final GT_Recipe aRecipe, int aParallelRecipes) {
- if (aRecipe.mOutputs.length > 16) {
- // Gendustry custom comb with a billion centrifuge outputs? Do it anyway.
- return true;
- }
+ return canBufferOutputs(aRecipe, aParallelRecipes, true);
+ }
+
+ public boolean canBufferOutputs(final GT_Recipe aRecipe, int aParallelRecipes, boolean aAllow16SlotWithoutCheck) {
- // Count slots available in output buses
- ArrayList<ItemStack> tBusStacks = new ArrayList<>();
+ Logger.INFO("Determining if we have space to buffer outputs. Parallel: "+aParallelRecipes);
- int tEmptySlots = 0;
- for (final GT_MetaTileEntity_Hatch_OutputBus tBus : this.mOutputBusses) {
- if (!isValidMetaTileEntity(tBus)) {
- continue;
+ // Null recipe or a recipe with lots of outputs?
+ // E.G. Gendustry custom comb with a billion centrifuge outputs?
+ // Do it anyway, provided the multi allows it. Default behaviour is aAllow16SlotWithoutCheck = true.
+ if (aRecipe == null || aRecipe.mOutputs.length > 16) {
+ if (aRecipe == null) {
+ return false;
}
- final IInventory tBusInv = tBus.getBaseMetaTileEntity();
- for (int i = 0; i < tBusInv.getSizeInventory(); i++) {
- if (tBus.getStackInSlot(i) == null) {
- tEmptySlots++;
+ else if (aRecipe.mOutputs.length > 16) {
+ if (aAllow16SlotWithoutCheck) {
+ return true;
}
else {
- tBusStacks.add(tBus.getStackInSlot(i));
+ // Do nothing, we want to check this recipe properly.
}
- }
- }
+ }
+ }
- int slotsNeeded = aRecipe.mOutputs.length;
- for (final ItemStack tRecipeOutput: aRecipe.mOutputs) {
- if (tRecipeOutput == null) continue;
- int amount = tRecipeOutput.stackSize * aParallelRecipes;
- for (final ItemStack tBusStack : tBusStacks) {
- if (GT_Utility.areStacksEqual(tBusStack, tRecipeOutput)) {
- if (tBusStack.stackSize + amount <= tBusStack.getMaxStackSize()) {
- slotsNeeded--;
- break;
+ // Do we even need to check for item outputs?
+ boolean aDoesOutputItems = aRecipe.mOutputs.length > 0;
+ // Do we even need to check for fluid outputs?
+ boolean aDoesOutputFluids = aRecipe.mFluidOutputs.length > 0;
+
+
+
+ /* ========================================
+ * Item Management
+ * ========================================
+ */
+
+ if (aDoesOutputItems) {
+ Logger.INFO("We have items to output.");
+
+ // How many slots are free across all the output buses?
+ int aInputBusSlotsFree = 0;
+
+ /*
+ * Create Variables for Item Output
+ */
+
+ AutoMap<FlexiblePair<ItemStack, Integer>> aItemMap = new AutoMap<FlexiblePair<ItemStack, Integer>>();
+ AutoMap<ItemStack> aOutputs = new AutoMap<ItemStack>(aRecipe.mOutputs);
+
+ for (final GT_MetaTileEntity_Hatch_OutputBus tBus : this.mOutputBusses) {
+ if (!isValidMetaTileEntity(tBus)) {
+ continue;
+ }
+ final IInventory tBusInv = tBus.getBaseMetaTileEntity();
+ for (int i = 0; i < tBusInv.getSizeInventory(); i++) {
+ if (tBus.getStackInSlot(i) == null) {
+ aInputBusSlotsFree++;
+ }
+ else {
+ ItemStack aT = tBus.getStackInSlot(i);
+ int aSize = aT.stackSize;
+ aT = aT.copy();
+ aT.stackSize = 0;
+ aItemMap.put(new FlexiblePair<ItemStack, Integer>(aT, aSize));
}
+ }
+ }
+
+ // Count the slots we need, later we can check if any are able to merge with existing stacks
+ int aRecipeSlotsRequired = 0;
+
+ // A map to hold the items we will be 'inputting' into the output buses. These itemstacks are actually the recipe outputs.
+ ConcurrentSet<FlexiblePair<ItemStack, Integer>> aInputMap = new ConcurrentHashSet<FlexiblePair<ItemStack, Integer>>();
+
+ // Iterate over the outputs, calculating require stack spacing they will require.
+ for (int i=0;i<aOutputs.size();i++) {
+ ItemStack aY = aOutputs.get(i);
+ if (aY == null) {
+ continue;
}
+ else {
+ int aStackSize = aY.stackSize * aParallelRecipes;
+ if (aStackSize > 64) {
+ int aSlotsNeedsForThisStack = (int) Math.ceil((double) ((float) aStackSize / 64f));
+ // Should round up and add as many stacks as required nicely.
+ aRecipeSlotsRequired += aSlotsNeedsForThisStack;
+ for (int o=0;o<aRecipeSlotsRequired;o++) {
+ int aStackToRemove = (aStackSize -= 64) > 64 ? 64 : aStackSize;
+ aY = aY.copy();
+ aY.stackSize = 0;
+ aInputMap.add(new FlexiblePair<ItemStack, Integer>(aY, aStackToRemove));
+ }
+ }
+ else {
+ // Only requires one slot
+ aRecipeSlotsRequired++;
+ aY = aY.copy();
+ aY.stackSize = 0;
+ aInputMap.add(new FlexiblePair<ItemStack, Integer>(aY, aStackSize));
+ }
+ }
+ }
+
+ // We have items to add to the output buses. See if any are not full stacks and see if we can make them full.
+ if (aInputMap.size() > 0) {
+ // Iterate over the current stored items in the Output busses, if any match and are not full, we can try account for merging.
+ busItems: for (FlexiblePair<ItemStack, Integer> y : aItemMap) {
+ // Iterate over the 'inputs', we can safely remove these as we go.
+ outputItems: for (FlexiblePair<ItemStack, Integer> u : aInputMap) {
+ // Create local vars for readability.
+ ItemStack aOutputBusStack = y.getKey();
+ ItemStack aOutputStack = u.getKey();
+ // Stacks match, including NBT.
+ if (GT_Utility.areStacksEqual(aOutputBusStack, aOutputStack, false)) {
+ // Stack Matches, but it's full, continue.
+ if (aOutputBusStack.stackSize >= 64) {
+ // This stack is full, no point checking it.
+ continue busItems;
+ }
+ else {
+ // We can merge these two stacks without any hassle.
+ if ((aOutputBusStack.stackSize + aOutputStack.stackSize) <= 64) {
+ // Update the stack size in the bus storage map.
+ y.setValue(aOutputBusStack.stackSize + aOutputStack.stackSize);
+ // Remove the 'input' stack from the recipe outputs, so we don't try count it again.
+ aInputMap.remove(u);
+ continue outputItems;
+ }
+ // Stack merging is too much, so we fill this stack, leave the remainder.
+ else {
+ int aRemainder = (aOutputBusStack.stackSize + aOutputStack.stackSize) - 64;
+ // Update the stack size in the bus storage map.
+ y.setValue(64);
+ // Create a new object to iterate over later, with the remainder data;
+ FlexiblePair<ItemStack, Integer> t = new FlexiblePair<ItemStack, Integer>(u.getKey(), aRemainder);
+ // Remove the 'input' stack from the recipe outputs, so we don't try count it again.
+ aInputMap.remove(u);
+ // Add the remainder stack.
+ aInputMap.add(t);
+ continue outputItems;
+ }
+ }
+ }
+ else {
+ continue outputItems;
+ }
+ }
+ }
}
+
+ // We have stacks that did not merge, do we have space for them?
+ if (aInputMap.size() > 0) {
+ if (aInputMap.size() > aInputBusSlotsFree) {
+ // We do not have enough free slots in total to accommodate the remaining managed stacks.
+ Logger.INFO("Failed to find enough space for all item outputs. Free: "+aInputBusSlotsFree+", Required: "+aInputMap.size());
+ return false;
+ }
+ }
+
+ /*
+ * End Item Management
+ */
+
}
- // Enough open slots?
- if (tEmptySlots < slotsNeeded) return false;
- // For each output fluid, make sure an output hatch can accept it.
- for (FluidStack tRecipeFluid: aRecipe.mFluidOutputs) {
- if (tRecipeFluid == null) continue;
- boolean tCanBufferFluid = false;
- int tRecipeAmount = tRecipeFluid.amount;
- for (final GT_MetaTileEntity_Hatch_Output tHatch : this.mOutputHatches) {
- FluidStack tHatchFluid = tHatch.getFluid();
- if (tHatchFluid == null) {
- if(tHatch.getCapacity() > tRecipeAmount) {
- tCanBufferFluid = true;
- break;
- }
+
+
+
+
+ /* ========================================
+ * Fluid Management
+ * ========================================
+ */
+
+
+
+ if (aDoesOutputFluids) {
+ Logger.INFO("We have Fluids to output.");
+ // How many slots are free across all the output buses?
+ int aFluidHatches = 0;
+ int aEmptyFluidHatches = 0;
+ int aFullFluidHatches = 0;
+ // Create Map for Fluid Output
+ ConcurrentHashSet<Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>> aOutputHatches = new ConcurrentHashSet<Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>>();
+ for (final GT_MetaTileEntity_Hatch_Output tBus : this.mOutputHatches) {
+ if (!isValidMetaTileEntity(tBus)) {
+ continue;
}
- else if (tHatchFluid.isFluidEqual(tRecipeFluid) && tHatch.getCapacity() - tHatchFluid.amount > tRecipeAmount) {
- tCanBufferFluid = true;
- break;
+ aFluidHatches++;
+ // Map the Hatch with the space left for easy checking later.
+ if (tBus.getFluid() == null) {
+ aOutputHatches.add(new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(tBus, null, tBus.getCapacity()));
+ }
+ else {
+ int aSpaceLeft = tBus.getCapacity() - tBus.getFluidAmount();
+ aOutputHatches.add(new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(tBus, tBus.getFluid(), aSpaceLeft));
+ }
+ }
+ // Create a map of all the fluids we would like to output, we can iterate over this and see how many we can merge into existing hatch stacks.
+ ConcurrentHashSet<FluidStack> aOutputFluids = new ConcurrentHashSet<FluidStack>();
+ // Ugly ass boxing
+ aOutputFluids.addAll(new AutoMap<FluidStack>(aRecipe.mFluidOutputs));
+ // Iterate the Hatches, updating their 'stored' data.
+ aHatchIterator: for (Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aHatchData : aOutputHatches) {
+ // The Hatch Itself
+ GT_MetaTileEntity_Hatch_Output aHatch = aHatchData.getValue_1();
+ // Fluid in the Hatch
+ FluidStack aHatchStack = aHatchData.getValue_2();
+ // Space left in Hatch
+ int aSpaceLeftInHatch = aHatch.getCapacity() - aHatch.getFluidAmount();
+ // Hatch is full,
+ if (aSpaceLeftInHatch <= 0) {
+ aFullFluidHatches++;
+ aOutputHatches.remove(aHatchData);
+ continue aHatchIterator;
+ }
+ // Hatch has space
+ else {
+ // Check if any fluids match
+ aFluidMatch: for (FluidStack aOutputStack : aOutputFluids) {
+ if (GT_Utility.areFluidsEqual(aHatchStack, aOutputStack)) {
+ int aFluidToPutIntoHatch = aOutputStack.amount;
+ // Not Enough space to insert all of the fluid.
+ // We fill this hatch and add a smaller Fluidstack back to the iterator.
+ if (aSpaceLeftInHatch < aFluidToPutIntoHatch) {
+ // Copy existing Hatch Stack
+ FluidStack aNewHatchStack = aHatchStack.copy();
+ aNewHatchStack.amount = 0;
+ // Copy existing Hatch Stack again
+ FluidStack aNewOutputStack = aHatchStack.copy();
+ aNewOutputStack.amount = 0;
+ // How much fluid do we have left after we fill the hatch?
+ int aFluidLeftAfterInsert = aFluidToPutIntoHatch - aSpaceLeftInHatch;
+ // Set new stacks to appropriate values
+ aNewHatchStack.amount = aHatch.getCapacity();
+ aNewOutputStack.amount = aFluidLeftAfterInsert;
+ // Remove fluid from output list, merge success
+ aOutputFluids.remove(aOutputStack);
+ // Remove hatch from hatch list, data is now invalid.
+ aOutputHatches.remove(aHatchData);
+ // Add remaining Fluid to Output list
+ aOutputFluids.add(aNewOutputStack);
+ // Re-add hatch to hatch list, with new data.
+ Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(aHatch, aNewHatchStack, aNewHatchStack.amount);
+ aOutputHatches.add(aNewHatchData);
+ continue aHatchIterator;
+ }
+ // We can fill this hatch perfectly (rare case), may as well add it directly to the full list.
+ else if (aSpaceLeftInHatch == aFluidToPutIntoHatch) {
+ // Copy Old Stack
+ FluidStack aNewHatchStack = aHatchStack.copy();
+ // Add in amount from output stack
+ aNewHatchStack.amount += aOutputStack.amount;
+ // Remove fluid from output list, merge success
+ aOutputFluids.remove(aOutputStack);
+ // Remove hatch from hatch list, data is now invalid.
+ aOutputHatches.remove(aHatchData);
+ // Re-add hatch to hatch list, with new data.
+ Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(aHatch, aNewHatchStack, aNewHatchStack.amount);
+ aOutputHatches.add(aNewHatchData);
+ continue aHatchIterator;
+ }
+ // We have more space than we need to merge, so we remove the stack from the output list and update the hatch list.
+ else {
+ // Copy Old Stack
+ FluidStack aNewHatchStack = aHatchStack.copy();
+ // Add in amount from output stack
+ aNewHatchStack.amount += aOutputStack.amount;
+ // Remove fluid from output list, merge success
+ aOutputFluids.remove(aOutputStack);
+ // Remove hatch from hatch list, data is now invalid.
+ aOutputHatches.remove(aHatchData);
+ // Re-add hatch to hatch list, with new data.
+ Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aNewHatchData = new Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer>(aHatch, aNewHatchStack, aNewHatchStack.amount);
+ aOutputHatches.add(aNewHatchData);
+ // Check next fluid
+ continue aFluidMatch;
+ }
+
+ }
+ else {
+ continue aFluidMatch;
+ }
+ }
}
}
- if (!tCanBufferFluid) return false;
+
+ for (Triplet<GT_MetaTileEntity_Hatch_Output, FluidStack, Integer> aFreeHatchCheck : aOutputHatches) {
+ // Free Hatch
+ if (aFreeHatchCheck.getValue_2() == null || aFreeHatchCheck.getValue_3() == 0 || aFreeHatchCheck.getValue_1().getFluid() == null) {
+ aEmptyFluidHatches++;
+ }
+ }
+
+ // We have Fluid Stacks we did not merge. Do we have space?
+ if (aOutputFluids.size() > 0) {
+ // Not enough space to add fluids.
+ if (aOutputFluids.size() < aEmptyFluidHatches) {
+ Logger.INFO("Failed to find enough space for all fluid outputs.");
+ return false;
+ }
+ }
+
+ /*
+ * End Fluid Management
+ */
}
+
return true;
}
@@ -484,21 +790,26 @@ GT_MetaTileEntity_MultiBlockBase {
public static Method aLogger = null;
public void log(String s) {
-
- boolean isDebugLogging = CORE.DEBUG;
boolean reset = true;
-
- if (aLogger == null || reset) {
- if (isDebugLogging) {
- aLogger = ReflectionUtils.getMethod(Logger.class, "INFO", String.class);
+ if (reset || aLogger == null) {
+ if (!AsmConfig.disableAllLogging) {
+ aLogger = ReflectionUtils.getMethod(
+ Logger.class, "INFO", String.class
+ );
}
else {
- aLogger = ReflectionUtils.getMethod(Logger.class, "MACHINE_INFO", String.class);
+ aLogger = ReflectionUtils.getMethod(
+ Logger.class, "MACHINE_INFO", String.class
+ );
}
}
try {
aLogger.invoke(null, s);
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {}
+ }
+ catch (IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ e.printStackTrace();
+ }
}
@@ -682,8 +993,7 @@ GT_MetaTileEntity_MultiBlockBase {
ItemStack[] aItemInputs, FluidStack[] aFluidInputs,
int aMaxParallelRecipes, int aEUPercent,
int aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe) {
- // Based on the Processing Array. A bit overkill, but very flexible.
-
+ // Based on the Processing Array. A bit overkill, but very flexible.
// Reset outputs and progress stats
this.mEUt = 0;
@@ -694,12 +1004,11 @@ GT_MetaTileEntity_MultiBlockBase {
long tVoltage = getMaxInputVoltage();
byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
log("Running checkRecipeGeneric(0)");
-
-
+
GT_Recipe tRecipe = findRecipe(
getBaseMetaTileEntity(), mLastRecipe, false,
- gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs);
-
+ gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs);
+
log("Running checkRecipeGeneric(1)");
// Remember last recipe - an optimization for findRecipe()
this.mLastRecipe = tRecipe;
@@ -708,6 +1017,50 @@ GT_MetaTileEntity_MultiBlockBase {
log("BAD RETURN - 1");
return false;
}
+
+
+ /*
+ * Check for Special Behaviours
+ */
+
+ // First populate the map if we need to.
+ if (mCustomBehviours == null || mCustomBehviours.isEmpty()) {
+ mCustomBehviours.putAll(Multiblock_API.getSpecialBehaviourItemMap());
+ }
+
+ // We have a special slot object in the recipe
+ if (tRecipe.mSpecialItems != null) {
+ // The special slot is an item
+ if (tRecipe.mSpecialItems instanceof ItemStack) {
+ // Make an Itemstack instance of this.
+ ItemStack aSpecialStack = (ItemStack) tRecipe.mSpecialItems;
+ // Check if this item is in an input bus.
+ boolean aDidFindMatch = false;
+ for (ItemStack aInputItemsToCheck : aItemInputs) {
+ // If we find a matching stack, continue.
+ if (GT_Utility.areStacksEqual(aSpecialStack, aInputItemsToCheck, false)) {
+ // Iterate all special behaviour items, to see if we need to utilise one.
+ aDidFindMatch = true;
+ break;
+ }
+ }
+ // Try prevent needless iteration loops if we don't have the required inputs at all.
+ if (aDidFindMatch) {
+ // Iterate all special behaviour items, to see if we need to utilise one.
+ for (SpecialMultiBehaviour aBehaviours : mCustomBehviours.values()) {
+ // Found a match, let's adjust this recipe now.
+ if (aBehaviours.isTriggerItem(aSpecialStack)) {
+ // Adjust this recipe to suit special item
+ aMaxParallelRecipes = aBehaviours.getMaxParallelRecipes();
+ aEUPercent = aBehaviours.getEUPercent();
+ aSpeedBonusPercent = aBehaviours.getSpeedBonusPercent();
+ aOutputChanceRoll = aBehaviours.getOutputChanceRoll();
+ break;
+ }
+ }
+ }
+ }
+ }
if (!this.canBufferOutputs(tRecipe, aMaxParallelRecipes)) {
log("BAD RETURN - 2");
@@ -743,6 +1096,7 @@ GT_MetaTileEntity_MultiBlockBase {
// -- Try not to fail after this point - inputs have already been consumed! --
+
// Convert speed bonus to duration multiplier
// e.g. 100% speed bonus = 200% speed = 100%/200% = 50% recipe duration.
aSpeedBonusPercent = Math.max(-99, aSpeedBonusPercent);
@@ -835,7 +1189,7 @@ GT_MetaTileEntity_MultiBlockBase {
log("GOOD RETURN - 1");
return true;
-}
+ }
@@ -932,10 +1286,10 @@ GT_MetaTileEntity_MultiBlockBase {
ItemStack[] aItemInputs, FluidStack[] aFluidInputs,
int aMaxParallelRecipes, int aEUPercent,
int aSpeedBonusPercent, int aOutputChanceRoll, GT_Recipe aRecipe) {
-
+
long tVoltage = getMaxInputVoltage();
byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
-
+
log("Running checkRecipeGeneric(0)");
GT_Recipe tRecipe = aRecipe != null ? aRecipe : findRecipe(
@@ -943,12 +1297,12 @@ GT_MetaTileEntity_MultiBlockBase {
gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs);
log("Running checkRecipeGeneric(1)");
-
+
//First we check whether or not we have an input cached for boosting.
//If not, we set it to the current recipe.
//If we do, we compare it against the current recipe, if thy are the same, we try return a boosted recipe, if not, we boost a new recipe.
boolean isRecipeInputTheSame = false;
-
+
//No cached recipe inputs, assume first run.
if (mInputVerificationForBoosting == null) {
mInputVerificationForBoosting = tRecipe.mInputs;
@@ -963,7 +1317,7 @@ GT_MetaTileEntity_MultiBlockBase {
isRecipeInputTheSame = false;
}
}
-
+
//Inputs are the same, let's see if there's a boosted version.
if (isRecipeInputTheSame) {
//Yes, let's just set that as the recipe
@@ -999,14 +1353,14 @@ GT_MetaTileEntity_MultiBlockBase {
mHasBoostedCurrentRecipe = false;
}
}
-
+
//Bad modify, let's just use the original recipe.
if (!mHasBoostedCurrentRecipe || mBoostedRecipe == null) {
tRecipe = aRecipe != null ? aRecipe : findRecipe(
getBaseMetaTileEntity(), mLastRecipe, false,
gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs);
}
-
+
// Remember last recipe - an optimization for findRecipe()
this.mLastRecipe = tRecipe;
@@ -1188,6 +1542,7 @@ GT_MetaTileEntity_MultiBlockBase {
this.mChargeHatches.clear();
this.mDischargeHatches.clear();
this.mControlCoreBus.clear();
+ this.mAirIntakes.clear();
this.mMultiDynamoHatches.clear();
}
}
@@ -1252,22 +1607,22 @@ 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.depleteInput(aNewGuiSlotContents);
this.updateSlots();
result = true;
}
return result;
}
-
+
protected boolean clearGUIItemSlot() {
return setGUIItemStack(null);
}
-
+
public ItemStack findItemInInventory(Item aSearchStack) {
return findItemInInventory(aSearchStack, 0);
@@ -1276,7 +1631,7 @@ GT_MetaTileEntity_MultiBlockBase {
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) {
@@ -1325,54 +1680,63 @@ GT_MetaTileEntity_MultiBlockBase {
public boolean causeMaintenanceIssue() {
boolean b = false;
switch (this.getBaseMetaTileEntity().getRandomNumber(6)) {
- case 0 : {
- this.mWrench = false;
- b = true;
- break;
- }
- case 1 : {
- this.mScrewdriver = false;
- b = true;
- break;
- }
- case 2 : {
- this.mSoftHammer = false;
- b = true;
- break;
- }
- case 3 : {
- this.mHardHammer = false;
- b = true;
- break;
- }
- case 4 : {
- this.mSolderingTool = false;
- b = true;
- break;
- }
- case 5 : {
- this.mCrowbar = false;
- b = true;
- break;
- }
+ case 0 : {
+ this.mWrench = false;
+ b = true;
+ break;
+ }
+ case 1 : {
+ this.mScrewdriver = false;
+ b = true;
+ break;
+ }
+ case 2 : {
+ this.mSoftHammer = false;
+ b = true;
+ break;
+ }
+ case 3 : {
+ this.mHardHammer = false;
+ b = true;
+ break;
+ }
+ case 4 : {
+ this.mSolderingTool = false;
+ b = true;
+ break;
+ }
+ case 5 : {
+ this.mCrowbar = false;
+ b = true;
+ break;
+ }
}
return b;
}
+ public void fixAllMaintenanceIssue() {
+ this.mCrowbar = true;
+ this.mWrench = true;
+ this.mHardHammer = true;
+ this.mSoftHammer = true;
+ this.mSolderingTool = true;
+ this.mScrewdriver = true;
+ }
+
public <E> boolean addToMachineListInternal(ArrayList<E> aList, final IMetaTileEntity aTileEntity,
final int aBaseCasingIndex) {
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) {
@@ -1387,13 +1751,15 @@ GT_MetaTileEntity_MultiBlockBase {
boolean aExists = false;
for (E m : aList) {
IGregTechTileEntity b = ((IMetaTileEntity) m).getBaseMetaTileEntity();
- BlockPos aPos = new BlockPos(b);
- if (b != null && aPos != null) {
- if (aCurPos.equals(aPos)) {
- if (GTplusplus.CURRENT_LOAD_PHASE == INIT_PHASE.STARTED) {
- log("Found Duplicate "+b.getInventoryName()+" at " + aPos.getLocationString());
+ if (b != null) {
+ BlockPos aPos = new BlockPos(b);
+ if (aPos != null) {
+ if (aCurPos.equals(aPos)) {
+ if (GTplusplus.CURRENT_LOAD_PHASE == INIT_PHASE.STARTED) {
+ log("Found Duplicate "+b.getInventoryName()+" at " + aPos.getLocationString());
+ }
+ return false;
}
- return false;
}
}
}
@@ -1546,6 +1912,20 @@ GT_MetaTileEntity_MultiBlockBase {
return addToMachineList(aTileEntity, aBaseCasingIndex);
}
+ public boolean addAirIntakeToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) {
+ if (aTileEntity == null) {
+ return false;
+ }
+ final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity();
+ if (aMetaTileEntity == null) {
+ return false;
+ }
+ if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_AirIntake) {
+ this.mAirIntakes.add((GT_MetaTileEntity_Hatch_AirIntake)aMetaTileEntity);
+ }
+ return addToMachineList(aTileEntity, aBaseCasingIndex);
+ }
+
public boolean addFluidInputToMachineList(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) {
if (aTileEntity == null) {
return false;
@@ -1569,6 +1949,10 @@ GT_MetaTileEntity_MultiBlockBase {
return false;
}
+ public boolean clearRecipeMapForAllInputHatches() {
+ return resetRecipeMapForAllInputHatches(null);
+ }
+
public boolean resetRecipeMapForAllInputHatches() {
return resetRecipeMapForAllInputHatches(this.getRecipeMap());
}
@@ -1588,17 +1972,22 @@ GT_MetaTileEntity_MultiBlockBase {
return cleared > 0;
}
public boolean resetRecipeMapForHatch(IGregTechTileEntity aTileEntity, GT_Recipe_Map aMap) {
- if (aTileEntity == null) {
- return false;
- }
- final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity();;
- if (aMetaTileEntity == null) {
- return false;
- }
- if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) {
- return resetRecipeMapForHatch((GT_MetaTileEntity_Hatch)aMetaTileEntity, aMap);
+ try {
+ if (aTileEntity == null) {
+ return false;
+ }
+ final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity();
+ if (aMetaTileEntity == null) {
+ return false;
+ }
+ if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) {
+ return resetRecipeMapForHatch((GT_MetaTileEntity_Hatch)aMetaTileEntity, aMap);
+ }
+ else {
+ return false;
+ }
}
- else {
+ catch (Throwable t) {
return false;
}
}
@@ -1611,12 +2000,23 @@ GT_MetaTileEntity_MultiBlockBase {
if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input || aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) {
if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input){
((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = null;
- ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = aMap;
- log("Remapped Input Hatch to "+aMap.mNEIName);
+ ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = aMap;
+ if (aMap != null && aMap.mNEIName != null) {
+ log("Remapped Input Hatch to "+aMap.mNEIName+".");
+ }
+ else {
+ log("Cleared Input Hatch.");
+ }
}
else {
((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mRecipeMap = null;
- ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mRecipeMap = aMap;
+ ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mRecipeMap = aMap;
+ if (aMap != null && aMap.mNEIName != null) {
+ log("Remapped Input Bus to "+aMap.mNEIName+".");
+ }
+ else {
+ log("Cleared Input Bus.");
+ }
}
return true;
}
@@ -1628,8 +2028,9 @@ GT_MetaTileEntity_MultiBlockBase {
@Override
public final void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {
super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ);
- resetRecipeMapForAllInputHatches();
+ clearRecipeMapForAllInputHatches();
onModeChangeByScrewdriver(aSide, aPlayer, aX, aY, aZ);
+ resetRecipeMapForAllInputHatches();
}
public void onModeChangeByScrewdriver(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {
@@ -1745,7 +2146,7 @@ GT_MetaTileEntity_MultiBlockBase {
@SuppressWarnings("rawtypes")
public boolean isThisHatchMultiDynamo(Object aMetaTileEntity){
- Class mDynamoClass;
+ Class<?> mDynamoClass;
mDynamoClass = ReflectionUtils.getClass("com.github.technus.tectech.thing.metaTileEntity.hatch.GT_MetaTileEntity_Hatch_DynamoMulti");
if (mDynamoClass != null){
if (mDynamoClass.isInstance(aMetaTileEntity)){
@@ -1784,20 +2185,16 @@ GT_MetaTileEntity_MultiBlockBase {
}
}
- private static Method calculatePollutionReduction;
+ private static Method calculatePollutionReduction = null;
public int calculatePollutionReductionForHatch(GT_MetaTileEntity_Hatch_Muffler i , int g) {
- if (calculatePollutionReduction == null) {
+ if (calculatePollutionReduction != null) {
try {
- calculatePollutionReduction = i.getClass().getDeclaredMethod("calculatePollutionReduction", int.class);
- } catch (NoSuchMethodException | SecurityException e) {
- calculatePollutionReduction = null;
+ return (int) calculatePollutionReduction.invoke(i, g);
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+
}
- }
- try {
- return (int) calculatePollutionReduction.invoke(i, g);
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
- return 0;
}
+ return 0;
}
@Override
@@ -2104,6 +2501,59 @@ GT_MetaTileEntity_MultiBlockBase {
return false;
}
+ @Override
+ public boolean depleteInput(final FluidStack aLiquid) {
+ if (aLiquid == null) {
+ return false;
+ }
+ for (final GT_MetaTileEntity_Hatch_Input tHatch : this.mInputHatches) {
+ tHatch.mRecipeMap = this.getRecipeMap();
+ if (isValidMetaTileEntity(tHatch)) {
+ FluidStack tLiquid = tHatch.getFluid();
+ if (tLiquid == null || !tLiquid.isFluidEqual(aLiquid) || tLiquid.amount < aLiquid.amount) {
+ continue;
+ }
+ tLiquid = tHatch.drain(aLiquid.amount, false);
+ if (tLiquid != null && tLiquid.amount >= aLiquid.amount) {
+ tLiquid = tHatch.drain(aLiquid.amount, true);
+ return tLiquid != null && tLiquid.amount >= aLiquid.amount;
+ }
+ continue;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void onServerStart() {
+ super.onServerStart();
+ tryTickWaitTimerDown();
+ }
+
+ @Override
+ public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) {
+ super.onFirstTick(aBaseMetaTileEntity);
+ tryTickWaitTimerDown();
+ }
+
+ @Override
+ public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
+ super.onPreTick(aBaseMetaTileEntity, aTick);
+ tryTickWaitTimerDown();
+ }
+
+ @Override
+ public void onCreated(ItemStack aStack, World aWorld, EntityPlayer aPlayer) {
+ super.onCreated(aStack, aWorld, aPlayer);
+ tryTickWaitTimerDown();
+ }
+
+ private final void tryTickWaitTimerDown() {
+ /*if (mStartUpCheck > 10) {
+ mStartUpCheck = 10;
+ }*/
+ }
+