reformatted all src files (#141)

This commit is contained in:
YoungOnion
2022-09-17 05:08:02 -06:00
committed by GitHub
parent 3328bfcda2
commit 9011273229
1056 changed files with 88127 additions and 110597 deletions
@@ -19,41 +19,35 @@
package appeng.parts.automation;
import appeng.api.config.Upgrades;
import appeng.util.inv.IAEAppEngInventory;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import appeng.api.config.Upgrades;
import appeng.util.inv.IAEAppEngInventory;
public class BlockUpgradeInventory extends UpgradeInventory {
private final Block block;
public class BlockUpgradeInventory extends UpgradeInventory
{
private final Block block;
public BlockUpgradeInventory(final Block block, final IAEAppEngInventory parent, final int s) {
super(parent, s);
this.block = block;
}
public BlockUpgradeInventory( final Block block, final IAEAppEngInventory parent, final int s )
{
super( parent, s );
this.block = block;
}
@Override
public int getMaxInstalled(final Upgrades upgrades) {
int max = 0;
@Override
public int getMaxInstalled( final Upgrades upgrades )
{
int max = 0;
for (final ItemStack is : upgrades.getSupported().keySet()) {
final Item encodedItem = is.getItem();
for( final ItemStack is : upgrades.getSupported().keySet() )
{
final Item encodedItem = is.getItem();
if (encodedItem instanceof ItemBlock && Block.getBlockFromItem(encodedItem) == this.block) {
max = upgrades.getSupported().get(is);
break;
}
}
if( encodedItem instanceof ItemBlock && Block.getBlockFromItem( encodedItem ) == this.block )
{
max = upgrades.getSupported().get( is );
break;
}
}
return max;
}
return max;
}
}
@@ -19,38 +19,32 @@
package appeng.parts.automation;
import net.minecraft.item.ItemStack;
import appeng.api.config.Upgrades;
import appeng.api.definitions.IItemDefinition;
import appeng.util.inv.IAEAppEngInventory;
import net.minecraft.item.ItemStack;
public final class DefinitionUpgradeInventory extends UpgradeInventory
{
private final IItemDefinition definition;
public final class DefinitionUpgradeInventory extends UpgradeInventory {
private final IItemDefinition definition;
public DefinitionUpgradeInventory( final IItemDefinition definition, final IAEAppEngInventory parent, final int s )
{
super( parent, s );
public DefinitionUpgradeInventory(final IItemDefinition definition, final IAEAppEngInventory parent, final int s) {
super(parent, s);
this.definition = definition;
}
this.definition = definition;
}
@Override
public int getMaxInstalled( final Upgrades upgrades )
{
int max = 0;
@Override
public int getMaxInstalled(final Upgrades upgrades) {
int max = 0;
for( final ItemStack stack : upgrades.getSupported().keySet() )
{
if( this.definition.isSameAs( stack ) )
{
max = upgrades.getSupported().get( stack );
break;
}
}
for (final ItemStack stack : upgrades.getSupported().keySet()) {
if (this.definition.isSameAs(stack)) {
max = upgrades.getSupported().get(stack);
break;
}
}
return max;
}
return max;
}
}
@@ -1,14 +1,6 @@
package appeng.parts.automation;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import appeng.api.config.Actionable;
import appeng.api.networking.security.IActionSource;
import appeng.api.parts.IPart;
@@ -23,243 +15,216 @@ import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.api.util.IConfigManager;
import appeng.helpers.IPriorityHost;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
public abstract class PartAbstractFormationPlane<T extends IAEStack<T>> extends PartUpgradeable implements ICellContainer, IPriorityHost, IMEInventory<T>
{
public abstract class PartAbstractFormationPlane<T extends IAEStack<T>> extends PartUpgradeable implements ICellContainer, IPriorityHost, IMEInventory<T> {
private boolean wasActive = false;
private int priority = 0;
protected boolean blocked = false;
private boolean wasActive = false;
private int priority = 0;
protected boolean blocked = false;
public PartAbstractFormationPlane( ItemStack is )
{
super( is );
}
public PartAbstractFormationPlane(ItemStack is) {
super(is);
}
protected abstract void updateHandler();
protected abstract void updateHandler();
@Override
protected int getUpgradeSlots()
{
return 5;
}
@Override
protected int getUpgradeSlots() {
return 5;
}
@Override
public void upgradesChanged()
{
this.updateHandler();
}
@Override
public void upgradesChanged() {
this.updateHandler();
}
@Override
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
{
this.updateHandler();
this.getHost().markForSave();
}
@Override
public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) {
this.updateHandler();
this.getHost().markForSave();
}
public void stateChanged()
{
final boolean currentActive = this.getProxy().isActive();
if( this.wasActive != currentActive )
{
this.wasActive = currentActive;
this.updateHandler();
this.getHost().markForUpdate();
}
}
public void stateChanged() {
final boolean currentActive = this.getProxy().isActive();
if (this.wasActive != currentActive) {
this.wasActive = currentActive;
this.updateHandler();
this.getHost().markForUpdate();
}
}
@Override
public void getBoxes( final IPartCollisionHelper bch )
{
int minX = 1;
int minY = 1;
int maxX = 15;
int maxY = 15;
@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 IPartHost host = this.getHost();
if (host != null) {
final TileEntity te = host.getTile();
final BlockPos pos = te.getPos();
final BlockPos pos = te.getPos();
final EnumFacing e = bch.getWorldX();
final EnumFacing u = bch.getWorldY();
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.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(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.getOpposite())), this.getSide())) {
minY = 0;
}
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( u ) ), this.getSide() ) )
{
maxY = 16;
}
}
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 );
}
bch.addBox(5, 5, 14, 11, 11, 15);
bch.addBox(minX, minY, 15, maxX, maxY, 16);
}
public PlaneConnections getConnections()
{
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 );
}
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;
boolean left = false, right = false, down = false, up = false;
final IPartHost host = this.getHost();
if( host != null )
{
final TileEntity te = host.getTile();
final IPartHost host = this.getHost();
if (host != null) {
final TileEntity te = host.getTile();
final BlockPos pos = te.getPos();
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.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(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.getOpposite())), this.getSide())) {
down = true;
}
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( facingUp ) ), this.getSide() ) )
{
up = true;
}
}
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(facingUp)), this.getSide())) {
up = true;
}
}
return PlaneConnections.of( up, right, down, left );
}
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();
@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() );
final BlockPos tePos = te.getPos().offset(side.getFacing());
this.blocked = !w.getBlockState( tePos ).getBlock().isReplaceable( w, tePos );
}
}
this.blocked = !w.getBlockState(tePos).getBlock().isReplaceable(w, tePos);
}
}
@Override
public float getCableConnectionLength( AECableType cable )
{
return 1;
}
@Override
public float getCableConnectionLength(AECableType cable) {
return 1;
}
protected boolean isTransitionPlane( final TileEntity blockTileEntity, final AEPartLocation side )
{
if( blockTileEntity instanceof IPartHost )
{
final IPart p = ( (IPartHost) blockTileEntity ).getPart( side );
return p != null && this.getClass() == p.getClass();
}
return false;
}
protected boolean isTransitionPlane(final TileEntity blockTileEntity, final AEPartLocation side) {
if (blockTileEntity instanceof IPartHost) {
final IPart p = ((IPartHost) blockTileEntity).getPart(side);
return p != null && this.getClass() == p.getClass();
}
return false;
}
@Override
public T extractItems( final T request, final Actionable mode, final IActionSource src )
{
return null;
}
@Override
public T extractItems(final T request, final Actionable mode, final IActionSource src) {
return null;
}
@Override
public IItemList<T> getAvailableItems( final IItemList<T> out )
{
return out;
}
@Override
public IItemList<T> getAvailableItems(final IItemList<T> out) {
return out;
}
@Override
public void readFromNBT( final NBTTagCompound data )
{
super.readFromNBT( data );
this.priority = data.getInteger( "priority" );
}
@Override
public void readFromNBT(final NBTTagCompound data) {
super.readFromNBT(data);
this.priority = data.getInteger("priority");
}
@Override
public void writeToNBT( final NBTTagCompound data )
{
super.writeToNBT( data );
data.setInteger( "priority", this.getPriority() );
}
@Override
public void writeToNBT(final NBTTagCompound data) {
super.writeToNBT(data);
data.setInteger("priority", this.getPriority());
}
@Override
public int getPriority()
{
return this.priority;
}
@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 setPriority(final int newValue) {
this.priority = newValue;
this.getHost().markForSave();
this.updateHandler();
}
@Override
public void blinkCell( final int slot )
{
// :P
}
@Override
public void blinkCell(final int slot) {
// :P
}
@Override
public void saveChanges( final ICellInventory<?> cell )
{
// nope!
}
@Override
public void saveChanges(final ICellInventory<?> cell) {
// nope!
}
}
@@ -19,24 +19,6 @@
package appeng.parts.automation;
import java.util.List;
import com.google.common.collect.Lists;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
@@ -69,515 +51,451 @@ import appeng.parts.PartBasicState;
import appeng.util.IWorldCallable;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
public class PartAnnihilationPlane extends PartBasicState implements IGridTickable, IWorldCallable<TickRateModulation>
{
private static final PlaneModels MODELS = new PlaneModels( "part/annihilation_plane_", "part/annihilation_plane_on_" );
@PartModels
public static List<IPartModel> getModels()
{
return MODELS.getModels();
}
private final IActionSource mySrc = new MachineSource( this );
private boolean isAccepting = true;
private boolean breaking = false;
public PartAnnihilationPlane( final ItemStack is )
{
super( is );
}
@Override
public TickRateModulation call( final World world ) throws Exception
{
this.breaking = false;
return this.breakBlock( true );
}
@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.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( e.getOpposite() ) ), this.getSide() ) )
{
minX = 0;
}
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( e ) ), this.getSide() ) )
{
maxX = 16;
}
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() ) )
{
maxY = 16;
}
}
bch.addBox( 5, 5, 14, 11, 11, 15 );
// The smaller collision hitbox here is needed to allow for the entity collision event
bch.addBox( minX, minY, 15, maxX, maxY, bch.isBBCollision() ? 15 : 16 );
}
/**
* @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.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingRight.getOpposite() ) ), this.getSide() ) )
{
left = true;
}
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingRight ) ), this.getSide() ) )
{
right = true;
}
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingUp.getOpposite() ) ), this.getSide() ) )
{
down = true;
}
if( this.isAnnihilationPlane( 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 ) )
{
this.refresh();
}
}
@Override
public void onEntityCollision( final Entity entity )
{
if( this.isAccepting && entity instanceof EntityItem && !entity.isDead && Platform.isServer() && this.getProxy().isActive() )
{
boolean capture = false;
final BlockPos pos = this.getTile().getPos();
// This is the middle point of the entities BB, which is better suited for comparisons that don't rely on it
// "touching" the plane
double posYMiddle = ( entity.getEntityBoundingBox().minY + entity.getEntityBoundingBox().maxY ) / 2.0D;
switch( this.getSide() )
{
case DOWN:
case UP:
if( entity.posX > pos.getX() && entity.posX < pos.getX() + 1 )
{
if( entity.posZ > pos.getZ() && entity.posZ < pos.getZ() + 1 )
{
if( ( entity.posY > pos.getY() + 0.9 && this.getSide() == AEPartLocation.UP ) || ( entity.posY < pos.getY() + 0.1 && this
.getSide() == AEPartLocation.DOWN ) )
{
capture = true;
}
}
}
break;
case SOUTH:
case NORTH:
if( entity.posX > pos.getX() && entity.posX < pos.getX() + 1 )
{
if( posYMiddle > pos.getY() && posYMiddle < pos.getY() + 1 )
{
if( ( entity.posZ > pos.getZ() + 0.9 && this.getSide() == AEPartLocation.SOUTH ) || ( entity.posZ < pos.getZ() + 0.1 && this
.getSide() == AEPartLocation.NORTH ) )
{
capture = true;
}
}
}
break;
case EAST:
case WEST:
if( entity.posZ > pos.getZ() && entity.posZ < pos.getZ() + 1 )
{
if( posYMiddle > pos.getY() && posYMiddle < pos.getY() + 1 )
{
if( ( entity.posX > pos.getX() + 0.9 && this.getSide() == AEPartLocation.EAST ) || ( entity.posX < pos.getX() + 0.1 && this
.getSide() == AEPartLocation.WEST ) )
{
capture = true;
}
}
}
break;
default:
// umm?
break;
}
if( capture )
{
final boolean changed = this.storeEntityItem( (EntityItem) entity );
if( changed )
{
AppEng.proxy.sendToAllNearExcept( null, pos.getX(), pos.getY(), pos.getZ(), 64, this.getTile().getWorld(),
new PacketTransitionEffect( entity.posX, entity.posY, entity.posZ, this.getSide(), false ) );
}
}
}
}
@Override
public float getCableConnectionLength( AECableType cable )
{
return 1;
}
/**
* Stores an {@link EntityItem} inside the network and either marks it as dead or sets it to the leftover stackSize.
*
* @param entityItem {@link EntityItem} to store
*/
private boolean storeEntityItem( final EntityItem entityItem )
{
if( !entityItem.isDead )
{
final IAEItemStack overflow = this.storeItemStack( entityItem.getItem() );
return this.handleOverflow( entityItem, overflow );
}
return false;
}
/**
* Stores an {@link ItemStack} inside the network.
*
* @param item {@link ItemStack} to store
*
* @return the leftover items, which could not be stored inside the network
*/
private IAEItemStack storeItemStack( final ItemStack item )
{
final IAEItemStack itemToStore = AEItemStack.fromItemStack( item );
try
{
final IStorageGrid storage = this.getProxy().getStorage();
final IEnergyGrid energy = this.getProxy().getEnergy();
final IAEItemStack overflow = Platform.poweredInsert( energy,
storage.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ), itemToStore, this.mySrc );
this.isAccepting = overflow == null;
return overflow;
}
catch( final GridAccessException e1 )
{
// :P
}
return null;
}
/**
* Handles a possible overflow or none at all.
* It will update the entity to match the leftover stack size as well as mark it as dead without any leftover
* amount.
*
* @param entityItem the entity to update or destroy
* @param overflow the leftover {@link IAEItemStack}
*
* @return true, if the entity was changed otherwise false.
*/
private boolean handleOverflow( final EntityItem entityItem, final IAEItemStack overflow )
{
if( overflow == null || overflow.getStackSize() == 0 )
{
entityItem.setDead();
return true;
}
final int oldStackSize = entityItem.getItem().getCount();
final int newStackSize = (int) overflow.getStackSize();
final boolean changed = oldStackSize != newStackSize;
entityItem.getItem().setCount( newStackSize );
return changed;
}
protected 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();
}
@Override
@MENetworkEventSubscribe
public void powerRender( final MENetworkPowerStatusChange c )
{
this.refresh();
this.getHost().markForUpdate();
}
private TickRateModulation breakBlock( final boolean modulate )
{
if( this.isAccepting && this.getProxy().isActive() )
{
try
{
final TileEntity te = this.getTile();
final WorldServer w = (WorldServer) te.getWorld();
final BlockPos pos = te.getPos().offset( this.getSide().getFacing() );
final IEnergyGrid energy = this.getProxy().getEnergy();
if( this.canHandleBlock( w, pos ) )
{
final List<ItemStack> items = this.obtainBlockDrops( w, pos );
final float requiredPower = this.calculateEnergyUsage( w, pos, items );
final boolean hasPower = energy.extractAEPower( requiredPower, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > requiredPower - 0.1;
final boolean canStore = this.canStoreItemStacks( items );
if( hasPower && canStore )
{
if( modulate )
{
energy.extractAEPower( requiredPower, Actionable.MODULATE, PowerMultiplier.CONFIG );
this.breakBlockAndStoreItems( w, pos );
AppEng.proxy.sendToAllNearExcept( null, pos.getX(), pos.getY(), pos.getZ(), 64, w,
new PacketTransitionEffect( pos.getX(), pos.getY(), pos.getZ(), this.getSide(), true ) );
}
else
{
this.breaking = true;
TickHandler.INSTANCE.addCallable( this.getTile().getWorld(), this );
}
return TickRateModulation.URGENT;
}
}
}
catch( final GridAccessException e1 )
{
// :P
}
}
// nothing to do here :)
return TickRateModulation.IDLE;
}
@Override
public TickingRequest getTickingRequest( final IGridNode node )
{
return new TickingRequest( TickRates.AnnihilationPlane.getMin(), TickRates.AnnihilationPlane.getMax(), false, true );
}
@Override
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
{
if( this.breaking )
{
return TickRateModulation.URGENT;
}
this.isAccepting = true;
return this.breakBlock( false );
}
/**
* Checks if this plane can handle the block at the specific coordinates.
*/
private boolean canHandleBlock( final WorldServer w, final BlockPos pos )
{
final IBlockState state = w.getBlockState( pos );
final Material material = state.getMaterial();
final float hardness = state.getBlockHardness( w, pos );
final boolean ignoreMaterials = material == Material.AIR || material == Material.LAVA || material == Material.WATER || material.isLiquid();
final boolean ignoreBlocks = state.getBlock() == Blocks.BEDROCK || state.getBlock() == Blocks.END_PORTAL || state
.getBlock() == Blocks.END_PORTAL_FRAME || state.getBlock() == Blocks.COMMAND_BLOCK;
return !ignoreMaterials && !ignoreBlocks && hardness >= 0f && !w.isAirBlock( pos ) && w.isBlockLoaded( pos ) && w.canMineBlockBody(
Platform.getPlayer( w ),
pos );
}
protected List<ItemStack> obtainBlockDrops( final WorldServer w, final BlockPos pos )
{
final ItemStack[] out = Platform.getBlockDrops( w, pos );
return Lists.newArrayList( out );
}
/**
* Checks if this plane can handle the block at the specific coordinates.
*/
protected float calculateEnergyUsage( final WorldServer w, final BlockPos pos, final List<ItemStack> items )
{
final IBlockState state = w.getBlockState( pos );
final float hardness = state.getBlockHardness( w, pos );
float requiredEnergy = 1 + hardness;
for( final ItemStack is : items )
{
requiredEnergy += is.getCount();
}
return requiredEnergy;
}
/**
* Checks if the network can store the possible drops.
*
* It also sets isAccepting to false, if the item can not be stored.
*
* @param itemStacks an array of {@link ItemStack} to test
*
* @return true, if the network can store at least a single item of all drops or no drops are reported
*/
private boolean canStoreItemStacks( final List<ItemStack> itemStacks )
{
boolean canStore = itemStacks.isEmpty();
try
{
final IStorageGrid storage = this.getProxy().getStorage();
for( final ItemStack itemStack : itemStacks )
{
final IAEItemStack itemToTest = AEItemStack.fromItemStack( itemStack );
final IAEItemStack overflow = storage.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
.injectItems( itemToTest, Actionable.SIMULATE, this.mySrc );
if( overflow == null || itemToTest.getStackSize() > overflow.getStackSize() )
{
canStore = true;
}
}
}
catch( final GridAccessException e )
{
// :P
}
this.isAccepting = canStore;
return canStore;
}
private void breakBlockAndStoreItems( final WorldServer w, final BlockPos pos )
{
w.destroyBlock( pos, true );
final AxisAlignedBB box = new AxisAlignedBB( pos ).grow( 0.2 );
for( final Object ei : w.getEntitiesWithinAABB( EntityItem.class, box ) )
{
if( ei instanceof EntityItem )
{
final EntityItem entityItem = (EntityItem) ei;
this.storeEntityItem( entityItem );
}
}
}
private void refresh()
{
this.isAccepting = true;
try
{
this.getProxy().getTick().alertDevice( this.getProxy().getNode() );
}
catch( final GridAccessException e )
{
// :P
}
}
@Override
public IPartModel getStaticModels()
{
return MODELS.getModel( this.getConnections(), this.isPowered(), this.isActive() );
}
import com.google.common.collect.Lists;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import java.util.List;
public class PartAnnihilationPlane extends PartBasicState implements IGridTickable, IWorldCallable<TickRateModulation> {
private static final PlaneModels MODELS = new PlaneModels("part/annihilation_plane_", "part/annihilation_plane_on_");
@PartModels
public static List<IPartModel> getModels() {
return MODELS.getModels();
}
private final IActionSource mySrc = new MachineSource(this);
private boolean isAccepting = true;
private boolean breaking = false;
public PartAnnihilationPlane(final ItemStack is) {
super(is);
}
@Override
public TickRateModulation call(final World world) throws Exception {
this.breaking = false;
return this.breakBlock(true);
}
@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.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(e.getOpposite())), this.getSide())) {
minX = 0;
}
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(e)), this.getSide())) {
maxX = 16;
}
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())) {
maxY = 16;
}
}
bch.addBox(5, 5, 14, 11, 11, 15);
// The smaller collision hitbox here is needed to allow for the entity collision event
bch.addBox(minX, minY, 15, maxX, maxY, bch.isBBCollision() ? 15 : 16);
}
/**
* @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.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(facingRight.getOpposite())), this.getSide())) {
left = true;
}
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(facingRight)), this.getSide())) {
right = true;
}
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(facingUp.getOpposite())), this.getSide())) {
down = true;
}
if (this.isAnnihilationPlane(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)) {
this.refresh();
}
}
@Override
public void onEntityCollision(final Entity entity) {
if (this.isAccepting && entity instanceof EntityItem && !entity.isDead && Platform.isServer() && this.getProxy().isActive()) {
boolean capture = false;
final BlockPos pos = this.getTile().getPos();
// This is the middle point of the entities BB, which is better suited for comparisons that don't rely on it
// "touching" the plane
double posYMiddle = (entity.getEntityBoundingBox().minY + entity.getEntityBoundingBox().maxY) / 2.0D;
switch (this.getSide()) {
case DOWN:
case UP:
if (entity.posX > pos.getX() && entity.posX < pos.getX() + 1) {
if (entity.posZ > pos.getZ() && entity.posZ < pos.getZ() + 1) {
if ((entity.posY > pos.getY() + 0.9 && this.getSide() == AEPartLocation.UP) || (entity.posY < pos.getY() + 0.1 && this
.getSide() == AEPartLocation.DOWN)) {
capture = true;
}
}
}
break;
case SOUTH:
case NORTH:
if (entity.posX > pos.getX() && entity.posX < pos.getX() + 1) {
if (posYMiddle > pos.getY() && posYMiddle < pos.getY() + 1) {
if ((entity.posZ > pos.getZ() + 0.9 && this.getSide() == AEPartLocation.SOUTH) || (entity.posZ < pos.getZ() + 0.1 && this
.getSide() == AEPartLocation.NORTH)) {
capture = true;
}
}
}
break;
case EAST:
case WEST:
if (entity.posZ > pos.getZ() && entity.posZ < pos.getZ() + 1) {
if (posYMiddle > pos.getY() && posYMiddle < pos.getY() + 1) {
if ((entity.posX > pos.getX() + 0.9 && this.getSide() == AEPartLocation.EAST) || (entity.posX < pos.getX() + 0.1 && this
.getSide() == AEPartLocation.WEST)) {
capture = true;
}
}
}
break;
default:
// umm?
break;
}
if (capture) {
final boolean changed = this.storeEntityItem((EntityItem) entity);
if (changed) {
AppEng.proxy.sendToAllNearExcept(null, pos.getX(), pos.getY(), pos.getZ(), 64, this.getTile().getWorld(),
new PacketTransitionEffect(entity.posX, entity.posY, entity.posZ, this.getSide(), false));
}
}
}
}
@Override
public float getCableConnectionLength(AECableType cable) {
return 1;
}
/**
* Stores an {@link EntityItem} inside the network and either marks it as dead or sets it to the leftover stackSize.
*
* @param entityItem {@link EntityItem} to store
*/
private boolean storeEntityItem(final EntityItem entityItem) {
if (!entityItem.isDead) {
final IAEItemStack overflow = this.storeItemStack(entityItem.getItem());
return this.handleOverflow(entityItem, overflow);
}
return false;
}
/**
* Stores an {@link ItemStack} inside the network.
*
* @param item {@link ItemStack} to store
* @return the leftover items, which could not be stored inside the network
*/
private IAEItemStack storeItemStack(final ItemStack item) {
final IAEItemStack itemToStore = AEItemStack.fromItemStack(item);
try {
final IStorageGrid storage = this.getProxy().getStorage();
final IEnergyGrid energy = this.getProxy().getEnergy();
final IAEItemStack overflow = Platform.poweredInsert(energy,
storage.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)), itemToStore, this.mySrc);
this.isAccepting = overflow == null;
return overflow;
} catch (final GridAccessException e1) {
// :P
}
return null;
}
/**
* Handles a possible overflow or none at all.
* It will update the entity to match the leftover stack size as well as mark it as dead without any leftover
* amount.
*
* @param entityItem the entity to update or destroy
* @param overflow the leftover {@link IAEItemStack}
* @return true, if the entity was changed otherwise false.
*/
private boolean handleOverflow(final EntityItem entityItem, final IAEItemStack overflow) {
if (overflow == null || overflow.getStackSize() == 0) {
entityItem.setDead();
return true;
}
final int oldStackSize = entityItem.getItem().getCount();
final int newStackSize = (int) overflow.getStackSize();
final boolean changed = oldStackSize != newStackSize;
entityItem.getItem().setCount(newStackSize);
return changed;
}
protected 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();
}
@Override
@MENetworkEventSubscribe
public void powerRender(final MENetworkPowerStatusChange c) {
this.refresh();
this.getHost().markForUpdate();
}
private TickRateModulation breakBlock(final boolean modulate) {
if (this.isAccepting && this.getProxy().isActive()) {
try {
final TileEntity te = this.getTile();
final WorldServer w = (WorldServer) te.getWorld();
final BlockPos pos = te.getPos().offset(this.getSide().getFacing());
final IEnergyGrid energy = this.getProxy().getEnergy();
if (this.canHandleBlock(w, pos)) {
final List<ItemStack> items = this.obtainBlockDrops(w, pos);
final float requiredPower = this.calculateEnergyUsage(w, pos, items);
final boolean hasPower = energy.extractAEPower(requiredPower, Actionable.SIMULATE, PowerMultiplier.CONFIG) > requiredPower - 0.1;
final boolean canStore = this.canStoreItemStacks(items);
if (hasPower && canStore) {
if (modulate) {
energy.extractAEPower(requiredPower, Actionable.MODULATE, PowerMultiplier.CONFIG);
this.breakBlockAndStoreItems(w, pos);
AppEng.proxy.sendToAllNearExcept(null, pos.getX(), pos.getY(), pos.getZ(), 64, w,
new PacketTransitionEffect(pos.getX(), pos.getY(), pos.getZ(), this.getSide(), true));
} else {
this.breaking = true;
TickHandler.INSTANCE.addCallable(this.getTile().getWorld(), this);
}
return TickRateModulation.URGENT;
}
}
} catch (final GridAccessException e1) {
// :P
}
}
// nothing to do here :)
return TickRateModulation.IDLE;
}
@Override
public TickingRequest getTickingRequest(final IGridNode node) {
return new TickingRequest(TickRates.AnnihilationPlane.getMin(), TickRates.AnnihilationPlane.getMax(), false, true);
}
@Override
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
if (this.breaking) {
return TickRateModulation.URGENT;
}
this.isAccepting = true;
return this.breakBlock(false);
}
/**
* Checks if this plane can handle the block at the specific coordinates.
*/
private boolean canHandleBlock(final WorldServer w, final BlockPos pos) {
final IBlockState state = w.getBlockState(pos);
final Material material = state.getMaterial();
final float hardness = state.getBlockHardness(w, pos);
final boolean ignoreMaterials = material == Material.AIR || material == Material.LAVA || material == Material.WATER || material.isLiquid();
final boolean ignoreBlocks = state.getBlock() == Blocks.BEDROCK || state.getBlock() == Blocks.END_PORTAL || state
.getBlock() == Blocks.END_PORTAL_FRAME || state.getBlock() == Blocks.COMMAND_BLOCK;
return !ignoreMaterials && !ignoreBlocks && hardness >= 0f && !w.isAirBlock(pos) && w.isBlockLoaded(pos) && w.canMineBlockBody(
Platform.getPlayer(w),
pos);
}
protected List<ItemStack> obtainBlockDrops(final WorldServer w, final BlockPos pos) {
final ItemStack[] out = Platform.getBlockDrops(w, pos);
return Lists.newArrayList(out);
}
/**
* Checks if this plane can handle the block at the specific coordinates.
*/
protected float calculateEnergyUsage(final WorldServer w, final BlockPos pos, final List<ItemStack> items) {
final IBlockState state = w.getBlockState(pos);
final float hardness = state.getBlockHardness(w, pos);
float requiredEnergy = 1 + hardness;
for (final ItemStack is : items) {
requiredEnergy += is.getCount();
}
return requiredEnergy;
}
/**
* Checks if the network can store the possible drops.
* <p>
* It also sets isAccepting to false, if the item can not be stored.
*
* @param itemStacks an array of {@link ItemStack} to test
* @return true, if the network can store at least a single item of all drops or no drops are reported
*/
private boolean canStoreItemStacks(final List<ItemStack> itemStacks) {
boolean canStore = itemStacks.isEmpty();
try {
final IStorageGrid storage = this.getProxy().getStorage();
for (final ItemStack itemStack : itemStacks) {
final IAEItemStack itemToTest = AEItemStack.fromItemStack(itemStack);
final IAEItemStack overflow = storage.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class))
.injectItems(itemToTest, Actionable.SIMULATE, this.mySrc);
if (overflow == null || itemToTest.getStackSize() > overflow.getStackSize()) {
canStore = true;
}
}
} catch (final GridAccessException e) {
// :P
}
this.isAccepting = canStore;
return canStore;
}
private void breakBlockAndStoreItems(final WorldServer w, final BlockPos pos) {
w.destroyBlock(pos, true);
final AxisAlignedBB box = new AxisAlignedBB(pos).grow(0.2);
for (final Object ei : w.getEntitiesWithinAABB(EntityItem.class, box)) {
if (ei instanceof EntityItem) {
final EntityItem entityItem = (EntityItem) ei;
this.storeEntityItem(entityItem);
}
}
}
private void refresh() {
this.isAccepting = true;
try {
this.getProxy().getTick().alertDevice(this.getProxy().getNode());
} catch (final GridAccessException e) {
// :P
}
}
@Override
public IPartModel getStaticModels() {
return MODELS.getModel(this.getConnections(), this.isPowered(), this.isActive());
}
}
@@ -19,26 +19,8 @@
package appeng.parts.automation;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.primitives.Ints;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.config.PowerMultiplier;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SchedulingMode;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.config.YesNo;
import appeng.api.config.*;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingLink;
@@ -67,344 +49,287 @@ import appeng.parts.PartModel;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.primitives.Ints;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
public class PartExportBus extends PartSharedItemBus implements ICraftingRequester
{
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/export_bus_base" );
public class PartExportBus extends PartSharedItemBus implements ICraftingRequester {
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/export_bus_base");
@PartModels
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/export_bus_off" ) );
@PartModels
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, new ResourceLocation(AppEng.MOD_ID, "part/export_bus_off"));
@PartModels
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/export_bus_on" ) );
@PartModels
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, new ResourceLocation(AppEng.MOD_ID, "part/export_bus_on"));
@PartModels
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/export_bus_has_channel" ) );
@PartModels
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, new ResourceLocation(AppEng.MOD_ID, "part/export_bus_has_channel"));
private final MultiCraftingTracker craftingTracker = new MultiCraftingTracker( this, 9 );
private final IActionSource mySrc;
private long itemToSend = 1;
private boolean didSomething = false;
private int nextSlot = 0;
private final MultiCraftingTracker craftingTracker = new MultiCraftingTracker(this, 9);
private final IActionSource mySrc;
private long itemToSend = 1;
private boolean didSomething = false;
private int nextSlot = 0;
@Reflected
public PartExportBus( final ItemStack is )
{
super( is );
@Reflected
public PartExportBus(final 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.mySrc = new MachineSource( this );
}
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.mySrc = new MachineSource(this);
}
@Override
public void readFromNBT( final NBTTagCompound extra )
{
super.readFromNBT( extra );
this.craftingTracker.readFromNBT( extra );
this.nextSlot = extra.getInteger( "nextSlot" );
}
@Override
public void readFromNBT(final NBTTagCompound extra) {
super.readFromNBT(extra);
this.craftingTracker.readFromNBT(extra);
this.nextSlot = extra.getInteger("nextSlot");
}
@Override
public void writeToNBT( final NBTTagCompound extra )
{
super.writeToNBT( extra );
this.craftingTracker.writeToNBT( extra );
extra.setInteger( "nextSlot", this.nextSlot );
}
@Override
public void writeToNBT(final NBTTagCompound extra) {
super.writeToNBT(extra);
this.craftingTracker.writeToNBT(extra);
extra.setInteger("nextSlot", this.nextSlot);
}
@Override
protected TickRateModulation doBusWork()
{
if( !this.getProxy().isActive() || !this.canDoBusWork() )
{
return TickRateModulation.IDLE;
}
@Override
protected TickRateModulation doBusWork() {
if (!this.getProxy().isActive() || !this.canDoBusWork()) {
return TickRateModulation.IDLE;
}
this.itemToSend = this.calculateItemsToSend();
this.didSomething = false;
this.itemToSend = this.calculateItemsToSend();
this.didSomething = false;
try
{
final InventoryAdaptor destination = this.getHandler();
final IMEMonitor<IAEItemStack> inv = this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
final IEnergyGrid energy = this.getProxy().getEnergy();
final ICraftingGrid cg = this.getProxy().getCrafting();
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE );
final SchedulingMode schedulingMode = (SchedulingMode) this.getConfigManager().getSetting( Settings.SCHEDULING_MODE );
try {
final InventoryAdaptor destination = this.getHandler();
final IMEMonitor<IAEItemStack> inv = this.getProxy().getStorage().getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
final IEnergyGrid energy = this.getProxy().getEnergy();
final ICraftingGrid cg = this.getProxy().getCrafting();
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting(Settings.FUZZY_MODE);
final SchedulingMode schedulingMode = (SchedulingMode) this.getConfigManager().getSetting(Settings.SCHEDULING_MODE);
if( destination != null )
{
int x = 0;
if (destination != null) {
int x = 0;
for( x = 0; x < this.availableSlots() && this.itemToSend > 0; x++ )
{
final int slotToExport = this.getStartingSlot( schedulingMode, x );
for (x = 0; x < this.availableSlots() && this.itemToSend > 0; x++) {
final int slotToExport = this.getStartingSlot(schedulingMode, x);
final IAEItemStack ais = this.getConfig().getAEStackInSlot( slotToExport );
final IAEItemStack ais = this.getConfig().getAEStackInSlot(slotToExport);
if( ais == null || this.itemToSend <= 0 )
{
continue;
}
if (ais == null || this.itemToSend <= 0) {
continue;
}
if( this.craftOnly() )
{
this.didSomething = this.craftingTracker.handleCrafting( slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc ) || this.didSomething;
if (this.craftOnly()) {
this.didSomething = this.craftingTracker.handleCrafting(slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc) || this.didSomething;
}
}
final long before = this.itemToSend;
final long before = this.itemToSend;
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
{
for( final IAEItemStack o : ImmutableList.copyOf( inv.getStorageList().findFuzzy( ais, fzMode ) ) )
{
this.pushItemIntoTarget( destination, energy, inv, o );
if( this.itemToSend <= 0 )
{
break;
}
}
}
else
{
if( inv.getStorageList().findPrecise( ais ) != null )
{
this.pushItemIntoTarget( destination, energy, inv, ais );
}
}
if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0) {
for (final IAEItemStack o : ImmutableList.copyOf(inv.getStorageList().findFuzzy(ais, fzMode))) {
this.pushItemIntoTarget(destination, energy, inv, o);
if (this.itemToSend <= 0) {
break;
}
}
} else {
if (inv.getStorageList().findPrecise(ais) != null) {
this.pushItemIntoTarget(destination, energy, inv, ais);
}
}
if( this.itemToSend == before && this.isCraftingEnabled() )
{
this.didSomething = this.craftingTracker.handleCrafting( slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc ) || this.didSomething;
}
}
if (this.itemToSend == before && this.isCraftingEnabled()) {
this.didSomething = this.craftingTracker.handleCrafting(slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc) || this.didSomething;
}
}
this.updateSchedulingMode( schedulingMode, x );
}
else
{
return TickRateModulation.SLEEP;
}
}
catch( final GridAccessException e )
{
// :P
}
this.updateSchedulingMode(schedulingMode, x);
} else {
return TickRateModulation.SLEEP;
}
} catch (final GridAccessException e) {
// :P
}
return this.didSomething ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
}
return this.didSomething ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
}
@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 float getCableConnectionLength( AECableType cable )
{
return 5;
}
@Override
public float getCableConnectionLength(AECableType cable) {
return 5;
}
@Override
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
{
if( Platform.isServer() )
{
Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_BUS );
}
return true;
}
@Override
public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
if (Platform.isServer()) {
Platform.openGUI(player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_BUS);
}
return true;
}
@Override
public TickingRequest getTickingRequest( final IGridNode node )
{
return new TickingRequest( TickRates.ExportBus.getMin(), TickRates.ExportBus.getMax(), this.isSleeping(), false );
}
@Override
public TickingRequest getTickingRequest(final IGridNode node) {
return new TickingRequest(TickRates.ExportBus.getMin(), TickRates.ExportBus.getMax(), this.isSleeping(), 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);
}
@Override
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
{
return this.doBusWork();
}
@Override
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
return this.doBusWork();
}
@Override
public ImmutableSet<ICraftingLink> getRequestedJobs()
{
return this.craftingTracker.getRequestedJobs();
}
@Override
public ImmutableSet<ICraftingLink> getRequestedJobs() {
return this.craftingTracker.getRequestedJobs();
}
@Override
public IAEItemStack injectCraftedItems( final ICraftingLink link, final IAEItemStack items, final Actionable mode )
{
final InventoryAdaptor d = this.getHandler();
@Override
public IAEItemStack injectCraftedItems(final ICraftingLink link, final IAEItemStack items, final Actionable mode) {
final InventoryAdaptor d = this.getHandler();
try
{
if( d != null && this.getProxy().isActive() )
{
final IEnergyGrid energy = this.getProxy().getEnergy();
final double power = items.getStackSize();
try {
if (d != null && this.getProxy().isActive()) {
final IEnergyGrid energy = this.getProxy().getEnergy();
final double power = items.getStackSize();
if( energy.extractAEPower( power, mode, PowerMultiplier.CONFIG ) > power - 0.01 )
{
ItemStack inputStack = items.getCachedItemStack( items.getStackSize() );
if (energy.extractAEPower(power, mode, PowerMultiplier.CONFIG) > power - 0.01) {
ItemStack inputStack = items.getCachedItemStack(items.getStackSize());
ItemStack remaining;
ItemStack remaining;
if( mode == Actionable.SIMULATE )
{
remaining = d.simulateAdd( inputStack );
items.setCachedItemStack( inputStack );
}
else
{
remaining = d.addItems( inputStack );
if( !remaining.isEmpty() )
{
items.setCachedItemStack( remaining );
}
}
if (mode == Actionable.SIMULATE) {
remaining = d.simulateAdd(inputStack);
items.setCachedItemStack(inputStack);
} else {
remaining = d.addItems(inputStack);
if (!remaining.isEmpty()) {
items.setCachedItemStack(remaining);
}
}
if( remaining == inputStack )
{
return items;
}
if (remaining == inputStack) {
return items;
}
return AEItemStack.fromItemStack( remaining );
}
}
}
catch( final GridAccessException e )
{
AELog.debug( e );
}
return AEItemStack.fromItemStack(remaining);
}
}
} catch (final GridAccessException e) {
AELog.debug(e);
}
return items;
}
return items;
}
@Override
public void jobStateChange( final ICraftingLink link )
{
this.craftingTracker.jobStateChange( link );
}
@Override
public void jobStateChange(final ICraftingLink link) {
this.craftingTracker.jobStateChange(link);
}
@Override
protected boolean isSleeping()
{
return this.getHandler() == null || super.isSleeping();
}
@Override
protected boolean isSleeping() {
return this.getHandler() == null || super.isSleeping();
}
private boolean craftOnly()
{
return this.getConfigManager().getSetting( Settings.CRAFT_ONLY ) == YesNo.YES;
}
private boolean craftOnly() {
return this.getConfigManager().getSetting(Settings.CRAFT_ONLY) == YesNo.YES;
}
private boolean isCraftingEnabled()
{
return this.getInstalledUpgrades( Upgrades.CRAFTING ) > 0;
}
private boolean isCraftingEnabled() {
return this.getInstalledUpgrades(Upgrades.CRAFTING) > 0;
}
private void pushItemIntoTarget( final InventoryAdaptor d, final IEnergyGrid energy, final IMEInventory<IAEItemStack> inv, IAEItemStack org )
{
ItemStack inputStack = org.getCachedItemStack( org.getStackSize() );
private void pushItemIntoTarget(final InventoryAdaptor d, final IEnergyGrid energy, final IMEInventory<IAEItemStack> inv, IAEItemStack org) {
ItemStack inputStack = org.getCachedItemStack(org.getStackSize());
ItemStack remaining = d.simulateAdd( inputStack );
ItemStack remaining = d.simulateAdd(inputStack);
// Store the stack in the cache for next time.
if( !remaining.isEmpty() )
{
org.setCachedItemStack( remaining );
if( remaining == inputStack )
{
return;
}
}
// Store the stack in the cache for next time.
if (!remaining.isEmpty()) {
org.setCachedItemStack(remaining);
if (remaining == inputStack) {
return;
}
}
final long canFit = remaining.isEmpty() ? this.itemToSend : this.itemToSend - remaining.getCount();
final long canFit = remaining.isEmpty() ? this.itemToSend : this.itemToSend - remaining.getCount();
if( canFit > 0 )
{
IAEItemStack ais = org.copy();
ais.setStackSize( canFit );
final IAEItemStack itemsToAdd = Platform.poweredExtraction( energy, inv, ais, this.mySrc );
if (canFit > 0) {
IAEItemStack ais = org.copy();
ais.setStackSize(canFit);
final IAEItemStack itemsToAdd = Platform.poweredExtraction(energy, inv, ais, this.mySrc);
if( itemsToAdd != null )
{
this.itemToSend -= itemsToAdd.getStackSize();
if (itemsToAdd != null) {
this.itemToSend -= itemsToAdd.getStackSize();
inputStack.setCount( Ints.saturatedCast( itemsToAdd.getStackSize() ) );
inputStack.setCount(Ints.saturatedCast(itemsToAdd.getStackSize()));
final ItemStack failed = d.addItems( inputStack );
if( !failed.isEmpty() )
{
ais.setStackSize( failed.getCount() );
inv.injectItems( ais, Actionable.MODULATE, this.mySrc );
}
else
{
this.didSomething = true;
}
}
else
{
org.setCachedItemStack( inputStack );
}
}
}
final ItemStack failed = d.addItems(inputStack);
if (!failed.isEmpty()) {
ais.setStackSize(failed.getCount());
inv.injectItems(ais, Actionable.MODULATE, this.mySrc);
} else {
this.didSomething = true;
}
} else {
org.setCachedItemStack(inputStack);
}
}
}
private int getStartingSlot( final SchedulingMode schedulingMode, final int x )
{
if( schedulingMode == SchedulingMode.RANDOM )
{
return Platform.getRandom().nextInt( this.availableSlots() );
}
private int getStartingSlot(final SchedulingMode schedulingMode, final int x) {
if (schedulingMode == SchedulingMode.RANDOM) {
return Platform.getRandom().nextInt(this.availableSlots());
}
if( schedulingMode == SchedulingMode.ROUNDROBIN )
{
return ( this.nextSlot + x ) % this.availableSlots();
}
if (schedulingMode == SchedulingMode.ROUNDROBIN) {
return (this.nextSlot + x) % this.availableSlots();
}
return x;
}
return x;
}
private void updateSchedulingMode( final SchedulingMode schedulingMode, final int x )
{
if( schedulingMode == SchedulingMode.ROUNDROBIN )
{
this.nextSlot = ( this.nextSlot + x ) % this.availableSlots();
}
}
private void updateSchedulingMode(final SchedulingMode schedulingMode, final int x) {
if (schedulingMode == SchedulingMode.ROUNDROBIN) {
this.nextSlot = (this.nextSlot + x) % this.availableSlots();
}
}
@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;
}
}
}
@@ -19,41 +19,8 @@
package appeng.parts.automation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemBlockSpecial;
import net.minecraft.item.ItemFirework;
import net.minecraft.item.ItemSkull;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.config.IncludeExclude;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.config.YesNo;
import appeng.api.config.*;
import appeng.api.networking.events.MENetworkCellArrayUpdate;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
@@ -77,319 +44,284 @@ import appeng.util.Platform;
import appeng.util.inv.InvOperation;
import appeng.util.prioritylist.FuzzyPriorityList;
import appeng.util.prioritylist.PrecisePriorityList;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.*;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.items.IItemHandler;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class PartFormationPlane extends PartAbstractFormationPlane<IAEItemStack>
{
public class PartFormationPlane extends PartAbstractFormationPlane<IAEItemStack> {
private static final PlaneModels MODELS = new PlaneModels( "part/formation_plane_", "part/formation_plane_on_" );
private static final PlaneModels MODELS = new PlaneModels("part/formation_plane_", "part/formation_plane_on_");
@PartModels
public static List<IPartModel> getModels()
{
return MODELS.getModels();
}
@PartModels
public static List<IPartModel> getModels() {
return MODELS.getModels();
}
private final MEInventoryHandler<IAEItemStack> myHandler = new MEInventoryHandler<>( this, AEApi.instance()
.storage()
.getStorageChannel( IItemStorageChannel.class ) );
private final AppEngInternalAEInventory Config = new AppEngInternalAEInventory( this, 63 );
private final MEInventoryHandler<IAEItemStack> myHandler = new MEInventoryHandler<>(this, AEApi.instance()
.storage()
.getStorageChannel(IItemStorageChannel.class));
private final AppEngInternalAEInventory Config = new AppEngInternalAEInventory(this, 63);
public PartFormationPlane( final ItemStack is )
{
super( is );
public PartFormationPlane(final ItemStack is) {
super(is);
this.getConfigManager().registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
this.getConfigManager().registerSetting( Settings.PLACE_BLOCK, YesNo.YES );
this.updateHandler();
}
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
this.getConfigManager().registerSetting(Settings.PLACE_BLOCK, YesNo.YES);
this.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.getPriority() );
@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 IItemList<IAEItemStack> priorityList = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
final int slotsToUse = 18 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 9;
for( int x = 0; x < this.Config.getSlots() && x < slotsToUse; x++ )
{
final IAEItemStack is = this.Config.getAEStackInSlot( 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 IAEItemStack is = this.Config.getAEStackInSlot(x);
if (is != null) {
priorityList.add(is);
}
}
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
{
this.myHandler.setPartitionList(
new FuzzyPriorityList<IAEItemStack>( priorityList, (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE ) ) );
}
else
{
this.myHandler.setPartitionList( new PrecisePriorityList<IAEItemStack>( priorityList ) );
}
if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0) {
this.myHandler.setPartitionList(
new FuzzyPriorityList<IAEItemStack>(priorityList, (FuzzyMode) this.getConfigManager().getSetting(Settings.FUZZY_MODE)));
} else {
this.myHandler.setPartitionList(new PrecisePriorityList<IAEItemStack>(priorityList));
}
try
{
this.getProxy().getGrid().postEvent( new MENetworkCellArrayUpdate() );
}
catch( final GridAccessException e )
{
// :P
}
}
try {
this.getProxy().getGrid().postEvent(new MENetworkCellArrayUpdate());
} catch (final GridAccessException e) {
// :P
}
}
@Override
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
super.onChangeInventory( inv, slot, mc, removedStack, newStack );
@Override
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
super.onChangeInventory(inv, slot, mc, removedStack, newStack);
if( inv == this.Config )
{
this.updateHandler();
}
}
if (inv == this.Config) {
this.updateHandler();
}
}
@Override
public void readFromNBT( final NBTTagCompound data )
{
super.readFromNBT( data );
this.Config.readFromNBT( data, "config" );
this.updateHandler();
}
@Override
public void readFromNBT(final NBTTagCompound data) {
super.readFromNBT(data);
this.Config.readFromNBT(data, "config");
this.updateHandler();
}
@Override
public void writeToNBT( final NBTTagCompound data )
{
super.writeToNBT( data );
this.Config.writeToNBT( data, "config" );
}
@Override
public void writeToNBT(final NBTTagCompound data) {
super.writeToNBT(data);
this.Config.writeToNBT(data, "config");
}
@Override
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "config" ) )
{
return this.Config;
}
@Override
public IItemHandler getInventoryByName(final String name) {
if (name.equals("config")) {
return this.Config;
}
return super.getInventoryByName( name );
}
return super.getInventoryByName(name);
}
@Override
@MENetworkEventSubscribe
public void powerRender( final MENetworkPowerStatusChange c )
{
this.stateChanged();
}
@Override
@MENetworkEventSubscribe
public void powerRender(final MENetworkPowerStatusChange c) {
this.stateChanged();
}
@Override
@MENetworkEventSubscribe
public void chanRender( final MENetworkChannelsChanged changedChannels )
{
this.stateChanged();
}
@Override
@MENetworkEventSubscribe
public void chanRender(final MENetworkChannelsChanged changedChannels) {
this.stateChanged();
}
@Override
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
{
if( Platform.isServer() )
{
Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_FORMATION_PLANE );
}
return true;
}
@Override
public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
if (Platform.isServer()) {
Platform.openGUI(player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_FORMATION_PLANE);
}
return true;
}
@Override
public List<IMEInventoryHandler> getCellArray( final IStorageChannel channel )
{
if( channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
{
final List<IMEInventoryHandler> handler = new ArrayList<>( 1 );
handler.add( this.myHandler );
return handler;
}
return Collections.emptyList();
}
@Override
public List<IMEInventoryHandler> getCellArray(final IStorageChannel channel) {
if (channel == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) {
final List<IMEInventoryHandler> handler = new ArrayList<>(1);
handler.add(this.myHandler);
return handler;
}
return Collections.emptyList();
}
@Override
public IAEItemStack injectItems( final IAEItemStack input, final Actionable type, final IActionSource src )
{
if( this.blocked || input == null || input.getStackSize() <= 0 )
{
return input;
}
@Override
public IAEItemStack injectItems(final IAEItemStack input, final Actionable type, final IActionSource src) {
if (this.blocked || input == null || input.getStackSize() <= 0) {
return input;
}
final YesNo placeBlock = (YesNo) this.getConfigManager().getSetting( Settings.PLACE_BLOCK );
final YesNo placeBlock = (YesNo) this.getConfigManager().getSetting(Settings.PLACE_BLOCK);
final ItemStack is = input.createItemStack();
final Item i = is.getItem();
final ItemStack is = input.createItemStack();
final Item i = is.getItem();
long maxStorage = Math.min( input.getStackSize(), is.getMaxStackSize() );
boolean worked = false;
long maxStorage = Math.min(input.getStackSize(), is.getMaxStackSize());
boolean worked = false;
final TileEntity te = this.getHost().getTile();
final World w = te.getWorld();
final AEPartLocation side = this.getSide();
final TileEntity te = this.getHost().getTile();
final World w = te.getWorld();
final AEPartLocation side = this.getSide();
final BlockPos tePos = te.getPos().offset( side.getFacing() );
final BlockPos tePos = te.getPos().offset(side.getFacing());
if( w.getBlockState( tePos ).getBlock().isReplaceable( w, tePos ) )
{
if( placeBlock == YesNo.YES && ( i instanceof ItemBlock || i instanceof ItemBlockSpecial || i instanceof IPlantable || i instanceof ItemSkull || i instanceof ItemFirework || i instanceof IPartItem || i == Item
.getItemFromBlock( Blocks.REEDS ) ) )
{
final EntityPlayer player = Platform.getPlayer( (WorldServer) w );
Platform.configurePlayer( player, side, this.getTile() );
EnumHand hand = player.getActiveHand();
player.setHeldItem( hand, is );
if (w.getBlockState(tePos).getBlock().isReplaceable(w, tePos)) {
if (placeBlock == YesNo.YES && (i instanceof ItemBlock || i instanceof ItemBlockSpecial || i instanceof IPlantable || i instanceof ItemSkull || i instanceof ItemFirework || i instanceof IPartItem || i == Item
.getItemFromBlock(Blocks.REEDS))) {
final EntityPlayer player = Platform.getPlayer((WorldServer) w);
Platform.configurePlayer(player, side, this.getTile());
EnumHand hand = player.getActiveHand();
player.setHeldItem(hand, is);
maxStorage = is.getCount();
worked = true;
if( type == Actionable.MODULATE )
{
if( i instanceof IPlantable || i instanceof ItemSkull || i == Item.getItemFromBlock( Blocks.REEDS ) )
{
boolean Worked = false;
maxStorage = is.getCount();
worked = true;
if (type == Actionable.MODULATE) {
if (i instanceof IPlantable || i instanceof ItemSkull || i == Item.getItemFromBlock(Blocks.REEDS)) {
boolean Worked = false;
if( side.xOffset == 0 && side.zOffset == 0 )
{
Worked = i.onItemUse( player, w, tePos.offset( side.getFacing() ), hand, side.getFacing().getOpposite(), side.xOffset,
side.yOffset, side.zOffset ) == EnumActionResult.SUCCESS;
}
if (side.xOffset == 0 && side.zOffset == 0) {
Worked = i.onItemUse(player, w, tePos.offset(side.getFacing()), hand, side.getFacing().getOpposite(), side.xOffset,
side.yOffset, side.zOffset) == EnumActionResult.SUCCESS;
}
if( !Worked && side.xOffset == 0 && side.zOffset == 0 )
{
Worked = i.onItemUse( player, w, tePos.offset( side.getFacing().getOpposite() ), hand, side.getFacing(), side.xOffset,
side.yOffset, side.zOffset ) == EnumActionResult.SUCCESS;
}
if (!Worked && side.xOffset == 0 && side.zOffset == 0) {
Worked = i.onItemUse(player, w, tePos.offset(side.getFacing().getOpposite()), hand, side.getFacing(), side.xOffset,
side.yOffset, side.zOffset) == EnumActionResult.SUCCESS;
}
if( !Worked && side.yOffset == 0 )
{
Worked = i.onItemUse( player, w, tePos.offset( EnumFacing.DOWN ), hand, EnumFacing.UP, side.xOffset, side.yOffset,
side.zOffset ) == EnumActionResult.SUCCESS;
}
if (!Worked && side.yOffset == 0) {
Worked = i.onItemUse(player, w, tePos.offset(EnumFacing.DOWN), hand, EnumFacing.UP, side.xOffset, side.yOffset,
side.zOffset) == EnumActionResult.SUCCESS;
}
if( !Worked )
{
i.onItemUse( player, w, tePos, hand, side.getFacing().getOpposite(), side.xOffset, side.yOffset, side.zOffset );
}
if (!Worked) {
i.onItemUse(player, w, tePos, hand, side.getFacing().getOpposite(), side.xOffset, side.yOffset, side.zOffset);
}
maxStorage -= is.getCount();
}
else
{
i.onItemUse( player, w, tePos, hand, side.getFacing().getOpposite(), side.xOffset, side.yOffset, side.zOffset );
maxStorage -= is.getCount();
}
}
else
{
maxStorage = 1;
}
maxStorage -= is.getCount();
} else {
i.onItemUse(player, w, tePos, hand, side.getFacing().getOpposite(), side.xOffset, side.yOffset, side.zOffset);
maxStorage -= is.getCount();
}
} else {
maxStorage = 1;
}
// Safe keeping
player.setHeldItem( hand, ItemStack.EMPTY );
}
else
{
worked = true;
// Safe keeping
player.setHeldItem(hand, ItemStack.EMPTY);
} else {
worked = true;
final int sum = this.countEntitesAround( w, tePos );
final int sum = this.countEntitesAround(w, tePos);
if( sum < AEConfig.instance().getFormationPlaneEntityLimit() )
{
if( type == Actionable.MODULATE )
{
is.setCount( (int) maxStorage );
final double x = ( side.xOffset != 0 ? 0 : .7 * ( Platform.getRandomFloat() - .5 ) ) + side.xOffset + .5 + te.getPos().getX();
final double y = ( side.yOffset != 0 ? 0 : .7 * ( Platform.getRandomFloat() - .5 ) ) + side.yOffset + .5 + te.getPos().getY();
final double z = ( side.zOffset != 0 ? 0 : .7 * ( Platform.getRandomFloat() - .5 ) ) + side.zOffset + .5 + te.getPos().getZ();
if (sum < AEConfig.instance().getFormationPlaneEntityLimit()) {
if (type == Actionable.MODULATE) {
is.setCount((int) maxStorage);
final double x = (side.xOffset != 0 ? 0 : .7 * (Platform.getRandomFloat() - .5)) + side.xOffset + .5 + te.getPos().getX();
final double y = (side.yOffset != 0 ? 0 : .7 * (Platform.getRandomFloat() - .5)) + side.yOffset + .5 + te.getPos().getY();
final double z = (side.zOffset != 0 ? 0 : .7 * (Platform.getRandomFloat() - .5)) + side.zOffset + .5 + te.getPos().getZ();
final EntityItem ei = new EntityItem( w, x, y, z, is.copy() );
final EntityItem ei = new EntityItem(w, x, y, z, is.copy());
Entity result = ei;
Entity result = ei;
ei.motionX = side.xOffset * 0.2;
ei.motionY = side.yOffset * 0.2;
ei.motionZ = side.zOffset * 0.2;
ei.motionX = side.xOffset * 0.2;
ei.motionY = side.yOffset * 0.2;
ei.motionZ = side.zOffset * 0.2;
if( is.getItem().hasCustomEntity( is ) )
{
result = is.getItem().createEntity( w, ei, is );
if( result != null )
{
ei.setDead();
}
else
{
result = ei;
}
}
if (is.getItem().hasCustomEntity(is)) {
result = is.getItem().createEntity(w, ei, is);
if (result != null) {
ei.setDead();
} else {
result = ei;
}
}
if( !w.spawnEntity( result ) )
{
result.setDead();
worked = false;
}
}
}
else
{
worked = false;
}
}
}
if (!w.spawnEntity(result)) {
result.setDead();
worked = false;
}
}
} else {
worked = false;
}
}
}
this.blocked = !w.getBlockState( tePos ).getBlock().isReplaceable( w, tePos );
this.blocked = !w.getBlockState(tePos).getBlock().isReplaceable(w, tePos);
if( worked )
{
final IAEItemStack out = input.copy();
out.decStackSize( maxStorage );
if( out.getStackSize() == 0 )
{
return null;
}
return out;
}
if (worked) {
final IAEItemStack out = input.copy();
out.decStackSize(maxStorage);
if (out.getStackSize() == 0) {
return null;
}
return out;
}
return input;
}
return input;
}
@Override
public IStorageChannel<IAEItemStack> getChannel()
{
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
}
@Override
public IStorageChannel<IAEItemStack> getChannel() {
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
}
@Override
public IPartModel getStaticModels()
{
return MODELS.getModel( this.getConnections(), this.isPowered(), this.isActive() );
}
@Override
public IPartModel getStaticModels() {
return MODELS.getModel(this.getConnections(), this.isPowered(), this.isActive());
}
@Override
public ItemStack getItemStackRepresentation()
{
return AEApi.instance().definitions().parts().formationPlane().maybeStack( 1 ).orElse( ItemStack.EMPTY );
}
@Override
public ItemStack getItemStackRepresentation() {
return AEApi.instance().definitions().parts().formationPlane().maybeStack(1).orElse(ItemStack.EMPTY);
}
@Override
public GuiBridge getGuiBridge()
{
return GuiBridge.GUI_FORMATION_PLANE;
}
@Override
public GuiBridge getGuiBridge() {
return GuiBridge.GUI_FORMATION_PLANE;
}
private int countEntitesAround( World world, BlockPos pos )
{
final AxisAlignedBB t = new AxisAlignedBB( pos ).grow( 8 );
final List<Entity> list = world.getEntitiesWithinAABB( Entity.class, t );
private int countEntitesAround(World world, BlockPos pos) {
final AxisAlignedBB t = new AxisAlignedBB(pos).grow(8);
final List<Entity> list = world.getEntitiesWithinAABB(Entity.class, t);
return list.size();
}
return list.size();
}
}
@@ -19,9 +19,11 @@
package appeng.parts.automation;
import java.util.ArrayList;
import java.util.List;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.api.parts.IPartModel;
import appeng.api.util.AEPartLocation;
import appeng.items.parts.PartModels;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
@@ -32,83 +34,67 @@ import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.api.parts.IPartModel;
import appeng.api.util.AEPartLocation;
import appeng.items.parts.PartModels;
import java.util.ArrayList;
import java.util.List;
public class PartIdentityAnnihilationPlane extends PartAnnihilationPlane
{
public class PartIdentityAnnihilationPlane extends PartAnnihilationPlane {
private static final PlaneModels MODELS = new PlaneModels( "part/identity_annihilation_plane_", "part/identity_annihilation_plane_on_" );
private static final PlaneModels MODELS = new PlaneModels("part/identity_annihilation_plane_", "part/identity_annihilation_plane_on_");
@PartModels
public static List<IPartModel> getModels()
{
return MODELS.getModels();
}
@PartModels
public static List<IPartModel> getModels() {
return MODELS.getModels();
}
private static final float SILK_TOUCH_FACTOR = 16;
private static final float SILK_TOUCH_FACTOR = 16;
public PartIdentityAnnihilationPlane( final ItemStack is )
{
super( is );
}
public PartIdentityAnnihilationPlane(final ItemStack is) {
super(is);
}
@Override
protected 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
protected 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
protected float calculateEnergyUsage( final WorldServer w, final BlockPos pos, final List<ItemStack> items )
{
final float requiredEnergy = super.calculateEnergyUsage( w, pos, items );
@Override
protected float calculateEnergyUsage(final WorldServer w, final BlockPos pos, final List<ItemStack> items) {
final float requiredEnergy = super.calculateEnergyUsage(w, pos, items);
return requiredEnergy * SILK_TOUCH_FACTOR;
}
return requiredEnergy * SILK_TOUCH_FACTOR;
}
@Override
protected List<ItemStack> obtainBlockDrops( final WorldServer w, final BlockPos pos )
{
final FakePlayer fakePlayer = FakePlayerFactory.getMinecraft( w );
final IBlockState state = w.getBlockState( pos );
@Override
protected List<ItemStack> obtainBlockDrops(final WorldServer w, final BlockPos pos) {
final FakePlayer fakePlayer = FakePlayerFactory.getMinecraft(w);
final IBlockState state = w.getBlockState(pos);
if( state.getBlock().canSilkHarvest( w, pos, state, fakePlayer ) )
{
final List<ItemStack> out = new ArrayList<>( 1 );
final Item item = Item.getItemFromBlock( state.getBlock() );
if (state.getBlock().canSilkHarvest(w, pos, state, fakePlayer)) {
final List<ItemStack> out = new ArrayList<>(1);
final Item item = Item.getItemFromBlock(state.getBlock());
if( item != Items.AIR )
{
int meta = 0;
if( item.getHasSubtypes() )
{
meta = state.getBlock().getMetaFromState( state );
}
final ItemStack itemstack = new ItemStack( item, 1, meta );
out.add( itemstack );
}
return out;
}
else
{
return super.obtainBlockDrops( w, pos );
}
}
if (item != Items.AIR) {
int meta = 0;
if (item.getHasSubtypes()) {
meta = state.getBlock().getMetaFromState(state);
}
final ItemStack itemstack = new ItemStack(item, 1, meta);
out.add(itemstack);
}
return out;
} else {
return super.obtainBlockDrops(w, pos);
}
}
@Override
public IPartModel getStaticModels()
{
return MODELS.getModel( this.getConnections(), this.isPowered(), this.isActive() );
}
@Override
public IPartModel getStaticModels() {
return MODELS.getModel(this.getConnections(), this.isPowered(), this.isActive());
}
}
@@ -19,19 +19,8 @@
package appeng.parts.automation;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.config.*;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.energy.IEnergySource;
@@ -56,286 +45,233 @@ import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.IInventoryDestination;
import appeng.util.item.AEItemStack;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.Vec3d;
public class PartImportBus extends PartSharedItemBus implements IInventoryDestination
{
public class PartImportBus extends PartSharedItemBus implements IInventoryDestination {
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/import_bus_base" );
@PartModels
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/import_bus_off" ) );
@PartModels
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/import_bus_on" ) );
@PartModels
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/import_bus_has_channel" ) );
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/import_bus_base");
@PartModels
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, new ResourceLocation(AppEng.MOD_ID, "part/import_bus_off"));
@PartModels
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, new ResourceLocation(AppEng.MOD_ID, "part/import_bus_on"));
@PartModels
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, new ResourceLocation(AppEng.MOD_ID, "part/import_bus_has_channel"));
private final IActionSource source;
private int itemsToSend; // used in tickingRequest
private boolean worked; // used in tickingRequest
private final IActionSource source;
private int itemsToSend; // used in tickingRequest
private boolean worked; // used in tickingRequest
@Reflected
public PartImportBus( final ItemStack is )
{
super( is );
@Reflected
public PartImportBus(final ItemStack is) {
super(is);
this.getConfigManager().registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
this.getConfigManager().registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
this.source = new MachineSource( this );
}
this.getConfigManager().registerSetting(Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE);
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
this.source = new MachineSource(this);
}
@Override
public boolean canInsert( final ItemStack stack )
{
if( stack.isEmpty() || stack.getItem() == Items.AIR )
{
return false;
}
@Override
public boolean canInsert(final ItemStack stack) {
if (stack.isEmpty() || stack.getItem() == Items.AIR) {
return false;
}
try
{
final IMEMonitor<IAEItemStack> inv = this.getProxy()
.getStorage()
.getInventory(
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
try {
final IMEMonitor<IAEItemStack> inv = this.getProxy()
.getStorage()
.getInventory(
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
final IAEItemStack out = inv.injectItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( stack ),
Actionable.SIMULATE,
this.source );
if( out == null )
{
return true;
}
return out.getStackSize() != stack.getCount();
}
catch( GridAccessException ex )
{
return false;
}
}
final IAEItemStack out = inv.injectItems(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(stack),
Actionable.SIMULATE,
this.source);
if (out == null) {
return true;
}
return out.getStackSize() != stack.getCount();
} catch (GridAccessException ex) {
return false;
}
}
@Override
public void getBoxes( final 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(final 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 float getCableConnectionLength( AECableType cable )
{
return 5;
}
@Override
public float getCableConnectionLength(AECableType cable) {
return 5;
}
@Override
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
{
if( Platform.isServer() )
{
Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_BUS );
}
return true;
}
@Override
public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
if (Platform.isServer()) {
Platform.openGUI(player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_BUS);
}
return true;
}
@Override
public TickingRequest getTickingRequest( final IGridNode node )
{
return new TickingRequest( TickRates.ImportBus.getMin(), TickRates.ImportBus.getMax(), this.isSleeping(), false );
}
@Override
public TickingRequest getTickingRequest(final IGridNode node) {
return new TickingRequest(TickRates.ImportBus.getMin(), TickRates.ImportBus.getMax(), this.isSleeping(), false);
}
@Override
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
{
return this.doBusWork();
}
@Override
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
return this.doBusWork();
}
@Override
protected TickRateModulation doBusWork()
{
if( !this.getProxy().isActive() || !this.canDoBusWork() )
{
return TickRateModulation.IDLE;
}
@Override
protected TickRateModulation doBusWork() {
if (!this.getProxy().isActive() || !this.canDoBusWork()) {
return TickRateModulation.IDLE;
}
this.worked = false;
this.worked = false;
final InventoryAdaptor myAdaptor = this.getHandler();
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE );
final InventoryAdaptor myAdaptor = this.getHandler();
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting(Settings.FUZZY_MODE);
if( myAdaptor != null )
{
try
{
this.itemsToSend = this.calculateItemsToSend();
if (myAdaptor != null) {
try {
this.itemsToSend = this.calculateItemsToSend();
final IMEMonitor<IAEItemStack> inv = this.getProxy()
.getStorage()
.getInventory(
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
final IEnergyGrid energy = this.getProxy().getEnergy();
final IMEMonitor<IAEItemStack> inv = this.getProxy()
.getStorage()
.getInventory(
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
final IEnergyGrid energy = this.getProxy().getEnergy();
boolean Configured = false;
for( int x = 0; x < this.availableSlots(); x++ )
{
final IAEItemStack ais = this.getConfig().getAEStackInSlot( x );
if( ais != null && this.itemsToSend > 0 )
{
Configured = true;
while( this.itemsToSend > 0 )
{
if( this.importStuff( myAdaptor, ais, inv, energy, fzMode ) )
{
break;
}
}
}
}
boolean Configured = false;
for (int x = 0; x < this.availableSlots(); x++) {
final IAEItemStack ais = this.getConfig().getAEStackInSlot(x);
if (ais != null && this.itemsToSend > 0) {
Configured = true;
while (this.itemsToSend > 0) {
if (this.importStuff(myAdaptor, ais, inv, energy, fzMode)) {
break;
}
}
}
}
if( !Configured )
{
while( this.itemsToSend > 0 )
{
if( this.importStuff( myAdaptor, null, inv, energy, fzMode ) )
{
break;
}
}
}
}
catch( final GridAccessException e )
{
// :3
}
}
else
{
return TickRateModulation.SLEEP;
}
if (!Configured) {
while (this.itemsToSend > 0) {
if (this.importStuff(myAdaptor, null, inv, energy, fzMode)) {
break;
}
}
}
} catch (final GridAccessException e) {
// :3
}
} else {
return TickRateModulation.SLEEP;
}
return this.worked ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
}
return this.worked ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
}
private boolean importStuff( final InventoryAdaptor myAdaptor, final IAEItemStack whatToImport, final IMEMonitor<IAEItemStack> inv, final IEnergySource energy, final FuzzyMode fzMode )
{
final int toSend = this.calculateMaximumAmountToImport( myAdaptor, whatToImport, inv, fzMode );
private boolean importStuff(final InventoryAdaptor myAdaptor, final IAEItemStack whatToImport, final IMEMonitor<IAEItemStack> inv, final IEnergySource energy, final FuzzyMode fzMode) {
final int toSend = this.calculateMaximumAmountToImport(myAdaptor, whatToImport, inv, fzMode);
if( toSend == 0 )
{
return true;
}
if (toSend == 0) {
return true;
}
final ItemStack newItems;
final ItemStack newItems;
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
{
newItems = myAdaptor.removeSimilarItems( toSend, whatToImport == null ? ItemStack.EMPTY : whatToImport.getDefinition(), fzMode, this );
}
else
{
newItems = myAdaptor.removeItems( toSend, whatToImport == null ? ItemStack.EMPTY : whatToImport.getDefinition(), this );
}
if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0) {
newItems = myAdaptor.removeSimilarItems(toSend, whatToImport == null ? ItemStack.EMPTY : whatToImport.getDefinition(), fzMode, this);
} else {
newItems = myAdaptor.removeItems(toSend, whatToImport == null ? ItemStack.EMPTY : whatToImport.getDefinition(), this);
}
if( !newItems.isEmpty() )
{
final IAEItemStack aeStack = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( newItems );
final IAEItemStack failed = Platform.poweredInsert( energy, inv, aeStack, this.source );
if (!newItems.isEmpty()) {
final IAEItemStack aeStack = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(newItems);
final IAEItemStack failed = Platform.poweredInsert(energy, inv, aeStack, this.source);
if( failed != null )
{
// try unpowered insert, better be a bit lenient then void items
final IAEItemStack spill = inv.injectItems( failed, Actionable.MODULATE, this.source );
if( spill != null )
{
// last resort try to put it back .. lets hope it's a chest type of thing
myAdaptor.addItems( spill.createItemStack() );
}
return true;
}
else
{
this.itemsToSend -= newItems.getCount();
this.worked = true;
}
}
else
{
return true;
}
if (failed != null) {
// try unpowered insert, better be a bit lenient then void items
final IAEItemStack spill = inv.injectItems(failed, Actionable.MODULATE, this.source);
if (spill != null) {
// last resort try to put it back .. lets hope it's a chest type of thing
myAdaptor.addItems(spill.createItemStack());
}
return true;
} else {
this.itemsToSend -= newItems.getCount();
this.worked = true;
}
} else {
return true;
}
return false;
}
return false;
}
private int calculateMaximumAmountToImport( final InventoryAdaptor myAdaptor, final IAEItemStack whatToImport, final IMEMonitor<IAEItemStack> inv, final FuzzyMode fzMode )
{
final int toSend = Math.min( this.itemsToSend, 64 );
final ItemStack itemStackToImport;
private int calculateMaximumAmountToImport(final InventoryAdaptor myAdaptor, final IAEItemStack whatToImport, final IMEMonitor<IAEItemStack> inv, final FuzzyMode fzMode) {
final int toSend = Math.min(this.itemsToSend, 64);
final ItemStack itemStackToImport;
if( whatToImport == null )
{
itemStackToImport = ItemStack.EMPTY;
}
else
{
itemStackToImport = whatToImport.getDefinition();
}
if (whatToImport == null) {
itemStackToImport = ItemStack.EMPTY;
} else {
itemStackToImport = whatToImport.getDefinition();
}
final IAEItemStack itemAmountNotStorable;
final ItemStack simResult;
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
{
simResult = myAdaptor.simulateSimilarRemove( toSend, itemStackToImport, fzMode, null );
itemAmountNotStorable = inv.injectItems( AEItemStack.fromItemStack( simResult ), Actionable.SIMULATE, this.source );
}
else
{
simResult = myAdaptor.simulateRemove( toSend, itemStackToImport, null );
itemAmountNotStorable = inv.injectItems( AEItemStack.fromItemStack( simResult ), Actionable.SIMULATE, this.source );
}
final IAEItemStack itemAmountNotStorable;
final ItemStack simResult;
if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0) {
simResult = myAdaptor.simulateSimilarRemove(toSend, itemStackToImport, fzMode, null);
itemAmountNotStorable = inv.injectItems(AEItemStack.fromItemStack(simResult), Actionable.SIMULATE, this.source);
} else {
simResult = myAdaptor.simulateRemove(toSend, itemStackToImport, null);
itemAmountNotStorable = inv.injectItems(AEItemStack.fromItemStack(simResult), Actionable.SIMULATE, this.source);
}
if( simResult.isEmpty() )
{
return 0;
}
if (simResult.isEmpty()) {
return 0;
}
if( itemAmountNotStorable != null )
{
if( simResult.getCount() == itemAmountNotStorable.getStackSize() )
{
return 0;
}
return (int) Math.min( simResult.getCount() - itemAmountNotStorable.getStackSize(), toSend );
}
if (itemAmountNotStorable != null) {
if (simResult.getCount() == itemAmountNotStorable.getStackSize()) {
return 0;
}
return (int) Math.min(simResult.getCount() - itemAmountNotStorable.getStackSize(), toSend);
}
return toSend;
}
return toSend;
}
@Override
protected boolean isSleeping()
{
return this.getHandler() == null || super.isSleeping();
}
@Override
protected boolean isSleeping() {
return this.getHandler() == null || super.isSleeping();
}
@Override
public RedstoneMode getRSMode()
{
return (RedstoneMode) this.getConfigManager().getSetting( Settings.REDSTONE_CONTROLLED );
}
@Override
public RedstoneMode getRSMode() {
return (RedstoneMode) this.getConfigManager().getSetting(Settings.REDSTONE_CONTROLLED);
}
@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;
}
}
}
@@ -55,8 +55,6 @@ import appeng.parts.PartModel;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.util.Platform;
import appeng.util.inv.InvOperation;
import appeng.util.item.OreHelper;
import appeng.util.item.OreReference;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
@@ -70,503 +68,406 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import java.util.Optional;
import java.util.Random;
public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherHost, IStackWatcherHost, ICraftingWatcherHost, IMEMonitorHandlerReceiver<IAEItemStack>, ICraftingProvider
{
@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 );
private static final int FLAG_ON = 4;
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 1 );
private boolean prevState = false;
private long lastReportedValue = 0;
private long reportingValue = 0;
private IStackWatcher myWatcher;
private IEnergyWatcher myEnergyWatcher;
private ICraftingWatcher myCraftingWatcher;
private double centerX;
private double centerY;
private double centerZ;
@Reflected
public PartLevelEmitter( final ItemStack is )
{
super( is );
this.getConfigManager().registerSetting( Settings.REDSTONE_EMITTER, RedstoneMode.HIGH_SIGNAL );
this.getConfigManager().registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
this.getConfigManager().registerSetting( Settings.LEVEL_TYPE, LevelType.ITEM_LEVEL );
this.getConfigManager().registerSetting( Settings.CRAFT_VIA_REDSTONE, YesNo.NO );
}
public long getReportingValue()
{
return this.reportingValue;
}
public void setReportingValue( final long v )
{
this.reportingValue = v;
if( this.getConfigManager().getSetting( Settings.LEVEL_TYPE ) == LevelType.ENERGY_LEVEL )
{
this.configureWatchers();
}
else
{
this.updateState();
}
}
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() ) );
}
}
// TODO: Make private again
public boolean isLevelEmitterOn()
{
if( Platform.isClient() )
{
return ( this.getClientFlags() & FLAG_ON ) == FLAG_ON;
}
if( !this.getProxy().isActive() )
{
return false;
}
if( this.getInstalledUpgrades( Upgrades.CRAFTING ) > 0 )
{
try
{
return this.getProxy().getCrafting().isRequesting( this.config.getAEStackInSlot( 0 ) );
}
catch( final GridAccessException e )
{
// :P
}
return this.prevState;
}
final boolean flipState = this.getConfigManager().getSetting( Settings.REDSTONE_EMITTER ) == RedstoneMode.LOW_SIGNAL;
return flipState ? this.reportingValue >= this.lastReportedValue + 1 : this.reportingValue < this.lastReportedValue + 1;
}
@Override
@MENetworkEventSubscribe
public void powerRender( final MENetworkPowerStatusChange powerEvent )
{
if (this.getProxy().isActive())
{
onListUpdate();
}
this.updateState();
}
@Override
@MENetworkEventSubscribe
public void chanRender( final MENetworkChannelsChanged c )
{
if (this.getProxy().isActive())
{
onListUpdate();
}
this.updateState();
}
@Override
protected int populateFlags( final int cf )
{
return cf | ( this.prevState ? FLAG_ON : 0 );
}
@Override
public void updateWatcher( final ICraftingWatcher newWatcher )
{
this.myCraftingWatcher = newWatcher;
this.configureWatchers();
}
@Override
public void onRequestChange( final ICraftingGrid craftingGrid, final IAEItemStack what )
{
this.updateState();
}
// update the system...
private void configureWatchers()
{
final IAEItemStack myStack = this.config.getAEStackInSlot( 0 );
if( this.myWatcher != null )
{
this.myWatcher.reset();
}
if( this.myEnergyWatcher != null )
{
this.myEnergyWatcher.reset();
}
if( this.myCraftingWatcher != null )
{
this.myCraftingWatcher.reset();
}
try
{
this.getProxy().getGrid().postEvent( new MENetworkCraftingPatternChange( this, this.getProxy().getNode() ) );
}
catch( final GridAccessException e1 )
{
// :/
}
if( this.getInstalledUpgrades( Upgrades.CRAFTING ) > 0 )
{
if( this.myCraftingWatcher != null && myStack != null )
{
this.myCraftingWatcher.add( myStack );
}
return;
}
if( this.getConfigManager().getSetting( Settings.LEVEL_TYPE ) == LevelType.ENERGY_LEVEL )
{
if( this.myEnergyWatcher != null )
{
this.myEnergyWatcher.add( this.reportingValue );
}
try
{
// update to power...
this.lastReportedValue = (long) this.getProxy().getEnergy().getStoredPower();
this.updateState();
// no more item stuff..
this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ).removeListener( this );
}
catch( final GridAccessException e )
{
// :P
}
return;
}
try
{
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 || myStack == null )
{
this.getProxy()
.getStorage()
.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
.addListener( this,
this.getProxy().getGrid() );
}
else
{
this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ).removeListener( this );
if( this.myWatcher != null )
{
this.myWatcher.add( myStack );
}
}
this.updateReportingValue( this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) );
}
catch( final GridAccessException e )
{
// >.>
}
}
private void updateReportingValue( final IMEMonitor<IAEItemStack> monitor )
{
final IAEItemStack myStack = this.config.getAEStackInSlot( 0 );
if( myStack == null )
{
if( monitor instanceof NetworkMonitor )
{
this.lastReportedValue = ( (NetworkMonitor<IAEItemStack>) monitor ).getGridCurrentCount();
}
}
else if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
{
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE );
this.lastReportedValue = 0;
monitor.getStorageList().findFuzzy( myStack, fzMode ).forEach( iaeItemStack -> lastReportedValue += iaeItemStack.getStackSize() );
}
else
{
this.lastReportedValue = 0;
IAEItemStack precise = monitor.getStorageList().findPrecise( myStack );
if( precise != null ) lastReportedValue = precise.getStackSize();
}
this.updateState();
}
@Override
public void updateWatcher( final IStackWatcher newWatcher )
{
this.myWatcher = newWatcher;
this.configureWatchers();
}
@Override
public void onStackChange( final IItemList o, final IAEStack fullStack, final IAEStack diffStack, final IActionSource src, final IStorageChannel chan )
{
if( chan == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) && fullStack.equals( this.config.getAEStackInSlot( 0 ) ) && this.getInstalledUpgrades( Upgrades.FUZZY ) == 0 )
{
this.lastReportedValue = fullStack.getStackSize();
this.updateState();
}
}
@Override
public void updateWatcher( final IEnergyWatcher newWatcher )
{
this.myEnergyWatcher = newWatcher;
this.configureWatchers();
}
@Override
public void onThresholdPass( final IEnergyGrid energyGrid )
{
this.lastReportedValue = (long) energyGrid.getStoredPower();
this.updateState();
}
@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<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource actionSource )
{
this.updateReportingValue( (IMEMonitor<IAEItemStack>) monitor );
}
@Override
public void onListUpdate()
{
try
{
this.updateReportingValue( this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) );
}
catch( final GridAccessException e )
{
// ;P
}
}
@Override
public AECableType getCableConnectionType( final AEPartLocation dir )
{
return AECableType.SMART;
}
@Override
public void getBoxes( final IPartCollisionHelper bch )
{
bch.addBox( 7, 7, 11, 9, 9, 16 );
}
@Override
public int isProvidingStrongPower()
{
return this.prevState ? 15 : 0;
}
@Override
public int isProvidingWeakPower()
{
return this.prevState ? 15 : 0;
}
@Override
public void randomDisplayTick( 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;
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,
new int[0] );
}
}
@Override
public float getCableConnectionLength( AECableType cable )
{
return 16;
}
@Override
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
{
if( Platform.isServer() )
{
Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_LEVEL_EMITTER );
}
return true;
}
@Override
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
{
this.configureWatchers();
}
@Override
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
if( inv == this.config )
{
this.configureWatchers();
}
super.onChangeInventory( inv, slot, mc, removedStack, newStack );
}
@Override
public void upgradesChanged()
{
this.configureWatchers();
this.updateState();
}
@Override
public boolean canConnectRedstone()
{
return true;
}
@Override
public void readFromNBT( final NBTTagCompound 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 NBTTagCompound data )
{
super.writeToNBT( data );
data.setLong( "lastReportedValue", this.lastReportedValue );
data.setLong( "reportingValue", this.reportingValue );
data.setBoolean( "prevState", this.prevState );
this.config.writeToNBT( data, "config" );
}
@Override
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "config" ) )
{
return this.config;
}
return super.getInventoryByName( name );
}
@Override
public boolean pushPattern( final ICraftingPatternDetails patternDetails, final InventoryCrafting table )
{
return false;
}
@Override
public boolean isBusy()
{
return true;
}
@Override
public void provideCrafting( final ICraftingProviderHelper craftingTracker )
{
if( this.getInstalledUpgrades( Upgrades.CRAFTING ) > 0 )
{
if( this.getConfigManager().getSetting( Settings.CRAFT_VIA_REDSTONE ) == YesNo.YES )
{
final IAEItemStack what = this.config.getAEStackInSlot( 0 );
if( what != null )
{
craftingTracker.setEmitable( what );
}
}
}
}
@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 class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherHost, IStackWatcherHost, ICraftingWatcherHost, IMEMonitorHandlerReceiver<IAEItemStack>, ICraftingProvider {
@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);
private static final int FLAG_ON = 4;
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, 1);
private boolean prevState = false;
private long lastReportedValue = 0;
private long reportingValue = 0;
private IStackWatcher myWatcher;
private IEnergyWatcher myEnergyWatcher;
private ICraftingWatcher myCraftingWatcher;
private double centerX;
private double centerY;
private double centerZ;
@Reflected
public PartLevelEmitter(final ItemStack is) {
super(is);
this.getConfigManager().registerSetting(Settings.REDSTONE_EMITTER, RedstoneMode.HIGH_SIGNAL);
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
this.getConfigManager().registerSetting(Settings.LEVEL_TYPE, LevelType.ITEM_LEVEL);
this.getConfigManager().registerSetting(Settings.CRAFT_VIA_REDSTONE, YesNo.NO);
}
public long getReportingValue() {
return this.reportingValue;
}
public void setReportingValue(final long v) {
this.reportingValue = v;
if (this.getConfigManager().getSetting(Settings.LEVEL_TYPE) == LevelType.ENERGY_LEVEL) {
this.configureWatchers();
} else {
this.updateState();
}
}
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()));
}
}
// TODO: Make private again
public boolean isLevelEmitterOn() {
if (Platform.isClient()) {
return (this.getClientFlags() & FLAG_ON) == FLAG_ON;
}
if (!this.getProxy().isActive()) {
return false;
}
if (this.getInstalledUpgrades(Upgrades.CRAFTING) > 0) {
try {
return this.getProxy().getCrafting().isRequesting(this.config.getAEStackInSlot(0));
} catch (final GridAccessException e) {
// :P
}
return this.prevState;
}
final boolean flipState = this.getConfigManager().getSetting(Settings.REDSTONE_EMITTER) == RedstoneMode.LOW_SIGNAL;
return flipState == (this.reportingValue >= this.lastReportedValue + 1);
}
@Override
@MENetworkEventSubscribe
public void powerRender(final MENetworkPowerStatusChange powerEvent) {
if (this.getProxy().isActive()) {
onListUpdate();
}
this.updateState();
}
@Override
@MENetworkEventSubscribe
public void chanRender(final MENetworkChannelsChanged c) {
if (this.getProxy().isActive()) {
onListUpdate();
}
this.updateState();
}
@Override
protected int populateFlags(final int cf) {
return cf | (this.prevState ? FLAG_ON : 0);
}
@Override
public void updateWatcher(final ICraftingWatcher newWatcher) {
this.myCraftingWatcher = newWatcher;
this.configureWatchers();
}
@Override
public void onRequestChange(final ICraftingGrid craftingGrid, final IAEItemStack what) {
this.updateState();
}
// update the system...
private void configureWatchers() {
final IAEItemStack myStack = this.config.getAEStackInSlot(0);
if (this.myWatcher != null) {
this.myWatcher.reset();
}
if (this.myEnergyWatcher != null) {
this.myEnergyWatcher.reset();
}
if (this.myCraftingWatcher != null) {
this.myCraftingWatcher.reset();
}
try {
this.getProxy().getGrid().postEvent(new MENetworkCraftingPatternChange(this, this.getProxy().getNode()));
} catch (final GridAccessException e1) {
// :/
}
if (this.getInstalledUpgrades(Upgrades.CRAFTING) > 0) {
if (this.myCraftingWatcher != null && myStack != null) {
this.myCraftingWatcher.add(myStack);
}
return;
}
if (this.getConfigManager().getSetting(Settings.LEVEL_TYPE) == LevelType.ENERGY_LEVEL) {
if (this.myEnergyWatcher != null) {
this.myEnergyWatcher.add(this.reportingValue);
}
try {
// update to power...
this.lastReportedValue = (long) this.getProxy().getEnergy().getStoredPower();
this.updateState();
// no more item stuff..
this.getProxy().getStorage().getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)).removeListener(this);
} catch (final GridAccessException e) {
// :P
}
return;
}
try {
if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0 || myStack == null) {
this.getProxy()
.getStorage()
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class))
.addListener(this,
this.getProxy().getGrid());
} else {
this.getProxy().getStorage().getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)).removeListener(this);
if (this.myWatcher != null) {
this.myWatcher.add(myStack);
}
}
this.updateReportingValue(this.getProxy().getStorage().getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)));
} catch (final GridAccessException e) {
// >.>
}
}
private void updateReportingValue(final IMEMonitor<IAEItemStack> monitor) {
final IAEItemStack myStack = this.config.getAEStackInSlot(0);
if (myStack == null) {
if (monitor instanceof NetworkMonitor) {
this.lastReportedValue = ((NetworkMonitor<IAEItemStack>) monitor).getGridCurrentCount();
}
} else if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0) {
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting(Settings.FUZZY_MODE);
this.lastReportedValue = 0;
monitor.getStorageList().findFuzzy(myStack, fzMode).forEach(iaeItemStack -> lastReportedValue += iaeItemStack.getStackSize());
} else {
this.lastReportedValue = 0;
IAEItemStack precise = monitor.getStorageList().findPrecise(myStack);
if (precise != null) lastReportedValue = precise.getStackSize();
}
this.updateState();
}
@Override
public void updateWatcher(final IStackWatcher newWatcher) {
this.myWatcher = newWatcher;
this.configureWatchers();
}
@Override
public void onStackChange(final IItemList o, final IAEStack fullStack, final IAEStack diffStack, final IActionSource src, final IStorageChannel chan) {
if (chan == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) && fullStack.equals(this.config.getAEStackInSlot(0)) && this.getInstalledUpgrades(Upgrades.FUZZY) == 0) {
this.lastReportedValue = fullStack.getStackSize();
this.updateState();
}
}
@Override
public void updateWatcher(final IEnergyWatcher newWatcher) {
this.myEnergyWatcher = newWatcher;
this.configureWatchers();
}
@Override
public void onThresholdPass(final IEnergyGrid energyGrid) {
this.lastReportedValue = (long) energyGrid.getStoredPower();
this.updateState();
}
@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<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource actionSource) {
this.updateReportingValue((IMEMonitor<IAEItemStack>) monitor);
}
@Override
public void onListUpdate() {
try {
this.updateReportingValue(this.getProxy().getStorage().getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)));
} catch (final GridAccessException e) {
// ;P
}
}
@Override
public AECableType getCableConnectionType(final AEPartLocation dir) {
return AECableType.SMART;
}
@Override
public void getBoxes(final IPartCollisionHelper bch) {
bch.addBox(7, 7, 11, 9, 9, 16);
}
@Override
public int isProvidingStrongPower() {
return this.prevState ? 15 : 0;
}
@Override
public int isProvidingWeakPower() {
return this.prevState ? 15 : 0;
}
@Override
public void randomDisplayTick(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;
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
);
}
}
@Override
public float getCableConnectionLength(AECableType cable) {
return 16;
}
@Override
public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
if (Platform.isServer()) {
Platform.openGUI(player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_LEVEL_EMITTER);
}
return true;
}
@Override
public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) {
this.configureWatchers();
}
@Override
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
if (inv == this.config) {
this.configureWatchers();
}
super.onChangeInventory(inv, slot, mc, removedStack, newStack);
}
@Override
public void upgradesChanged() {
this.configureWatchers();
this.updateState();
}
@Override
public boolean canConnectRedstone() {
return true;
}
@Override
public void readFromNBT(final NBTTagCompound 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 NBTTagCompound data) {
super.writeToNBT(data);
data.setLong("lastReportedValue", this.lastReportedValue);
data.setLong("reportingValue", this.reportingValue);
data.setBoolean("prevState", this.prevState);
this.config.writeToNBT(data, "config");
}
@Override
public IItemHandler getInventoryByName(final String name) {
if (name.equals("config")) {
return this.config;
}
return super.getInventoryByName(name);
}
@Override
public boolean pushPattern(final ICraftingPatternDetails patternDetails, final InventoryCrafting table) {
return false;
}
@Override
public boolean isBusy() {
return true;
}
@Override
public void provideCrafting(final ICraftingProviderHelper craftingTracker) {
if (this.getInstalledUpgrades(Upgrades.CRAFTING) > 0) {
if (this.getConfigManager().getSetting(Settings.CRAFT_VIA_REDSTONE) == YesNo.YES) {
final IAEItemStack what = this.config.getAEStackInSlot(0);
if (what != null) {
craftingTracker.setEmitable(what);
}
}
}
}
@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;
}
}
}
@@ -19,13 +19,6 @@
package appeng.parts.automation;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Upgrades;
import appeng.api.networking.ticking.IGridTickable;
@@ -33,148 +26,129 @@ import appeng.api.networking.ticking.TickRateModulation;
import appeng.me.GridAccessException;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.util.InventoryAdaptor;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
public abstract class PartSharedItemBus extends PartUpgradeable implements IGridTickable
{
public abstract class PartSharedItemBus extends PartUpgradeable implements IGridTickable {
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 9 );
private boolean lastRedstone = false;
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, 9);
private boolean lastRedstone = false;
public PartSharedItemBus( final ItemStack is )
{
super( is );
}
public PartSharedItemBus(final ItemStack is) {
super(is);
}
@Override
public void upgradesChanged()
{
this.updateState();
}
@Override
public void upgradesChanged() {
this.updateState();
}
@Override
public void readFromNBT( final net.minecraft.nbt.NBTTagCompound extra )
{
super.readFromNBT( extra );
this.getConfig().readFromNBT( extra, "config" );
}
@Override
public void readFromNBT(final net.minecraft.nbt.NBTTagCompound extra) {
super.readFromNBT(extra);
this.getConfig().readFromNBT(extra, "config");
}
@Override
public void writeToNBT( final net.minecraft.nbt.NBTTagCompound extra )
{
super.writeToNBT( extra );
this.getConfig().writeToNBT( extra, "config" );
}
@Override
public void writeToNBT(final net.minecraft.nbt.NBTTagCompound extra) {
super.writeToNBT(extra);
this.getConfig().writeToNBT(extra, "config");
}
@Override
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "config" ) )
{
return this.getConfig();
}
@Override
public IItemHandler getInventoryByName(final String name) {
if (name.equals("config")) {
return this.getConfig();
}
return super.getInventoryByName( name );
}
return super.getInventoryByName(name);
}
@Override
public void onNeighborChanged( IBlockAccess 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(IBlockAccess 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();
}
}
}
protected InventoryAdaptor getHandler()
{
final TileEntity self = this.getHost().getTile();
final TileEntity target = this.getTileEntity( self, self.getPos().offset( this.getSide().getFacing() ) );
protected InventoryAdaptor getHandler() {
final TileEntity self = this.getHost().getTile();
final TileEntity target = this.getTileEntity(self, self.getPos().offset(this.getSide().getFacing()));
return InventoryAdaptor.getAdaptor( target, this.getSide().getFacing().getOpposite() );
}
return InventoryAdaptor.getAdaptor(target, this.getSide().getFacing().getOpposite());
}
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().getLoadedChunk( pos.getX() >> 4, pos.getZ() >> 4 ) != null )
{
return w.getTileEntity( pos );
}
if (w.getChunkProvider().getLoadedChunk(pos.getX() >> 4, pos.getZ() >> 4) != null) {
return w.getTileEntity(pos);
}
return null;
}
return null;
}
protected int availableSlots()
{
return Math.min( 1 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 4, this.getConfig().getSlots() );
}
protected int availableSlots() {
return Math.min(1 + this.getInstalledUpgrades(Upgrades.CAPACITY) * 4, this.getConfig().getSlots());
}
protected int calculateItemsToSend()
{
switch( this.getInstalledUpgrades( Upgrades.SPEED ) )
{
default:
case 0:
return 1;
case 1:
return 8;
case 2:
return 32;
case 3:
return 64;
case 4:
return 96;
}
}
protected int calculateItemsToSend() {
switch (this.getInstalledUpgrades(Upgrades.SPEED)) {
default:
case 0:
return 1;
case 1:
return 8;
case 2:
return 32;
case 3:
return 64;
case 4:
return 96;
}
}
/**
* Checks if the bus can actually do something.
*
* Currently this tests if the chunk for the target is actually loaded.
*
* @return true, if the the bus should do its work.
*/
protected boolean canDoBusWork()
{
final TileEntity self = this.getHost().getTile();
final BlockPos selfPos = self.getPos().offset( this.getSide().getFacing() );
final int xCoordinate = selfPos.getX();
final int zCoordinate = selfPos.getZ();
final World world = self.getWorld();
/**
* Checks if the bus can actually do something.
* <p>
* Currently this tests if the chunk for the target is actually loaded.
*
* @return true, if the the bus should do its work.
*/
protected boolean canDoBusWork() {
final TileEntity self = this.getHost().getTile();
final BlockPos selfPos = self.getPos().offset(this.getSide().getFacing());
final int xCoordinate = selfPos.getX();
final int zCoordinate = selfPos.getZ();
final World world = self.getWorld();
return world != null && world.getChunkProvider().getLoadedChunk( xCoordinate >> 4, zCoordinate >> 4 ) != null;
}
return world != null && world.getChunkProvider().getLoadedChunk(xCoordinate >> 4, zCoordinate >> 4) != null;
}
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
}
}
protected abstract TickRateModulation doBusWork();
protected abstract TickRateModulation doBusWork();
AppEngInternalAEInventory getConfig()
{
return this.config;
}
AppEngInternalAEInventory getConfig() {
return this.config;
}
}
@@ -19,11 +19,6 @@
package appeng.parts.automation;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Upgrades;
import appeng.api.util.IConfigManager;
@@ -32,140 +27,121 @@ import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import java.util.List;
public abstract class PartUpgradeable extends PartBasicState implements IAEAppEngInventory, IConfigManagerHost
{
private final IConfigManager manager;
private final UpgradeInventory upgrades;
public abstract class PartUpgradeable extends PartBasicState implements IAEAppEngInventory, IConfigManagerHost {
private final IConfigManager manager;
private final UpgradeInventory upgrades;
public PartUpgradeable( final ItemStack is )
{
super( is );
this.upgrades = new StackUpgradeInventory( this.getItemStack(), this, this.getUpgradeSlots() );
this.manager = new ConfigManager( this );
}
public PartUpgradeable(final ItemStack is) {
super(is);
this.upgrades = new StackUpgradeInventory(this.getItemStack(), this, this.getUpgradeSlots());
this.manager = new ConfigManager(this);
}
protected int getUpgradeSlots()
{
return 4;
}
protected int getUpgradeSlots() {
return 4;
}
@Override
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
{
@Override
public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) {
}
}
@Override
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
if( inv == this.upgrades )
{
this.upgradesChanged();
}
}
@Override
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
if (inv == this.upgrades) {
this.upgradesChanged();
}
}
public void upgradesChanged()
{
public void upgradesChanged() {
}
}
protected boolean isSleeping()
{
if( this.getInstalledUpgrades( Upgrades.REDSTONE ) > 0 )
{
switch( this.getRSMode() )
{
case IGNORE:
return false;
protected boolean isSleeping() {
if (this.getInstalledUpgrades(Upgrades.REDSTONE) > 0) {
switch (this.getRSMode()) {
case IGNORE:
return false;
case HIGH_SIGNAL:
if( this.getHost().hasRedstone( this.getSide() ) )
{
return false;
}
case HIGH_SIGNAL:
if (this.getHost().hasRedstone(this.getSide())) {
return false;
}
break;
break;
case LOW_SIGNAL:
if( !this.getHost().hasRedstone( this.getSide() ) )
{
return false;
}
case LOW_SIGNAL:
if (!this.getHost().hasRedstone(this.getSide())) {
return false;
}
break;
break;
case SIGNAL_PULSE:
default:
break;
}
case SIGNAL_PULSE:
default:
break;
}
return true;
}
return true;
}
return false;
}
return false;
}
@Override
public int getInstalledUpgrades( final Upgrades u )
{
return this.upgrades.getInstalledUpgrades( u );
}
@Override
public int getInstalledUpgrades(final Upgrades u) {
return this.upgrades.getInstalledUpgrades(u);
}
@Override
public boolean canConnectRedstone()
{
return this.upgrades.getMaxInstalled( Upgrades.REDSTONE ) > 0;
}
@Override
public boolean canConnectRedstone() {
return this.upgrades.getMaxInstalled(Upgrades.REDSTONE) > 0;
}
@Override
public void readFromNBT( final net.minecraft.nbt.NBTTagCompound extra )
{
super.readFromNBT( extra );
this.manager.readFromNBT( extra );
this.upgrades.readFromNBT( extra, "upgrades" );
}
@Override
public void readFromNBT(final net.minecraft.nbt.NBTTagCompound extra) {
super.readFromNBT(extra);
this.manager.readFromNBT(extra);
this.upgrades.readFromNBT(extra, "upgrades");
}
@Override
public void writeToNBT( final net.minecraft.nbt.NBTTagCompound extra )
{
super.writeToNBT( extra );
this.manager.writeToNBT( extra );
this.upgrades.writeToNBT( extra, "upgrades" );
}
@Override
public void writeToNBT(final net.minecraft.nbt.NBTTagCompound extra) {
super.writeToNBT(extra);
this.manager.writeToNBT(extra);
this.upgrades.writeToNBT(extra, "upgrades");
}
@Override
public void getDrops( final List<ItemStack> drops, final boolean wrenched )
{
for( final ItemStack is : this.upgrades )
{
if( !is.isEmpty() )
{
drops.add( is );
}
}
}
@Override
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
for (final ItemStack is : this.upgrades) {
if (!is.isEmpty()) {
drops.add(is);
}
}
}
@Override
public IConfigManager getConfigManager()
{
return this.manager;
}
@Override
public IConfigManager getConfigManager() {
return this.manager;
}
@Override
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "upgrades" ) )
{
return this.upgrades;
}
@Override
public IItemHandler getInventoryByName(final String name) {
if (name.equals("upgrades")) {
return this.upgrades;
}
return null;
}
return null;
}
public RedstoneMode getRSMode()
{
return null;
}
public RedstoneMode getRSMode() {
return null;
}
}
@@ -19,14 +19,8 @@
package appeng.parts.automation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
import appeng.client.render.cablebus.CubeBuilder;
import com.google.common.collect.ImmutableList;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
@@ -36,87 +30,78 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.util.EnumFacing;
import appeng.client.render.cablebus.CubeBuilder;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Built-in model for annihilation planes that supports connected textures.
*/
public class PlaneBakedModel implements IBakedModel
{
public class PlaneBakedModel implements IBakedModel {
private final TextureAtlasSprite frontTexture;
private final TextureAtlasSprite frontTexture;
private final List<BakedQuad> quads;
private final List<BakedQuad> quads;
PlaneBakedModel( VertexFormat format, TextureAtlasSprite frontTexture, TextureAtlasSprite sidesTexture, TextureAtlasSprite backTexture, PlaneConnections connections )
{
this.frontTexture = frontTexture;
PlaneBakedModel(VertexFormat format, TextureAtlasSprite frontTexture, TextureAtlasSprite sidesTexture, TextureAtlasSprite backTexture, PlaneConnections connections) {
this.frontTexture = frontTexture;
List<BakedQuad> quads = new ArrayList<>( 4 * 6 );
List<BakedQuad> quads = new ArrayList<>(4 * 6);
CubeBuilder builder = new CubeBuilder( format, quads );
CubeBuilder builder = new CubeBuilder(format, quads);
builder.setTextures( sidesTexture, sidesTexture, frontTexture, backTexture, sidesTexture, sidesTexture );
builder.setTextures(sidesTexture, sidesTexture, frontTexture, backTexture, sidesTexture, sidesTexture);
// Keep the orientation of the X axis in mind here. When looking at a quad facing north from the front,
// The X-axis points left
int minX = connections.isRight() ? 0 : 1;
int maxX = connections.isLeft() ? 16 : 15;
int minY = connections.isDown() ? 0 : 1;
int maxY = connections.isUp() ? 16 : 15;
// Keep the orientation of the X axis in mind here. When looking at a quad facing north from the front,
// The X-axis points left
int minX = connections.isRight() ? 0 : 1;
int maxX = connections.isLeft() ? 16 : 15;
int minY = connections.isDown() ? 0 : 1;
int maxY = connections.isUp() ? 16 : 15;
builder.addCube( minX, minY, 0, maxX, maxY, 1 );
builder.addCube(minX, minY, 0, maxX, maxY, 1);
this.quads = ImmutableList.copyOf( quads );
}
this.quads = ImmutableList.copyOf(quads);
}
@Override
public List<BakedQuad> getQuads( @Nullable IBlockState state, @Nullable EnumFacing side, long rand )
{
if( side == null )
{
return this.quads;
}
else
{
return Collections.emptyList();
}
}
@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
if (side == null) {
return this.quads;
} else {
return Collections.emptyList();
}
}
@Override
public boolean isAmbientOcclusion()
{
return false;
}
@Override
public boolean isAmbientOcclusion() {
return false;
}
@Override
public boolean isGui3d()
{
return false;
}
@Override
public boolean isGui3d() {
return false;
}
@Override
public boolean isBuiltInRenderer()
{
return false;
}
@Override
public boolean isBuiltInRenderer() {
return false;
}
@Override
public TextureAtlasSprite getParticleTexture()
{
return this.frontTexture;
}
@Override
public TextureAtlasSprite getParticleTexture() {
return this.frontTexture;
}
@Override
public ItemCameraTransforms getItemCameraTransforms()
{
return ItemCameraTransforms.DEFAULT;
}
@Override
public ItemCameraTransforms getItemCameraTransforms() {
return ItemCameraTransforms.DEFAULT;
}
@Override
public ItemOverrideList getOverrides()
{
return ItemOverrideList.NONE;
}
@Override
public ItemOverrideList getOverrides() {
return ItemOverrideList.NONE;
}
}
@@ -19,122 +19,106 @@
package appeng.parts.automation;
import com.google.common.base.Strings;
import java.util.ArrayList;
import java.util.List;
import com.google.common.base.Strings;
/**
* Models in which directions - looking at the front face - a plane (annihilation, formation, etc.) is connected to
* other planes of the same type.
*/
public final class PlaneConnections
{
public final class PlaneConnections {
private final boolean up;
private final boolean right;
private final boolean down;
private final boolean left;
private final boolean up;
private final boolean right;
private final boolean down;
private final boolean left;
private static final int BITMASK_UP = 8;
private static final int BITMASK_RIGHT = 4;
private static final int BITMASK_DOWN = 2;
private static final int BITMASK_LEFT = 1;
private static final int BITMASK_UP = 8;
private static final int BITMASK_RIGHT = 4;
private static final int BITMASK_DOWN = 2;
private static final int BITMASK_LEFT = 1;
public static final List<PlaneConnections> PERMUTATIONS = generatePermutations();
public static final List<PlaneConnections> PERMUTATIONS = generatePermutations();
private static List<PlaneConnections> generatePermutations()
{
List<PlaneConnections> connections = new ArrayList<>( 16 );
private static List<PlaneConnections> generatePermutations() {
List<PlaneConnections> connections = new ArrayList<>(16);
for( int i = 0; i < 16; i++ )
{
boolean up = ( i & BITMASK_UP ) != 0;
boolean right = ( i & BITMASK_RIGHT ) != 0;
boolean down = ( i & BITMASK_DOWN ) != 0;
boolean left = ( i & BITMASK_LEFT ) != 0;
for (int i = 0; i < 16; i++) {
boolean up = (i & BITMASK_UP) != 0;
boolean right = (i & BITMASK_RIGHT) != 0;
boolean down = (i & BITMASK_DOWN) != 0;
boolean left = (i & BITMASK_LEFT) != 0;
connections.add( new PlaneConnections( up, right, down, left ) );
}
connections.add(new PlaneConnections(up, right, down, left));
}
return connections;
}
return connections;
}
private PlaneConnections( boolean up, boolean right, boolean down, boolean left )
{
this.up = up;
this.right = right;
this.down = down;
this.left = left;
}
private PlaneConnections(boolean up, boolean right, boolean down, boolean left) {
this.up = up;
this.right = right;
this.down = down;
this.left = left;
}
public static PlaneConnections of( boolean up, boolean right, boolean down, boolean left )
{
return PERMUTATIONS.get( getIndex( up, right, down, left ) );
}
public static PlaneConnections of(boolean up, boolean right, boolean down, boolean left) {
return PERMUTATIONS.get(getIndex(up, right, down, left));
}
public boolean isUp()
{
return this.up;
}
public boolean isUp() {
return this.up;
}
public boolean isRight()
{
return this.right;
}
public boolean isRight() {
return this.right;
}
public boolean isDown()
{
return this.down;
}
public boolean isDown() {
return this.down;
}
public boolean isLeft()
{
return this.left;
}
public boolean isLeft() {
return this.left;
}
// The combination of connections expressed as a number ranging from [0,15]
public int getIndex()
{
return getIndex( this.up, this.right, this.down, this.left );
}
// The combination of connections expressed as a number ranging from [0,15]
public int getIndex() {
return getIndex(this.up, this.right, this.down, this.left);
}
private static int getIndex( boolean up, boolean right, boolean down, boolean left )
{
return ( up ? BITMASK_UP : 0 ) + ( right ? BITMASK_RIGHT : 0 ) + ( left ? BITMASK_LEFT : 0 ) + ( down ? BITMASK_DOWN : 0 );
}
private static int getIndex(boolean up, boolean right, boolean down, boolean left) {
return (up ? BITMASK_UP : 0) + (right ? BITMASK_RIGHT : 0) + (left ? BITMASK_LEFT : 0) + (down ? BITMASK_DOWN : 0);
}
// Returns a suffix that expresses the connection states as a string
public String getFilenameSuffix()
{
String suffix = Integer.toBinaryString( this.getIndex() );
return Strings.padStart( suffix, 4, '0' );
}
// Returns a suffix that expresses the connection states as a string
public String getFilenameSuffix() {
String suffix = Integer.toBinaryString(this.getIndex());
return Strings.padStart(suffix, 4, '0');
}
@Override
public boolean equals( Object o )
{
if( this == o )
{
return true;
}
if( o == null || this.getClass() != o.getClass() )
{
return false;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || this.getClass() != o.getClass()) {
return false;
}
PlaneConnections that = (PlaneConnections) o;
return this.up == that.up && this.right == that.right && this.down == that.down && this.left == that.left;
}
PlaneConnections that = (PlaneConnections) o;
return this.up == that.up && this.right == that.right && this.down == that.down && this.left == that.left;
}
@Override
public int hashCode()
{
int result = ( this.up ? 1 : 0 );
result = 31 * result + ( this.right ? 1 : 0 );
result = 31 * result + ( this.down ? 1 : 0 );
result = 31 * result + ( this.left ? 1 : 0 );
return result;
}
@Override
public int hashCode() {
int result = (this.up ? 1 : 0);
result = 31 * result + (this.right ? 1 : 0);
result = 31 * result + (this.down ? 1 : 0);
result = 31 * result + (this.left ? 1 : 0);
return result;
}
}
@@ -19,12 +19,7 @@
package appeng.parts.automation;
import java.util.Collection;
import java.util.Collections;
import java.util.function.Function;
import com.google.common.collect.Lists;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
@@ -33,52 +28,50 @@ import net.minecraftforge.client.model.IModel;
import net.minecraftforge.common.model.IModelState;
import net.minecraftforge.common.model.TRSRTransformation;
import java.util.Collection;
import java.util.Collections;
import java.util.function.Function;
/**
* Built-in model for annihilation planes that supports connected textures.
*/
public class PlaneModel implements IModel
{
public class PlaneModel implements IModel {
private final ResourceLocation frontTexture;
private final ResourceLocation sidesTexture;
private final ResourceLocation backTexture;
private final PlaneConnections connections;
private final ResourceLocation frontTexture;
private final ResourceLocation sidesTexture;
private final ResourceLocation backTexture;
private final PlaneConnections connections;
public PlaneModel( ResourceLocation frontTexture, ResourceLocation sidesTexture, ResourceLocation backTexture, PlaneConnections connections )
{
this.frontTexture = frontTexture;
this.sidesTexture = sidesTexture;
this.backTexture = backTexture;
this.connections = connections;
}
public PlaneModel(ResourceLocation frontTexture, ResourceLocation sidesTexture, ResourceLocation backTexture, PlaneConnections connections) {
this.frontTexture = frontTexture;
this.sidesTexture = sidesTexture;
this.backTexture = backTexture;
this.connections = connections;
}
@Override
public Collection<ResourceLocation> getDependencies()
{
return Collections.emptyList();
}
@Override
public Collection<ResourceLocation> getDependencies() {
return Collections.emptyList();
}
@Override
public Collection<ResourceLocation> getTextures()
{
return Lists.newArrayList( this.frontTexture, this.sidesTexture, this.backTexture );
}
@Override
public Collection<ResourceLocation> getTextures() {
return Lists.newArrayList(this.frontTexture, this.sidesTexture, this.backTexture);
}
@Override
public IBakedModel bake( IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter )
{
TextureAtlasSprite frontSprite = bakedTextureGetter.apply( this.frontTexture );
TextureAtlasSprite sidesSprite = bakedTextureGetter.apply( this.sidesTexture );
TextureAtlasSprite backSprite = bakedTextureGetter.apply( this.backTexture );
@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
TextureAtlasSprite frontSprite = bakedTextureGetter.apply(this.frontTexture);
TextureAtlasSprite sidesSprite = bakedTextureGetter.apply(this.sidesTexture);
TextureAtlasSprite backSprite = bakedTextureGetter.apply(this.backTexture);
return new PlaneBakedModel( format, frontSprite, sidesSprite, backSprite, this.connections );
}
return new PlaneBakedModel(format, frontSprite, sidesSprite, backSprite, this.connections);
}
@Override
public IModelState getDefaultState()
{
return TRSRTransformation.identity();
}
@Override
public IModelState getDefaultState() {
return TRSRTransformation.identity();
}
}
@@ -19,80 +19,68 @@
package appeng.parts.automation;
import appeng.api.parts.IPartModel;
import appeng.core.AppEng;
import appeng.parts.PartModel;
import com.google.common.collect.ImmutableMap;
import net.minecraft.util.ResourceLocation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import net.minecraft.util.ResourceLocation;
import appeng.api.parts.IPartModel;
import appeng.core.AppEng;
import appeng.parts.PartModel;
/**
* Contains a mapping from a Plane's connections to the models to use for that state.
*/
public class PlaneModels
{
public class PlaneModels {
public static final ResourceLocation MODEL_CHASSIS_OFF = new ResourceLocation( AppEng.MOD_ID, "part/transition_plane_off" );
public static final ResourceLocation MODEL_CHASSIS_ON = new ResourceLocation( AppEng.MOD_ID, "part/transition_plane_on" );
public static final ResourceLocation MODEL_CHASSIS_HAS_CHANNEL = new ResourceLocation( AppEng.MOD_ID, "part/transition_plane_has_channel" );
public static final ResourceLocation MODEL_CHASSIS_OFF = new ResourceLocation(AppEng.MOD_ID, "part/transition_plane_off");
public static final ResourceLocation MODEL_CHASSIS_ON = new ResourceLocation(AppEng.MOD_ID, "part/transition_plane_on");
public static final ResourceLocation MODEL_CHASSIS_HAS_CHANNEL = new ResourceLocation(AppEng.MOD_ID, "part/transition_plane_has_channel");
private final Map<PlaneConnections, IPartModel> modelsOff;
private final Map<PlaneConnections, IPartModel> modelsOff;
private final Map<PlaneConnections, IPartModel> modelsOn;
private final Map<PlaneConnections, IPartModel> modelsOn;
private final Map<PlaneConnections, IPartModel> modelsHasChannel;
private final Map<PlaneConnections, IPartModel> modelsHasChannel;
public PlaneModels( String prefixOff, String prefixOn )
{
Map<PlaneConnections, IPartModel> modelsOff = new HashMap<>();
Map<PlaneConnections, IPartModel> modelsOn = new HashMap<>();
Map<PlaneConnections, IPartModel> modelsHasChannel = new HashMap<>();
public PlaneModels(String prefixOff, String prefixOn) {
Map<PlaneConnections, IPartModel> modelsOff = new HashMap<>();
Map<PlaneConnections, IPartModel> modelsOn = new HashMap<>();
Map<PlaneConnections, IPartModel> modelsHasChannel = new HashMap<>();
for( PlaneConnections permutation : PlaneConnections.PERMUTATIONS )
{
ResourceLocation planeOff = new ResourceLocation( AppEng.MOD_ID, prefixOff + permutation.getFilenameSuffix() );
ResourceLocation planeOn = new ResourceLocation( AppEng.MOD_ID, prefixOn + permutation.getFilenameSuffix() );
for (PlaneConnections permutation : PlaneConnections.PERMUTATIONS) {
ResourceLocation planeOff = new ResourceLocation(AppEng.MOD_ID, prefixOff + permutation.getFilenameSuffix());
ResourceLocation planeOn = new ResourceLocation(AppEng.MOD_ID, prefixOn + permutation.getFilenameSuffix());
modelsOff.put( permutation, new PartModel( MODEL_CHASSIS_OFF, planeOff ) );
modelsOn.put( permutation, new PartModel( MODEL_CHASSIS_ON, planeOff ) );
modelsHasChannel.put( permutation, new PartModel( MODEL_CHASSIS_HAS_CHANNEL, planeOn ) );
}
modelsOff.put(permutation, new PartModel(MODEL_CHASSIS_OFF, planeOff));
modelsOn.put(permutation, new PartModel(MODEL_CHASSIS_ON, planeOff));
modelsHasChannel.put(permutation, new PartModel(MODEL_CHASSIS_HAS_CHANNEL, planeOn));
}
this.modelsOff = ImmutableMap.copyOf( modelsOff );
this.modelsOn = ImmutableMap.copyOf( modelsOn );
this.modelsHasChannel = ImmutableMap.copyOf( modelsHasChannel );
}
this.modelsOff = ImmutableMap.copyOf(modelsOff);
this.modelsOn = ImmutableMap.copyOf(modelsOn);
this.modelsHasChannel = ImmutableMap.copyOf(modelsHasChannel);
}
public IPartModel getModel( PlaneConnections connections, boolean hasPower, boolean hasChannel )
{
if( hasPower && hasChannel )
{
return this.modelsHasChannel.get( connections );
}
else if( hasPower )
{
return this.modelsOn.get( connections );
}
else
{
return this.modelsOff.get( connections );
}
}
public IPartModel getModel(PlaneConnections connections, boolean hasPower, boolean hasChannel) {
if (hasPower && hasChannel) {
return this.modelsHasChannel.get(connections);
} else if (hasPower) {
return this.modelsOn.get(connections);
} else {
return this.modelsOff.get(connections);
}
}
public List<IPartModel> getModels()
{
List<IPartModel> result = new ArrayList<>();
this.modelsOff.values().forEach( result::add );
this.modelsOn.values().forEach( result::add );
this.modelsHasChannel.values().forEach( result::add );
return result;
}
public List<IPartModel> getModels() {
List<IPartModel> result = new ArrayList<>();
this.modelsOff.values().forEach(result::add);
this.modelsOn.values().forEach(result::add);
this.modelsHasChannel.values().forEach(result::add);
return result;
}
}
@@ -19,36 +19,30 @@
package appeng.parts.automation;
import net.minecraft.item.ItemStack;
import appeng.api.config.Upgrades;
import appeng.util.inv.IAEAppEngInventory;
import net.minecraft.item.ItemStack;
public class StackUpgradeInventory extends UpgradeInventory
{
private final ItemStack stack;
public class StackUpgradeInventory extends UpgradeInventory {
private final ItemStack stack;
public StackUpgradeInventory( final ItemStack stack, final IAEAppEngInventory inventory, final int s )
{
super( inventory, s );
this.stack = stack;
}
public StackUpgradeInventory(final ItemStack stack, final IAEAppEngInventory inventory, final int s) {
super(inventory, s);
this.stack = stack;
}
@Override
public int getMaxInstalled( final Upgrades upgrades )
{
int max = 0;
@Override
public int getMaxInstalled(final Upgrades upgrades) {
int max = 0;
for( final ItemStack is : upgrades.getSupported().keySet() )
{
if( ItemStack.areItemsEqual( this.stack, is ) )
{
max = upgrades.getSupported().get( is );
break;
}
}
for (final ItemStack is : upgrades.getSupported().keySet()) {
if (ItemStack.areItemsEqual(this.stack, is)) {
max = upgrades.getSupported().get(is);
break;
}
}
return max;
}
return max;
}
}
@@ -19,22 +19,6 @@
package appeng.parts.automation;
import javax.annotation.Nonnull;
import appeng.api.AEApi;
import appeng.container.slot.SlotRestrictedInput;
import appeng.core.Api;
import appeng.helpers.DualityInterface;
import appeng.util.inv.ItemHandlerIterator;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Items;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.Upgrades;
import appeng.api.implementations.items.IUpgradeModule;
import appeng.tile.inventory.AppEngInternalInventory;
@@ -42,177 +26,159 @@ import appeng.util.Platform;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import appeng.util.inv.filter.IAEItemFilter;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.items.IItemHandler;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
public abstract class UpgradeInventory extends AppEngInternalInventory implements IAEAppEngInventory
{
private final IAEAppEngInventory parent;
public abstract class UpgradeInventory extends AppEngInternalInventory implements IAEAppEngInventory {
private final IAEAppEngInventory parent;
private boolean cached = false;
private int fuzzyUpgrades = 0;
private int speedUpgrades = 0;
private int redstoneUpgrades = 0;
private int capacityUpgrades = 0;
private int inverterUpgrades = 0;
private int craftingUpgrades = 0;
private int patternExpansionUpgrades = 0;
private boolean cached = false;
private int fuzzyUpgrades = 0;
private int speedUpgrades = 0;
private int redstoneUpgrades = 0;
private int capacityUpgrades = 0;
private int inverterUpgrades = 0;
private int craftingUpgrades = 0;
private int patternExpansionUpgrades = 0;
public UpgradeInventory( final IAEAppEngInventory parent, final int s )
{
super( null, s, 1 );
this.setTileEntity( this );
this.parent = parent;
this.setFilter( new UpgradeInvFilter() );
}
public UpgradeInventory(final IAEAppEngInventory parent, final int s) {
super(null, s, 1);
this.setTileEntity(this);
this.parent = parent;
this.setFilter(new UpgradeInvFilter());
}
@Override
protected boolean eventsEnabled()
{
return true;
}
@Override
protected boolean eventsEnabled() {
return true;
}
public int getInstalledUpgrades( final Upgrades u )
{
if( !this.cached )
{
this.updateUpgradeInfo();
}
public int getInstalledUpgrades(final Upgrades u) {
if (!this.cached) {
this.updateUpgradeInfo();
}
switch( u )
{
case CAPACITY:
return this.capacityUpgrades;
case FUZZY:
return this.fuzzyUpgrades;
case REDSTONE:
return this.redstoneUpgrades;
case SPEED:
return this.speedUpgrades;
case INVERTER:
return this.inverterUpgrades;
case CRAFTING:
return this.craftingUpgrades;
case PATTERN_EXPANSION:
return this.patternExpansionUpgrades;
default:
return 0;
}
}
switch (u) {
case CAPACITY:
return this.capacityUpgrades;
case FUZZY:
return this.fuzzyUpgrades;
case REDSTONE:
return this.redstoneUpgrades;
case SPEED:
return this.speedUpgrades;
case INVERTER:
return this.inverterUpgrades;
case CRAFTING:
return this.craftingUpgrades;
case PATTERN_EXPANSION:
return this.patternExpansionUpgrades;
default:
return 0;
}
}
public abstract int getMaxInstalled( Upgrades upgrades );
public abstract int getMaxInstalled(Upgrades upgrades);
private void updateUpgradeInfo()
{
this.cached = true;
this.patternExpansionUpgrades = this.inverterUpgrades = this.capacityUpgrades = this.redstoneUpgrades = this.speedUpgrades = this.fuzzyUpgrades = this.craftingUpgrades = 0;
private void updateUpgradeInfo() {
this.cached = true;
this.patternExpansionUpgrades = this.inverterUpgrades = this.capacityUpgrades = this.redstoneUpgrades = this.speedUpgrades = this.fuzzyUpgrades = this.craftingUpgrades = 0;
for( final ItemStack is : this )
{
if( is == null || is.getItem() == Items.AIR || !( is.getItem() instanceof IUpgradeModule ) )
{
continue;
}
for (final ItemStack is : this) {
if (is == null || is.getItem() == Items.AIR || !(is.getItem() instanceof IUpgradeModule)) {
continue;
}
final Upgrades myUpgrade = ( (IUpgradeModule) is.getItem() ).getType( is );
switch( myUpgrade )
{
case CAPACITY:
this.capacityUpgrades++;
break;
case FUZZY:
this.fuzzyUpgrades++;
break;
case REDSTONE:
this.redstoneUpgrades++;
break;
case SPEED:
this.speedUpgrades++;
break;
case INVERTER:
this.inverterUpgrades++;
break;
case CRAFTING:
this.craftingUpgrades++;
break;
case PATTERN_EXPANSION:
this.patternExpansionUpgrades++;
break;
default:
break;
}
}
final Upgrades myUpgrade = ((IUpgradeModule) is.getItem()).getType(is);
switch (myUpgrade) {
case CAPACITY:
this.capacityUpgrades++;
break;
case FUZZY:
this.fuzzyUpgrades++;
break;
case REDSTONE:
this.redstoneUpgrades++;
break;
case SPEED:
this.speedUpgrades++;
break;
case INVERTER:
this.inverterUpgrades++;
break;
case CRAFTING:
this.craftingUpgrades++;
break;
case PATTERN_EXPANSION:
this.patternExpansionUpgrades++;
break;
default:
break;
}
}
this.capacityUpgrades = Math.min( this.capacityUpgrades, this.getMaxInstalled( Upgrades.CAPACITY ) );
this.fuzzyUpgrades = Math.min( this.fuzzyUpgrades, this.getMaxInstalled( Upgrades.FUZZY ) );
this.redstoneUpgrades = Math.min( this.redstoneUpgrades, this.getMaxInstalled( Upgrades.REDSTONE ) );
this.speedUpgrades = Math.min( this.speedUpgrades, this.getMaxInstalled( Upgrades.SPEED ) );
this.inverterUpgrades = Math.min( this.inverterUpgrades, this.getMaxInstalled( Upgrades.INVERTER ) );
this.craftingUpgrades = Math.min( this.craftingUpgrades, this.getMaxInstalled( Upgrades.CRAFTING ) );
this.patternExpansionUpgrades = Math.min( this.patternExpansionUpgrades, this.getMaxInstalled( Upgrades.PATTERN_EXPANSION ) );
}
this.capacityUpgrades = Math.min(this.capacityUpgrades, this.getMaxInstalled(Upgrades.CAPACITY));
this.fuzzyUpgrades = Math.min(this.fuzzyUpgrades, this.getMaxInstalled(Upgrades.FUZZY));
this.redstoneUpgrades = Math.min(this.redstoneUpgrades, this.getMaxInstalled(Upgrades.REDSTONE));
this.speedUpgrades = Math.min(this.speedUpgrades, this.getMaxInstalled(Upgrades.SPEED));
this.inverterUpgrades = Math.min(this.inverterUpgrades, this.getMaxInstalled(Upgrades.INVERTER));
this.craftingUpgrades = Math.min(this.craftingUpgrades, this.getMaxInstalled(Upgrades.CRAFTING));
this.patternExpansionUpgrades = Math.min(this.patternExpansionUpgrades, this.getMaxInstalled(Upgrades.PATTERN_EXPANSION));
}
@Override
public void readFromNBT( final NBTTagCompound target )
{
super.readFromNBT( target );
this.updateUpgradeInfo();
}
@Override
public void readFromNBT(final NBTTagCompound target) {
super.readFromNBT(target);
this.updateUpgradeInfo();
}
@Override
public void saveChanges()
{
if( this.parent != null )
{
this.parent.saveChanges();
}
}
@Override
public void saveChanges() {
if (this.parent != null) {
this.parent.saveChanges();
}
}
@Override
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
this.cached = false;
if( this.parent != null && Platform.isServer() )
{
this.parent.onChangeInventory( inv, slot, mc, removedStack, newStack );
}
}
@Override
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
this.cached = false;
if (this.parent != null && Platform.isServer()) {
this.parent.onChangeInventory(inv, slot, mc, removedStack, newStack);
}
}
@Nonnull
@Override
public ItemStack extractItem( int slot, int amount, boolean simulate )
{
return super.extractItem( slot, amount, simulate );
}
@Nonnull
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
return super.extractItem(slot, amount, simulate);
}
private class UpgradeInvFilter implements IAEItemFilter
{
private class UpgradeInvFilter implements IAEItemFilter {
@Override
public boolean allowExtract( IItemHandler inv, int slot, int amount )
{
return true;
}
@Override
public boolean allowExtract(IItemHandler inv, int slot, int amount) {
return true;
}
@Override
public boolean allowInsert( IItemHandler inv, int slot, ItemStack itemstack )
{
if( itemstack.isEmpty() )
{
return false;
}
final Item it = itemstack.getItem();
if( it instanceof IUpgradeModule )
{
final Upgrades u = ( (IUpgradeModule) it ).getType( itemstack );
if( u != null )
{
return UpgradeInventory.this.getInstalledUpgrades( u ) < UpgradeInventory.this.getMaxInstalled( u );
}
}
return false;
}
}
@Override
public boolean allowInsert(IItemHandler inv, int slot, ItemStack itemstack) {
if (itemstack.isEmpty()) {
return false;
}
final Item it = itemstack.getItem();
if (it instanceof IUpgradeModule) {
final Upgrades u = ((IUpgradeModule) it).getType(itemstack);
if (u != null) {
return UpgradeInventory.this.getInstalledUpgrades(u) < UpgradeInventory.this.getMaxInstalled(u);
}
}
return false;
}
}
}