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

Fix chemical plant #821

Merged
merged 2 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import gregtech.api.util.GT_Utility;
import gregtech.api.util.IGT_HatchAdder;
import gregtech.common.items.GT_MetaGenerated_Tool_01;
import gregtech.common.tileentities.machines.IDualInputHatch;
import gtPlusPlus.GTplusplus;
import gtPlusPlus.GTplusplus.INIT_PHASE;
import gtPlusPlus.api.objects.Logger;
Expand Down Expand Up @@ -725,7 +726,10 @@ else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output)
aDidAdd = addToMachineListInternal(mOutputHatches, aMetaTileEntity, aBaseCasingIndex);

// Process Remaining hatches using Vanilla GT Logic
else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus)
else if (aMetaTileEntity instanceof IDualInputHatch hatch) {
hatch.updateCraftingIcon(this.getMachineCraftingIcon());
aDidAdd = addToMachineListInternal(mDualInputHatches, aMetaTileEntity, aBaseCasingIndex);
} else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus)
aDidAdd = addToMachineListInternal(mInputBusses, aMetaTileEntity, aBaseCasingIndex);
else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus)
aDidAdd = addToMachineListInternal(mOutputBusses, aMetaTileEntity, aBaseCasingIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import static gregtech.api.util.GT_Utility.filterValidMTEs;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -61,6 +63,7 @@
import gregtech.api.util.GT_ParallelHelper;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Utility;
import gregtech.common.tileentities.machines.IDualInputHatch;
import gtPlusPlus.api.objects.data.AutoMap;
import gtPlusPlus.api.objects.data.Triplet;
import gtPlusPlus.api.recipe.GTPPRecipeMaps;
Expand Down Expand Up @@ -351,13 +354,14 @@ public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack a
mCoilTier = checkCoil.getTier();
getBaseMetaTileEntity().sendBlockEvent(GregTechTileClientEvents.CHANGE_CUSTOM_DATA, getUpdateData());
updateHatchTexture();
return mMachineCasingTier >= 9 || mMachineCasingTier >= maxTierOfHatch;
return (mMachineCasingTier >= 9 || mMachineCasingTier >= maxTierOfHatch) && mCatalystBuses.size() <= 1;
}
return false;
}

public void updateHatchTexture() {
for (GT_MetaTileEntity_Hatch h : mCatalystBuses) h.updateTexture(getCasingTextureID());
for (IDualInputHatch h : mDualInputHatches) h.updateTexture(getCasingTextureID());
for (GT_MetaTileEntity_Hatch h : mInputBusses) h.updateTexture(getCasingTextureID());
for (GT_MetaTileEntity_Hatch h : mMaintenanceHatches) h.updateTexture(getCasingTextureID());
for (GT_MetaTileEntity_Hatch h : mEnergyHatches) h.updateTexture(getCasingTextureID());
Expand Down Expand Up @@ -573,21 +577,19 @@ protected CheckRecipeResult validateRecipe(@NotNull GT_Recipe recipe) {
return CheckRecipeResultRegistry.insufficientMachineTier(recipe.mSpecialValue);
}
// checks if it has a catalyst

boolean needsCalayst = false;
ItemStack catalyst = null;
for (ItemStack item : recipe.mInputs) {
if (ItemUtils.isCatalyst(item)) {
needsCalayst = true;
catalyst = item;
break;
}
}
if (needsCalayst) {
catalystRecipe = findCatalyst(inputItems, recipe.mInputs);
if (catalystRecipe == null || mCatalystBuses.size() != 1) {

if (catalyst != null) {
catalystRecipe = findCatalyst(getCatalystInputs().toArray(new ItemStack[0]), catalyst);
if (catalystRecipe == null) {
return SimpleCheckRecipeResult.ofFailure("no_catalyst");
}
} else {
catalystRecipe = null;
}

// checks if it has enough catalyst durability
Expand Down Expand Up @@ -641,18 +643,12 @@ private int getParallelLimitedByCatalyst(ItemStack[] aItemInputs, ItemStack aRec
return 0;
}

private ItemStack findCatalyst(ItemStack[] aItemInputs, ItemStack[] aRecipeInputs) {
private ItemStack findCatalyst(ItemStack[] aItemInputs, ItemStack catalyst) {
if (aItemInputs != null) {
for (final ItemStack aInput : aItemInputs) {
if (aInput != null) {
if (ItemUtils.isCatalyst(aInput)) {
for (ItemStack aRecipeInput : aRecipeInputs) {
if (GT_Utility.areStacksEqual(aRecipeInput, aInput, true)) {
return aInput;
}
}
}
}
Optional<ItemStack> foundCatalyst = Arrays.stream(aItemInputs)
.filter(i -> GT_Utility.areStacksEqual(i, catalyst, true)).findFirst();
if (foundCatalyst.isPresent()) {
return foundCatalyst.get();
}
}
return null;
Expand All @@ -675,6 +671,12 @@ public ArrayList<ItemStack> getStoredInputs() {
if (this.getControllerSlot() != null) {
tItems.add(this.getControllerSlot());
}
tItems.addAll(getCatalystInputs());
return tItems;
}

public ArrayList<ItemStack> getCatalystInputs() {
ArrayList<ItemStack> tItems = new ArrayList<>();
for (GT_MetaTileEntity_Hatch_Catalysts tHatch : filterValidMTEs(mCatalystBuses)) {
AutoMap<ItemStack> aHatchContent = tHatch.getContentUsageSlots();
if (!aHatchContent.isEmpty()) {
Expand Down