aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod
diff options
context:
space:
mode:
Diffstat (limited to 'src/Java/gtPlusPlus/xmod')
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java372
1 files changed, 344 insertions, 28 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java
index 654d036bf8..81a25b3266 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java
@@ -1,41 +1,63 @@
package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.chemplant;
import static gregtech.api.enums.GT_Values.E;
+import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashSet;
+import java.util.List;
+
+import org.apache.commons.lang3.ArrayUtils;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.api.GregTech_API;
+import gregtech.api.enums.ItemList;
+import gregtech.api.enums.Materials;
import gregtech.api.enums.Textures;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.interfaces.tileentity.IHasWorldObjectAndCoords;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock;
+import gregtech.api.objects.GT_ItemStack;
import gregtech.api.objects.GT_RenderedTexture;
+import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Recipe;
+import gregtech.api.util.GT_Utility;
import gregtech.api.util.GT_Recipe.GT_Recipe_Map;
import gregtech.api.util.Recipe_GT;
+import gtPlusPlus.api.helpers.GregtechPlusPlus_API.Multiblock_API;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.data.AutoMap;
+import gtPlusPlus.api.objects.minecraft.multi.SpecialMultiBehaviour;
+import gtPlusPlus.core.item.chemistry.AgriculturalChem;
+import gtPlusPlus.core.item.chemistry.GenericChem;
+import gtPlusPlus.core.item.chemistry.general.ItemGenericChemBase;
import gtPlusPlus.core.lib.CORE;
+import gtPlusPlus.core.util.math.MathUtils;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase;
import gtPlusPlus.xmod.gregtech.common.Meta_GT_Proxy;
import gtPlusPlus.xmod.gregtech.common.StaticFields59;
import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock;
import net.minecraft.block.Block;
+import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
+import net.minecraftforge.fluids.FluidStack;
public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase {
-
+
private int mSolidCasingTier = 0;
private int mMachineCasingTier = 0;
private int mPipeCasingTier = 0;
private int mCoilTier = 0;
+
/**
* Internal Recipe Map which holds the actual recipes, backed by the real map, shown by NEI.
*/
@@ -78,13 +100,30 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase {
@Override
public String[] getTooltip() {
return new String[] {
- "Heavy Industry, now right at your doorstep!",
"Controller Block for the Chemical Plant",
- "27 Coils",
- "18 Pipe Casings",
- "57 Tiered Machine Casings",
+ "Heavy Industry, now right at your doorstep!",
+ "Solid Casings dictate Chemical Plant tier",
+ "Machine Casings dictate Hatch tier",
+ "Higher tier coils speed up the machine",
+ "CuNi 50% , FeAlCr 100% , Ni4Cr 150% , ...",
+ "Higher tier pipe casings boost parallel and reduce catalyst consumption",
+ "+2 parallel per tier, 20% extra chance of not damaging catalyst per tier",
+ "27x Coils",
+ "18x Pipe Casings",
+ "57x Tiered Machine Casings",
"80+ Solid Casings",
- "Hatch tier is limited to Machine Casing tier",
+ "Construction Guide:",
+ "Controller is placed on a middle casing in the bottom layer",
+ "Hatches can only be placed on the bottom layer edges",
+ "7x7x7 Hollow frame of solid casings",
+ "5x1x5 layer of solid casings (fills in top layer)",
+ "5x1x5 layer of machine casings (fills in bottom layer)",
+ "In the central 3x5x3:",
+ "3x1x3 layer of Coils, surrounded by ring of Machine Casings",
+ "3x1x3 layer of Pipe Casings",
+ "3x1x3 layer of Coils",
+ "3x1x3 layer of Pipe Casings",
+ "3x1x3 layer of Coils, surrounded by ring of Machine Casings",
};
}
@@ -121,7 +160,6 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase {
aOriginalTexture = Textures.BlockIcons.CASING_BLOCKS[11];
}
-
if (aSide == aFacing) {
return new ITexture[]{aOriginalTexture, new GT_RenderedTexture(aActive ? TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active : TexturesGtBlock.Overlay_Machine_Controller_Advanced)};
}
@@ -158,7 +196,7 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase {
@Override
public int getEuDiscountForParallelism() {
- return 0;
+ return 100;
}
private int getSolidCasingTier() {
@@ -699,24 +737,6 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase {
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@Override
public int getMaxEfficiency(final ItemStack aStack) {
return 10000;
@@ -741,6 +761,15 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase {
public String getCustomGUIResourceName() {
return null;
}
+
+ // Same speed bonus as pyro oven
+ public int getSpeedBonus() {
+ return 50 * (this.mCoilTier - 2);
+ }
+
+ public int getMaxCatalystDurability() {
+ return 50;
+ }
@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
@@ -758,10 +787,297 @@ public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase {
}
@Override
- public boolean checkRecipe(final ItemStack aStack) {
- return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), 0);
+ public boolean checkRecipe(final ItemStack aStack) {
+ return checkRecipeGeneric(getMaxParallelRecipes(), getEuDiscountForParallelism(), getSpeedBonus());
}
+
+
+ @Override
+ 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.
+
+ // 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));
+ long tEnergy = getMaxInputEnergy();
+ log("Running checkRecipeGeneric(0)");
+
+ GT_Recipe tRecipe = 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 (tRecipe.mSpecialValue > this.mSolidCasingTier) {
+ log("solid tier is too low");
+ return false;
+ }
+
+
+ if (!this.canBufferOutputs(tRecipe, aMaxParallelRecipes)) {
+ log("BAD RETURN - 2");
+ return false;
+ }
+
+ // checks if it has enough catalyst durabilety
+ ArrayList<ItemStack>tCatalysts = null;
+ int tMaxParrallelCatalyst = aMaxParallelRecipes;
+ ItemStack tCatalystRecipe = findCatalyst(tRecipe.mInputs);
+ if (tCatalystRecipe != null) {
+ log("needs catalyst");
+ tCatalysts = new ArrayList<ItemStack>();
+ tMaxParrallelCatalyst = getCatalysts(aItemInputs, tCatalystRecipe, aMaxParallelRecipes,tCatalysts);
+ }
+
+ if (tMaxParrallelCatalyst == 0) {
+ log("found not enough catalists catalyst");
+ return false;
+ }
+
+ // EU discount
+ float tRecipeEUt = (tRecipe.mEUt * aEUPercent) / 100.0f;
+ float tTotalEUt = 0.0f;
+ log("aEUPercent "+aEUPercent);
+ log("mEUt "+tRecipe.mEUt);
+
+ int parallelRecipes = 0;
+
+ log("parallelRecipes: "+parallelRecipes);
+ log("aMaxParallelRecipes: "+tMaxParrallelCatalyst);
+ log("tTotalEUt: "+tTotalEUt);
+ log("tVoltage: "+tVoltage);
+ log("tEnergy: "+tEnergy);
+ log("tRecipeEUt: "+tRecipeEUt);
+ // Count recipes to do in parallel, consuming input items and fluids and considering input voltage limits
+ for (; parallelRecipes < tMaxParrallelCatalyst && tTotalEUt < (tEnergy - tRecipeEUt); parallelRecipes++) {
+ if (!tRecipe.isRecipeInputEqual(true, aFluidInputs, aItemInputs)) {
+ log("Broke at "+parallelRecipes+".");
+ break;
+ }
+ log("Bumped EU from "+tTotalEUt+" to "+(tTotalEUt+tRecipeEUt)+".");
+ tTotalEUt += tRecipeEUt;
+ }
+
+ if (parallelRecipes == 0) {
+ log("BAD RETURN - 3");
+ return false;
+ }
+
+ if (tCatalysts != null) {
+ log("damaging catalyst");
+ for (int j = 0;j<parallelRecipes;j++) {
+ log("j = "+j);
+ for (int i = 0;i<tCatalysts.size();i++) {
+ log("i = "+i);
+ if (tCatalysts.get(i) != null && tCatalysts.get(i).stackSize != 0) {
+ damageCatalyst(tCatalysts.get(i));
+ break;
+ }
+ }
+ }
+ }
+
+ // -- 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);
+
+ this.mEUt = (int)Math.ceil(tTotalEUt);
+ 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;
+ }
+
+ private int getCatalysts(ItemStack[] aItemInputs,ItemStack aRecipeCatalyst,int aMaxParrallel,ArrayList<ItemStack> aOutPut) {
+ int allowedParrallel = 0;
+ for (final ItemStack aInput : aItemInputs) {
+ if (aRecipeCatalyst.isItemEqual(aInput)) {
+ if (aInput.stackSize == 1) {
+ int damage = getDamage(aInput) + aMaxParrallel;
+ if (damage >getMaxCatalystDuarbilerty() ) {
+ aOutPut.add(aInput);
+ allowedParrallel += aMaxParrallel + (getMaxCatalystDuarbilerty() - damage);
+ if (allowedParrallel >aMaxParrallel ) {
+ return aMaxParrallel;
+ }
+ continue;
+ }
+ }
+ aOutPut.add(aInput);
+ return aMaxParrallel;
+ }
+ }
+ return allowedParrallel;
+ }
+
+ private ItemStack findCatalyst(ItemStack[] aItemInputs) {
+ if (aItemInputs != null) {
+ for (final ItemStack aInput : aItemInputs) {
+ if (aInput != null) {
+ if (aInput.isItemEqual(GenericChem.mRedCatalyst))
+ return aInput;
+ else if (aInput.isItemEqual(GenericChem.mYellowCatalyst))
+ return aInput;
+ else if (aInput.isItemEqual(GenericChem.mBlueCatalyst))
+ return aInput;
+ else if (aInput.isItemEqual(GenericChem.mOrangeCatalyst))
+ return aInput;
+ else if (aInput.isItemEqual(GenericChem.mPurpleCatalyst))
+ return aInput;
+ else if (aInput.isItemEqual(AgriculturalChem.mGreenCatalyst))
+ return aInput;
+ else if (aInput.isItemEqual(GenericChem.mBrownCatalyst))
+ return aInput;
+ }
+ }
+ }
+ return null;
+ }
+
+
+ private void damageCatalyst(ItemStack aStack) {
+ if (MathUtils.randFloat(0, 10000000)/10000000f < (1.2f - (0.2 * this.mPipeCasingTier))) {
+ int damage = getDamage(aStack) + 1;
+ log("damage catalyst "+damage);
+ if (damage >= getMaxCatalystDurability()) {
+ log("consume catalyst");
+ ItemStack emptyCatalyst = ItemUtils.getSimpleStack(AgriculturalChem.mCatalystCarrier,1);
+ addOutput(emptyCatalyst);
+ setDamage(aStack,0);
+ aStack.stackSize -= 1;
+ }
+ else {
+ setDamage(aStack,damage);
+ }
+ }
+ else
+ log("not consuming catalyst");
+ }
+ }
+
+ private int getDamage(ItemStack aStack) {
+ if (aStack.getTagCompound() == null || aStack.getTagCompound().hasNoTags()) {
+ final NBTTagCompound tagMain = new NBTTagCompound();
+ final NBTTagCompound tagNBT = new NBTTagCompound();
+ tagNBT.setInteger("Damage", 0);
+ tagMain.setTag("catalyst", tagNBT);
+ aStack.setTagCompound(tagMain);
+ }
+ NBTTagCompound aNBT = aStack.getTagCompound();
+ return aNBT.getCompoundTag("catalyst").getInteger("Damage");
+ }
+
+ private void setDamage(ItemStack aStack,int aAmount) {
+ NBTTagCompound aNBT = aStack.getTagCompound();
+ aNBT = aNBT.getCompoundTag("catalyst");
+ aNBT.setInteger("Damage", aAmount);
+ }
+
@SideOnly(Side.CLIENT)