Fix Platform#postChanges to check all registered channels (#3644)
This commit is contained in:
@@ -28,6 +28,7 @@ import java.util.Collection;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
@@ -35,6 +36,7 @@ import appeng.api.networking.crafting.ICraftingLink;
|
||||
import appeng.api.networking.crafting.ICraftingRequester;
|
||||
import appeng.api.networking.energy.IEnergySource;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.networking.storage.IStorageGrid;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
@@ -116,4 +118,15 @@ public interface IStorageHelper
|
||||
* @return items not inserted or {@code null} if everything was inserted.
|
||||
*/
|
||||
<T extends IAEStack<T>> T poweredInsert( final IEnergySource energy, final IMEInventory<T> inv, final T input, final IActionSource src, final Actionable mode );
|
||||
|
||||
/**
|
||||
* Posts alteration of stored items to the provided {@link IStorageGrid}.
|
||||
* This can be used by cell containers to notify the grid of storage cell changes.
|
||||
*
|
||||
* @param gs the storage grid.
|
||||
* @param removedCell the removed cell itemstack
|
||||
* @param addedCell the added cell itemstack
|
||||
* @param src the action source
|
||||
*/
|
||||
void postChanges( @Nonnull final IStorageGrid gs, @Nonnull final ItemStack removedCell, @Nonnull final ItemStack addedCell, @Nonnull final IActionSource src );
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import appeng.api.networking.crafting.ICraftingLink;
|
||||
import appeng.api.networking.crafting.ICraftingRequester;
|
||||
import appeng.api.networking.energy.IEnergySource;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.networking.storage.IStorageGrid;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.IStorageHelper;
|
||||
@@ -119,6 +120,17 @@ public class ApiStorage implements IStorageHelper
|
||||
return Platform.poweredExtraction( energy, inv, request, src, mode );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postChanges( IStorageGrid gs, ItemStack removedCell, ItemStack addedCell, IActionSource src )
|
||||
{
|
||||
Preconditions.checkNotNull( gs );
|
||||
Preconditions.checkNotNull( removedCell );
|
||||
Preconditions.checkNotNull( addedCell );
|
||||
Preconditions.checkNotNull( src );
|
||||
|
||||
Platform.postChanges( gs, removedCell, addedCell, src );
|
||||
}
|
||||
|
||||
private static final class ItemStorageChannel implements IItemStorageChannel
|
||||
{
|
||||
|
||||
|
||||
@@ -101,8 +101,7 @@ import appeng.api.networking.storage.IStorageGrid;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IMEMonitorHandlerReceiver;
|
||||
import appeng.api.storage.channels.IFluidStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
@@ -1281,56 +1280,36 @@ public class Platform
|
||||
return input;
|
||||
}
|
||||
|
||||
@SuppressWarnings( { "rawtypes", "unchecked" } )
|
||||
public static void postChanges( final IStorageGrid gs, final ItemStack removed, final ItemStack added, final IActionSource src )
|
||||
{
|
||||
|
||||
final IItemStorageChannel itemChannel = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
|
||||
final IFluidStorageChannel fluidChannel = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
|
||||
final IItemList<IAEItemStack> itemChanges = itemChannel.createList();
|
||||
final IItemList<IAEFluidStack> fluidChanges = fluidChannel.createList();
|
||||
|
||||
if( !removed.isEmpty() )
|
||||
for( final IStorageChannel<?> chan : AEApi.instance().storage().storageChannels() )
|
||||
{
|
||||
final IMEInventory<IAEItemStack> myItems = AEApi.instance().registries().cell().getCellInventory( removed, null, itemChannel );
|
||||
final IItemList<?> myChanges = chan.createList();
|
||||
|
||||
if( myItems != null )
|
||||
if( !removed.isEmpty() )
|
||||
{
|
||||
for( final IAEItemStack is : myItems.getAvailableItems( itemChanges ) )
|
||||
final IMEInventory myInv = AEApi.instance().registries().cell().getCellInventory( removed, null, chan );
|
||||
if( myInv != null )
|
||||
{
|
||||
is.setStackSize( -is.getStackSize() );
|
||||
myInv.getAvailableItems( myChanges );
|
||||
for( final IAEStack is : myChanges )
|
||||
{
|
||||
is.setStackSize( -is.getStackSize() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final IMEInventory<IAEFluidStack> myFluids = AEApi.instance().registries().cell().getCellInventory( removed, null, fluidChannel );
|
||||
|
||||
if( myFluids != null )
|
||||
if( !added.isEmpty() )
|
||||
{
|
||||
for( final IAEFluidStack is : myFluids.getAvailableItems( fluidChanges ) )
|
||||
final IMEInventory myInv = AEApi.instance().registries().cell().getCellInventory( added, null, chan );
|
||||
if( myInv != null )
|
||||
{
|
||||
is.setStackSize( -is.getStackSize() );
|
||||
myInv.getAvailableItems( myChanges );
|
||||
}
|
||||
|
||||
}
|
||||
gs.postAlterationOfStoredItems( chan, myChanges, src );
|
||||
}
|
||||
|
||||
if( !added.isEmpty() )
|
||||
{
|
||||
final IMEInventory<IAEItemStack> myItems = AEApi.instance().registries().cell().getCellInventory( added, null, itemChannel );
|
||||
|
||||
if( myItems != null )
|
||||
{
|
||||
myItems.getAvailableItems( itemChanges );
|
||||
}
|
||||
|
||||
final IMEInventory<IAEFluidStack> myFluids = AEApi.instance().registries().cell().getCellInventory( added, null, fluidChannel );
|
||||
|
||||
if( myFluids != null )
|
||||
{
|
||||
myFluids.getAvailableItems( fluidChanges );
|
||||
}
|
||||
}
|
||||
|
||||
gs.postAlterationOfStoredItems( itemChannel, itemChanges, src );
|
||||
gs.postAlterationOfStoredItems( fluidChannel, fluidChanges, src );
|
||||
}
|
||||
|
||||
public static <T extends IAEStack<T>> void postListChanges( final IItemList<T> before, final IItemList<T> after, final IMEMonitorHandlerReceiver<T> meMonitorPassthrough, final IActionSource source )
|
||||
|
||||
Reference in New Issue
Block a user