Add Fluid Formation/Annihilation Planes (#3591)

Fixes #3572
This commit is contained in:
fscan
2018-07-08 16:54:22 +02:00
committed by GitHub
parent 96af371882
commit e5ab9df086
28 changed files with 1341 additions and 241 deletions
@@ -40,7 +40,6 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;
@@ -60,24 +59,16 @@ import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.networking.security.IActionSource;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartHost;
import appeng.api.parts.IPartItem;
import appeng.api.parts.IPartModel;
import appeng.api.storage.ICellContainer;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.api.util.IConfigManager;
import appeng.core.AEConfig;
import appeng.core.sync.GuiBridge;
import appeng.helpers.IPriorityHost;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.storage.MEInventoryHandler;
@@ -88,7 +79,7 @@ import appeng.util.prioritylist.FuzzyPriorityList;
import appeng.util.prioritylist.PrecisePriorityList;
public class PartFormationPlane extends PartUpgradeable implements ICellContainer, IPriorityHost, IMEInventory<IAEItemStack>
public class PartFormationPlane extends PartAbstractFormationPlane<IAEItemStack>
{
private static final PlaneModels MODELS = new PlaneModels( "part/formation_plane_", "part/formation_plane_on_" );
@@ -99,11 +90,10 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
return MODELS.getModels();
}
private final MEInventoryHandler myHandler = new MEInventoryHandler( this, AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
private final MEInventoryHandler<IAEItemStack> myHandler = new MEInventoryHandler<>( this, AEApi.instance()
.storage()
.getStorageChannel( IItemStorageChannel.class ) );
private final AppEngInternalAEInventory Config = new AppEngInternalAEInventory( this, 63 );
private int priority = 0;
private boolean wasActive = false;
private boolean blocked = false;
public PartFormationPlane( final ItemStack is )
{
@@ -114,11 +104,12 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
this.updateHandler();
}
private void updateHandler()
@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.priority );
this.myHandler.setPriority( this.getPriority() );
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
@@ -134,11 +125,12 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
{
this.myHandler.setPartitionList( new FuzzyPriorityList( priorityList, (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE ) ) );
this.myHandler.setPartitionList(
new FuzzyPriorityList<IAEItemStack>( priorityList, (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE ) ) );
}
else
{
this.myHandler.setPartitionList( new PrecisePriorityList( priorityList ) );
this.myHandler.setPartitionList( new PrecisePriorityList<IAEItemStack>( priorityList ) );
}
try
@@ -151,19 +143,6 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
}
}
@Override
protected int getUpgradeSlots()
{
return 5;
}
@Override
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
{
this.updateHandler();
this.getHost().markForSave();
}
@Override
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
@@ -175,18 +154,11 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
}
}
@Override
public void upgradesChanged()
{
this.updateHandler();
}
@Override
public void readFromNBT( final NBTTagCompound data )
{
super.readFromNBT( data );
this.Config.readFromNBT( data, "config" );
this.priority = data.getInteger( "priority" );
this.updateHandler();
}
@@ -195,7 +167,6 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
{
super.writeToNBT( data );
this.Config.writeToNBT( data, "config" );
data.setInteger( "priority", this.priority );
}
@Override
@@ -213,161 +184,13 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
@MENetworkEventSubscribe
public void powerRender( final MENetworkPowerStatusChange c )
{
final boolean currentActive = this.getProxy().isActive();
if( this.wasActive != currentActive )
{
this.wasActive = currentActive;
this.updateHandler();// proxy.getGrid().postEvent( new MENetworkCellArrayUpdate() );
this.getHost().markForUpdate();
}
this.stateChanged();
}
@MENetworkEventSubscribe
public void updateChannels( final MENetworkChannelsChanged changedChannels )
{
final boolean currentActive = this.getProxy().isActive();
if( this.wasActive != currentActive )
{
this.wasActive = currentActive;
this.updateHandler();// proxy.getGrid().postEvent( new MENetworkCellArrayUpdate() );
this.getHost().markForUpdate();
}
}
@Override
public void getBoxes( final IPartCollisionHelper bch )
{
int minX = 1;
int minY = 1;
int maxX = 15;
int maxY = 15;
final IPartHost host = this.getHost();
if( host != null )
{
final TileEntity te = host.getTile();
final BlockPos pos = te.getPos();
final EnumFacing e = bch.getWorldX();
final EnumFacing u = bch.getWorldY();
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( e.getOpposite() ) ), this.getSide() ) )
{
minX = 0;
}
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( e ) ), this.getSide() ) )
{
maxX = 16;
}
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( u.getOpposite() ) ), this.getSide() ) )
{
minY = 0;
}
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( u ) ), this.getSide() ) )
{
maxY = 16;
}
}
bch.addBox( 5, 5, 14, 11, 11, 15 );
bch.addBox( minX, minY, 15, maxX, maxY, 16 );
}
// TODO: Consolidate this with the impl in PartAnnihilationPlane
/**
* @return An object describing which adjacent planes this plane connects to visually.
*/
public PlaneConnections getConnections()
{
final EnumFacing facingRight, facingUp;
AEPartLocation location = this.getSide();
switch( location )
{
case UP:
facingRight = EnumFacing.EAST;
facingUp = EnumFacing.NORTH;
break;
case DOWN:
facingRight = EnumFacing.WEST;
facingUp = EnumFacing.NORTH;
break;
case NORTH:
facingRight = EnumFacing.WEST;
facingUp = EnumFacing.UP;
break;
case SOUTH:
facingRight = EnumFacing.EAST;
facingUp = EnumFacing.UP;
break;
case WEST:
facingRight = EnumFacing.SOUTH;
facingUp = EnumFacing.UP;
break;
case EAST:
facingRight = EnumFacing.NORTH;
facingUp = EnumFacing.UP;
break;
default:
case INTERNAL:
return PlaneConnections.of( false, false, false, false );
}
boolean left = false, right = false, down = false, up = false;
final IPartHost host = this.getHost();
if( host != null )
{
final TileEntity te = host.getTile();
final BlockPos pos = te.getPos();
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( facingRight.getOpposite() ) ), this.getSide() ) )
{
left = true;
}
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( facingRight ) ), this.getSide() ) )
{
right = true;
}
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( facingUp.getOpposite() ) ), this.getSide() ) )
{
down = true;
}
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( facingUp ) ), this.getSide() ) )
{
up = true;
}
}
return PlaneConnections.of( up, right, down, left );
}
@Override
public void onNeighborChanged( IBlockAccess w, BlockPos pos, BlockPos neighbor )
{
if( pos.offset( this.getSide().getFacing() ).equals( neighbor ) )
{
final TileEntity te = this.getHost().getTile();
final AEPartLocation side = this.getSide();
final BlockPos tePos = te.getPos().offset( side.getFacing() );
this.blocked = !w.getBlockState( tePos ).getBlock().isReplaceable( w, tePos );
}
}
@Override
public float getCableConnectionLength( AECableType cable )
{
return 1;
this.stateChanged();
}
@Override
@@ -387,16 +210,6 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
return false;
}
private boolean isTransitionPlane( final TileEntity blockTileEntity, final AEPartLocation side )
{
if( blockTileEntity instanceof IPartHost )
{
final IPart p = ( (IPartHost) blockTileEntity ).getPart( side );
return p instanceof PartFormationPlane;
}
return false;
}
@Override
public List<IMEInventoryHandler> getCellArray( final IStorageChannel channel )
{
@@ -409,26 +222,6 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
return Collections.emptyList();
}
@Override
public int getPriority()
{
return this.priority;
}
@Override
public void setPriority( final int newValue )
{
this.priority = newValue;
this.getHost().markForSave();
this.updateHandler();
}
@Override
public void blinkCell( final int slot )
{
// :P
}
@Override
public IAEItemStack injectItems( final IAEItemStack input, final Actionable type, final IActionSource src )
{
@@ -584,29 +377,11 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
}
@Override
public IAEItemStack extractItems( final IAEItemStack request, final Actionable mode, final IActionSource src )
{
return null;
}
@Override
public IItemList<IAEItemStack> getAvailableItems( final IItemList<IAEItemStack> out )
{
return out;
}
@Override
public IStorageChannel getChannel()
public IStorageChannel<IAEItemStack> getChannel()
{
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
}
@Override
public void saveChanges( final IMEInventory cellInventory )
{
// nope!
}
@Override
public IPartModel getStaticModels()
{