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