Skip to content

Commit

Permalink
Fix fluid is registered twice in crafting CPU (GTNewHorizons#237)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Robertz <dream-master@gmx.net>
  • Loading branch information
2 people authored and lordIcocain committed Nov 27, 2024
1 parent cda00b1 commit 6f288ca
Showing 1 changed file with 2 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.networking.GridFlags;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.events.MENetworkCellArrayUpdate;
import appeng.api.networking.events.MENetworkChannelsChanged;
Expand All @@ -31,19 +30,16 @@
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.helpers.IPriorityHost;
import appeng.me.GridAccessException;
import appeng.me.cache.CraftingGridCache;
import appeng.me.storage.MEInventoryHandler;
import appeng.tile.grid.AENetworkTile;

public class TileFluidDiscretizer extends AENetworkTile implements IPriorityHost, ICellContainer {

private final BaseActionSource ownActionSource = new MachineSource(this);
private final FluidDiscretizingInventory fluidDropInv = new FluidDiscretizingInventory();
private final FluidCraftingInventory fluidCraftInv = new FluidCraftingInventory();
private boolean prevActiveState = false;

public TileFluidDiscretizer() {
Expand All @@ -60,12 +56,8 @@ public boolean canBeRotated() {
@Override
@SuppressWarnings("rawtypes")
public List<IMEInventoryHandler> getCellArray(StorageChannel channel) {
if (getProxy().isActive()) {
if (channel == StorageChannel.ITEMS) {
return Collections.singletonList(fluidDropInv.invHandler);
} else if (channel == StorageChannel.FLUIDS) {
return Collections.singletonList(fluidCraftInv.invHandler);
}
if (channel == StorageChannel.ITEMS && getProxy().isActive()) {
return Collections.singletonList(fluidDropInv.invHandler);
}
return Collections.emptyList();
}
Expand Down Expand Up @@ -263,85 +255,4 @@ public void onListUpdate() {
// NO-OP
}
}

private class FluidCraftingInventoryHandler extends MEInventoryHandler<IAEFluidStack> {

public FluidCraftingInventoryHandler(IMEInventory<IAEFluidStack> i, StorageChannel channel) {
super(i, channel);
}

@Override
public boolean isPrioritized(IAEFluidStack input) {
return true;
}

@Override
public boolean canAccept(IAEFluidStack input) {
ICraftingGrid craftingGrid;
try {
craftingGrid = getProxy().getGrid().getCache(ICraftingGrid.class);
} catch (GridAccessException e) {
return false;
}
if (craftingGrid instanceof CraftingGridCache craftingGridCache) {
return craftingGridCache.canAccept(ItemFluidDrop.newAeStack(input));
}
return false;
}

@Override
public boolean isAutoCraftingInventory() {
return true;
}
}

private class FluidCraftingInventory implements IMEInventory<IAEFluidStack> {

private final MEInventoryHandler<IAEFluidStack> invHandler = new FluidCraftingInventoryHandler(
this,
getChannel());

FluidCraftingInventory() {
invHandler.setPriority(Integer.MAX_VALUE);
}

@Override
@SuppressWarnings("rawtypes")
public IAEFluidStack injectItems(IAEFluidStack input, Actionable type, BaseActionSource src) {
ICraftingGrid craftingGrid;
try {
craftingGrid = getProxy().getGrid().getCache(ICraftingGrid.class);
} catch (GridAccessException e) {
return null;
}
if (craftingGrid instanceof CraftingGridCache) {
IAEStack remaining = ((CraftingGridCache) craftingGrid)
.injectItems(ItemFluidDrop.newAeStack(input), type, ownActionSource);
if (remaining instanceof IAEItemStack) {
return ItemFluidDrop.getAeFluidStack((IAEItemStack) remaining);
}
}
return null;
}

@Override
public IAEFluidStack extractItems(IAEFluidStack request, Actionable mode, BaseActionSource src) {
return null;
}

@Override
public IItemList<IAEFluidStack> getAvailableItems(IItemList<IAEFluidStack> out, int iteration) {
return out;
}

@Override
public IAEFluidStack getAvailableItem(@Nonnull IAEFluidStack request, int iteration) {
return null;
}

@Override
public StorageChannel getChannel() {
return StorageChannel.FLUIDS;
}
}
}

0 comments on commit 6f288ca

Please sign in to comment.