Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Duplication Glitch with ME Storage Hatches/Buses #2646

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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 @@ -257,6 +257,8 @@ protected boolean checkPreviousRecipeDistinct(IItemHandlerModifiable previousBus
}

protected boolean prepareRecipeDistinct(Recipe recipe) {
((RecipeMapMultiblockController) metaTileEntity).refreshAllBeforeConsumption();

recipe = Recipe.trimRecipeOutputs(recipe, getRecipeMap(), metaTileEntity.getItemOutputLimit(),
metaTileEntity.getFluidOutputLimit());

Expand All @@ -280,6 +282,12 @@ protected boolean prepareRecipeDistinct(Recipe recipe) {
return false;
}

@Override
public boolean prepareRecipe(Recipe recipe) {
((RecipeMapMultiblockController) metaTileEntity).refreshAllBeforeConsumption();
IntegerLimit marked this conversation as resolved.
Show resolved Hide resolved
return super.prepareRecipe(recipe);
}

@Override
protected void modifyOverclockPre(@NotNull OCParams ocParams, @NotNull RecipePropertyStorage storage) {
super.modifyOverclockPre(ocParams, storage);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package gregtech.api.metatileentity.interfaces;

/**
* This Interface represents a MultiblockPart that should be refreshed before final recipe validation and input
* consumption.
*/
public interface IRefreshBeforeConsumption {

/**
* Called Server Side Only.
*/
void refreshBeforeConsumption();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import gregtech.api.capability.impl.MultiblockRecipeLogic;
import gregtech.api.items.itemhandlers.GTItemStackHandler;
import gregtech.api.metatileentity.IDataInfoProvider;
import gregtech.api.metatileentity.interfaces.IRefreshBeforeConsumption;
import gregtech.api.pattern.PatternMatchContext;
import gregtech.api.pattern.TraceabilityPredicate;
import gregtech.api.recipes.Recipe;
Expand Down Expand Up @@ -48,6 +49,7 @@ public abstract class RecipeMapMultiblockController extends MultiblockWithDispla
protected IMultipleTankHandler inputFluidInventory;
protected IMultipleTankHandler outputFluidInventory;
protected IEnergyContainer energyContainer;
protected List<IRefreshBeforeConsumption> refreshBeforeConsumptions;

private boolean isDistinct = false;

Expand All @@ -57,6 +59,7 @@ public RecipeMapMultiblockController(ResourceLocation metaTileEntityId, RecipeMa
super(metaTileEntityId);
this.recipeMap = recipeMap;
this.recipeMapWorkable = new MultiblockRecipeLogic(this);
this.refreshBeforeConsumptions = new ArrayList<>();
resetTileAbilities();
}

Expand Down Expand Up @@ -84,6 +87,12 @@ public MultiblockRecipeLogic getRecipeMapWorkable() {
return recipeMapWorkable;
}

public void refreshAllBeforeConsumption() {
for (var refresh : refreshBeforeConsumptions) {
refresh.refreshBeforeConsumption();
}
}

/**
* Performs extra checks for validity of given recipe before multiblock
* will start it's processing.
Expand Down Expand Up @@ -129,6 +138,12 @@ protected void initializeAbilities() {
inputEnergy.addAll(getAbilities(MultiblockAbility.SUBSTATION_INPUT_ENERGY));
inputEnergy.addAll(getAbilities(MultiblockAbility.INPUT_LASER));
this.energyContainer = new EnergyContainerList(inputEnergy);

for (IMultiblockPart part : getMultiblockParts()) {
if (part instanceof IRefreshBeforeConsumption refresh) {
refreshBeforeConsumptions.add(refresh);
}
}
}

private void resetTileAbilities() {
Expand All @@ -137,6 +152,7 @@ private void resetTileAbilities() {
this.outputInventory = new GTItemStackHandler(this, 0);
this.outputFluidInventory = new FluidTankList(true);
this.energyContainer = new EnergyContainerList(Lists.newArrayList());
this.refreshBeforeConsumptions.clear();
}

protected boolean allowSameFluidFillForOutputs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public boolean prepareRecipe(Recipe recipe) {
parallel = getParallel(recipe, holderEfficiency, turbineMaxVoltage);

// Null check fluid here, since it can return null on first join into world or first form
((RecipeMapMultiblockController) metaTileEntity).refreshAllBeforeConsumption();
FluidStack inputFluid = getInputFluidStack();
if (inputFluid == null || getInputFluidStack().amount < recipeFluidStack.amount * parallel) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import gregtech.api.gui.widgets.ImageCycleButtonWidget;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.metatileentity.interfaces.IRefreshBeforeConsumption;
import gregtech.api.metatileentity.multiblock.MultiblockAbility;
import gregtech.api.metatileentity.multiblock.MultiblockControllerBase;
import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController;
Expand Down Expand Up @@ -37,7 +38,7 @@

import static gregtech.api.capability.GregtechDataCodes.UPDATE_AUTO_PULL;

public class MetaTileEntityMEStockingBus extends MetaTileEntityMEInputBus {
public class MetaTileEntityMEStockingBus extends MetaTileEntityMEInputBus implements IRefreshBeforeConsumption {

private static final int CONFIG_SIZE = 16;
private boolean autoPull;
Expand Down Expand Up @@ -391,6 +392,14 @@ protected void readConfigFromTag(NBTTagCompound tag) {
super.readConfigFromTag(tag);
}

@Override
public void refreshBeforeConsumption() {
if (isWorkingEnabled() && updateMEStatus()) {
if (autoPull) refreshList();
syncME();
}
}

private static class ExportOnlyAEStockingItemList extends ExportOnlyAEItemList {

private final MetaTileEntityMEStockingBus holder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import gregtech.api.gui.widgets.ImageCycleButtonWidget;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.metatileentity.interfaces.IRefreshBeforeConsumption;
import gregtech.api.metatileentity.multiblock.MultiblockAbility;
import gregtech.api.metatileentity.multiblock.MultiblockControllerBase;
import gregtech.common.metatileentities.multi.multiblockpart.appeng.slot.ExportOnlyAEFluidList;
Expand Down Expand Up @@ -37,7 +38,7 @@

import static gregtech.api.capability.GregtechDataCodes.UPDATE_AUTO_PULL;

public class MetaTileEntityMEStockingHatch extends MetaTileEntityMEInputHatch {
public class MetaTileEntityMEStockingHatch extends MetaTileEntityMEInputHatch implements IRefreshBeforeConsumption {

private static final int CONFIG_SIZE = 16;
private boolean autoPull;
Expand Down Expand Up @@ -294,6 +295,14 @@ protected void readConfigFromTag(NBTTagCompound tag) {
super.readConfigFromTag(tag);
}

@Override
public void refreshBeforeConsumption() {
if (isWorkingEnabled() && updateMEStatus()) {
if (autoPull) refreshList();
syncME();
}
}

private static class ExportOnlyAEStockingFluidSlot extends ExportOnlyAEFluidSlot {

public ExportOnlyAEStockingFluidSlot(MetaTileEntityMEStockingHatch holder, IAEFluidStack config,
Expand Down