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
Changes from 1 commit
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
@@ -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());

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

@Override
public boolean prepareRecipe(Recipe recipe) {
((RecipeMapMultiblockController) metaTileEntity).refreshAllBeforeConsumption();
return super.prepareRecipe(recipe);
}

@Override
protected void modifyOverclockPre(@NotNull OCParams ocParams, @NotNull RecipePropertyStorage storage) {
super.modifyOverclockPre(ocParams, storage);
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
@@ -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;
@@ -32,11 +33,13 @@
import codechicken.lib.render.pipeline.IVertexOperation;
import codechicken.lib.vec.Matrix4;
import com.google.common.collect.Lists;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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

public abstract class RecipeMapMultiblockController extends MultiblockWithDisplayBase implements IDataInfoProvider,
ICleanroomReceiver, IDistinctBusController {
@@ -48,6 +51,7 @@ public abstract class RecipeMapMultiblockController extends MultiblockWithDispla
protected IMultipleTankHandler inputFluidInventory;
protected IMultipleTankHandler outputFluidInventory;
protected IEnergyContainer energyContainer;
protected List<IRefreshBeforeConsumption> refreshBeforeConsumptions;

private boolean isDistinct = false;

@@ -84,6 +88,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.
@@ -129,6 +139,11 @@ protected void initializeAbilities() {
inputEnergy.addAll(getAbilities(MultiblockAbility.SUBSTATION_INPUT_ENERGY));
inputEnergy.addAll(getAbilities(MultiblockAbility.INPUT_LASER));
this.energyContainer = new EnergyContainerList(inputEnergy);

this.refreshBeforeConsumptions = getMultiblockParts().stream()
.filter(p -> p instanceof IRefreshBeforeConsumption)
.map(p -> (IRefreshBeforeConsumption) p)
.collect(Collectors.toList());
}

private void resetTileAbilities() {
@@ -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 = new ObjectArrayList<>(0);
}

protected boolean allowSameFluidFillForOutputs() {
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
@@ -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;
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
@@ -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;
@@ -294,6 +295,14 @@ protected void readConfigFromTag(NBTTagCompound tag) {
super.readConfigFromTag(tag);
}

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

private static class ExportOnlyAEStockingFluidSlot extends ExportOnlyAEFluidSlot {

public ExportOnlyAEStockingFluidSlot(MetaTileEntityMEStockingHatch holder, IAEFluidStack config,