Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
Implement generic processing logic (#340)
Browse files Browse the repository at this point in the history
* Migrated MegaMultiBlockBase to ExtendedPowerBase

* Migrated MOC

* Migrated MCR

* Migrated MCR

* Migrated MVF

* Migrated MEBF

* Migrated MDT

* Use Energy.or(ExoticEnergy) instead of TTEnabledEnergyHatchElement

* Set GPL power to be totalEU voltage at 1 ampere

* Fix coil tier of MEBF

* Migrated CAL

* Migrated EIC

* Migrated vat

* Fixed MDT void protection

* Clean up code

* Updated dep

* Updated deps

* Update dependencies.gradle

* Update dependencies.gradle

* Update dependencies.gradle

* Fix EIC power

* Update src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/mega/GT_TileEntity_MegaBlastFurnace.java

Co-authored-by: miozune <[email protected]>

* Update src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_CircuitAssemblyLine.java

Co-authored-by: miozune <[email protected]>

* Addressed reviews

---------

Co-authored-by: Martin Robertz <[email protected]>
Co-authored-by: miozune <[email protected]>
Former-commit-id: 22b6cb394f6e14b02cc3e5b83666f74bf066537c
  • Loading branch information
3 people authored Jul 17, 2023
1 parent 6cacdb9 commit 05e3a8b
Show file tree
Hide file tree
Showing 17 changed files with 390 additions and 1,601 deletions.
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Add your dependencies here

dependencies {
api('com.github.GTNewHorizons:GT5-Unofficial:5.09.43.122:dev')
api('com.github.GTNewHorizons:GT5-Unofficial:5.09.43.127:dev')
api("com.github.GTNewHorizons:TecTech:5.2.34:dev")
api("com.github.GTNewHorizons:GalacticGregGT5:1.0.9:dev") {
exclude group:"com.github.GTNewHorizons", module:"bartworks"
}
api("com.github.GTNewHorizons:Avaritia:1.45:dev")
implementation("com.github.GTNewHorizons:TinkersConstruct:1.9.38-GTNH:dev")

compileOnly("TGregworks:TGregworks:1.7.10-GTNH-1.0.24:deobf") {transitive = false}
compileOnly("com.github.GTNewHorizons:TinkersGregworks:GTNH-1.0.24-pre:dev") {transitive = false}
compileOnly("com.github.GTNewHorizons:OpenComputers:1.9.12-GTNH:api") {transitive = false}
}
4 changes: 4 additions & 0 deletions src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.github.bartimaeusnek.bartworks.system.material.WerkstoffLoader;
import com.github.bartimaeusnek.bartworks.system.material.processingLoaders.DownTierLoader;
import com.github.bartimaeusnek.bartworks.system.oredict.OreDictHandler;
import com.github.bartimaeusnek.bartworks.util.ResultWrongSievert;
import com.github.bartimaeusnek.bartworks.util.log.DebugLog;

import cpw.mods.fml.common.FMLCommonHandler;
Expand All @@ -75,6 +76,7 @@
import cpw.mods.fml.common.network.NetworkRegistry;
import gregtech.api.GregTech_API;
import gregtech.api.enums.Mods;
import gregtech.api.recipe.check.CheckRecipeResultRegistry;
import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Recipe;

Expand Down Expand Up @@ -180,6 +182,8 @@ public void postInit(FMLPostInitializationEvent postinit) {
WerkstoffLoader.run();
LocalisationLoader.localiseAll();

CheckRecipeResultRegistry.register(new ResultWrongSievert(0, ResultWrongSievert.NeededSievertType.EXACTLY));

RadioHatchMaterialLoader.run();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose;
import static gregtech.api.enums.GT_Values.V;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER_ACTIVE;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER_ACTIVE_GLOW;
Expand All @@ -31,7 +30,6 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

import javax.annotation.Nullable;

Expand All @@ -48,6 +46,8 @@
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;

import org.jetbrains.annotations.NotNull;

import com.github.bartimaeusnek.bartworks.API.SideReference;
import com.github.bartimaeusnek.bartworks.MainMod;
import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler;
Expand All @@ -60,6 +60,7 @@
import com.github.bartimaeusnek.bartworks.util.BioCulture;
import com.github.bartimaeusnek.bartworks.util.Coords;
import com.github.bartimaeusnek.bartworks.util.MathUtils;
import com.github.bartimaeusnek.bartworks.util.ResultWrongSievert;
import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
import com.gtnewhorizon.structurelib.structure.StructureDefinition;
Expand All @@ -69,13 +70,15 @@
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.logic.ProcessingLogic;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMultiBlockBase;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output;
import gregtech.api.recipe.check.CheckRecipeResult;
import gregtech.api.recipe.check.CheckRecipeResultRegistry;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Utility;

public class GT_TileEntity_BioVat extends GT_MetaTileEntity_EnhancedMultiBlockBase<GT_TileEntity_BioVat> {

Expand All @@ -86,7 +89,6 @@ public class GT_TileEntity_BioVat extends GT_MetaTileEntity_EnhancedMultiBlockBa
private final HashSet<EntityPlayerMP> playerMPHashSet = new HashSet<>();
private final ArrayList<GT_MetaTileEntity_RadioHatch> mRadHatches = new ArrayList<>();
private int height = 1;
private GT_Recipe mLastRecipe;
private Fluid mFluid = FluidRegistry.LAVA;
private BioCulture mCulture;
private ItemStack mStack;
Expand Down Expand Up @@ -168,14 +170,6 @@ public static int[] specialValueUnpack(int aSpecialValue) {
return ret;
}

public boolean isLiquidInput(byte aSide) {
return false;
}

public boolean isLiquidOutput(byte aSide) {
return false;
}

private int getInputCapacity() {
return this.mInputHatches.stream().mapToInt(GT_MetaTileEntity_Hatch_Input::getCapacity).sum();
}
Expand Down Expand Up @@ -230,115 +224,60 @@ private int calcMod(double x) {
return MathUtils.clamp(1, ret, ConfigHandler.bioVatMaxParallelBonus);
}

private List<ItemStack> getItemInputs() {
ArrayList<ItemStack> tInputList = this.getStoredInputs();
int tInputList_sS = tInputList.size();
for (int i = 0; i < tInputList_sS - 1; i++) {
for (int j = i + 1; j < tInputList_sS; j++) {
if (GT_Utility.areStacksEqual(tInputList.get(i), tInputList.get(j))) {
if (tInputList.get(i).stackSize >= tInputList.get(j).stackSize) {
tInputList.remove(j--);
tInputList_sS = tInputList.size();
} else {
tInputList.remove(i--);
tInputList_sS = tInputList.size();
break;
@Override
protected ProcessingLogic createProcessingLogic() {
return new ProcessingLogic() {

@NotNull
@Override
protected CheckRecipeResult validateRecipe(@NotNull GT_Recipe recipe) {
if (!BW_Util.areStacksEqualOrNull((ItemStack) recipe.mSpecialItems, getControllerSlot()))
return CheckRecipeResultRegistry.NO_RECIPE;
int[] conditions = GT_TileEntity_BioVat.specialValueUnpack(recipe.mSpecialValue);
mNeededSievert = conditions[3];

if (mGlassTier < conditions[0]) {
return CheckRecipeResultRegistry.insufficientMachineTier(conditions[0]);
}

if (conditions[2] == 0) {
if (mSievert < mNeededSievert) {
return ResultWrongSievert.insufficientSievert(mNeededSievert);
}
} else {
if (mSievert != conditions[3]) {
return ResultWrongSievert.wrongSievert(conditions[3]);
}
}

return CheckRecipeResultRegistry.SUCCESSFUL;
}
}
return tInputList;
}

private List<FluidStack> getFluidInputs() {
ArrayList<FluidStack> tFluidList = this.getStoredFluids();
int tFluidList_sS = tFluidList.size();
for (int i = 0; i < tFluidList_sS - 1; i++) {
for (int j = i + 1; j < tFluidList_sS; j++) {
if (GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j))) {
if (tFluidList.get(i).amount >= tFluidList.get(j).amount) {
tFluidList.remove(j--);
tFluidList_sS = tFluidList.size();
} else {
tFluidList.remove(i--);
tFluidList_sS = tFluidList.size();
break;

@NotNull
@Override
public CheckRecipeResult process() {
CheckRecipeResult result = super.process();
if (!result.wasSuccessful()) {
return result;
}
// We already made sure the recipe runs. Now the vat looks for as many "parallels" as it can do
mExpectedMultiplier = getExpectedMultiplier(lastRecipe.getFluidOutput(0), true);
mTimes = 1;
for (int i = 1; i < mExpectedMultiplier; i++) {
if (depleteInput(lastRecipe.mFluidInputs[0])) {
mTimes++;
}
}
this.outputFluids[0].amount *= mTimes;
return result;
}
}
return tFluidList;
};
}

@Override
public boolean checkRecipe(ItemStack itemStack) {
GT_Recipe.GT_Recipe_Map gtRecipeMap = this.getRecipeMap();

if (gtRecipeMap == null) return false;

ItemStack[] tInputs = getItemInputs().toArray(new ItemStack[0]);
FluidStack[] tFluids = getFluidInputs().toArray(new FluidStack[0]);

if (tFluids.length <= 0) return false;

long tVoltage = getMaxInputVoltage();
byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
long tEnergy = V[tTier];

GT_Recipe gtRecipe = gtRecipeMap.findRecipe(
this.getBaseMetaTileEntity(),
this.mLastRecipe,
false,
tEnergy,
tFluids,
itemStack,
tInputs);

if (gtRecipe == null) return false;

assert gtRecipe.mFluidInputs.length == 1;
assert gtRecipe.mFluidOutputs.length == 1;

if (!BW_Util.areStacksEqualOrNull((ItemStack) gtRecipe.mSpecialItems, itemStack)) return false;

int[] conditions = GT_TileEntity_BioVat.specialValueUnpack(gtRecipe.mSpecialValue);

this.mNeededSievert = conditions[3];

if (conditions[2] == 0 ? (this.mSievert < this.mNeededSievert || this.mGlassTier < conditions[0])
: (this.mSievert != conditions[3] || this.mGlassTier < conditions[0]))
return false;

this.mEfficiency = (10000 - (this.getIdealStatus() - this.getRepairStatus()) * 1000);
this.mEfficiencyIncrease = 10000;

if (!canOutputAll(gtRecipe)) return false;
if (!gtRecipe.isRecipeInputEqual(true, tFluids, tInputs)) return false;

final FluidStack recipeFluidOutput = gtRecipe.getFluidOutput(0);
final FluidStack recipeFluidInput = gtRecipe.mFluidInputs[0];

this.mExpectedMultiplier = this.getExpectedMultiplier(recipeFluidOutput, true);

this.mTimes = 1;
for (int i = 1; i < this.mExpectedMultiplier; i++) {
if (this.depleteInput(recipeFluidInput)) {
this.mTimes++;
}
}

this.mOutputFluids = new FluidStack[] {
new FluidStack(recipeFluidOutput, recipeFluidOutput.amount * this.mTimes) };

BW_Util.calculateOverclockedNessMulti(gtRecipe.mEUt, gtRecipe.mDuration, 1, tEnergy, this);

if (this.mEUt > 0) this.mEUt = -this.mEUt;
this.mProgresstime = 0;

if (gtRecipe.mCanBeBuffered) this.mLastRecipe = gtRecipe;

this.updateSlots();
return true;
protected void setupProcessingLogic(ProcessingLogic logic) {
super.setupProcessingLogic(logic);
logic.setSpecialSlotItem(getControllerSlot());
}

public FluidStack getStoredFluidOutputs() {
Expand Down
Loading

0 comments on commit 05e3a8b

Please sign in to comment.