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

Commit

Permalink
Implement generic processing logic (#176)
Browse files Browse the repository at this point in the history
* Removed deprecated bartworks interface

* Migrated PrAss

* Migrated CoAL

* Migrated CoolantTower

* Migrated EHE

* Migrated compacts

* Migrated large turbine base

* Migrated UCFE

* Migrated FRF

* Migrated naq gen

* Migrated YOTTA

* Migrated LEG

* Migrated LES

* Migrated NA

* Updated deps

* Updated deps

* Derp

* Fixed PrAss in precise mode

* Added missing GPL getters in NA

* Fixed power of NA

* Enabled batch mode and void protection in FRF

* Addressed reviews

* Deleted LongPowerUsageBase in favor of ExtendedPowerMultiBlockBase

* Addressed reviews

* Limit recipe duration to 1 tick

* Updated dep
  • Loading branch information
minecraft7771 authored Jul 17, 2023
1 parent d80fe13 commit 328376f
Show file tree
Hide file tree
Showing 18 changed files with 264 additions and 536 deletions.
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Add your dependencies here

dependencies {
api('com.github.GTNewHorizons:GT5-Unofficial:5.09.43.104:dev')
api('com.github.GTNewHorizons:bartworks:0.7.24:dev')
api('com.github.GTNewHorizons:GT5-Unofficial:5.09.43.130:dev')
api('com.github.GTNewHorizons:bartworks:0.7.30:dev')
implementation('thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev')
implementation('com.github.GTNewHorizons:GTplusplus:1.9.52:dev')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import static gregtech.api.enums.GT_HatchElement.*;
import static gregtech.api.enums.Textures.BlockIcons.*;

import java.util.ArrayList;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

Expand All @@ -15,16 +14,15 @@
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;

import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;

import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment;
import com.gtnewhorizon.structurelib.structure.StructureDefinition;

import goodgenerator.blocks.tileEntity.base.GT_MetaTileEntity_LongPowerUsageBase;
import goodgenerator.loader.Loaders;
import goodgenerator.util.MyRecipeAdder;
import gregtech.api.GregTech_API;
Expand All @@ -34,18 +32,20 @@
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus;
import gregtech.api.logic.ProcessingLogic;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_ExtendedPowerMultiBlockBase;
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_StructureUtility;
import gregtech.api.util.GT_Utility;

public class ComponentAssemblyLine extends GT_MetaTileEntity_LongPowerUsageBase<ComponentAssemblyLine>
public class ComponentAssemblyLine extends GT_MetaTileEntity_ExtendedPowerMultiBlockBase<ComponentAssemblyLine>
implements ISurvivalConstructable {

private int casingTier;
private GT_Recipe lastRecipe;
protected static final String STRUCTURE_PIECE_MAIN = "main";
private static final IStructureDefinition<ComponentAssemblyLine> STRUCTURE_DEFINITION = StructureDefinition
.<ComponentAssemblyLine>builder()
Expand Down Expand Up @@ -262,45 +262,24 @@ public boolean isCorrectMachinePart(ItemStack aStack) {
}

@Override
public boolean checkRecipe(ItemStack aStack) {
this.mEfficiencyIncrease = 10000;
this.mEfficiency = (10000 - (this.getIdealStatus() - this.getRepairStatus()) * 1000);
FluidStack[] tFluids = getStoredFluids().toArray(new FluidStack[0]);

if (inputSeparation) {
ArrayList<ItemStack> tInputList = new ArrayList<>();
for (GT_MetaTileEntity_Hatch_InputBus tHatch : mInputBusses) {
IGregTechTileEntity tInputBus = tHatch.getBaseMetaTileEntity();
for (int i = tInputBus.getSizeInventory() - 1; i >= 0; i--) {
if (tInputBus.getStackInSlot(i) != null) tInputList.add(tInputBus.getStackInSlot(i));
protected ProcessingLogic createProcessingLogic() {
return new ProcessingLogic() {

@NotNull
@Override
protected CheckRecipeResult validateRecipe(@NotNull GT_Recipe recipe) {
if (recipe.mSpecialValue > casingTier + 1) {
return CheckRecipeResultRegistry.insufficientMachineTier(recipe.mSpecialValue);
}
ItemStack[] tInputs = tInputList.toArray(new ItemStack[0]);
if (processRecipe(tInputs, tFluids)) return true;
else tInputList.clear();
return CheckRecipeResultRegistry.SUCCESSFUL;
}
} else {
ItemStack[] tItems = getStoredInputs().toArray(new ItemStack[0]);
return processRecipe(tItems, tFluids);
}
return false;
};
}

private boolean processRecipe(ItemStack[] tInputs, FluidStack[] tFluidInputs) {
long totalEU = getRealVoltage();
this.lastRecipe = getRecipeMap()
.findRecipe(getBaseMetaTileEntity(), this.lastRecipe, false, totalEU, tFluidInputs, tInputs);
if (this.lastRecipe == null) return false;
if (this.lastRecipe.mSpecialValue > casingTier + 1) return false;
if (!this.lastRecipe.isRecipeInputEqual(true, tFluidInputs, tInputs)) return false;

calculateOverclockedNessMulti((long) this.lastRecipe.mEUt, this.lastRecipe.mDuration, 1, totalEU);
if (this.lEUt > 0) {
this.lEUt = (-this.lEUt);
}

mOutputItems = this.lastRecipe.mOutputs;
updateSlots();
return true;
@Override
protected void setProcessingLogicPower(ProcessingLogic logic) {
logic.setAvailableVoltage(getMaxInputEu());
logic.setAvailableAmperage(1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;

import org.jetbrains.annotations.NotNull;

import com.github.technus.tectech.thing.metaTileEntity.multi.base.GT_MetaTileEntity_MultiblockBase_EM;
import com.gtnewhorizon.structurelib.alignment.constructable.IConstructable;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
Expand All @@ -29,6 +31,8 @@
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_MultiInput;
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_ModHandler;
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
Expand Down Expand Up @@ -188,15 +192,15 @@ public boolean onRunningTick(ItemStack aStack) {
}

@Override
public boolean checkRecipe_EM(ItemStack aStack) {
protected @NotNull CheckRecipeResult checkProcessing_EM() {
this.mMaxProgresstime = 20;
int steam = 0;

for (GT_MetaTileEntity_Hatch_Input tHatch : mInputHatches) {
steam += maybeDrainHatch(tHatch);
}
addOutput(GT_ModHandler.getDistilledWater(steam / 160));
return true;
return CheckRecipeResultRegistry.SUCCESSFUL;
}

private int maybeDrainHatch(GT_MetaTileEntity_Hatch_Input tHatch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;

import org.jetbrains.annotations.NotNull;

import com.gtnewhorizon.structurelib.alignment.constructable.IConstructable;
import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
import com.gtnewhorizon.structurelib.structure.IItemSource;
Expand All @@ -41,6 +43,8 @@
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output;
import gregtech.api.multitileentity.multiblock.casing.Glasses;
import gregtech.api.recipe.check.CheckRecipeResult;
import gregtech.api.recipe.check.CheckRecipeResultRegistry;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.*;

Expand Down Expand Up @@ -190,12 +194,12 @@ protected GT_Multiblock_Tooltip_Builder createTooltip() {
}

@Override
public boolean checkRecipe_EM(ItemStack aStack) {
public @NotNull CheckRecipeResult checkProcessing_EM() {
tRunningRecipe = null;
if (mHotFluidHatch.getFluid() == null) return true;
if (mHotFluidHatch.getFluid() == null) return CheckRecipeResultRegistry.SUCCESSFUL;
MyRecipeAdder.ExtremeHeatExchangerRecipe tRecipe = MyRecipeAdder.mXHeatExchangerFuelMap
.get(mHotFluidHatch.getFluid().getFluid());
if (tRecipe == null) return false;
if (tRecipe == null) return CheckRecipeResultRegistry.NO_RECIPE;
tRunningRecipe = tRecipe;
this.hotName = mHotFluidHatch.getFluid().getFluid().getName();
int tMaxConsume = tRecipe.getMaxHotFluidConsume();
Expand Down Expand Up @@ -224,7 +228,7 @@ public boolean checkRecipe_EM(ItemStack aStack) {
mCooledFluidHatch.fill(new FluidStack(tRecipe.getCooledFluid(), tRealConsume), true);
this.mEfficiencyIncrease = 160;

return true;
return CheckRecipeResultRegistry.SUCCESSFUL;
}

@Override
Expand Down
Loading

0 comments on commit 328376f

Please sign in to comment.