aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base
diff options
context:
space:
mode:
author‭huajijam <strhuaji@gmail.com>2019-05-17 23:26:41 +0800
committer‭huajijam <strhuaji@gmail.com>2019-05-17 23:26:41 +0800
commit5920c6db3ff62d89ba41db4eda59cc6d70ddce3b (patch)
treed4d6d5036e8cb95d2232066f0ee257f59b5aa967 /src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base
parent787c31758d2ea3259f8da9c5c7ffd4b28429eb9a (diff)
parentcacc2915ef0039e3460817e4f116d44cf8e44e5f (diff)
downloadGT5-Unofficial-5920c6db3ff62d89ba41db4eda59cc6d70ddce3b.tar.gz
GT5-Unofficial-5920c6db3ff62d89ba41db4eda59cc6d70ddce3b.tar.bz2
GT5-Unofficial-5920c6db3ff62d89ba41db4eda59cc6d70ddce3b.zip
Automatic synchronization
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base')
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java221
1 files changed, 193 insertions, 28 deletions
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..0e1ef0e47e 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;
@@ -539,26 +540,149 @@ GT_MetaTileEntity_MultiBlockBase {
}
+ /*
+ * public boolean checkRecipeGeneric( 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.
+ *
+ *
+ * if (this.doesMachineBoostOutput()) { log("Boosting."); return
+ * checkRecipeBoostedOutputs(aItemInputs, aFluidInputs, aMaxParallelRecipes,
+ * aEUPercent, aSpeedBonusPercent, aOutputChanceRoll, aRecipe); }
+ *
+ *
+ * //Control Core to control the Multiblocks behaviour. int aControlCoreTier =
+ * getControlCoreTier();
+ *
+ * //If no core, return false; if (aControlCoreTier > 0) {
+ * log("Control core found."); }
+ *
+ *
+ * // Reset outputs and progress stats this.mEUt = 0; this.mMaxProgresstime = 0;
+ * this.mOutputItems = new ItemStack[]{}; this.mOutputFluids = new
+ * FluidStack[]{};
+ *
+ * long tVoltage = getMaxInputVoltage(); byte tTier = (byte) Math.max(1,
+ * GT_Utility.getTier(tVoltage)); log("Running checkRecipeGeneric(0)");
+ *
+ * //Check to see if Voltage Tier > Control Core Tier if (tTier >
+ * aControlCoreTier) {
+ * log("Control core found is lower tier than power tier. OK"); tTier = (byte)
+ * aControlCoreTier; }
+ *
+ * tTier = (byte) MathUtils.getValueWithinRange(tTier, 0, 9);
+ *
+ * GT_Recipe tRecipe = aRecipe != null ? aRecipe : findRecipe(
+ * getBaseMetaTileEntity(), mLastRecipe, false,
+ * gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs);
+ *
+ * log("Running checkRecipeGeneric(1)"); // Remember last recipe - an
+ * optimization for findRecipe() this.mLastRecipe = tRecipe;
+ *
+ * if (tRecipe == null) { log("BAD RETURN - 1"); return false; }
+ *
+ * if (!this.canBufferOutputs(tRecipe, aMaxParallelRecipes)) {
+ * log("BAD RETURN - 2"); return false; }
+ *
+ * // EU discount float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f; float
+ * tTotalEUt = 0.0f;
+ *
+ * int parallelRecipes = 0;
+ *
+ * log("parallelRecipes: "+parallelRecipes);
+ * log("aMaxParallelRecipes: "+aMaxParallelRecipes);
+ * log("tTotalEUt: "+tTotalEUt); log("tVoltage: "+tVoltage);
+ * log("tRecipeEUt: "+tRecipeEUt); Logger.INFO("EU1: "+tRecipeEUt); // Count
+ * recipes to do in parallel, consuming input items and fluids and considering
+ * input voltage limits for (; parallelRecipes < aMaxParallelRecipes &&
+ * tTotalEUt < (tVoltage - tRecipeEUt); parallelRecipes++) { if
+ * (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
+ * log("Broke at "+parallelRecipes+"."); break; }
+ * log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+"."); tTotalEUt
+ * += tRecipeEUt; Logger.INFO("EU2: "+tTotalEUt); }
+ *
+ * if (parallelRecipes == 0) { log("BAD RETURN - 3"); return false; }
+ *
+ * Logger.INFO("EU3: "+tTotalEUt);
+ *
+ * // -- 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); float tTimeFactor = 100.0f / (100.0f +
+ * aSpeedBonusPercent); this.mMaxProgresstime = (int)(tRecipe.mDuration *
+ * tTimeFactor * 10000);
+ *
+ * int aTempEu = (int) Math.floor(tTotalEUt); Logger.INFO("EU4: "+aTempEu);
+ * this.mEUt = (int) aTempEu;
+ *
+ *
+ * this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
+ * this.mEfficiencyIncrease = 10000;
+ *
+ * // Overclock if (this.mEUt <= 16) { this.mEUt = (this.mEUt * (1 << tTier - 1)
+ * * (1 << tTier - 1)); this.mMaxProgresstime = (this.mMaxProgresstime / (1 <<
+ * tTier - 1)); } else { while (this.mEUt <=
+ * gregtech.api.enums.GT_Values.V[(tTier - 1)]) { this.mEUt *= 4;
+ * this.mMaxProgresstime /= 2; } }
+ *
+ * if (this.mEUt > 0) { this.mEUt = (-this.mEUt); }
+ *
+ * this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
+ *
+ * // Collect fluid outputs FluidStack[] tOutputFluids = new
+ * FluidStack[tRecipe.mFluidOutputs.length]; for (int h = 0; h <
+ * tRecipe.mFluidOutputs.length; h++) { if (tRecipe.getFluidOutput(h) != null) {
+ * tOutputFluids[h] = tRecipe.getFluidOutput(h).copy(); tOutputFluids[h].amount
+ * *= parallelRecipes; } }
+ *
+ * // Collect output item types ItemStack[] tOutputItems = new
+ * ItemStack[tRecipe.mOutputs.length]; for (int h = 0; h <
+ * tRecipe.mOutputs.length; h++) { if (tRecipe.getOutput(h) != null) {
+ * tOutputItems[h] = tRecipe.getOutput(h).copy(); tOutputItems[h].stackSize = 0;
+ * } }
+ *
+ * // Set output item stack sizes (taking output chance into account) for (int f
+ * = 0; f < tOutputItems.length; f++) { if (tRecipe.mOutputs[f] != null &&
+ * tOutputItems[f] != null) { for (int g = 0; g < parallelRecipes; g++) { if
+ * (getBaseMetaTileEntity().getRandomNumber(aOutputChanceRoll) <
+ * tRecipe.getOutputChance(f)) tOutputItems[f].stackSize +=
+ * tRecipe.mOutputs[f].stackSize; } } }
+ *
+ * tOutputItems = removeNulls(tOutputItems);
+ *
+ * // Sanitize item stack size, splitting any stacks greater than max stack size
+ * List<ItemStack> splitStacks = new ArrayList<ItemStack>(); for (ItemStack
+ * tItem : tOutputItems) { while (tItem.getMaxStackSize() < tItem.stackSize) {
+ * ItemStack tmp = tItem.copy(); tmp.stackSize = tmp.getMaxStackSize();
+ * tItem.stackSize = tItem.stackSize - tItem.getMaxStackSize();
+ * splitStacks.add(tmp); } }
+ *
+ * if (splitStacks.size() > 0) { ItemStack[] tmp = new
+ * ItemStack[splitStacks.size()]; tmp = splitStacks.toArray(tmp); tOutputItems =
+ * ArrayUtils.addAll(tOutputItems, tmp); }
+ *
+ * // Strip empty stacks List<ItemStack> tSList = new ArrayList<ItemStack>();
+ * for (ItemStack tS : tOutputItems) { if (tS.stackSize > 0) tSList.add(tS); }
+ * tOutputItems = tSList.toArray(new ItemStack[tSList.size()]);
+ *
+ * // Commit outputs this.mOutputItems = tOutputItems; this.mOutputFluids =
+ * tOutputFluids; updateSlots();
+ *
+ * // Play sounds (GT++ addition - GT multiblocks play no sounds)
+ * startProcess();
+ *
+ * log("GOOD RETURN - 1"); return true; }
+ */
+
public boolean checkRecipeGeneric(
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.
-
-
- if (this.doesMachineBoostOutput()) {
- log("Boosting.");
- return checkRecipeBoostedOutputs(aItemInputs, aFluidInputs, aMaxParallelRecipes, aEUPercent, aSpeedBonusPercent, aOutputChanceRoll, aRecipe);
- }
-
-
- //Control Core to control the Multiblocks behaviour.
- int aControlCoreTier = getControlCoreTier();
-
- //If no core, return false;
- if (aControlCoreTier > 0) {
- log("Control core found.");
- }
+ // Based on the Processing Array. A bit overkill, but very flexible.
// Reset outputs and progress stats
@@ -571,15 +695,8 @@ GT_MetaTileEntity_MultiBlockBase {
byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
log("Running checkRecipeGeneric(0)");
- //Check to see if Voltage Tier > Control Core Tier
- if (tTier > aControlCoreTier) {
- log("Control core found is lower tier than power tier. OK");
- tTier = (byte) aControlCoreTier;
- }
- tTier = (byte) MathUtils.getValueWithinRange(tTier, 0, 9);
-
- GT_Recipe tRecipe = aRecipe != null ? aRecipe : findRecipe(
+ GT_Recipe tRecipe = findRecipe(
getBaseMetaTileEntity(), mLastRecipe, false,
gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs);
@@ -635,7 +752,7 @@ GT_MetaTileEntity_MultiBlockBase {
this.mEUt = (int)Math.ceil(tTotalEUt);
this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
- this.mEfficiencyIncrease = 10000;
+ this.mEfficiencyIncrease = 10000;
// Overclock
if (this.mEUt <= 16) {
@@ -718,8 +835,7 @@ GT_MetaTileEntity_MultiBlockBase {
log("GOOD RETURN - 1");
return true;
- }
-
+}
@@ -1136,6 +1252,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 +1365,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) {