Skip to content

Commit

Permalink
Skip un-extractable slots.
Browse files Browse the repository at this point in the history
  • Loading branch information
PrototypeTrousers committed Feb 22, 2021
1 parent a7a1a87 commit e2e6f6e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/main/java/appeng/fluids/parts/FluidHandlerAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.Map;

import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidTankProperties;
Expand Down Expand Up @@ -195,10 +196,13 @@ private static class InventoryCache
{
private IAEFluidStack[] cachedAeStacks = new IAEFluidStack[0];
private final IFluidHandler fluidHandler;
private ArrayList<Integer> skipSlots;


public InventoryCache( IFluidHandler fluidHandler )
{
this.fluidHandler = fluidHandler;
this.skipSlots = new ArrayList<>(this.fluidHandler.getTankProperties().length);
}

public List<IAEFluidStack> update()
Expand All @@ -211,13 +215,22 @@ public List<IAEFluidStack> update()
if( slots > this.cachedAeStacks.length )
{
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, slots );
this.skipSlots = new ArrayList<>(this.fluidHandler.getTankProperties().length);
}

for( int slot = 0; slot < slots; slot++ )
{
if (skipSlots.contains( slot ))
continue;
// Save the old stuff
final IAEFluidStack oldAEFS = this.cachedAeStacks[slot];
final FluidStack newFS = tankProperties[slot].getContents();
FluidStack newFS = tankProperties[slot].getContents();
if (newFS != null) {
if (this.fluidHandler.drain( 1, false ) == null){
newFS = null;
skipSlots.add( slot );
}
}

this.handlePossibleSlotChanges( slot, oldAEFS, newFS, changes );
}
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/appeng/parts/misc/ItemHandlerAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import java.util.List;
import java.util.Map;

import it.unimi.dsi.fastutil.ints.IntList;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.items.IItemHandler;

import appeng.api.AEApi;
Expand Down Expand Up @@ -268,10 +270,12 @@ private static class InventoryCache
{
private IAEItemStack[] cachedAeStacks = new IAEItemStack[0];
private final IItemHandler itemHandler;
private ArrayList<Integer> skipSlots;

public InventoryCache( IItemHandler itemHandler )
{
this.itemHandler = itemHandler;
this.skipSlots = new ArrayList<>(this.itemHandler.getSlots());
}

public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
Expand All @@ -289,14 +293,22 @@ public List<IAEItemStack> update()
if( slots > this.cachedAeStacks.length )
{
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, slots );
this.skipSlots = new ArrayList<>(this.itemHandler.getSlots());
}

for( int slot = 0; slot < slots; slot++ )
{
if (skipSlots.contains( slot ))
continue;
// Save the old stuff
final IAEItemStack oldAeIS = this.cachedAeStacks[slot];
final ItemStack newIS = this.itemHandler.getStackInSlot( slot );

ItemStack newIS = this.itemHandler.getStackInSlot( slot );
if (!newIS.isEmpty()) {
if (this.itemHandler.extractItem( slot,1,true ).isEmpty()){
newIS = ItemStack.EMPTY;
skipSlots.add( slot );
}
}
this.handlePossibleSlotChanges( slot, oldAeIS, newIS, changes );
}

Expand Down

0 comments on commit e2e6f6e

Please sign in to comment.