pick 97420a31d The big reformat of 2020
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -45,253 +44,213 @@ import appeng.me.GridAccessException;
|
||||
import appeng.me.helpers.IGridProxyable;
|
||||
import appeng.me.storage.ITickingMonitor;
|
||||
|
||||
|
||||
/**
|
||||
* Wraps an Fluid Handler in such a way that it can be used as an IMEInventory for fluids.
|
||||
* Wraps an Fluid Handler in such a way that it can be used as an IMEInventory
|
||||
* for fluids.
|
||||
*
|
||||
* @author BrockWS
|
||||
* @version rv6 - 22/05/2018
|
||||
* @since rv6 22/05/2018
|
||||
*/
|
||||
public class FluidHandlerAdapter implements IMEInventory<IAEFluidStack>, IBaseMonitor<IAEFluidStack>, ITickingMonitor
|
||||
{
|
||||
private final Map<IMEMonitorHandlerReceiver<IAEFluidStack>, Object> listeners = new HashMap<>();
|
||||
private IActionSource source;
|
||||
private final IFluidHandler fluidHandler;
|
||||
private final IGridProxyable proxyable;
|
||||
private final FluidHandlerAdapter.InventoryCache cache;
|
||||
public class FluidHandlerAdapter implements IMEInventory<IAEFluidStack>, IBaseMonitor<IAEFluidStack>, ITickingMonitor {
|
||||
private final Map<IMEMonitorHandlerReceiver<IAEFluidStack>, Object> listeners = new HashMap<>();
|
||||
private IActionSource source;
|
||||
private final IFluidHandler fluidHandler;
|
||||
private final IGridProxyable proxyable;
|
||||
private final FluidHandlerAdapter.InventoryCache cache;
|
||||
|
||||
FluidHandlerAdapter( IFluidHandler fluidHandler, IGridProxyable proxy )
|
||||
{
|
||||
this.fluidHandler = fluidHandler;
|
||||
this.proxyable = proxy;
|
||||
this.cache = new FluidHandlerAdapter.InventoryCache( this.fluidHandler );
|
||||
}
|
||||
FluidHandlerAdapter(IFluidHandler fluidHandler, IGridProxyable proxy) {
|
||||
this.fluidHandler = fluidHandler;
|
||||
this.proxyable = proxy;
|
||||
this.cache = new FluidHandlerAdapter.InventoryCache(this.fluidHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidStack injectItems( IAEFluidStack input, Actionable type, IActionSource src )
|
||||
{
|
||||
FluidStack fluidStack = input.getFluidStack();
|
||||
@Override
|
||||
public IAEFluidStack injectItems(IAEFluidStack input, Actionable type, IActionSource src) {
|
||||
FluidStack fluidStack = input.getFluidStack();
|
||||
|
||||
// Insert
|
||||
int wasFillled = this.fluidHandler.fill( fluidStack, type.getFluidAction() );
|
||||
int remaining = fluidStack.getAmount() - wasFillled;
|
||||
if( fluidStack.getAmount() == remaining )
|
||||
{
|
||||
// The stack was unmodified, target tank is full
|
||||
return input;
|
||||
}
|
||||
// Insert
|
||||
int wasFillled = this.fluidHandler.fill(fluidStack, type.getFluidAction());
|
||||
int remaining = fluidStack.getAmount() - wasFillled;
|
||||
if (fluidStack.getAmount() == remaining) {
|
||||
// The stack was unmodified, target tank is full
|
||||
return input;
|
||||
}
|
||||
|
||||
if( type == Actionable.MODULATE )
|
||||
{
|
||||
try
|
||||
{
|
||||
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
|
||||
}
|
||||
catch( GridAccessException ignore )
|
||||
{
|
||||
// meh
|
||||
}
|
||||
}
|
||||
if (type == Actionable.MODULATE) {
|
||||
try {
|
||||
this.proxyable.getProxy().getTick().alertDevice(this.proxyable.getProxy().getNode());
|
||||
} catch (GridAccessException ignore) {
|
||||
// meh
|
||||
}
|
||||
}
|
||||
|
||||
fluidStack.setAmount( remaining );
|
||||
fluidStack.setAmount(remaining);
|
||||
|
||||
return AEFluidStack.fromFluidStack( fluidStack );
|
||||
}
|
||||
return AEFluidStack.fromFluidStack(fluidStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEFluidStack extractItems( IAEFluidStack request, Actionable mode, IActionSource src )
|
||||
{
|
||||
FluidStack requestedFluidStack = request.getFluidStack();
|
||||
@Override
|
||||
public IAEFluidStack extractItems(IAEFluidStack request, Actionable mode, IActionSource src) {
|
||||
FluidStack requestedFluidStack = request.getFluidStack();
|
||||
|
||||
// Drain the fluid from the tank
|
||||
FluidStack gathered = this.fluidHandler.drain( requestedFluidStack, mode.getFluidAction() );
|
||||
if( gathered == null )
|
||||
{
|
||||
// If nothing was pulled from the tank, return null
|
||||
return null;
|
||||
}
|
||||
// Drain the fluid from the tank
|
||||
FluidStack gathered = this.fluidHandler.drain(requestedFluidStack, mode.getFluidAction());
|
||||
if (gathered == null) {
|
||||
// If nothing was pulled from the tank, return null
|
||||
return null;
|
||||
}
|
||||
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
try
|
||||
{
|
||||
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
|
||||
}
|
||||
catch( GridAccessException ignore )
|
||||
{
|
||||
// meh
|
||||
}
|
||||
}
|
||||
return AEFluidStack.fromFluidStack( gathered );
|
||||
}
|
||||
if (mode == Actionable.MODULATE) {
|
||||
try {
|
||||
this.proxyable.getProxy().getTick().alertDevice(this.proxyable.getProxy().getNode());
|
||||
} catch (GridAccessException ignore) {
|
||||
// meh
|
||||
}
|
||||
}
|
||||
return AEFluidStack.fromFluidStack(gathered);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation onTick()
|
||||
{
|
||||
List<IAEFluidStack> changes = this.cache.update();
|
||||
if( !changes.isEmpty() )
|
||||
{
|
||||
this.postDifference( changes );
|
||||
return TickRateModulation.URGENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public TickRateModulation onTick() {
|
||||
List<IAEFluidStack> changes = this.cache.update();
|
||||
if (!changes.isEmpty()) {
|
||||
this.postDifference(changes);
|
||||
return TickRateModulation.URGENT;
|
||||
} else {
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<IAEFluidStack> getAvailableItems( IItemList<IAEFluidStack> out )
|
||||
{
|
||||
return this.cache.getAvailableItems( out );
|
||||
}
|
||||
@Override
|
||||
public IItemList<IAEFluidStack> getAvailableItems(IItemList<IAEFluidStack> out) {
|
||||
return this.cache.getAvailableItems(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel<IAEFluidStack> getChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
|
||||
}
|
||||
@Override
|
||||
public IStorageChannel<IAEFluidStack> getChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActionSource( IActionSource source )
|
||||
{
|
||||
this.source = source;
|
||||
}
|
||||
@Override
|
||||
public void setActionSource(IActionSource source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener( final IMEMonitorHandlerReceiver<IAEFluidStack> l, final Object verificationToken )
|
||||
{
|
||||
this.listeners.put( l, verificationToken );
|
||||
}
|
||||
@Override
|
||||
public void addListener(final IMEMonitorHandlerReceiver<IAEFluidStack> l, final Object verificationToken) {
|
||||
this.listeners.put(l, verificationToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener( final IMEMonitorHandlerReceiver<IAEFluidStack> l )
|
||||
{
|
||||
this.listeners.remove( l );
|
||||
}
|
||||
@Override
|
||||
public void removeListener(final IMEMonitorHandlerReceiver<IAEFluidStack> l) {
|
||||
this.listeners.remove(l);
|
||||
}
|
||||
|
||||
private void postDifference( Iterable<IAEFluidStack> a )
|
||||
{
|
||||
final Iterator<Map.Entry<IMEMonitorHandlerReceiver<IAEFluidStack>, Object>> i = this.listeners.entrySet().iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
final Map.Entry<IMEMonitorHandlerReceiver<IAEFluidStack>, Object> l = i.next();
|
||||
final IMEMonitorHandlerReceiver<IAEFluidStack> key = l.getKey();
|
||||
if( key.isValid( l.getValue() ) )
|
||||
{
|
||||
key.postChange( this, a, this.source );
|
||||
}
|
||||
else
|
||||
{
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void postDifference(Iterable<IAEFluidStack> a) {
|
||||
final Iterator<Map.Entry<IMEMonitorHandlerReceiver<IAEFluidStack>, Object>> i = this.listeners.entrySet()
|
||||
.iterator();
|
||||
while (i.hasNext()) {
|
||||
final Map.Entry<IMEMonitorHandlerReceiver<IAEFluidStack>, Object> l = i.next();
|
||||
final IMEMonitorHandlerReceiver<IAEFluidStack> key = l.getKey();
|
||||
if (key.isValid(l.getValue())) {
|
||||
key.postChange(this, a, this.source);
|
||||
} else {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class InventoryCache
|
||||
{
|
||||
private IAEFluidStack[] cachedAeStacks = new IAEFluidStack[0];
|
||||
private final IFluidHandler fluidHandler;
|
||||
private static class InventoryCache {
|
||||
private IAEFluidStack[] cachedAeStacks = new IAEFluidStack[0];
|
||||
private final IFluidHandler fluidHandler;
|
||||
|
||||
public InventoryCache( IFluidHandler fluidHandler )
|
||||
{
|
||||
this.fluidHandler = fluidHandler;
|
||||
}
|
||||
public InventoryCache(IFluidHandler fluidHandler) {
|
||||
this.fluidHandler = fluidHandler;
|
||||
}
|
||||
|
||||
public List<IAEFluidStack> update()
|
||||
{
|
||||
final List<IAEFluidStack> changes = new ArrayList<>();
|
||||
final int slots = fluidHandler.getTanks();
|
||||
public List<IAEFluidStack> update() {
|
||||
final List<IAEFluidStack> changes = new ArrayList<>();
|
||||
final int slots = fluidHandler.getTanks();
|
||||
|
||||
// Make room for new slots
|
||||
if( slots > this.cachedAeStacks.length )
|
||||
{
|
||||
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, slots );
|
||||
}
|
||||
// Make room for new slots
|
||||
if (slots > this.cachedAeStacks.length) {
|
||||
this.cachedAeStacks = Arrays.copyOf(this.cachedAeStacks, slots);
|
||||
}
|
||||
|
||||
for( int slot = 0; slot < slots; slot++ )
|
||||
{
|
||||
// Save the old stuff
|
||||
final IAEFluidStack oldAEFS = this.cachedAeStacks[slot];
|
||||
final FluidStack newFS = fluidHandler.getFluidInTank( slot );
|
||||
for (int slot = 0; slot < slots; slot++) {
|
||||
// Save the old stuff
|
||||
final IAEFluidStack oldAEFS = this.cachedAeStacks[slot];
|
||||
final FluidStack newFS = fluidHandler.getFluidInTank(slot);
|
||||
|
||||
this.handlePossibleSlotChanges( slot, oldAEFS, newFS, changes );
|
||||
}
|
||||
this.handlePossibleSlotChanges(slot, oldAEFS, newFS, changes);
|
||||
}
|
||||
|
||||
// Handle cases where the number of slots actually is lower now than before
|
||||
if( slots < this.cachedAeStacks.length )
|
||||
{
|
||||
for( int slot = slots; slot < this.cachedAeStacks.length; slot++ )
|
||||
{
|
||||
final IAEFluidStack aeStack = this.cachedAeStacks[slot];
|
||||
// Handle cases where the number of slots actually is lower now than before
|
||||
if (slots < this.cachedAeStacks.length) {
|
||||
for (int slot = slots; slot < this.cachedAeStacks.length; slot++) {
|
||||
final IAEFluidStack aeStack = this.cachedAeStacks[slot];
|
||||
|
||||
if( aeStack != null )
|
||||
{
|
||||
final IAEFluidStack a = aeStack.copy();
|
||||
a.setStackSize( -a.getStackSize() );
|
||||
changes.add( a );
|
||||
}
|
||||
}
|
||||
if (aeStack != null) {
|
||||
final IAEFluidStack a = aeStack.copy();
|
||||
a.setStackSize(-a.getStackSize());
|
||||
changes.add(a);
|
||||
}
|
||||
}
|
||||
|
||||
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, slots );
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
this.cachedAeStacks = Arrays.copyOf(this.cachedAeStacks, slots);
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
|
||||
public IItemList<IAEFluidStack> getAvailableItems( IItemList<IAEFluidStack> out )
|
||||
{
|
||||
Arrays.stream( this.cachedAeStacks ).forEach( out::add );
|
||||
return out;
|
||||
}
|
||||
public IItemList<IAEFluidStack> getAvailableItems(IItemList<IAEFluidStack> out) {
|
||||
Arrays.stream(this.cachedAeStacks).forEach(out::add);
|
||||
return out;
|
||||
}
|
||||
|
||||
private void handlePossibleSlotChanges( int slot, IAEFluidStack oldAeFS, FluidStack newFS, List<IAEFluidStack> changes )
|
||||
{
|
||||
if( oldAeFS != null && oldAeFS.getFluidStack().isFluidEqual( newFS ) )
|
||||
{
|
||||
this.handleStackSizeChanged( slot, oldAeFS, newFS, changes );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.handleFluidChanged( slot, oldAeFS, newFS, changes );
|
||||
}
|
||||
}
|
||||
private void handlePossibleSlotChanges(int slot, IAEFluidStack oldAeFS, FluidStack newFS,
|
||||
List<IAEFluidStack> changes) {
|
||||
if (oldAeFS != null && oldAeFS.getFluidStack().isFluidEqual(newFS)) {
|
||||
this.handleStackSizeChanged(slot, oldAeFS, newFS, changes);
|
||||
} else {
|
||||
this.handleFluidChanged(slot, oldAeFS, newFS, changes);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleStackSizeChanged( int slot, IAEFluidStack oldAeFS, FluidStack newFS, List<IAEFluidStack> changes )
|
||||
{
|
||||
// Still the same fluid, but amount might have changed
|
||||
final long diff = newFS.getAmount() - oldAeFS.getStackSize();
|
||||
private void handleStackSizeChanged(int slot, IAEFluidStack oldAeFS, FluidStack newFS,
|
||||
List<IAEFluidStack> changes) {
|
||||
// Still the same fluid, but amount might have changed
|
||||
final long diff = newFS.getAmount() - oldAeFS.getStackSize();
|
||||
|
||||
if( diff != 0 )
|
||||
{
|
||||
final IAEFluidStack stack = oldAeFS.copy();
|
||||
stack.setStackSize( newFS.getAmount() );
|
||||
if (diff != 0) {
|
||||
final IAEFluidStack stack = oldAeFS.copy();
|
||||
stack.setStackSize(newFS.getAmount());
|
||||
|
||||
this.cachedAeStacks[slot] = stack;
|
||||
this.cachedAeStacks[slot] = stack;
|
||||
|
||||
final IAEFluidStack a = stack.copy();
|
||||
a.setStackSize( diff );
|
||||
changes.add( a );
|
||||
}
|
||||
}
|
||||
final IAEFluidStack a = stack.copy();
|
||||
a.setStackSize(diff);
|
||||
changes.add(a);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleFluidChanged( int slot, IAEFluidStack oldAeFS, FluidStack newFS, List<IAEFluidStack> changes )
|
||||
{
|
||||
// Completely different fluid
|
||||
this.cachedAeStacks[slot] = AEFluidStack.fromFluidStack( newFS );
|
||||
private void handleFluidChanged(int slot, IAEFluidStack oldAeFS, FluidStack newFS,
|
||||
List<IAEFluidStack> changes) {
|
||||
// Completely different fluid
|
||||
this.cachedAeStacks[slot] = AEFluidStack.fromFluidStack(newFS);
|
||||
|
||||
// If we had a stack previously in this slot, notify the network about its disappearance
|
||||
if( oldAeFS != null )
|
||||
{
|
||||
oldAeFS.setStackSize( -oldAeFS.getStackSize() );
|
||||
changes.add( oldAeFS );
|
||||
}
|
||||
// If we had a stack previously in this slot, notify the network about its
|
||||
// disappearance
|
||||
if (oldAeFS != null) {
|
||||
oldAeFS.setStackSize(-oldAeFS.getStackSize());
|
||||
changes.add(oldAeFS);
|
||||
}
|
||||
|
||||
// Notify the network about the new stack. Note that this is null if newFS was null
|
||||
if( this.cachedAeStacks[slot] != null )
|
||||
{
|
||||
changes.add( this.cachedAeStacks[slot] );
|
||||
}
|
||||
}
|
||||
}
|
||||
// Notify the network about the new stack. Note that this is null if newFS was
|
||||
// null
|
||||
if (this.cachedAeStacks[slot] != null) {
|
||||
changes.add(this.cachedAeStacks[slot]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import appeng.parts.automation.PlaneModelData;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.advancements.CriteriaTriggers;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
@@ -63,289 +63,255 @@ import appeng.me.GridAccessException;
|
||||
import appeng.me.helpers.MachineSource;
|
||||
import appeng.parts.PartBasicState;
|
||||
import appeng.parts.automation.PlaneConnections;
|
||||
import appeng.parts.automation.PlaneModelData;
|
||||
import appeng.parts.automation.PlaneModels;
|
||||
import appeng.util.Platform;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
public class PartFluidAnnihilationPlane extends PartBasicState implements IGridTickable {
|
||||
private static final PlaneModels MODELS = new PlaneModels("part/fluid_annihilation_plane",
|
||||
"part/fluid_annihilation_plane_on");
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels() {
|
||||
return MODELS.getModels();
|
||||
}
|
||||
|
||||
public class PartFluidAnnihilationPlane extends PartBasicState implements IGridTickable
|
||||
{
|
||||
private static final PlaneModels MODELS = new PlaneModels( "part/fluid_annihilation_plane", "part/fluid_annihilation_plane_on" );
|
||||
private final IActionSource mySrc = new MachineSource(this);
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels()
|
||||
{
|
||||
return MODELS.getModels();
|
||||
}
|
||||
public PartFluidAnnihilationPlane(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
private final IActionSource mySrc = new MachineSource( this );
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
int minX = 1;
|
||||
int minY = 1;
|
||||
int maxX = 15;
|
||||
int maxY = 15;
|
||||
|
||||
public PartFluidAnnihilationPlane( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
final IPartHost host = this.getHost();
|
||||
if (host != null) {
|
||||
final TileEntity te = host.getTile();
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
int minX = 1;
|
||||
int minY = 1;
|
||||
int maxX = 15;
|
||||
int maxY = 15;
|
||||
final BlockPos pos = te.getPos();
|
||||
|
||||
final IPartHost host = this.getHost();
|
||||
if( host != null )
|
||||
{
|
||||
final TileEntity te = host.getTile();
|
||||
final Direction e = bch.getWorldX();
|
||||
final Direction u = bch.getWorldY();
|
||||
|
||||
final BlockPos pos = te.getPos();
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(e.getOpposite())), this.getSide())) {
|
||||
minX = 0;
|
||||
}
|
||||
|
||||
final Direction e = bch.getWorldX();
|
||||
final Direction u = bch.getWorldY();
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(e)), this.getSide())) {
|
||||
maxX = 16;
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( e.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
minX = 0;
|
||||
}
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(u.getOpposite())), this.getSide())) {
|
||||
minY = 0;
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( e ) ), this.getSide() ) )
|
||||
{
|
||||
maxX = 16;
|
||||
}
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(e)), this.getSide())) {
|
||||
maxY = 16;
|
||||
}
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( u.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
minY = 0;
|
||||
}
|
||||
bch.addBox(5, 5, 14, 11, 11, 15);
|
||||
bch.addBox(minX, minY, 15, maxX, maxY, 16);
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( e ) ), this.getSide() ) )
|
||||
{
|
||||
maxY = 16;
|
||||
}
|
||||
}
|
||||
public PlaneConnections getConnections() {
|
||||
|
||||
bch.addBox( 5, 5, 14, 11, 11, 15 );
|
||||
bch.addBox( minX, minY, 15, maxX, maxY, 16 );
|
||||
}
|
||||
final Direction facingRight, facingUp;
|
||||
AEPartLocation location = this.getSide();
|
||||
switch (location) {
|
||||
case UP:
|
||||
facingRight = Direction.EAST;
|
||||
facingUp = Direction.NORTH;
|
||||
break;
|
||||
case DOWN:
|
||||
facingRight = Direction.WEST;
|
||||
facingUp = Direction.NORTH;
|
||||
break;
|
||||
case NORTH:
|
||||
facingRight = Direction.WEST;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
case SOUTH:
|
||||
facingRight = Direction.EAST;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
case WEST:
|
||||
facingRight = Direction.SOUTH;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
case EAST:
|
||||
facingRight = Direction.NORTH;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
default:
|
||||
case INTERNAL:
|
||||
return PlaneConnections.of(false, false, false, false);
|
||||
}
|
||||
|
||||
public PlaneConnections getConnections()
|
||||
{
|
||||
boolean left = false, right = false, down = false, up = false;
|
||||
|
||||
final Direction facingRight, facingUp;
|
||||
AEPartLocation location = this.getSide();
|
||||
switch( location )
|
||||
{
|
||||
case UP:
|
||||
facingRight = Direction.EAST;
|
||||
facingUp = Direction.NORTH;
|
||||
break;
|
||||
case DOWN:
|
||||
facingRight = Direction.WEST;
|
||||
facingUp = Direction.NORTH;
|
||||
break;
|
||||
case NORTH:
|
||||
facingRight = Direction.WEST;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
case SOUTH:
|
||||
facingRight = Direction.EAST;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
case WEST:
|
||||
facingRight = Direction.SOUTH;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
case EAST:
|
||||
facingRight = Direction.NORTH;
|
||||
facingUp = Direction.UP;
|
||||
break;
|
||||
default:
|
||||
case INTERNAL:
|
||||
return PlaneConnections.of( false, false, false, false );
|
||||
}
|
||||
final IPartHost host = this.getHost();
|
||||
if (host != null) {
|
||||
final TileEntity te = host.getTile();
|
||||
|
||||
boolean left = false, right = false, down = false, up = false;
|
||||
final BlockPos pos = te.getPos();
|
||||
|
||||
final IPartHost host = this.getHost();
|
||||
if( host != null )
|
||||
{
|
||||
final TileEntity te = host.getTile();
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(facingRight.getOpposite())),
|
||||
this.getSide())) {
|
||||
left = true;
|
||||
}
|
||||
|
||||
final BlockPos pos = te.getPos();
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(facingRight)), this.getSide())) {
|
||||
right = true;
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingRight.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
left = true;
|
||||
}
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(facingUp.getOpposite())),
|
||||
this.getSide())) {
|
||||
down = true;
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingRight ) ), this.getSide() ) )
|
||||
{
|
||||
right = true;
|
||||
}
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(facingUp)), this.getSide())) {
|
||||
up = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingUp.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
down = true;
|
||||
}
|
||||
return PlaneConnections.of(up, right, down, left);
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingUp ) ), this.getSide() ) )
|
||||
{
|
||||
up = true;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockReader w, BlockPos pos, BlockPos neighbor) {
|
||||
if (pos.offset(this.getSide().getFacing()).equals(neighbor)) {
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
return PlaneConnections.of( up, right, down, left );
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockReader w, BlockPos pos, BlockPos neighbor )
|
||||
{
|
||||
if( pos.offset( this.getSide().getFacing() ).equals( neighbor ) )
|
||||
{
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
private boolean isAnnihilationPlane(final TileEntity blockTileEntity, final AEPartLocation side) {
|
||||
if (blockTileEntity instanceof IPartHost) {
|
||||
final IPart p = ((IPartHost) blockTileEntity).getPart(side);
|
||||
return p != null && p.getClass() == this.getClass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
private void refresh() {
|
||||
try {
|
||||
this.getProxy().getTick().alertDevice(this.getProxy().getNode());
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAnnihilationPlane( final TileEntity blockTileEntity, final AEPartLocation side )
|
||||
{
|
||||
if( blockTileEntity instanceof IPartHost )
|
||||
{
|
||||
final IPart p = ( (IPartHost) blockTileEntity ).getPart( side );
|
||||
return p != null && p.getClass() == this.getClass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void chanRender(final MENetworkChannelsChanged c) {
|
||||
this.refresh();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
private void refresh()
|
||||
{
|
||||
try
|
||||
{
|
||||
this.getProxy().getTick().alertDevice( this.getProxy().getNode() );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(final MENetworkPowerStatusChange c) {
|
||||
this.refresh();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void chanRender( final MENetworkChannelsChanged c )
|
||||
{
|
||||
this.refresh();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
private TickRateModulation pickupFluid() {
|
||||
if (!this.getProxy().isActive()) {
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.refresh();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
final TileEntity te = this.getTile();
|
||||
final World w = te.getWorld();
|
||||
final BlockPos pos = te.getPos().offset(this.getSide().getFacing());
|
||||
|
||||
private TickRateModulation pickupFluid()
|
||||
{
|
||||
if( !this.getProxy().isActive() )
|
||||
{
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
BlockState blockstate = w.getBlockState(pos);
|
||||
if (blockstate.getBlock() instanceof IBucketPickupHandler) {
|
||||
IFluidState fluidState = blockstate.getFluidState();
|
||||
|
||||
final TileEntity te = this.getTile();
|
||||
final World w = te.getWorld();
|
||||
final BlockPos pos = te.getPos().offset( this.getSide().getFacing() );
|
||||
Fluid fluid = fluidState.getFluid();
|
||||
if (fluid != Fluids.EMPTY && fluidState.isSource()) {
|
||||
|
||||
BlockState blockstate = w.getBlockState(pos);
|
||||
if (blockstate.getBlock() instanceof IBucketPickupHandler) {
|
||||
IFluidState fluidState = blockstate.getFluidState();
|
||||
// Attempt to store the fluid in the network
|
||||
final IAEFluidStack blockFluid = AEFluidStack
|
||||
.fromFluidStack(new FluidStack(fluidState.getFluid(), FluidAttributes.BUCKET_VOLUME));
|
||||
if (this.storeFluid(blockFluid, false)) {
|
||||
// If that would succeed, actually slurp up the liquid as if we were using a
|
||||
// bucket
|
||||
// This _MIGHT_ change the liquid, and if it does, and we dont have enough
|
||||
// space,
|
||||
// tough luck. you loose the source block.
|
||||
fluid = ((IBucketPickupHandler) blockstate.getBlock()).pickupFluid(w, pos, blockstate);
|
||||
this.storeFluid(AEFluidStack.fromFluidStack(new FluidStack(fluid, FluidAttributes.BUCKET_VOLUME)),
|
||||
true);
|
||||
|
||||
Fluid fluid = fluidState.getFluid();
|
||||
if (fluid != Fluids.EMPTY && fluidState.isSource()) {
|
||||
AppEng.proxy.sendToAllNearExcept(null, pos.getX(), pos.getY(), pos.getZ(), 64, w,
|
||||
new PacketTransitionEffect(pos.getX(), pos.getY(), pos.getZ(), this.getSide(), true));
|
||||
|
||||
// Attempt to store the fluid in the network
|
||||
final IAEFluidStack blockFluid = AEFluidStack.fromFluidStack( new FluidStack(fluidState.getFluid(), FluidAttributes.BUCKET_VOLUME) );
|
||||
if( this.storeFluid( blockFluid, false ) )
|
||||
{
|
||||
// If that would succeed, actually slurp up the liquid as if we were using a bucket
|
||||
// This _MIGHT_ change the liquid, and if it does, and we dont have enough space,
|
||||
// tough luck. you loose the source block.
|
||||
fluid = ((IBucketPickupHandler)blockstate.getBlock()).pickupFluid(w, pos, blockstate);
|
||||
this.storeFluid( AEFluidStack.fromFluidStack( new FluidStack( fluid, FluidAttributes.BUCKET_VOLUME) ), true );
|
||||
return TickRateModulation.URGENT;
|
||||
}
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
}
|
||||
|
||||
AppEng.proxy.sendToAllNearExcept( null, pos.getX(), pos.getY(), pos.getZ(), 64, w,
|
||||
new PacketTransitionEffect( pos.getX(), pos.getY(), pos.getZ(), this.getSide(), true ) );
|
||||
// nothing to do here :)
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
return TickRateModulation.URGENT;
|
||||
}
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(final IGridNode node) {
|
||||
return new TickingRequest(TickRates.AnnihilationPlane.getMin(), TickRates.AnnihilationPlane.getMax(), false,
|
||||
true);
|
||||
}
|
||||
|
||||
// nothing to do here :)
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
|
||||
return this.pickupFluid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest( final IGridNode node )
|
||||
{
|
||||
return new TickingRequest( TickRates.AnnihilationPlane.getMin(), TickRates.AnnihilationPlane.getMax(), false, true );
|
||||
}
|
||||
private boolean storeFluid(IAEFluidStack stack, boolean modulate) {
|
||||
try {
|
||||
final IStorageGrid storage = this.getProxy().getStorage();
|
||||
final IMEInventory<IAEFluidStack> inv = storage
|
||||
.getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class));
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
|
||||
{
|
||||
return this.pickupFluid();
|
||||
}
|
||||
if (modulate) {
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
return Platform.poweredInsert(energy, inv, stack, this.mySrc) == null;
|
||||
} else {
|
||||
final float requiredPower = stack.getStackSize() / Math.min(1.0f, stack.getChannel().transferFactor());
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
|
||||
private boolean storeFluid( IAEFluidStack stack, boolean modulate )
|
||||
{
|
||||
try
|
||||
{
|
||||
final IStorageGrid storage = this.getProxy().getStorage();
|
||||
final IMEInventory<IAEFluidStack> inv = storage.getInventory( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) );
|
||||
if (energy.extractAEPower(requiredPower, Actionable.SIMULATE, PowerMultiplier.CONFIG) < requiredPower) {
|
||||
return false;
|
||||
}
|
||||
final IAEFluidStack leftOver = inv.injectItems(stack, Actionable.SIMULATE, this.mySrc);
|
||||
return leftOver == null || leftOver.getStackSize() == 0;
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if( modulate )
|
||||
{
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
return Platform.poweredInsert( energy, inv, stack, this.mySrc ) == null;
|
||||
}
|
||||
else
|
||||
{
|
||||
final float requiredPower = stack.getStackSize() / Math.min( 1.0f, stack.getChannel().transferFactor() );
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return MODELS.getModel(this.isPowered(), this.isActive());
|
||||
}
|
||||
|
||||
if( energy.extractAEPower( requiredPower, Actionable.SIMULATE, PowerMultiplier.CONFIG ) < requiredPower )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
final IAEFluidStack leftOver = inv.injectItems( stack, Actionable.SIMULATE, this.mySrc );
|
||||
return leftOver == null || leftOver.getStackSize() == 0;
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return MODELS.getModel( this.isPowered(), this.isActive() );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IModelData getModelData() {
|
||||
return new PlaneModelData(getConnections());
|
||||
}
|
||||
@Nonnull
|
||||
@Override
|
||||
public IModelData getModelData() {
|
||||
return new PlaneModelData(getConnections());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -50,143 +49,121 @@ import appeng.me.GridAccessException;
|
||||
import appeng.me.helpers.MachineSource;
|
||||
import appeng.parts.PartModel;
|
||||
|
||||
|
||||
/**
|
||||
* @author BrockWS
|
||||
* @version rv6 - 30/04/2018
|
||||
* @since rv6 30/04/2018
|
||||
*/
|
||||
public class PartFluidExportBus extends PartSharedFluidBus
|
||||
{
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/fluid_export_bus_base" );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_export_bus_off" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_export_bus_on" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_export_bus_has_channel" ) );
|
||||
public class PartFluidExportBus extends PartSharedFluidBus {
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/fluid_export_bus_base");
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_export_bus_off"));
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_export_bus_on"));
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_export_bus_has_channel"));
|
||||
|
||||
private final IActionSource source;
|
||||
private final IActionSource source;
|
||||
|
||||
public PartFluidExportBus( ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
this.getConfigManager().registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
|
||||
this.getConfigManager().registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
||||
this.getConfigManager().registerSetting( Settings.CRAFT_ONLY, YesNo.NO );
|
||||
this.getConfigManager().registerSetting( Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT );
|
||||
this.source = new MachineSource( this );
|
||||
}
|
||||
public PartFluidExportBus(ItemStack is) {
|
||||
super(is);
|
||||
this.getConfigManager().registerSetting(Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE);
|
||||
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
|
||||
this.getConfigManager().registerSetting(Settings.CRAFT_ONLY, YesNo.NO);
|
||||
this.getConfigManager().registerSetting(Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT);
|
||||
this.source = new MachineSource(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest( IGridNode node )
|
||||
{
|
||||
return new TickingRequest( TickRates.FluidExportBus.getMin(), TickRates.FluidExportBus.getMax(), this.isSleeping(), false );
|
||||
}
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node) {
|
||||
return new TickingRequest(TickRates.FluidExportBus.getMin(), TickRates.FluidExportBus.getMax(),
|
||||
this.isSleeping(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest( IGridNode node, int ticksSinceLastCall )
|
||||
{
|
||||
return this.canDoBusWork() ? this.doBusWork() : TickRateModulation.IDLE;
|
||||
}
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) {
|
||||
return this.canDoBusWork() ? this.doBusWork() : TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canDoBusWork()
|
||||
{
|
||||
return this.getProxy().isActive();
|
||||
}
|
||||
@Override
|
||||
protected boolean canDoBusWork() {
|
||||
return this.getProxy().isActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TickRateModulation doBusWork()
|
||||
{
|
||||
if( !this.canDoBusWork() )
|
||||
{
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
@Override
|
||||
protected TickRateModulation doBusWork() {
|
||||
if (!this.canDoBusWork()) {
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
final TileEntity te = this.getConnectedTE();
|
||||
LazyOptional<IFluidHandler> fhOpt = LazyOptional.empty();
|
||||
if( te != null )
|
||||
{
|
||||
te.getCapability( CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, this.getSide().getFacing().getOpposite() );
|
||||
}
|
||||
if( fhOpt.isPresent() )
|
||||
{
|
||||
try
|
||||
{
|
||||
final IFluidHandler fh = fhOpt.orElse( null );
|
||||
final IMEMonitor<IAEFluidStack> inv = this.getProxy().getStorage().getInventory( this.getChannel() );
|
||||
final TileEntity te = this.getConnectedTE();
|
||||
LazyOptional<IFluidHandler> fhOpt = LazyOptional.empty();
|
||||
if (te != null) {
|
||||
te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, this.getSide().getFacing().getOpposite());
|
||||
}
|
||||
if (fhOpt.isPresent()) {
|
||||
try {
|
||||
final IFluidHandler fh = fhOpt.orElse(null);
|
||||
final IMEMonitor<IAEFluidStack> inv = this.getProxy().getStorage().getInventory(this.getChannel());
|
||||
|
||||
if( fh != null )
|
||||
{
|
||||
for( int i = 0; i < this.getConfig().getSlots(); i++ )
|
||||
{
|
||||
IAEFluidStack fluid = this.getConfig().getFluidInSlot( i );
|
||||
if( fluid != null )
|
||||
{
|
||||
final IAEFluidStack toExtract = fluid.copy();
|
||||
if (fh != null) {
|
||||
for (int i = 0; i < this.getConfig().getSlots(); i++) {
|
||||
IAEFluidStack fluid = this.getConfig().getFluidInSlot(i);
|
||||
if (fluid != null) {
|
||||
final IAEFluidStack toExtract = fluid.copy();
|
||||
|
||||
toExtract.setStackSize( this.calculateAmountToSend() );
|
||||
toExtract.setStackSize(this.calculateAmountToSend());
|
||||
|
||||
final IAEFluidStack out = inv.extractItems( toExtract, Actionable.SIMULATE, this.source );
|
||||
final IAEFluidStack out = inv.extractItems(toExtract, Actionable.SIMULATE, this.source);
|
||||
|
||||
if( out != null )
|
||||
{
|
||||
int wasInserted = fh.fill( out.getFluidStack(), FluidAction.EXECUTE );
|
||||
if (out != null) {
|
||||
int wasInserted = fh.fill(out.getFluidStack(), FluidAction.EXECUTE);
|
||||
|
||||
if( wasInserted > 0 )
|
||||
{
|
||||
toExtract.setStackSize( wasInserted );
|
||||
inv.extractItems( toExtract, Actionable.MODULATE, this.source );
|
||||
if (wasInserted > 0) {
|
||||
toExtract.setStackSize(wasInserted);
|
||||
inv.extractItems(toExtract, Actionable.MODULATE, this.source);
|
||||
|
||||
return TickRateModulation.FASTER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return TickRateModulation.FASTER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
} catch (GridAccessException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 4, 4, 12, 12, 12, 14 );
|
||||
bch.addBox( 5, 5, 14, 11, 11, 15 );
|
||||
bch.addBox( 6, 6, 15, 10, 10, 16 );
|
||||
bch.addBox( 6, 6, 11, 10, 10, 12 );
|
||||
}
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(4, 4, 12, 12, 12, 14);
|
||||
bch.addBox(5, 5, 14, 11, 11, 15);
|
||||
bch.addBox(6, 6, 15, 10, 10, 16);
|
||||
bch.addBox(6, 6, 11, 10, 10, 12);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneMode getRSMode()
|
||||
{
|
||||
return (RedstoneMode) this.getConfigManager().getSetting( Settings.REDSTONE_CONTROLLED );
|
||||
}
|
||||
@Override
|
||||
public RedstoneMode getRSMode() {
|
||||
return (RedstoneMode) this.getConfigManager().getSetting(Settings.REDSTONE_CONTROLLED);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
if( this.isActive() && this.isPowered() )
|
||||
{
|
||||
return MODELS_HAS_CHANNEL;
|
||||
}
|
||||
else if( this.isPowered() )
|
||||
{
|
||||
return MODELS_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
@Nonnull
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
if (this.isActive() && this.isPowered()) {
|
||||
return MODELS_HAS_CHANNEL;
|
||||
} else if (this.isPowered()) {
|
||||
return MODELS_ON;
|
||||
} else {
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerFormationPlane;
|
||||
import appeng.fluids.container.ContainerFluidFormationPlane;
|
||||
import appeng.parts.automation.PlaneModelData;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
@@ -22,7 +19,6 @@ import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
@@ -47,7 +43,10 @@ import appeng.api.storage.channels.IFluidStorageChannel;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerFormationPlane;
|
||||
import appeng.fluids.container.ContainerFluidFormationPlane;
|
||||
import appeng.fluids.util.AEFluidInventory;
|
||||
import appeng.fluids.util.IAEFluidInventory;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
@@ -55,197 +54,168 @@ import appeng.items.parts.PartModels;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.storage.MEInventoryHandler;
|
||||
import appeng.parts.automation.PartAbstractFormationPlane;
|
||||
import appeng.parts.automation.PlaneModelData;
|
||||
import appeng.parts.automation.PlaneModels;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.prioritylist.PrecisePriorityList;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
public class PartFluidFormationPlane extends PartAbstractFormationPlane<IAEFluidStack> implements IAEFluidInventory {
|
||||
private static final PlaneModels MODELS = new PlaneModels("part/fluid_formation_plane",
|
||||
"part/fluid_formation_plane_on");
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels() {
|
||||
return MODELS.getModels();
|
||||
}
|
||||
|
||||
public class PartFluidFormationPlane extends PartAbstractFormationPlane<IAEFluidStack> implements IAEFluidInventory
|
||||
{
|
||||
private static final PlaneModels MODELS = new PlaneModels( "part/fluid_formation_plane", "part/fluid_formation_plane_on" );
|
||||
private final MEInventoryHandler<IAEFluidStack> myHandler = new MEInventoryHandler<>(this,
|
||||
AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class));
|
||||
private final AEFluidInventory config = new AEFluidInventory(this, 63);
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels()
|
||||
{
|
||||
return MODELS.getModels();
|
||||
}
|
||||
public PartFluidFormationPlane(final ItemStack is) {
|
||||
super(is);
|
||||
this.updateHandler();
|
||||
}
|
||||
|
||||
private final MEInventoryHandler<IAEFluidStack> myHandler = new MEInventoryHandler<>( this, AEApi.instance()
|
||||
.storage()
|
||||
.getStorageChannel( IFluidStorageChannel.class ) );
|
||||
private final AEFluidInventory config = new AEFluidInventory( this, 63 );
|
||||
@Override
|
||||
protected void updateHandler() {
|
||||
this.myHandler.setBaseAccess(AccessRestriction.WRITE);
|
||||
this.myHandler.setWhitelist(
|
||||
this.getInstalledUpgrades(Upgrades.INVERTER) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST);
|
||||
this.myHandler.setPriority(this.getPriority());
|
||||
|
||||
public PartFluidFormationPlane( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
this.updateHandler();
|
||||
}
|
||||
final IItemList<IAEFluidStack> priorityList = AEApi.instance().storage()
|
||||
.getStorageChannel(IFluidStorageChannel.class).createList();
|
||||
|
||||
@Override
|
||||
protected void updateHandler()
|
||||
{
|
||||
this.myHandler.setBaseAccess( AccessRestriction.WRITE );
|
||||
this.myHandler.setWhitelist( this.getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST );
|
||||
this.myHandler.setPriority( this.getPriority() );
|
||||
final int slotsToUse = 18 + this.getInstalledUpgrades(Upgrades.CAPACITY) * 9;
|
||||
for (int x = 0; x < this.config.getSlots() && x < slotsToUse; x++) {
|
||||
final IAEFluidStack is = this.config.getFluidInSlot(x);
|
||||
if (is != null) {
|
||||
priorityList.add(is);
|
||||
}
|
||||
}
|
||||
this.myHandler.setPartitionList(new PrecisePriorityList<IAEFluidStack>(priorityList));
|
||||
|
||||
final IItemList<IAEFluidStack> priorityList = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
|
||||
try {
|
||||
this.getProxy().getGrid().postEvent(new MENetworkCellArrayUpdate());
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
final int slotsToUse = 18 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 9;
|
||||
for( int x = 0; x < this.config.getSlots() && x < slotsToUse; x++ )
|
||||
{
|
||||
final IAEFluidStack is = this.config.getFluidInSlot( x );
|
||||
if( is != null )
|
||||
{
|
||||
priorityList.add( is );
|
||||
}
|
||||
}
|
||||
this.myHandler.setPartitionList( new PrecisePriorityList<IAEFluidStack>( priorityList ) );
|
||||
@Override
|
||||
public IAEFluidStack injectItems(IAEFluidStack input, Actionable type, IActionSource src) {
|
||||
if (this.blocked || input == null || input.getStackSize() < FluidAttributes.BUCKET_VOLUME) {
|
||||
// need a full bucket
|
||||
return input;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
this.getProxy().getGrid().postEvent( new MENetworkCellArrayUpdate() );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
final TileEntity te = this.getHost().getTile();
|
||||
final World w = te.getWorld();
|
||||
final AEPartLocation side = this.getSide();
|
||||
final BlockPos pos = te.getPos().offset(side.getFacing());
|
||||
final BlockState state = w.getBlockState(pos);
|
||||
|
||||
@Override
|
||||
public IAEFluidStack injectItems( IAEFluidStack input, Actionable type, IActionSource src )
|
||||
{
|
||||
if( this.blocked || input == null || input.getStackSize() < FluidAttributes.BUCKET_VOLUME )
|
||||
{
|
||||
// need a full bucket
|
||||
return input;
|
||||
}
|
||||
if (this.canReplace(w, state, pos)) {
|
||||
if (type == Actionable.MODULATE) {
|
||||
final FluidStack fs = input.getFluidStack();
|
||||
fs.setAmount(FluidAttributes.BUCKET_VOLUME);
|
||||
|
||||
final TileEntity te = this.getHost().getTile();
|
||||
final World w = te.getWorld();
|
||||
final AEPartLocation side = this.getSide();
|
||||
final BlockPos pos = te.getPos().offset( side.getFacing() );
|
||||
final BlockState state = w.getBlockState( pos );
|
||||
final FluidTank tank = new FluidTank(FluidAttributes.BUCKET_VOLUME, e -> e.isFluidEqual(fs));
|
||||
if (!FluidUtil.tryPlaceFluid(null, w, Hand.MAIN_HAND, pos, tank, fs)) {
|
||||
return input;
|
||||
}
|
||||
}
|
||||
final IAEFluidStack ret = input.copy();
|
||||
ret.setStackSize(input.getStackSize() - FluidAttributes.BUCKET_VOLUME);
|
||||
return ret.getStackSize() == 0 ? null : ret;
|
||||
}
|
||||
this.blocked = true;
|
||||
return input;
|
||||
}
|
||||
|
||||
if( this.canReplace( w, state, pos ) )
|
||||
{
|
||||
if( type == Actionable.MODULATE )
|
||||
{
|
||||
final FluidStack fs = input.getFluidStack();
|
||||
fs.setAmount( FluidAttributes.BUCKET_VOLUME );
|
||||
private boolean canReplace(World w, BlockState state, BlockPos pos) {
|
||||
return state.getMaterial().isReplaceable() && w.getFluidState(pos).isEmpty() && !state.getMaterial().isLiquid();
|
||||
}
|
||||
|
||||
final FluidTank tank = new FluidTank( FluidAttributes.BUCKET_VOLUME, e -> e.isFluidEqual( fs ) );
|
||||
if( !FluidUtil.tryPlaceFluid( null, w, Hand.MAIN_HAND, pos, tank, fs ) )
|
||||
{
|
||||
return input;
|
||||
}
|
||||
}
|
||||
final IAEFluidStack ret = input.copy();
|
||||
ret.setStackSize( input.getStackSize() - FluidAttributes.BUCKET_VOLUME );
|
||||
return ret.getStackSize() == 0 ? null : ret;
|
||||
}
|
||||
this.blocked = true;
|
||||
return input;
|
||||
}
|
||||
@Override
|
||||
public void onFluidInventoryChanged(IAEFluidTank inv, int slot) {
|
||||
if (inv == this.config) {
|
||||
this.updateHandler();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canReplace( World w, BlockState state, BlockPos pos )
|
||||
{
|
||||
return state.getMaterial().isReplaceable() && w.getFluidState(pos).isEmpty() && !state.getMaterial().isLiquid();
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final CompoundNBT data) {
|
||||
super.readFromNBT(data);
|
||||
this.config.readFromNBT(data, "config");
|
||||
this.updateHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFluidInventoryChanged( IAEFluidTank inv, int slot )
|
||||
{
|
||||
if( inv == this.config )
|
||||
{
|
||||
this.updateHandler();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final CompoundNBT data) {
|
||||
super.writeToNBT(data);
|
||||
this.config.writeToNBT(data, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final CompoundNBT data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.config.readFromNBT( data, "config" );
|
||||
this.updateHandler();
|
||||
}
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(final MENetworkPowerStatusChange c) {
|
||||
this.stateChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final CompoundNBT data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
this.config.writeToNBT( data, "config" );
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void updateChannels(final MENetworkChannelsChanged changedChannels) {
|
||||
this.stateChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.stateChanged();
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(ContainerFluidFormationPlane.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void updateChannels( final MENetworkChannelsChanged changedChannels )
|
||||
{
|
||||
this.stateChanged();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final PlayerEntity player, final Hand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
ContainerOpener.openContainer(ContainerFluidFormationPlane.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
@Override
|
||||
public IStorageChannel<IAEFluidStack> getChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public List<IMEInventoryHandler> getCellArray(final IStorageChannel channel) {
|
||||
if (this.getProxy().isActive()
|
||||
&& channel == AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)) {
|
||||
final List<IMEInventoryHandler> handler = new ArrayList<>(1);
|
||||
handler.add(this.myHandler);
|
||||
return handler;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel<IAEFluidStack> getChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return MODELS.getModel(this.isPowered(), this.isActive());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IMEInventoryHandler> getCellArray( final IStorageChannel channel )
|
||||
{
|
||||
if( this.getProxy().isActive() && channel == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) )
|
||||
{
|
||||
final List<IMEInventoryHandler> handler = new ArrayList<>( 1 );
|
||||
handler.add( this.myHandler );
|
||||
return handler;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@Nonnull
|
||||
@Override
|
||||
public IModelData getModelData() {
|
||||
return new PlaneModelData(getConnections());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return MODELS.getModel( this.isPowered(), this.isActive() );
|
||||
}
|
||||
public IAEFluidTank getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IModelData getModelData() {
|
||||
return new PlaneModelData(getConnections());
|
||||
}
|
||||
@Override
|
||||
public ItemStack getItemStackRepresentation() {
|
||||
return AEApi.instance().definitions().parts().fluidFormationnPlane().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
public IAEFluidTank getConfig()
|
||||
{
|
||||
return this.config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStackRepresentation()
|
||||
{
|
||||
return AEApi.instance().definitions().parts().fluidFormationnPlane().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerType<?> getContainerType()
|
||||
{
|
||||
return ContainerFluidFormationPlane.TYPE;
|
||||
}
|
||||
@Override
|
||||
public ContainerType<?> getContainerType() {
|
||||
return ContainerFluidFormationPlane.TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -51,157 +50,132 @@ import appeng.me.GridAccessException;
|
||||
import appeng.me.helpers.MachineSource;
|
||||
import appeng.parts.PartModel;
|
||||
|
||||
|
||||
/**
|
||||
* @author BrockWS
|
||||
* @version rv6 - 30/04/2018
|
||||
* @since rv6 30/04/2018
|
||||
*/
|
||||
public class PartFluidImportBus extends PartSharedFluidBus
|
||||
{
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/fluid_import_bus_base" );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_import_bus_off" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_import_bus_on" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_import_bus_has_channel" ) );
|
||||
public class PartFluidImportBus extends PartSharedFluidBus {
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/fluid_import_bus_base");
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_import_bus_off"));
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_import_bus_on"));
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_import_bus_has_channel"));
|
||||
|
||||
private final IActionSource source;
|
||||
private final IActionSource source;
|
||||
|
||||
public PartFluidImportBus( ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
this.getConfigManager().registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
|
||||
this.getConfigManager().registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
||||
this.getConfigManager().registerSetting( Settings.CRAFT_ONLY, YesNo.NO );
|
||||
this.getConfigManager().registerSetting( Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT );
|
||||
this.source = new MachineSource( this );
|
||||
}
|
||||
public PartFluidImportBus(ItemStack is) {
|
||||
super(is);
|
||||
this.getConfigManager().registerSetting(Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE);
|
||||
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
|
||||
this.getConfigManager().registerSetting(Settings.CRAFT_ONLY, YesNo.NO);
|
||||
this.getConfigManager().registerSetting(Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT);
|
||||
this.source = new MachineSource(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest( IGridNode node )
|
||||
{
|
||||
return new TickingRequest( TickRates.FluidImportBus.getMin(), TickRates.FluidImportBus.getMax(), this.isSleeping(), false );
|
||||
}
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node) {
|
||||
return new TickingRequest(TickRates.FluidImportBus.getMin(), TickRates.FluidImportBus.getMax(),
|
||||
this.isSleeping(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest( IGridNode node, int ticksSinceLastCall )
|
||||
{
|
||||
return this.canDoBusWork() ? this.doBusWork() : TickRateModulation.IDLE;
|
||||
}
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) {
|
||||
return this.canDoBusWork() ? this.doBusWork() : TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TickRateModulation doBusWork()
|
||||
{
|
||||
if( !this.canDoBusWork() )
|
||||
{
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
@Override
|
||||
protected TickRateModulation doBusWork() {
|
||||
if (!this.canDoBusWork()) {
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
final TileEntity te = this.getConnectedTE();
|
||||
LazyOptional<IFluidHandler> fhOpt = LazyOptional.empty();
|
||||
if( te != null )
|
||||
{
|
||||
te.getCapability( CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, this.getSide().getFacing().getOpposite() );
|
||||
}
|
||||
if( fhOpt.isPresent() )
|
||||
{
|
||||
try
|
||||
{
|
||||
final IFluidHandler fh = fhOpt.orElse( null );
|
||||
final IMEMonitor<IAEFluidStack> inv = this.getProxy().getStorage().getInventory( this.getChannel() );
|
||||
final TileEntity te = this.getConnectedTE();
|
||||
LazyOptional<IFluidHandler> fhOpt = LazyOptional.empty();
|
||||
if (te != null) {
|
||||
te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, this.getSide().getFacing().getOpposite());
|
||||
}
|
||||
if (fhOpt.isPresent()) {
|
||||
try {
|
||||
final IFluidHandler fh = fhOpt.orElse(null);
|
||||
final IMEMonitor<IAEFluidStack> inv = this.getProxy().getStorage().getInventory(this.getChannel());
|
||||
|
||||
if( fh != null )
|
||||
{
|
||||
final FluidStack fluidStack = fh.drain( this.calculateAmountToSend(), FluidAction.SIMULATE );
|
||||
if (fh != null) {
|
||||
final FluidStack fluidStack = fh.drain(this.calculateAmountToSend(), FluidAction.SIMULATE);
|
||||
|
||||
if( this.filterEnabled() && !this.isInFilter( fluidStack ) )
|
||||
{
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
if (this.filterEnabled() && !this.isInFilter(fluidStack)) {
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
|
||||
final AEFluidStack aeFluidStack = AEFluidStack.fromFluidStack( fluidStack );
|
||||
final AEFluidStack aeFluidStack = AEFluidStack.fromFluidStack(fluidStack);
|
||||
|
||||
if( aeFluidStack != null )
|
||||
{
|
||||
final IAEFluidStack notInserted = inv.injectItems( aeFluidStack, Actionable.MODULATE, this.source );
|
||||
if (aeFluidStack != null) {
|
||||
final IAEFluidStack notInserted = inv.injectItems(aeFluidStack, Actionable.MODULATE,
|
||||
this.source);
|
||||
|
||||
if( notInserted != null && notInserted.getStackSize() > 0 )
|
||||
{
|
||||
aeFluidStack.decStackSize( notInserted.getStackSize() );
|
||||
}
|
||||
if (notInserted != null && notInserted.getStackSize() > 0) {
|
||||
aeFluidStack.decStackSize(notInserted.getStackSize());
|
||||
}
|
||||
|
||||
fh.drain( aeFluidStack.getFluidStack(), FluidAction.EXECUTE );
|
||||
fh.drain(aeFluidStack.getFluidStack(), FluidAction.EXECUTE);
|
||||
|
||||
return TickRateModulation.FASTER;
|
||||
}
|
||||
return TickRateModulation.FASTER;
|
||||
}
|
||||
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
} catch (GridAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canDoBusWork()
|
||||
{
|
||||
return this.getProxy().isActive();
|
||||
}
|
||||
@Override
|
||||
protected boolean canDoBusWork() {
|
||||
return this.getProxy().isActive();
|
||||
}
|
||||
|
||||
private boolean isInFilter( FluidStack fluid )
|
||||
{
|
||||
for( int i = 0; i < this.getConfig().getSlots(); i++ )
|
||||
{
|
||||
final IAEFluidStack stack = this.getConfig().getFluidInSlot( i );
|
||||
if( stack != null && stack.equals( fluid ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private boolean isInFilter(FluidStack fluid) {
|
||||
for (int i = 0; i < this.getConfig().getSlots(); i++) {
|
||||
final IAEFluidStack stack = this.getConfig().getFluidInSlot(i);
|
||||
if (stack != null && stack.equals(fluid)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean filterEnabled()
|
||||
{
|
||||
for( int i = 0; i < this.getConfig().getSlots(); i++ )
|
||||
{
|
||||
final IAEFluidStack stack = this.getConfig().getFluidInSlot( i );
|
||||
if( stack != null )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private boolean filterEnabled() {
|
||||
for (int i = 0; i < this.getConfig().getSlots(); i++) {
|
||||
final IAEFluidStack stack = this.getConfig().getFluidInSlot(i);
|
||||
if (stack != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneMode getRSMode()
|
||||
{
|
||||
return (RedstoneMode) this.getConfigManager().getSetting( Settings.REDSTONE_CONTROLLED );
|
||||
}
|
||||
@Override
|
||||
public RedstoneMode getRSMode() {
|
||||
return (RedstoneMode) this.getConfigManager().getSetting(Settings.REDSTONE_CONTROLLED);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
if( this.isActive() && this.isPowered() )
|
||||
{
|
||||
return MODELS_HAS_CHANNEL;
|
||||
}
|
||||
else if( this.isPowered() )
|
||||
{
|
||||
return MODELS_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
@Nonnull
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
if (this.isActive() && this.isPowered()) {
|
||||
return MODELS_HAS_CHANNEL;
|
||||
} else if (this.isPowered()) {
|
||||
return MODELS_ON;
|
||||
} else {
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,8 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -54,8 +50,10 @@ import appeng.api.storage.IStorageMonitorable;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.core.AppEng;
|
||||
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import appeng.fluids.helper.DualityFluidInterface;
|
||||
import appeng.fluids.helper.IFluidInterfaceHost;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
@@ -65,182 +63,154 @@ import appeng.parts.PartBasicState;
|
||||
import appeng.parts.PartModel;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class PartFluidInterface extends PartBasicState
|
||||
implements IGridTickable, IStorageMonitorable, IFluidInterfaceHost, IPriorityHost {
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/fluid_interface_base");
|
||||
|
||||
public class PartFluidInterface extends PartBasicState implements IGridTickable, IStorageMonitorable, IFluidInterfaceHost, IPriorityHost
|
||||
{
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/fluid_interface_base" );
|
||||
@PartModels
|
||||
public static final PartModel MODELS_OFF = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_interface_off"));
|
||||
|
||||
@PartModels
|
||||
public static final PartModel MODELS_OFF = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_interface_off" ) );
|
||||
@PartModels
|
||||
public static final PartModel MODELS_ON = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_interface_on"));
|
||||
|
||||
@PartModels
|
||||
public static final PartModel MODELS_ON = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_interface_on" ) );
|
||||
@PartModels
|
||||
public static final PartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_interface_has_channel"));
|
||||
|
||||
@PartModels
|
||||
public static final PartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_interface_has_channel" ) );
|
||||
private final DualityFluidInterface duality = new DualityFluidInterface(this.getProxy(), this);
|
||||
|
||||
private final DualityFluidInterface duality = new DualityFluidInterface( this.getProxy(), this );
|
||||
@Reflected
|
||||
public PartFluidInterface(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Reflected
|
||||
public PartFluidInterface( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
@Override
|
||||
public DualityFluidInterface getDualityFluidInterface() {
|
||||
return this.duality;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DualityFluidInterface getDualityFluidInterface()
|
||||
{
|
||||
return this.duality;
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange(final MENetworkChannelsChanged c) {
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange( final MENetworkChannelsChanged c )
|
||||
{
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange(final MENetworkPowerStatusChange c) {
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(2, 2, 14, 14, 14, 16);
|
||||
bch.addBox(5, 5, 12, 11, 11, 14);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 2, 2, 14, 14, 14, 16 );
|
||||
bch.addBox( 5, 5, 12, 11, 11, 14 );
|
||||
}
|
||||
@Override
|
||||
public void gridChanged() {
|
||||
this.duality.gridChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gridChanged()
|
||||
{
|
||||
this.duality.gridChanged();
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final CompoundNBT data) {
|
||||
super.readFromNBT(data);
|
||||
this.duality.readFromNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final CompoundNBT data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.duality.readFromNBT( data );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final CompoundNBT data) {
|
||||
super.writeToNBT(data);
|
||||
this.duality.writeToNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final CompoundNBT data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
this.duality.writeToNBT( data );
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final PlayerEntity p, final Hand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(ContainerFluidInterface.TYPE, p, ContainerLocator.forPart(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final PlayerEntity p, final Hand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
ContainerOpener.openContainer(ContainerFluidInterface.TYPE, p, ContainerLocator.forPart(this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public <T extends IAEStack<T>> IMEMonitor<T> getInventory(IStorageChannel<T> channel) {
|
||||
return this.duality.getInventory(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends IAEStack<T>> IMEMonitor<T> getInventory( IStorageChannel<T> channel )
|
||||
{
|
||||
return this.duality.getInventory( channel );
|
||||
}
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(final IGridNode node) {
|
||||
return this.duality.getTickingRequest(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest( final IGridNode node )
|
||||
{
|
||||
return this.duality.getTickingRequest( node );
|
||||
}
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
|
||||
return this.duality.tickingRequest(node, ticksSinceLastCall);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
|
||||
{
|
||||
return this.duality.tickingRequest( node, ticksSinceLastCall );
|
||||
}
|
||||
@Override
|
||||
public EnumSet<Direction> getTargets() {
|
||||
return EnumSet.of(this.getSide().getFacing());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<Direction> getTargets()
|
||||
{
|
||||
return EnumSet.of( this.getSide().getFacing() );
|
||||
}
|
||||
@Override
|
||||
public TileEntity getTileEntity() {
|
||||
return super.getHost().getTile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTileEntity()
|
||||
{
|
||||
return super.getHost().getTile();
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
if (this.isActive() && this.isPowered()) {
|
||||
return MODELS_HAS_CHANNEL;
|
||||
} else if (this.isPowered()) {
|
||||
return MODELS_ON;
|
||||
} else {
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
if( this.isActive() && this.isPowered() )
|
||||
{
|
||||
return MODELS_HAS_CHANNEL;
|
||||
}
|
||||
else if( this.isPowered() )
|
||||
{
|
||||
return MODELS_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return this.duality.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
{
|
||||
return this.duality.getPriority();
|
||||
}
|
||||
@Override
|
||||
public void setPriority(final int newValue) {
|
||||
this.duality.setPriority(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPriority( final int newValue )
|
||||
{
|
||||
this.duality.setPriority( newValue );
|
||||
}
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(Capability<T> capabilityClass) {
|
||||
return this.duality.getCapability(capabilityClass, this.getSide().getFacing());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> LazyOptional<T> getCapability(Capability<T> capabilityClass )
|
||||
{
|
||||
return this.duality.getCapability( capabilityClass, this.getSide().getFacing() );
|
||||
}
|
||||
@Override
|
||||
public int getInstalledUpgrades(Upgrades u) {
|
||||
return this.duality.getInstalledUpgrades(u);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstalledUpgrades( Upgrades u )
|
||||
{
|
||||
return this.duality.getInstalledUpgrades( u );
|
||||
}
|
||||
@Override
|
||||
public IConfigManager getConfigManager() {
|
||||
return this.duality.getConfigManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return this.duality.getConfigManager();
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getInventoryByName(String name) {
|
||||
return this.duality.getInventoryByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName( String name )
|
||||
{
|
||||
return this.duality.getInventoryByName( name );
|
||||
}
|
||||
@Override
|
||||
public ItemStack getItemStackRepresentation() {
|
||||
return AEApi.instance().definitions().parts().fluidIface().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStackRepresentation()
|
||||
{
|
||||
return AEApi.instance().definitions().parts().fluidIface().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerType<?> getContainerType()
|
||||
{
|
||||
return ContainerFluidInterface.TYPE;
|
||||
}
|
||||
@Override
|
||||
public ContainerType<?> getContainerType() {
|
||||
return ContainerFluidInterface.TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.fluids.container.ContainerFluidLevelEmitter;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
@@ -39,8 +35,10 @@ import appeng.api.storage.data.IItemList;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.core.AppEng;
|
||||
|
||||
import appeng.fluids.container.ContainerFluidLevelEmitter;
|
||||
import appeng.fluids.util.AEFluidInventory;
|
||||
import appeng.fluids.util.IAEFluidInventory;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
@@ -51,329 +49,276 @@ import appeng.parts.automation.PartUpgradeable;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class PartFluidLevelEmitter extends PartUpgradeable
|
||||
implements IStackWatcherHost, IConfigManagerHost, IAEFluidInventory, IMEMonitorHandlerReceiver<IAEFluidStack> {
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE_OFF = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/level_emitter_base_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE_ON = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/level_emitter_base_on");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/level_emitter_status_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/level_emitter_status_on");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/level_emitter_status_has_channel");
|
||||
|
||||
public class PartFluidLevelEmitter extends PartUpgradeable implements IStackWatcherHost, IConfigManagerHost, IAEFluidInventory, IMEMonitorHandlerReceiver<IAEFluidStack>
|
||||
{
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE_OFF = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_base_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE_ON = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_base_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_status_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_status_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_status_has_channel" );
|
||||
public static final PartModel MODEL_OFF_OFF = new PartModel(MODEL_BASE_OFF, MODEL_STATUS_OFF);
|
||||
public static final PartModel MODEL_OFF_ON = new PartModel(MODEL_BASE_OFF, MODEL_STATUS_ON);
|
||||
public static final PartModel MODEL_OFF_HAS_CHANNEL = new PartModel(MODEL_BASE_OFF, MODEL_STATUS_HAS_CHANNEL);
|
||||
public static final PartModel MODEL_ON_OFF = new PartModel(MODEL_BASE_ON, MODEL_STATUS_OFF);
|
||||
public static final PartModel MODEL_ON_ON = new PartModel(MODEL_BASE_ON, MODEL_STATUS_ON);
|
||||
public static final PartModel MODEL_ON_HAS_CHANNEL = new PartModel(MODEL_BASE_ON, MODEL_STATUS_HAS_CHANNEL);
|
||||
|
||||
public static final PartModel MODEL_OFF_OFF = new PartModel( MODEL_BASE_OFF, MODEL_STATUS_OFF );
|
||||
public static final PartModel MODEL_OFF_ON = new PartModel( MODEL_BASE_OFF, MODEL_STATUS_ON );
|
||||
public static final PartModel MODEL_OFF_HAS_CHANNEL = new PartModel( MODEL_BASE_OFF, MODEL_STATUS_HAS_CHANNEL );
|
||||
public static final PartModel MODEL_ON_OFF = new PartModel( MODEL_BASE_ON, MODEL_STATUS_OFF );
|
||||
public static final PartModel MODEL_ON_ON = new PartModel( MODEL_BASE_ON, MODEL_STATUS_ON );
|
||||
public static final PartModel MODEL_ON_HAS_CHANNEL = new PartModel( MODEL_BASE_ON, MODEL_STATUS_HAS_CHANNEL );
|
||||
private static final int FLAG_ON = 4;
|
||||
|
||||
private static final int FLAG_ON = 4;
|
||||
private boolean prevState = false;
|
||||
private long lastReportedValue = 0;
|
||||
private long reportingValue = 0;
|
||||
private IStackWatcher stackWatcher = null;
|
||||
private final AEFluidInventory config = new AEFluidInventory(this, 1);
|
||||
|
||||
private boolean prevState = false;
|
||||
private long lastReportedValue = 0;
|
||||
private long reportingValue = 0;
|
||||
private IStackWatcher stackWatcher = null;
|
||||
private final AEFluidInventory config = new AEFluidInventory( this, 1 );
|
||||
public PartFluidLevelEmitter(ItemStack is) {
|
||||
super(is);
|
||||
|
||||
public PartFluidLevelEmitter( ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
this.getConfigManager().registerSetting(Settings.REDSTONE_EMITTER, RedstoneMode.HIGH_SIGNAL);
|
||||
}
|
||||
|
||||
this.getConfigManager().registerSetting( Settings.REDSTONE_EMITTER, RedstoneMode.HIGH_SIGNAL );
|
||||
}
|
||||
public long getReportingValue() {
|
||||
return this.reportingValue;
|
||||
}
|
||||
|
||||
public long getReportingValue()
|
||||
{
|
||||
return this.reportingValue;
|
||||
}
|
||||
public void setReportingValue(final long v) {
|
||||
this.reportingValue = v;
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
public void setReportingValue( final long v )
|
||||
{
|
||||
this.reportingValue = v;
|
||||
this.updateState();
|
||||
}
|
||||
@Override
|
||||
public void updateSetting(IConfigManager manager, Settings settingName, Enum<?> newValue) {
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(IConfigManager manager, Settings settingName, Enum<?> newValue )
|
||||
{
|
||||
this.configureWatchers();
|
||||
}
|
||||
@Override
|
||||
public void updateWatcher(IStackWatcher newWatcher) {
|
||||
this.stackWatcher = newWatcher;
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher( IStackWatcher newWatcher )
|
||||
{
|
||||
this.stackWatcher = newWatcher;
|
||||
this.configureWatchers();
|
||||
}
|
||||
@Override
|
||||
public void onStackChange(IItemList<?> o, IAEStack<?> fullStack, IAEStack<?> diffStack, IActionSource src,
|
||||
IStorageChannel<?> chan) {
|
||||
if (chan == AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)
|
||||
&& fullStack.equals(this.config.getFluidInSlot(0))) {
|
||||
this.lastReportedValue = fullStack.getStackSize();
|
||||
this.updateState();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStackChange( IItemList<?> o, IAEStack<?> fullStack, IAEStack<?> diffStack, IActionSource src, IStorageChannel<?> chan )
|
||||
{
|
||||
if( chan == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) && fullStack.equals( this.config.getFluidInSlot( 0 ) ) )
|
||||
{
|
||||
this.lastReportedValue = fullStack.getStackSize();
|
||||
this.updateState();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onFluidInventoryChanged(IAEFluidTank inv, int slot) {
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFluidInventoryChanged( IAEFluidTank inv, int slot )
|
||||
{
|
||||
this.configureWatchers();
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void channelChanged(final MENetworkChannelsChanged c) {
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void channelChanged( final MENetworkChannelsChanged c )
|
||||
{
|
||||
this.updateState();
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void powerChanged(final MENetworkPowerStatusChange c) {
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerChanged( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.updateState();
|
||||
}
|
||||
@Override
|
||||
public int isProvidingStrongPower() {
|
||||
return this.prevState ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower()
|
||||
{
|
||||
return this.prevState ? 15 : 0;
|
||||
}
|
||||
@Override
|
||||
public int isProvidingWeakPower() {
|
||||
return this.prevState ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower()
|
||||
{
|
||||
return this.prevState ? 15 : 0;
|
||||
}
|
||||
@Override
|
||||
protected int populateFlags(final int cf) {
|
||||
return cf | (this.prevState ? FLAG_ON : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int populateFlags( final int cf )
|
||||
{
|
||||
return cf | ( this.prevState ? FLAG_ON : 0 );
|
||||
}
|
||||
@Override
|
||||
public boolean isValid(final Object effectiveGrid) {
|
||||
try {
|
||||
return this.getProxy().getGrid() == effectiveGrid;
|
||||
} catch (final GridAccessException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid( final Object effectiveGrid )
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.getProxy().getGrid() == effectiveGrid;
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void postChange(final IBaseMonitor<IAEFluidStack> monitor, final Iterable<IAEFluidStack> change,
|
||||
final IActionSource actionSource) {
|
||||
this.updateReportingValue((IMEMonitor<IAEFluidStack>) monitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postChange( final IBaseMonitor<IAEFluidStack> monitor, final Iterable<IAEFluidStack> change, final IActionSource actionSource )
|
||||
{
|
||||
this.updateReportingValue( (IMEMonitor<IAEFluidStack>) monitor );
|
||||
}
|
||||
@Override
|
||||
public void onListUpdate() {
|
||||
try {
|
||||
final IStorageChannel<IAEFluidStack> channel = AEApi.instance().storage()
|
||||
.getStorageChannel(IFluidStorageChannel.class);
|
||||
final IMEMonitor<IAEFluidStack> inventory = this.getProxy().getStorage().getInventory(channel);
|
||||
|
||||
@Override
|
||||
public void onListUpdate()
|
||||
{
|
||||
try
|
||||
{
|
||||
final IStorageChannel<IAEFluidStack> channel = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
|
||||
final IMEMonitor<IAEFluidStack> inventory = this.getProxy().getStorage().getInventory( channel );
|
||||
this.updateReportingValue(inventory);
|
||||
} catch (final GridAccessException e) {
|
||||
// ;P
|
||||
}
|
||||
}
|
||||
|
||||
this.updateReportingValue( inventory );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// ;P
|
||||
}
|
||||
}
|
||||
private void updateState() {
|
||||
final boolean isOn = this.isLevelEmitterOn();
|
||||
if (this.prevState != isOn) {
|
||||
this.getHost().markForUpdate();
|
||||
final TileEntity te = this.getHost().getTile();
|
||||
this.prevState = isOn;
|
||||
Platform.notifyBlocksOfNeighbors(te.getWorld(), te.getPos());
|
||||
Platform.notifyBlocksOfNeighbors(te.getWorld(), te.getPos().offset(this.getSide().getFacing()));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
final boolean isOn = this.isLevelEmitterOn();
|
||||
if( this.prevState != isOn )
|
||||
{
|
||||
this.getHost().markForUpdate();
|
||||
final TileEntity te = this.getHost().getTile();
|
||||
this.prevState = isOn;
|
||||
Platform.notifyBlocksOfNeighbors( te.getWorld(), te.getPos() );
|
||||
Platform.notifyBlocksOfNeighbors( te.getWorld(), te.getPos().offset( this.getSide().getFacing() ) );
|
||||
}
|
||||
}
|
||||
private void configureWatchers() {
|
||||
final IFluidStorageChannel channel = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
|
||||
|
||||
private void configureWatchers()
|
||||
{
|
||||
final IFluidStorageChannel channel = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
|
||||
if (this.stackWatcher != null) {
|
||||
this.stackWatcher.reset();
|
||||
|
||||
if( this.stackWatcher != null )
|
||||
{
|
||||
this.stackWatcher.reset();
|
||||
final IAEFluidStack myStack = this.config.getFluidInSlot(0);
|
||||
|
||||
final IAEFluidStack myStack = this.config.getFluidInSlot( 0 );
|
||||
try {
|
||||
if (myStack != null) {
|
||||
this.getProxy().getStorage().getInventory(channel).removeListener(this);
|
||||
this.stackWatcher.add(myStack);
|
||||
} else {
|
||||
this.getProxy().getStorage().getInventory(channel).addListener(this, this.getProxy().getGrid());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if( myStack != null )
|
||||
{
|
||||
this.getProxy().getStorage().getInventory( channel ).removeListener( this );
|
||||
this.stackWatcher.add( myStack );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory( channel )
|
||||
.addListener( this, this.getProxy().getGrid() );
|
||||
}
|
||||
final IMEMonitor<IAEFluidStack> inventory = this.getProxy().getStorage().getInventory(channel);
|
||||
|
||||
final IMEMonitor<IAEFluidStack> inventory = this.getProxy().getStorage().getInventory( channel );
|
||||
this.updateReportingValue(inventory);
|
||||
} catch (GridAccessException e) {
|
||||
// NOP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.updateReportingValue( inventory );
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
// NOP
|
||||
}
|
||||
}
|
||||
}
|
||||
private void updateReportingValue(final IMEMonitor<IAEFluidStack> monitor) {
|
||||
final IAEFluidStack myStack = this.config.getFluidInSlot(0);
|
||||
|
||||
private void updateReportingValue( final IMEMonitor<IAEFluidStack> monitor )
|
||||
{
|
||||
final IAEFluidStack myStack = this.config.getFluidInSlot( 0 );
|
||||
if (myStack == null) {
|
||||
this.lastReportedValue = 0;
|
||||
for (final IAEFluidStack st : monitor.getStorageList()) {
|
||||
this.lastReportedValue += st.getStackSize();
|
||||
}
|
||||
} else {
|
||||
final IAEFluidStack r = monitor.getStorageList().findPrecise(myStack);
|
||||
if (r == null) {
|
||||
this.lastReportedValue = 0;
|
||||
} else {
|
||||
this.lastReportedValue = r.getStackSize();
|
||||
}
|
||||
}
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
if( myStack == null )
|
||||
{
|
||||
this.lastReportedValue = 0;
|
||||
for( final IAEFluidStack st : monitor.getStorageList() )
|
||||
{
|
||||
this.lastReportedValue += st.getStackSize();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final IAEFluidStack r = monitor.getStorageList().findPrecise( myStack );
|
||||
if( r == null )
|
||||
{
|
||||
this.lastReportedValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.lastReportedValue = r.getStackSize();
|
||||
}
|
||||
}
|
||||
this.updateState();
|
||||
}
|
||||
private boolean isLevelEmitterOn() {
|
||||
if (Platform.isClient()) {
|
||||
return (this.getClientFlags() & FLAG_ON) == FLAG_ON;
|
||||
}
|
||||
|
||||
private boolean isLevelEmitterOn()
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return ( this.getClientFlags() & FLAG_ON ) == FLAG_ON;
|
||||
}
|
||||
if (!this.getProxy().isActive()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !this.getProxy().isActive() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
final boolean flipState = this.getConfigManager()
|
||||
.getSetting(Settings.REDSTONE_EMITTER) == RedstoneMode.LOW_SIGNAL;
|
||||
return flipState ? this.reportingValue > this.lastReportedValue : this.reportingValue <= this.lastReportedValue;
|
||||
}
|
||||
|
||||
final boolean flipState = this.getConfigManager().getSetting( Settings.REDSTONE_EMITTER ) == RedstoneMode.LOW_SIGNAL;
|
||||
return flipState ? this.reportingValue > this.lastReportedValue : this.reportingValue <= this.lastReportedValue;
|
||||
}
|
||||
@Override
|
||||
public AECableType getCableConnectionType(final AEPartLocation dir) {
|
||||
return AECableType.SMART;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType( final AEPartLocation dir )
|
||||
{
|
||||
return AECableType.SMART;
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
@Override
|
||||
public boolean canConnectRedstone() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(7, 7, 11, 9, 9, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 7, 7, 11, 9, 9, 16 );
|
||||
}
|
||||
@Override
|
||||
public void animateTick(final World world, final BlockPos pos, final Random r) {
|
||||
if (this.isLevelEmitterOn()) {
|
||||
final AEPartLocation d = this.getSide();
|
||||
|
||||
@Override
|
||||
public void animateTick( final World world, final BlockPos pos, final Random r )
|
||||
{
|
||||
if( this.isLevelEmitterOn() )
|
||||
{
|
||||
final AEPartLocation d = this.getSide();
|
||||
final double d0 = d.xOffset * 0.45F + (r.nextFloat() - 0.5F) * 0.2D;
|
||||
final double d1 = d.yOffset * 0.45F + (r.nextFloat() - 0.5F) * 0.2D;
|
||||
final double d2 = d.zOffset * 0.45F + (r.nextFloat() - 0.5F) * 0.2D;
|
||||
|
||||
final double d0 = d.xOffset * 0.45F + ( r.nextFloat() - 0.5F ) * 0.2D;
|
||||
final double d1 = d.yOffset * 0.45F + ( r.nextFloat() - 0.5F ) * 0.2D;
|
||||
final double d2 = d.zOffset * 0.45F + ( r.nextFloat() - 0.5F ) * 0.2D;
|
||||
// FIXME world.spawnParticle( EnumParticleTypes.REDSTONE, 0.5 + pos.getX() + d0,
|
||||
// 0.5 + pos.getY() + d1, 0.5 + pos.getZ() + d2, 0.0D, 0.0D, 0.0D,
|
||||
// FIXME new int[0] );
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME world.spawnParticle( EnumParticleTypes.REDSTONE, 0.5 + pos.getX() + d0, 0.5 + pos.getY() + d1, 0.5 + pos.getZ() + d2, 0.0D, 0.0D, 0.0D,
|
||||
// FIXME new int[0] );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(ContainerFluidLevelEmitter.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final PlayerEntity player, final Hand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
ContainerOpener.openContainer(ContainerFluidLevelEmitter.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
if (this.isActive() && this.isPowered()) {
|
||||
return this.isLevelEmitterOn() ? MODEL_ON_HAS_CHANNEL : MODEL_OFF_HAS_CHANNEL;
|
||||
} else if (this.isPowered()) {
|
||||
return this.isLevelEmitterOn() ? MODEL_ON_ON : MODEL_OFF_ON;
|
||||
} else {
|
||||
return this.isLevelEmitterOn() ? MODEL_ON_OFF : MODEL_OFF_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
if( this.isActive() && this.isPowered() )
|
||||
{
|
||||
return this.isLevelEmitterOn() ? MODEL_ON_HAS_CHANNEL : MODEL_OFF_HAS_CHANNEL;
|
||||
}
|
||||
else if( this.isPowered() )
|
||||
{
|
||||
return this.isLevelEmitterOn() ? MODEL_ON_ON : MODEL_OFF_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.isLevelEmitterOn() ? MODEL_ON_OFF : MODEL_OFF_OFF;
|
||||
}
|
||||
}
|
||||
public IAEFluidTank getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
public IAEFluidTank getConfig()
|
||||
{
|
||||
return this.config;
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final CompoundNBT data) {
|
||||
super.readFromNBT(data);
|
||||
this.lastReportedValue = data.getLong("lastReportedValue");
|
||||
this.reportingValue = data.getLong("reportingValue");
|
||||
this.prevState = data.getBoolean("prevState");
|
||||
this.config.readFromNBT(data, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final CompoundNBT data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.lastReportedValue = data.getLong( "lastReportedValue" );
|
||||
this.reportingValue = data.getLong( "reportingValue" );
|
||||
this.prevState = data.getBoolean( "prevState" );
|
||||
this.config.readFromNBT( data, "config" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final CompoundNBT data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
data.putLong( "lastReportedValue", this.lastReportedValue );
|
||||
data.putLong( "reportingValue", this.reportingValue );
|
||||
data.putBoolean("prevState", this.prevState);
|
||||
this.config.writeToNBT( data, "config" );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final CompoundNBT data) {
|
||||
super.writeToNBT(data);
|
||||
data.putLong("lastReportedValue", this.lastReportedValue);
|
||||
data.putLong("reportingValue", this.reportingValue);
|
||||
data.putBoolean("prevState", this.prevState);
|
||||
this.config.writeToNBT(data, "config");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,16 +18,12 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import appeng.fluids.container.ContainerFluidStorageBus;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -68,9 +64,12 @@ import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.capabilities.Capabilities;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.settings.TickRates;
|
||||
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import appeng.fluids.container.ContainerFluidStorageBus;
|
||||
import appeng.fluids.util.AEFluidInventory;
|
||||
import appeng.fluids.util.IAEFluidInventory;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
@@ -86,417 +85,361 @@ import appeng.util.Platform;
|
||||
import appeng.util.prioritylist.FuzzyPriorityList;
|
||||
import appeng.util.prioritylist.PrecisePriorityList;
|
||||
|
||||
|
||||
/**
|
||||
* @author BrockWS
|
||||
* @version rv6 - 22/05/2018
|
||||
* @since rv6 22/05/2018
|
||||
*/
|
||||
public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMonitorHandlerReceiver<IAEFluidStack>, IAEFluidInventory
|
||||
{
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/fluid_storage_bus_base" );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_storage_bus_off" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_storage_bus_on" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/fluid_storage_bus_has_channel" ) );
|
||||
public class PartFluidStorageBus extends PartSharedStorageBus
|
||||
implements IMEMonitorHandlerReceiver<IAEFluidStack>, IAEFluidInventory {
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID,
|
||||
"part/fluid_storage_bus_base");
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_storage_bus_off"));
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_storage_bus_on"));
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE,
|
||||
new ResourceLocation(AppEng.MOD_ID, "part/fluid_storage_bus_has_channel"));
|
||||
|
||||
private final IActionSource source;
|
||||
private final AEFluidInventory config = new AEFluidInventory( this, 63 );
|
||||
private boolean cached = false;
|
||||
private ITickingMonitor monitor = null;
|
||||
private MEInventoryHandler<IAEFluidStack> handler = null;
|
||||
private int handlerHash = 0;
|
||||
private byte resetCacheLogic = 0;
|
||||
private final IActionSource source;
|
||||
private final AEFluidInventory config = new AEFluidInventory(this, 63);
|
||||
private boolean cached = false;
|
||||
private ITickingMonitor monitor = null;
|
||||
private MEInventoryHandler<IAEFluidStack> handler = null;
|
||||
private int handlerHash = 0;
|
||||
private byte resetCacheLogic = 0;
|
||||
|
||||
public PartFluidStorageBus( ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
this.getConfigManager().registerSetting( Settings.ACCESS, AccessRestriction.READ_WRITE );
|
||||
this.getConfigManager().registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
||||
this.getConfigManager().registerSetting( Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY );
|
||||
this.source = new MachineSource( this );
|
||||
}
|
||||
public PartFluidStorageBus(ItemStack is) {
|
||||
super(is);
|
||||
this.getConfigManager().registerSetting(Settings.ACCESS, AccessRestriction.READ_WRITE);
|
||||
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
|
||||
this.getConfigManager().registerSetting(Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY);
|
||||
this.source = new MachineSource(this);
|
||||
}
|
||||
|
||||
private IMEInventory<IAEFluidStack> getInventoryWrapper( TileEntity target )
|
||||
{
|
||||
Direction targetSide = this.getSide().getFacing().getOpposite();
|
||||
// Prioritize a handler to directly link to another ME network
|
||||
IStorageMonitorableAccessor accessor = target.getCapability( Capabilities.STORAGE_MONITORABLE_ACCESSOR, targetSide ).orElse( null );
|
||||
if( accessor != null )
|
||||
{
|
||||
IStorageMonitorable inventory = accessor.getInventory( this.source );
|
||||
if( inventory != null )
|
||||
{
|
||||
return inventory.getInventory( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) );
|
||||
}
|
||||
private IMEInventory<IAEFluidStack> getInventoryWrapper(TileEntity target) {
|
||||
Direction targetSide = this.getSide().getFacing().getOpposite();
|
||||
// Prioritize a handler to directly link to another ME network
|
||||
IStorageMonitorableAccessor accessor = target
|
||||
.getCapability(Capabilities.STORAGE_MONITORABLE_ACCESSOR, targetSide).orElse(null);
|
||||
if (accessor != null) {
|
||||
IStorageMonitorable inventory = accessor.getInventory(this.source);
|
||||
if (inventory != null) {
|
||||
return inventory.getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class));
|
||||
}
|
||||
|
||||
// So this could / can be a design decision. If the tile does support our custom capability,
|
||||
// but it does not return an inventory for the action source, we do NOT fall back to using
|
||||
// IItemHandler's, as that might circumvent the security setings, and might also cause
|
||||
// performance issues.
|
||||
return null;
|
||||
}
|
||||
// So this could / can be a design decision. If the tile does support our custom
|
||||
// capability,
|
||||
// but it does not return an inventory for the action source, we do NOT fall
|
||||
// back to using
|
||||
// IItemHandler's, as that might circumvent the security setings, and might also
|
||||
// cause
|
||||
// performance issues.
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check via cap for IItemHandler
|
||||
IFluidHandler handlerExt = target.getCapability( CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, targetSide ).orElse( null );
|
||||
if( handlerExt != null )
|
||||
{
|
||||
return new FluidHandlerAdapter( handlerExt, this );
|
||||
}
|
||||
// Check via cap for IItemHandler
|
||||
IFluidHandler handlerExt = target.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, targetSide)
|
||||
.orElse(null);
|
||||
if (handlerExt != null) {
|
||||
return new FluidHandlerAdapter(handlerExt, this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest( IGridNode node, int ticksSinceLastCall )
|
||||
{
|
||||
if( this.resetCacheLogic != 0 )
|
||||
{
|
||||
this.resetCache();
|
||||
}
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) {
|
||||
if (this.resetCacheLogic != 0) {
|
||||
this.resetCache();
|
||||
}
|
||||
|
||||
if( this.monitor != null )
|
||||
{
|
||||
return this.monitor.onTick();
|
||||
}
|
||||
if (this.monitor != null) {
|
||||
return this.monitor.onTick();
|
||||
}
|
||||
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void resetCache()
|
||||
{
|
||||
final boolean fullReset = this.resetCacheLogic == 2;
|
||||
this.resetCacheLogic = 0;
|
||||
@Override
|
||||
protected void resetCache() {
|
||||
final boolean fullReset = this.resetCacheLogic == 2;
|
||||
this.resetCacheLogic = 0;
|
||||
|
||||
final IMEInventory<IAEFluidStack> in = this.getInternalHandler();
|
||||
IItemList<IAEFluidStack> before = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
|
||||
if( in != null )
|
||||
{
|
||||
before = in.getAvailableItems( before );
|
||||
}
|
||||
final IMEInventory<IAEFluidStack> in = this.getInternalHandler();
|
||||
IItemList<IAEFluidStack> before = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)
|
||||
.createList();
|
||||
if (in != null) {
|
||||
before = in.getAvailableItems(before);
|
||||
}
|
||||
|
||||
this.cached = false;
|
||||
if( fullReset )
|
||||
{
|
||||
this.handlerHash = 0;
|
||||
}
|
||||
this.cached = false;
|
||||
if (fullReset) {
|
||||
this.handlerHash = 0;
|
||||
}
|
||||
|
||||
final IMEInventory<IAEFluidStack> out = this.getInternalHandler();
|
||||
final IMEInventory<IAEFluidStack> out = this.getInternalHandler();
|
||||
|
||||
if( in != out )
|
||||
{
|
||||
IItemList<IAEFluidStack> after = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
|
||||
if( out != null )
|
||||
{
|
||||
after = out.getAvailableItems( after );
|
||||
}
|
||||
Platform.postListChanges( before, after, this, this.source );
|
||||
}
|
||||
}
|
||||
if (in != out) {
|
||||
IItemList<IAEFluidStack> after = AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)
|
||||
.createList();
|
||||
if (out != null) {
|
||||
after = out.getAvailableItems(after);
|
||||
}
|
||||
Platform.postListChanges(before, after, this, this.source);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void resetCache( final boolean fullReset )
|
||||
{
|
||||
if( this.getHost() == null || this.getHost().getTile() == null || this.getHost().getTile().getWorld() == null || this.getHost().getTile().getWorld().isRemote )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
protected void resetCache(final boolean fullReset) {
|
||||
if (this.getHost() == null || this.getHost().getTile() == null || this.getHost().getTile().getWorld() == null
|
||||
|| this.getHost().getTile().getWorld().isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( fullReset )
|
||||
{
|
||||
this.resetCacheLogic = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.resetCacheLogic = 1;
|
||||
}
|
||||
if (fullReset) {
|
||||
this.resetCacheLogic = 2;
|
||||
} else {
|
||||
this.resetCacheLogic = 1;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
this.getProxy().getTick().alertDevice( this.getProxy().getNode() );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
try {
|
||||
this.getProxy().getTick().alertDevice(this.getProxy().getNode());
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final PlayerEntity player, final Hand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
ContainerOpener.openContainer(ContainerFluidStorageBus.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(ContainerFluidStorageBus.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFluidInventoryChanged( IAEFluidTank inv, int slot )
|
||||
{
|
||||
if( inv == this.config )
|
||||
{
|
||||
this.resetCache( true );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onFluidInventoryChanged(IAEFluidTank inv, int slot) {
|
||||
if (inv == this.config) {
|
||||
this.resetCache(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final CompoundNBT data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.config.readFromNBT( data, "config" );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final CompoundNBT data) {
|
||||
super.readFromNBT(data);
|
||||
this.config.readFromNBT(data, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final CompoundNBT data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
this.config.writeToNBT( data, "config" );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final CompoundNBT data) {
|
||||
super.writeToNBT(data);
|
||||
this.config.writeToNBT(data, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid( final Object verificationToken )
|
||||
{
|
||||
return this.handler == verificationToken;
|
||||
}
|
||||
@Override
|
||||
public boolean isValid(final Object verificationToken) {
|
||||
return this.handler == verificationToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postChange( final IBaseMonitor<IAEFluidStack> monitor, final Iterable<IAEFluidStack> change, final IActionSource source )
|
||||
{
|
||||
try
|
||||
{
|
||||
if( this.getProxy().isActive() )
|
||||
{
|
||||
this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ), change, this.source );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :(
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void postChange(final IBaseMonitor<IAEFluidStack> monitor, final Iterable<IAEFluidStack> change,
|
||||
final IActionSource source) {
|
||||
try {
|
||||
if (this.getProxy().isActive()) {
|
||||
this.getProxy().getStorage().postAlterationOfStoredItems(
|
||||
AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class), change, this.source);
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// :(
|
||||
}
|
||||
}
|
||||
|
||||
public MEInventoryHandler<IAEFluidStack> getInternalHandler()
|
||||
{
|
||||
if( this.cached )
|
||||
{
|
||||
return this.handler;
|
||||
}
|
||||
public MEInventoryHandler<IAEFluidStack> getInternalHandler() {
|
||||
if (this.cached) {
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
final boolean wasSleeping = this.monitor == null;
|
||||
final boolean wasSleeping = this.monitor == null;
|
||||
|
||||
this.cached = true;
|
||||
final TileEntity self = this.getHost().getTile();
|
||||
final TileEntity target = self.getWorld().getTileEntity( self.getPos().offset( this.getSide().getFacing() ) );
|
||||
final int newHandlerHash = this.createHandlerHash( target );
|
||||
this.cached = true;
|
||||
final TileEntity self = this.getHost().getTile();
|
||||
final TileEntity target = self.getWorld().getTileEntity(self.getPos().offset(this.getSide().getFacing()));
|
||||
final int newHandlerHash = this.createHandlerHash(target);
|
||||
|
||||
if( newHandlerHash != 0 && newHandlerHash == this.handlerHash )
|
||||
{
|
||||
return this.handler;
|
||||
}
|
||||
if (newHandlerHash != 0 && newHandlerHash == this.handlerHash) {
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
this.handlerHash = newHandlerHash;
|
||||
this.handler = null;
|
||||
this.monitor = null;
|
||||
if( target != null )
|
||||
{
|
||||
IMEInventory<IAEFluidStack> inv = this.getInventoryWrapper( target );
|
||||
if( inv instanceof ITickingMonitor )
|
||||
{
|
||||
this.monitor = (ITickingMonitor) inv;
|
||||
this.monitor.setActionSource( new MachineSource( this ) );
|
||||
}
|
||||
this.handlerHash = newHandlerHash;
|
||||
this.handler = null;
|
||||
this.monitor = null;
|
||||
if (target != null) {
|
||||
IMEInventory<IAEFluidStack> inv = this.getInventoryWrapper(target);
|
||||
if (inv instanceof ITickingMonitor) {
|
||||
this.monitor = (ITickingMonitor) inv;
|
||||
this.monitor.setActionSource(new MachineSource(this));
|
||||
}
|
||||
|
||||
if( inv != null )
|
||||
{
|
||||
this.checkInterfaceVsStorageBus( target, this.getSide().getOpposite() );
|
||||
if (inv != null) {
|
||||
this.checkInterfaceVsStorageBus(target, this.getSide().getOpposite());
|
||||
|
||||
this.handler = new MEInventoryHandler<>( inv, AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) );
|
||||
this.handler = new MEInventoryHandler<>(inv,
|
||||
AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class));
|
||||
|
||||
this.handler.setBaseAccess( (AccessRestriction) this.getConfigManager().getSetting( Settings.ACCESS ) );
|
||||
this.handler.setWhitelist( this.getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST );
|
||||
this.handler.setPriority( this.getPriority() );
|
||||
this.handler.setBaseAccess((AccessRestriction) this.getConfigManager().getSetting(Settings.ACCESS));
|
||||
this.handler.setWhitelist(this.getInstalledUpgrades(Upgrades.INVERTER) > 0 ? IncludeExclude.BLACKLIST
|
||||
: IncludeExclude.WHITELIST);
|
||||
this.handler.setPriority(this.getPriority());
|
||||
|
||||
final IItemList<IAEFluidStack> priorityList = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
|
||||
final IItemList<IAEFluidStack> priorityList = AEApi.instance().storage()
|
||||
.getStorageChannel(IFluidStorageChannel.class).createList();
|
||||
|
||||
final int slotsToUse = 18 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 9;
|
||||
for( int x = 0; x < this.config.getSlots() && x < slotsToUse; x++ )
|
||||
{
|
||||
final IAEFluidStack is = this.config.getFluidInSlot( x );
|
||||
if( is != null )
|
||||
{
|
||||
priorityList.add( is );
|
||||
}
|
||||
}
|
||||
final int slotsToUse = 18 + this.getInstalledUpgrades(Upgrades.CAPACITY) * 9;
|
||||
for (int x = 0; x < this.config.getSlots() && x < slotsToUse; x++) {
|
||||
final IAEFluidStack is = this.config.getFluidInSlot(x);
|
||||
if (is != null) {
|
||||
priorityList.add(is);
|
||||
}
|
||||
}
|
||||
|
||||
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
{
|
||||
this.handler.setPartitionList( new FuzzyPriorityList<IAEFluidStack>( priorityList, (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.handler.setPartitionList( new PrecisePriorityList<IAEFluidStack>( priorityList ) );
|
||||
}
|
||||
if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0) {
|
||||
this.handler.setPartitionList(new FuzzyPriorityList<IAEFluidStack>(priorityList,
|
||||
(FuzzyMode) this.getConfigManager().getSetting(Settings.FUZZY_MODE)));
|
||||
} else {
|
||||
this.handler.setPartitionList(new PrecisePriorityList<IAEFluidStack>(priorityList));
|
||||
}
|
||||
|
||||
if( inv instanceof IBaseMonitor )
|
||||
{
|
||||
( (IBaseMonitor<IAEFluidStack>) inv ).addListener( this, this.handler );
|
||||
}
|
||||
}
|
||||
}
|
||||
if (inv instanceof IBaseMonitor) {
|
||||
((IBaseMonitor<IAEFluidStack>) inv).addListener(this, this.handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update sleep state...
|
||||
if( wasSleeping != ( this.monitor == null ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
final ITickManager tm = this.getProxy().getTick();
|
||||
if( this.monitor == null )
|
||||
{
|
||||
tm.sleepDevice( this.getProxy().getNode() );
|
||||
}
|
||||
else
|
||||
{
|
||||
tm.wakeDevice( this.getProxy().getNode() );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException ignore )
|
||||
{
|
||||
// :(
|
||||
}
|
||||
}
|
||||
// update sleep state...
|
||||
if (wasSleeping != (this.monitor == null)) {
|
||||
try {
|
||||
final ITickManager tm = this.getProxy().getTick();
|
||||
if (this.monitor == null) {
|
||||
tm.sleepDevice(this.getProxy().getNode());
|
||||
} else {
|
||||
tm.wakeDevice(this.getProxy().getNode());
|
||||
}
|
||||
} catch (final GridAccessException ignore) {
|
||||
// :(
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// force grid to update handlers...
|
||||
this.getProxy().getGrid().postEvent( new MENetworkCellArrayUpdate() );
|
||||
}
|
||||
catch( final GridAccessException ignore )
|
||||
{
|
||||
// :3
|
||||
}
|
||||
try {
|
||||
// force grid to update handlers...
|
||||
this.getProxy().getGrid().postEvent(new MENetworkCellArrayUpdate());
|
||||
} catch (final GridAccessException ignore) {
|
||||
// :3
|
||||
}
|
||||
|
||||
return this.handler;
|
||||
}
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
private void checkInterfaceVsStorageBus( final TileEntity target, final AEPartLocation side )
|
||||
{
|
||||
IInterfaceHost achievement = null;
|
||||
private void checkInterfaceVsStorageBus(final TileEntity target, final AEPartLocation side) {
|
||||
IInterfaceHost achievement = null;
|
||||
|
||||
if( target instanceof IInterfaceHost )
|
||||
{
|
||||
achievement = (IInterfaceHost) target;
|
||||
}
|
||||
if (target instanceof IInterfaceHost) {
|
||||
achievement = (IInterfaceHost) target;
|
||||
}
|
||||
|
||||
if( target instanceof IPartHost )
|
||||
{
|
||||
final Object part = ( (IPartHost) target ).getPart( side );
|
||||
if( part instanceof IInterfaceHost )
|
||||
{
|
||||
achievement = (IInterfaceHost) part;
|
||||
}
|
||||
}
|
||||
if (target instanceof IPartHost) {
|
||||
final Object part = ((IPartHost) target).getPart(side);
|
||||
if (part instanceof IInterfaceHost) {
|
||||
achievement = (IInterfaceHost) part;
|
||||
}
|
||||
}
|
||||
|
||||
if( achievement != null && achievement.getActionableNode() != null )
|
||||
{
|
||||
// Platform.addStat( achievement.getActionableNode().getPlayerID(), Achievements.Recursive.getAchievement()
|
||||
// );
|
||||
// Platform.addStat( getActionableNode().getPlayerID(), Achievements.Recursive.getAchievement() );
|
||||
}
|
||||
}
|
||||
if (achievement != null && achievement.getActionableNode() != null) {
|
||||
// Platform.addStat( achievement.getActionableNode().getPlayerID(),
|
||||
// Achievements.Recursive.getAchievement()
|
||||
// );
|
||||
// Platform.addStat( getActionableNode().getPlayerID(),
|
||||
// Achievements.Recursive.getAchievement() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IMEInventoryHandler> getCellArray( final IStorageChannel channel )
|
||||
{
|
||||
if( channel == this.getStorageChannel() )
|
||||
{
|
||||
final IMEInventoryHandler<IAEFluidStack> out = this.getProxy().isActive() ? this.getInternalHandler() : null;
|
||||
if( out != null )
|
||||
{
|
||||
return Collections.singletonList( out );
|
||||
}
|
||||
}
|
||||
return super.getCellArray( channel );
|
||||
}
|
||||
@Override
|
||||
public List<IMEInventoryHandler> getCellArray(final IStorageChannel channel) {
|
||||
if (channel == this.getStorageChannel()) {
|
||||
final IMEInventoryHandler<IAEFluidStack> out = this.getProxy().isActive() ? this.getInternalHandler()
|
||||
: null;
|
||||
if (out != null) {
|
||||
return Collections.singletonList(out);
|
||||
}
|
||||
}
|
||||
return super.getCellArray(channel);
|
||||
}
|
||||
|
||||
private int createHandlerHash( TileEntity target )
|
||||
{
|
||||
if( target == null )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
private int createHandlerHash(TileEntity target) {
|
||||
if (target == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
final Direction targetSide = this.getSide().getFacing().getOpposite();
|
||||
final Direction targetSide = this.getSide().getFacing().getOpposite();
|
||||
|
||||
LazyOptional<IStorageMonitorableAccessor> accessorOpt = target.getCapability( Capabilities.STORAGE_MONITORABLE_ACCESSOR, targetSide );
|
||||
if( accessorOpt.isPresent() )
|
||||
{
|
||||
return Objects.hash( target, accessorOpt.orElse( null ) );
|
||||
}
|
||||
LazyOptional<IStorageMonitorableAccessor> accessorOpt = target
|
||||
.getCapability(Capabilities.STORAGE_MONITORABLE_ACCESSOR, targetSide);
|
||||
if (accessorOpt.isPresent()) {
|
||||
return Objects.hash(target, accessorOpt.orElse(null));
|
||||
}
|
||||
|
||||
final IFluidHandler fluidHandler = target.getCapability( CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, targetSide ).orElse( null );
|
||||
final IFluidHandler fluidHandler = target
|
||||
.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, targetSide).orElse(null);
|
||||
|
||||
if( fluidHandler != null )
|
||||
{
|
||||
return Objects.hash( target, fluidHandler, fluidHandler.getTanks() );
|
||||
}
|
||||
if (fluidHandler != null) {
|
||||
return Objects.hash(target, fluidHandler, fluidHandler.getTanks());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest( IGridNode node )
|
||||
{
|
||||
return new TickingRequest( TickRates.FluidStorageBus.getMin(), TickRates.FluidStorageBus.getMax(), this.isSleeping(), true );
|
||||
}
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node) {
|
||||
return new TickingRequest(TickRates.FluidStorageBus.getMin(), TickRates.FluidStorageBus.getMax(),
|
||||
this.isSleeping(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListUpdate()
|
||||
{
|
||||
// not used here.
|
||||
}
|
||||
@Override
|
||||
public void onListUpdate() {
|
||||
// not used here.
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel getStorageChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
|
||||
}
|
||||
@Override
|
||||
public IStorageChannel getStorageChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
|
||||
}
|
||||
|
||||
public IAEFluidTank getConfig()
|
||||
{
|
||||
return this.config;
|
||||
}
|
||||
public IAEFluidTank getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
if( this.isActive() && this.isPowered() )
|
||||
{
|
||||
return MODELS_HAS_CHANNEL;
|
||||
}
|
||||
else if( this.isPowered() )
|
||||
{
|
||||
return MODELS_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
@Nonnull
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
if (this.isActive() && this.isPowered()) {
|
||||
return MODELS_HAS_CHANNEL;
|
||||
} else if (this.isPowered()) {
|
||||
return MODELS_ON;
|
||||
} else {
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStackRepresentation()
|
||||
{
|
||||
return AEApi.instance().definitions().parts().fluidStorageBus().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
}
|
||||
@Override
|
||||
public ItemStack getItemStackRepresentation() {
|
||||
return AEApi.instance().definitions().parts().fluidStorageBus().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerType<?> getContainerType()
|
||||
{
|
||||
return ContainerFluidStorageBus.TYPE;
|
||||
}
|
||||
@Override
|
||||
public ContainerType<?> getContainerType() {
|
||||
return ContainerFluidStorageBus.TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import appeng.fluids.container.ContainerFluidTerminal;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.ContainerType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -27,43 +25,38 @@ import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.core.AppEng;
|
||||
|
||||
import appeng.fluids.container.ContainerFluidTerminal;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.parts.PartModel;
|
||||
import appeng.parts.reporting.AbstractPartTerminal;
|
||||
|
||||
|
||||
/**
|
||||
* @author BrockWS
|
||||
* @version rv6 - 12/05/2018
|
||||
* @since rv6 12/05/2018
|
||||
*/
|
||||
public class PartFluidTerminal extends AbstractPartTerminal
|
||||
{
|
||||
public class PartFluidTerminal extends AbstractPartTerminal {
|
||||
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/fluid_terminal_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/fluid_terminal_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation(AppEng.MOD_ID, "part/fluid_terminal_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation(AppEng.MOD_ID, "part/fluid_terminal_on");
|
||||
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF );
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_ON );
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL );
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF);
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_ON);
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL);
|
||||
|
||||
public PartFluidTerminal( ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
public PartFluidTerminal(ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerType<?> getContainerType(PlayerEntity player )
|
||||
{
|
||||
return ContainerFluidTerminal.TYPE;
|
||||
}
|
||||
@Override
|
||||
public ContainerType<?> getContainerType(PlayerEntity player) {
|
||||
return ContainerFluidTerminal.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return this.selectModel( MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return this.selectModel(MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,6 @@
|
||||
|
||||
package appeng.fluids.parts;
|
||||
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.fluids.container.ContainerFluidIO;
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
@@ -43,156 +38,132 @@ import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.storage.channels.IFluidStorageChannel;
|
||||
import appeng.api.util.AECableType;
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.fluids.container.ContainerFluidIO;
|
||||
import appeng.fluids.container.ContainerFluidInterface;
|
||||
import appeng.fluids.util.AEFluidInventory;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.automation.PartUpgradeable;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
/**
|
||||
* @author BrockWS
|
||||
* @version rv6 - 30/04/2018
|
||||
* @since rv6 30/04/2018
|
||||
*/
|
||||
public abstract class PartSharedFluidBus extends PartUpgradeable implements IGridTickable
|
||||
{
|
||||
public abstract class PartSharedFluidBus extends PartUpgradeable implements IGridTickable {
|
||||
|
||||
private final AEFluidInventory config = new AEFluidInventory( null, 9 );
|
||||
private boolean lastRedstone;
|
||||
private final AEFluidInventory config = new AEFluidInventory(null, 9);
|
||||
private boolean lastRedstone;
|
||||
|
||||
public PartSharedFluidBus( ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
public PartSharedFluidBus(ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upgradesChanged()
|
||||
{
|
||||
this.updateState();
|
||||
}
|
||||
@Override
|
||||
public void upgradesChanged() {
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockReader w, BlockPos pos, BlockPos neighbor )
|
||||
{
|
||||
this.updateState();
|
||||
if( this.lastRedstone != this.getHost().hasRedstone( this.getSide() ) )
|
||||
{
|
||||
this.lastRedstone = !this.lastRedstone;
|
||||
if( this.lastRedstone && this.getRSMode() == RedstoneMode.SIGNAL_PULSE )
|
||||
{
|
||||
this.doBusWork();
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockReader w, BlockPos pos, BlockPos neighbor) {
|
||||
this.updateState();
|
||||
if (this.lastRedstone != this.getHost().hasRedstone(this.getSide())) {
|
||||
this.lastRedstone = !this.lastRedstone;
|
||||
if (this.lastRedstone && this.getRSMode() == RedstoneMode.SIGNAL_PULSE) {
|
||||
this.doBusWork();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
try
|
||||
{
|
||||
if( !this.isSleeping() )
|
||||
{
|
||||
this.getProxy().getTick().wakeDevice( this.getProxy().getNode() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getProxy().getTick().sleepDevice( this.getProxy().getNode() );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
private void updateState() {
|
||||
try {
|
||||
if (!this.isSleeping()) {
|
||||
this.getProxy().getTick().wakeDevice(this.getProxy().getNode());
|
||||
} else {
|
||||
this.getProxy().getTick().sleepDevice(this.getProxy().getNode());
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final PlayerEntity player, final Hand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
ContainerOpener.openContainer(ContainerFluidIO.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
ContainerOpener.openContainer(ContainerFluidIO.TYPE, player, ContainerLocator.forPart(this));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 6, 6, 11, 10, 10, 13 );
|
||||
bch.addBox( 5, 5, 13, 11, 11, 14 );
|
||||
bch.addBox( 4, 4, 14, 12, 12, 16 );
|
||||
}
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper bch) {
|
||||
bch.addBox(6, 6, 11, 10, 10, 13);
|
||||
bch.addBox(5, 5, 13, 11, 11, 14);
|
||||
bch.addBox(4, 4, 14, 12, 12, 16);
|
||||
}
|
||||
|
||||
protected TileEntity getConnectedTE()
|
||||
{
|
||||
TileEntity self = this.getHost().getTile();
|
||||
return this.getTileEntity( self, self.getPos().offset( this.getSide().getFacing() ) );
|
||||
}
|
||||
protected TileEntity getConnectedTE() {
|
||||
TileEntity self = this.getHost().getTile();
|
||||
return this.getTileEntity(self, self.getPos().offset(this.getSide().getFacing()));
|
||||
}
|
||||
|
||||
private TileEntity getTileEntity( final TileEntity self, final BlockPos pos )
|
||||
{
|
||||
final World w = self.getWorld();
|
||||
private TileEntity getTileEntity(final TileEntity self, final BlockPos pos) {
|
||||
final World w = self.getWorld();
|
||||
|
||||
if( w.getChunkProvider().isChunkLoaded( new ChunkPos( pos ) ) )
|
||||
{
|
||||
return w.getTileEntity( pos );
|
||||
}
|
||||
if (w.getChunkProvider().isChunkLoaded(new ChunkPos(pos))) {
|
||||
return w.getTileEntity(pos);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected int calculateAmountToSend()
|
||||
{
|
||||
double amount = this.getChannel().transferFactor();
|
||||
switch( this.getInstalledUpgrades( Upgrades.SPEED ) )
|
||||
{
|
||||
case 4:
|
||||
amount = amount * 1.5;
|
||||
case 3:
|
||||
amount = amount * 2;
|
||||
case 2:
|
||||
amount = amount * 4;
|
||||
case 1:
|
||||
amount = amount * 8;
|
||||
case 0:
|
||||
default:
|
||||
return MathHelper.floor( amount );
|
||||
}
|
||||
}
|
||||
protected int calculateAmountToSend() {
|
||||
double amount = this.getChannel().transferFactor();
|
||||
switch (this.getInstalledUpgrades(Upgrades.SPEED)) {
|
||||
case 4:
|
||||
amount = amount * 1.5;
|
||||
case 3:
|
||||
amount = amount * 2;
|
||||
case 2:
|
||||
amount = amount * 4;
|
||||
case 1:
|
||||
amount = amount * 8;
|
||||
case 0:
|
||||
default:
|
||||
return MathHelper.floor(amount);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( CompoundNBT extra )
|
||||
{
|
||||
super.readFromNBT( extra );
|
||||
this.config.readFromNBT( extra, "config" );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(CompoundNBT extra) {
|
||||
super.readFromNBT(extra);
|
||||
this.config.readFromNBT(extra, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( CompoundNBT extra )
|
||||
{
|
||||
super.writeToNBT( extra );
|
||||
this.config.writeToNBT( extra, "config" );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(CompoundNBT extra) {
|
||||
super.writeToNBT(extra);
|
||||
this.config.writeToNBT(extra, "config");
|
||||
}
|
||||
|
||||
public IAEFluidTank getConfig()
|
||||
{
|
||||
return this.config;
|
||||
}
|
||||
public IAEFluidTank getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
protected IFluidStorageChannel getChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class );
|
||||
}
|
||||
protected IFluidStorageChannel getChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
protected abstract TickRateModulation doBusWork();
|
||||
protected abstract TickRateModulation doBusWork();
|
||||
|
||||
protected abstract boolean canDoBusWork();
|
||||
protected abstract boolean canDoBusWork();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user