@@ -31,9 +31,9 @@ import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.IContainerListener;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.ForgeModContainer;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
@@ -107,12 +107,11 @@ public class ContainerFluidTerminal extends AEBaseContainer implements IConfigMa
|
||||
{
|
||||
this.serverCM = terminal.getConfigManager();
|
||||
this.monitor = terminal.getInventory( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) );
|
||||
|
||||
|
||||
if( this.monitor != null )
|
||||
{
|
||||
{
|
||||
this.monitor.addListener( this, null );
|
||||
|
||||
|
||||
|
||||
if( terminal instanceof IEnergySource )
|
||||
{
|
||||
this.setPowerSource( (IEnergySource) terminal );
|
||||
@@ -142,7 +141,7 @@ public class ContainerFluidTerminal extends AEBaseContainer implements IConfigMa
|
||||
this.setPowerSource( new ChannelPowerSrc( this.networkNode, (IEnergySource) g.getCache( IEnergyGrid.class ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -355,20 +354,19 @@ public class ContainerFluidTerminal extends AEBaseContainer implements IConfigMa
|
||||
return;
|
||||
}
|
||||
ItemStack held = player.inventory.getItemStack();
|
||||
if( !held.hasCapability( CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null ) )
|
||||
{ // For now only do simple i/o with held tanks
|
||||
if( held.getCount() != 1 )
|
||||
{
|
||||
// only support stacksize 1 for now
|
||||
return;
|
||||
}
|
||||
IFluidHandlerItem fh = FluidUtil.getFluidHandler( held );
|
||||
if( fh == null )
|
||||
{
|
||||
throw new NullPointerException( held.getDisplayName() + " did not give FLUID_HANDLER_ITEM_CAPABILITY" );
|
||||
// only fluid handlers items
|
||||
return;
|
||||
}
|
||||
boolean isBucket = held.getItem() == Items.BUCKET ||
|
||||
held.getItem() == Items.WATER_BUCKET ||
|
||||
held.getItem() == Items.LAVA_BUCKET ||
|
||||
held.getItem() == Items.MILK_BUCKET ||
|
||||
held.getItem() == ForgeModContainer.getInstance().universalBucket;
|
||||
boolean isBucket = held.getItem() == Items.BUCKET || held.getItem() == Items.WATER_BUCKET || held.getItem() == Items.LAVA_BUCKET || held
|
||||
.getItem() == Items.MILK_BUCKET || held.getItem() == ForgeModContainer.getInstance().universalBucket;
|
||||
|
||||
if( action == InventoryAction.FILL_ITEM && this.clientRequestedTargetFluid != null )
|
||||
{
|
||||
@@ -377,7 +375,7 @@ public class ContainerFluidTerminal extends AEBaseContainer implements IConfigMa
|
||||
AELog.debug( "Filling %s with %s, %s mb", held.getDisplayName(), this.clientRequestedTargetFluid.getFluidStack().getLocalizedName(),
|
||||
stack.getStackSize() );
|
||||
|
||||
if( isBucket && stack.getStackSize() < 1000 )
|
||||
if( isBucket && stack.getStackSize() < Fluid.BUCKET_VOLUME )
|
||||
{ // Although buckets support less than a buckets worth of fluid, it does not display how much it holds
|
||||
return;
|
||||
}
|
||||
@@ -388,8 +386,8 @@ public class ContainerFluidTerminal extends AEBaseContainer implements IConfigMa
|
||||
stack.setStackSize( amountAllowed );
|
||||
|
||||
// Check if we can pull out of the system
|
||||
IAEFluidStack canPull = this.monitor.extractItems( stack, Actionable.SIMULATE, this.getActionSource() );
|
||||
if( canPull == null || canPull.getStackSize() < 1 || ( isBucket && canPull.getStackSize() < 1000 ) )
|
||||
IAEFluidStack canPull = Platform.poweredExtraction( this.getPowerSource(), this.monitor, stack, this.getActionSource(), Actionable.SIMULATE );
|
||||
if( canPull == null || canPull.getStackSize() < 1 || ( isBucket && canPull.getStackSize() != Fluid.BUCKET_VOLUME ) )
|
||||
{
|
||||
// Either we couldn't pull out of the system,
|
||||
// or we are using a bucket and can only pull out less than a buckets worth of fluid
|
||||
@@ -405,16 +403,10 @@ public class ContainerFluidTerminal extends AEBaseContainer implements IConfigMa
|
||||
return;
|
||||
}
|
||||
|
||||
if( isBucket )
|
||||
{
|
||||
// We need to handle buckets separately
|
||||
ItemStack filledBucket = FluidUtil.getFilledBucket( pulled.getFluidStack() );
|
||||
player.inventory.setItemStack( filledBucket );
|
||||
}
|
||||
else
|
||||
{
|
||||
fh.fill( pulled.getFluidStack(), true );
|
||||
}
|
||||
// Actually fill
|
||||
fh.fill( pulled.getFluidStack(), true );
|
||||
|
||||
player.inventory.setItemStack( fh.getContainer() );
|
||||
this.updateHeld( player );
|
||||
}
|
||||
else if( action == InventoryAction.EMPTY_ITEM )
|
||||
@@ -430,31 +422,26 @@ public class ContainerFluidTerminal extends AEBaseContainer implements IConfigMa
|
||||
}
|
||||
|
||||
// Check if we can push into the system
|
||||
IAEFluidStack canPush = this.monitor.injectItems( AEFluidStack.fromFluidStack( extract ), Actionable.SIMULATE, this.getActionSource() );
|
||||
if( isBucket && canPush != null && canPush.getStackSize() > 0 )
|
||||
IAEFluidStack notPushed = Platform.poweredInsert( this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack( extract ),
|
||||
this.getActionSource(), Actionable.SIMULATE );
|
||||
if( isBucket && notPushed != null && notPushed.getStackSize() > 0 )
|
||||
{
|
||||
// We can't push enough for the bucket
|
||||
return;
|
||||
}
|
||||
|
||||
IAEFluidStack inserted = Platform.poweredInsert( this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack( extract ),
|
||||
IAEFluidStack notInserted = Platform.poweredInsert( this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack( extract ),
|
||||
this.getActionSource() );
|
||||
if( inserted != null && inserted.getStackSize() > 0 )
|
||||
if( notInserted != null && notInserted.getStackSize() > 0 )
|
||||
{
|
||||
// Only try to extract the amount we DID insert
|
||||
extract.amount -= Math.toIntExact( inserted.getStackSize() );
|
||||
extract.amount -= Math.toIntExact( notInserted.getStackSize() );
|
||||
}
|
||||
|
||||
if( isBucket )
|
||||
{
|
||||
// Remove bucket and replace with EmptyBucket
|
||||
player.inventory.setItemStack( new ItemStack( Items.BUCKET, 1 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Actually drain
|
||||
fh.drain( extract, true );
|
||||
}
|
||||
// Actually drain
|
||||
fh.drain( extract, true );
|
||||
|
||||
player.inventory.setItemStack( fh.getContainer() );
|
||||
this.updateHeld( player );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1173,6 +1173,11 @@ public class Platform
|
||||
}
|
||||
|
||||
public static <T extends IAEStack<T>> T poweredExtraction( final IEnergySource energy, final IMEInventory<T> cell, final T request, final IActionSource src )
|
||||
{
|
||||
return poweredExtraction( energy, cell, request, src, Actionable.MODULATE );
|
||||
}
|
||||
|
||||
public static <T extends IAEStack<T>> T poweredExtraction( final IEnergySource energy, final IMEInventory<T> cell, final T request, final IActionSource src, final Actionable mode )
|
||||
{
|
||||
final T possible = cell.extractItems( request.copy(), Actionable.SIMULATE, src );
|
||||
|
||||
@@ -1182,29 +1187,39 @@ public class Platform
|
||||
retrieved = possible.getStackSize();
|
||||
}
|
||||
|
||||
final double availablePower = energy.extractAEPower( retrieved, Actionable.SIMULATE, PowerMultiplier.CONFIG );
|
||||
|
||||
final long itemToExtract = Math.min( (long) ( availablePower + 0.9 ), retrieved );
|
||||
final double energyFactor = Math.max( 1.0, cell.getChannel().transferFactor() );
|
||||
final double availablePower = energy.extractAEPower( retrieved / energyFactor, Actionable.SIMULATE, PowerMultiplier.CONFIG );
|
||||
final long itemToExtract = Math.min( (long) ( ( availablePower * energyFactor ) + 0.9 ), retrieved );
|
||||
|
||||
if( itemToExtract > 0 )
|
||||
{
|
||||
energy.extractAEPower( retrieved, Actionable.MODULATE, PowerMultiplier.CONFIG );
|
||||
|
||||
possible.setStackSize( itemToExtract );
|
||||
final T ret = cell.extractItems( possible, Actionable.MODULATE, src );
|
||||
|
||||
if( ret != null )
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
src.player().ifPresent( player -> Stats.ItemsExtracted.addToPlayer( player, (int) ret.getStackSize() ) );
|
||||
}
|
||||
energy.extractAEPower( retrieved / energyFactor, Actionable.MODULATE, PowerMultiplier.CONFIG );
|
||||
possible.setStackSize( itemToExtract );
|
||||
final T ret = cell.extractItems( possible, Actionable.MODULATE, src );
|
||||
|
||||
return ret;
|
||||
if( ret != null )
|
||||
{
|
||||
src.player().ifPresent( player -> Stats.ItemsExtracted.addToPlayer( player, (int) ret.getStackSize() ) );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
return possible.setStackSize( itemToExtract );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T extends IAEStack<T>> T poweredInsert( final IEnergySource energy, final IMEInventory<T> cell, final T input, final IActionSource src )
|
||||
{
|
||||
return poweredInsert( energy, cell, input, src, Actionable.MODULATE );
|
||||
}
|
||||
|
||||
public static <T extends IAEStack<T>> T poweredInsert( final IEnergySource energy, final IMEInventory<T> cell, final T input, final IActionSource src, final Actionable mode )
|
||||
{
|
||||
final T possible = cell.injectItems( input.copy(), Actionable.SIMULATE, src );
|
||||
|
||||
@@ -1214,40 +1229,47 @@ public class Platform
|
||||
stored -= possible.getStackSize();
|
||||
}
|
||||
|
||||
final int energyFactor = Math.min( 1, input.getChannel().transferFactor() );
|
||||
final double energyFactor = Math.max( 1.0, cell.getChannel().transferFactor() );
|
||||
final double availablePower = energy.extractAEPower( stored / energyFactor, Actionable.SIMULATE, PowerMultiplier.CONFIG );
|
||||
final long itemToAdd = Math.min( (long) ( availablePower + 0.9 ), stored );
|
||||
final long itemToAdd = Math.min( (long) ( ( availablePower * energyFactor ) + 0.9 ), stored );
|
||||
|
||||
if( itemToAdd > 0 )
|
||||
{
|
||||
energy.extractAEPower( stored / energyFactor, Actionable.MODULATE, PowerMultiplier.CONFIG );
|
||||
|
||||
if( itemToAdd < input.getStackSize() )
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
final long original = input.getStackSize();
|
||||
final T split = input.copy();
|
||||
split.decStackSize( itemToAdd );
|
||||
input.setStackSize( itemToAdd );
|
||||
split.add( cell.injectItems( input, Actionable.MODULATE, src ) );
|
||||
energy.extractAEPower( stored / energyFactor, Actionable.MODULATE, PowerMultiplier.CONFIG );
|
||||
if( itemToAdd < input.getStackSize() )
|
||||
{
|
||||
final long original = input.getStackSize();
|
||||
final T split = input.copy();
|
||||
split.decStackSize( itemToAdd );
|
||||
input.setStackSize( itemToAdd );
|
||||
split.add( cell.injectItems( input, Actionable.MODULATE, src ) );
|
||||
|
||||
src.player().ifPresent( player ->
|
||||
{
|
||||
final long diff = original - split.getStackSize();
|
||||
Stats.ItemsInserted.addToPlayer( player, (int) diff );
|
||||
} );
|
||||
|
||||
return split;
|
||||
}
|
||||
|
||||
final T ret = cell.injectItems( input, Actionable.MODULATE, src );
|
||||
|
||||
src.player().ifPresent( player ->
|
||||
{
|
||||
final long diff = original - split.getStackSize();
|
||||
final long diff = ret == null ? input.getStackSize() : input.getStackSize() - ret.getStackSize();
|
||||
Stats.ItemsInserted.addToPlayer( player, (int) diff );
|
||||
} );
|
||||
|
||||
return split;
|
||||
return ret;
|
||||
}
|
||||
|
||||
final T ret = cell.injectItems( input, Actionable.MODULATE, src );
|
||||
|
||||
src.player().ifPresent( player ->
|
||||
else
|
||||
{
|
||||
final long diff = ret == null ? input.getStackSize() : input.getStackSize() - ret.getStackSize();
|
||||
Stats.ItemsInserted.addToPlayer( player, (int) diff );
|
||||
} );
|
||||
|
||||
return ret;
|
||||
final T ret = input.copy().setStackSize( input.getStackSize() - itemToAdd );
|
||||
return ( ret != null && ret.getStackSize() > 0 ) ? ret : null;
|
||||
}
|
||||
}
|
||||
|
||||
return input;
|
||||
|
||||
Reference in New Issue
Block a user