2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
package appeng.parts.automation;
|
|
|
|
|
2015-01-02 18:52:47 +01:00
|
|
|
|
2015-02-26 22:33:23 +01:00
|
|
|
import java.util.concurrent.Callable;
|
|
|
|
|
2014-02-14 05:27:15 +01:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.material.Material;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.client.renderer.RenderBlocks;
|
2014-02-14 05:27:15 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
|
|
import net.minecraft.init.Blocks;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-03-15 07:58:21 +01:00
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
2014-02-14 05:27:15 +01:00
|
|
|
import net.minecraft.world.WorldServer;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
2015-03-26 10:23:59 +01:00
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
2014-02-14 05:27:15 +01:00
|
|
|
import appeng.api.config.Actionable;
|
|
|
|
import appeng.api.config.PowerMultiplier;
|
|
|
|
import appeng.api.networking.IGridNode;
|
|
|
|
import appeng.api.networking.energy.IEnergyGrid;
|
2014-02-14 07:15:04 +01:00
|
|
|
import appeng.api.networking.events.MENetworkChannelsChanged;
|
|
|
|
import appeng.api.networking.events.MENetworkEventSubscribe;
|
|
|
|
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
2014-02-14 05:27:15 +01:00
|
|
|
import appeng.api.networking.security.BaseActionSource;
|
|
|
|
import appeng.api.networking.security.MachineSource;
|
|
|
|
import appeng.api.networking.storage.IStorageGrid;
|
|
|
|
import appeng.api.networking.ticking.IGridTickable;
|
|
|
|
import appeng.api.networking.ticking.TickRateModulation;
|
|
|
|
import appeng.api.networking.ticking.TickingRequest;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.parts.IPart;
|
2014-09-20 22:20:53 +02:00
|
|
|
import appeng.api.parts.IPartCollisionHelper;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.parts.IPartHost;
|
|
|
|
import appeng.api.parts.IPartRenderHelper;
|
2014-02-14 05:27:15 +01:00
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.client.texture.CableBusTextures;
|
2014-03-17 20:59:50 +01:00
|
|
|
import appeng.core.settings.TickRates;
|
2014-02-14 05:27:15 +01:00
|
|
|
import appeng.core.sync.packets.PacketTransitionEffect;
|
2015-02-26 22:33:23 +01:00
|
|
|
import appeng.hooks.TickHandler;
|
2014-02-14 05:27:15 +01:00
|
|
|
import appeng.me.GridAccessException;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.parts.PartBasicState;
|
2014-02-14 05:27:15 +01:00
|
|
|
import appeng.server.ServerHelper;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
import appeng.util.item.AEItemStack;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-01-02 18:52:47 +01:00
|
|
|
|
2015-02-26 22:33:23 +01:00
|
|
|
public class PartAnnihilationPlane extends PartBasicState implements IGridTickable, Callable<TickRateModulation>
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-01-02 18:52:47 +01:00
|
|
|
private final BaseActionSource mySrc = new MachineSource( this );
|
2015-01-03 02:53:14 +01:00
|
|
|
private boolean isAccepting = true;
|
2015-02-26 22:33:23 +01:00
|
|
|
private boolean breaking = false;
|
2015-01-02 18:52:47 +01:00
|
|
|
|
|
|
|
public PartAnnihilationPlane( ItemStack is )
|
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
super( is );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-02-26 22:33:23 +01:00
|
|
|
@Override
|
|
|
|
public TickRateModulation call() throws Exception
|
|
|
|
{
|
|
|
|
this.breaking = false;
|
2015-03-26 11:20:31 +01:00
|
|
|
return this.breakBlock( true );
|
2015-02-26 22:33:23 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public void getBoxes( 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 int x = te.xCoord;
|
|
|
|
final int y = te.yCoord;
|
|
|
|
final int z = te.zCoord;
|
|
|
|
|
|
|
|
final ForgeDirection e = bch.getWorldX();
|
|
|
|
final ForgeDirection u = bch.getWorldY();
|
|
|
|
|
|
|
|
if( this.isAnnihilationPlane( te.getWorldObj().getTileEntity( x - e.offsetX, y - e.offsetY, z - e.offsetZ ), this.side ) )
|
|
|
|
{
|
|
|
|
minX = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( this.isAnnihilationPlane( te.getWorldObj().getTileEntity( x + e.offsetX, y + e.offsetY, z + e.offsetZ ), this.side ) )
|
|
|
|
{
|
|
|
|
maxX = 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( this.isAnnihilationPlane( te.getWorldObj().getTileEntity( x - u.offsetX, y - u.offsetY, z - u.offsetZ ), this.side ) )
|
|
|
|
{
|
|
|
|
minY = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( this.isAnnihilationPlane( te.getWorldObj().getTileEntity( x + u.offsetX, y + u.offsetY, z + u.offsetZ ), this.side ) )
|
|
|
|
{
|
|
|
|
maxY = 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bch.addBox( 5, 5, 14, 11, 11, 15 );
|
|
|
|
bch.addBox( minX, minY, 15, maxX, maxY, bch.isBBCollision() ? 15 : 16 );
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
2015-01-02 18:52:47 +01:00
|
|
|
@SideOnly( Side.CLIENT )
|
|
|
|
public void renderInventory( IPartRenderHelper rh, RenderBlocks renderer )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
rh.setTexture( CableBusTextures.PartPlaneSides.getIcon(), CableBusTextures.PartPlaneSides.getIcon(), CableBusTextures.PartTransitionPlaneBack.getIcon(), this.is.getIconIndex(), CableBusTextures.PartPlaneSides.getIcon(), CableBusTextures.PartPlaneSides.getIcon() );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
rh.setBounds( 1, 1, 15, 15, 15, 16 );
|
|
|
|
rh.renderInventoryBox( renderer );
|
|
|
|
|
|
|
|
rh.setBounds( 5, 5, 14, 11, 11, 15 );
|
|
|
|
rh.renderInventoryBox( renderer );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-02 18:52:47 +01:00
|
|
|
@SideOnly( Side.CLIENT )
|
|
|
|
public void renderStatic( int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
int minX = 1;
|
|
|
|
int minY = 1;
|
|
|
|
int maxX = 15;
|
|
|
|
int maxY = 15;
|
|
|
|
|
2015-01-02 18:52:47 +01:00
|
|
|
final ForgeDirection e = rh.getWorldX();
|
|
|
|
final ForgeDirection u = rh.getWorldY();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-01-02 18:52:47 +01:00
|
|
|
final TileEntity te = this.getHost().getTile();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.isAnnihilationPlane( te.getWorldObj().getTileEntity( x - e.offsetX, y - e.offsetY, z - e.offsetZ ), this.side ) )
|
2015-01-02 18:52:47 +01:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
minX = 0;
|
2015-01-02 18:52:47 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.isAnnihilationPlane( te.getWorldObj().getTileEntity( x + e.offsetX, y + e.offsetY, z + e.offsetZ ), this.side ) )
|
2015-01-02 18:52:47 +01:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
maxX = 16;
|
2015-01-02 18:52:47 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.isAnnihilationPlane( te.getWorldObj().getTileEntity( x - u.offsetX, y - u.offsetY, z - u.offsetZ ), this.side ) )
|
2015-01-02 18:52:47 +01:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
minY = 0;
|
2015-01-02 18:52:47 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.isAnnihilationPlane( te.getWorldObj().getTileEntity( x + u.offsetX, y + u.offsetY, z + u.offsetZ ), this.side ) )
|
2015-01-02 18:52:47 +01:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
maxY = 16;
|
2015-01-02 18:52:47 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-01-02 18:52:47 +01:00
|
|
|
final boolean isActive = ( this.clientFlags & ( this.POWERED_FLAG | this.CHANNEL_FLAG ) ) == ( this.POWERED_FLAG | this.CHANNEL_FLAG );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderCache = rh.useSimplifiedRendering( x, y, z, this, this.renderCache );
|
2015-01-03 02:53:14 +01:00
|
|
|
rh.setTexture( CableBusTextures.PartPlaneSides.getIcon(), CableBusTextures.PartPlaneSides.getIcon(), CableBusTextures.PartTransitionPlaneBack.getIcon(), isActive ? CableBusTextures.BlockAnnihilationPlaneOn.getIcon() : this.is.getIconIndex(), CableBusTextures.PartPlaneSides.getIcon(), CableBusTextures.PartPlaneSides.getIcon() );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
rh.setBounds( minX, minY, 15, maxX, maxY, 16 );
|
|
|
|
rh.renderBlock( x, y, z, renderer );
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
rh.setTexture( CableBusTextures.PartMonitorSidesStatus.getIcon(), CableBusTextures.PartMonitorSidesStatus.getIcon(), CableBusTextures.PartTransitionPlaneBack.getIcon(), isActive ? CableBusTextures.BlockAnnihilationPlaneOn.getIcon() : this.is.getIconIndex(), CableBusTextures.PartMonitorSidesStatus.getIcon(), CableBusTextures.PartMonitorSidesStatus.getIcon() );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
rh.setBounds( 5, 5, 14, 11, 11, 15 );
|
|
|
|
rh.renderBlock( x, y, z, renderer );
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.renderLights( x, y, z, rh, renderer );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
@Override
|
|
|
|
public void onNeighborChanged()
|
|
|
|
{
|
|
|
|
this.isAccepting = true;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
this.proxy.getTick().alertDevice( this.proxy.getNode() );
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( final GridAccessException e )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEntityCollision( Entity entity )
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.isAccepting && entity instanceof EntityItem && !entity.isDead && Platform.isServer() && this.proxy.isActive() )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
boolean capture = false;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( this.side )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
case DOWN:
|
|
|
|
case UP:
|
2015-04-03 08:54:31 +02:00
|
|
|
if( entity.posX > this.tile.xCoord && entity.posX < this.tile.xCoord + 1 )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( entity.posZ > this.tile.zCoord && entity.posZ < this.tile.zCoord + 1 )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ( entity.posY > this.tile.yCoord + 0.9 && this.side == ForgeDirection.UP ) || ( entity.posY < this.tile.yCoord + 0.1 && this.side == ForgeDirection.DOWN ) )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
capture = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SOUTH:
|
|
|
|
case NORTH:
|
2015-04-03 08:54:31 +02:00
|
|
|
if( entity.posX > this.tile.xCoord && entity.posX < this.tile.xCoord + 1 )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( entity.posY > this.tile.yCoord && entity.posY < this.tile.yCoord + 1 )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ( entity.posZ > this.tile.zCoord + 0.9 && this.side == ForgeDirection.SOUTH ) || ( entity.posZ < this.tile.zCoord + 0.1 && this.side == ForgeDirection.NORTH ) )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
capture = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EAST:
|
|
|
|
case WEST:
|
2015-04-03 08:54:31 +02:00
|
|
|
if( entity.posZ > this.tile.zCoord && entity.posZ < this.tile.zCoord + 1 )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( entity.posY > this.tile.yCoord && entity.posY < this.tile.yCoord + 1 )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ( entity.posX > this.tile.xCoord + 0.9 && this.side == ForgeDirection.EAST ) || ( entity.posX < this.tile.xCoord + 0.1 && this.side == ForgeDirection.WEST ) )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
capture = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// umm?
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( capture )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
ServerHelper.proxy.sendToAllNearExcept( null, this.tile.xCoord, this.tile.yCoord, this.tile.zCoord, 64, this.tile.getWorldObj(), new PacketTransitionEffect( entity.posX, entity.posY, entity.posZ, this.side, false ) );
|
|
|
|
this.storeEntityItem( (EntityItem) entity );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public int cableConnectionRenderTo()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
/**
|
|
|
|
* 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 void storeEntityItem( EntityItem entityItem )
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !entityItem.isDead )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
this.storeItemStack( entityItem.getEntityItem() );
|
|
|
|
entityItem.setDead();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores an {@link ItemStack} inside the network.
|
|
|
|
*
|
|
|
|
* @param item {@link ItemStack} to store
|
|
|
|
*/
|
|
|
|
private void storeItemStack( ItemStack item )
|
|
|
|
{
|
|
|
|
final IAEItemStack itemToStore = AEItemStack.create( item );
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final IStorageGrid storage = this.proxy.getStorage();
|
|
|
|
final IEnergyGrid energy = this.proxy.getEnergy();
|
|
|
|
final IAEItemStack overflow = Platform.poweredInsert( energy, storage.getItemInventory(), itemToStore, this.mySrc );
|
|
|
|
|
|
|
|
this.spawnOverflowItemStack( overflow );
|
|
|
|
|
|
|
|
this.isAccepting = overflow == null;
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( final GridAccessException e1 )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void spawnOverflowItemStack( IAEItemStack overflow )
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( overflow == null )
|
2015-01-03 02:53:14 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final TileEntity tileEntity = this.getTile();
|
|
|
|
final WorldServer world = (WorldServer) tileEntity.getWorldObj();
|
|
|
|
|
|
|
|
final int x = tileEntity.xCoord + this.side.offsetX;
|
|
|
|
final int y = tileEntity.yCoord + this.side.offsetY;
|
|
|
|
final int z = tileEntity.zCoord + this.side.offsetZ;
|
|
|
|
|
|
|
|
Platform.spawnDrops( world, x, y, z, Lists.newArrayList( overflow.getItemStack() ) );
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private boolean isAnnihilationPlane( TileEntity blockTileEntity, ForgeDirection side )
|
|
|
|
{
|
|
|
|
if( blockTileEntity instanceof IPartHost )
|
|
|
|
{
|
|
|
|
final IPart p = ( (IPartHost) blockTileEntity ).getPart( side );
|
|
|
|
return p instanceof PartAnnihilationPlane;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the plane is accepting items.
|
|
|
|
*
|
|
|
|
* This might be improved if a performance problem shows up.
|
|
|
|
*
|
|
|
|
* @return true if planes accepts items.
|
|
|
|
*/
|
|
|
|
private boolean isAccepting()
|
|
|
|
{
|
|
|
|
return this.isAccepting;
|
|
|
|
}
|
|
|
|
|
2014-09-28 20:34:00 +02:00
|
|
|
@Override
|
2014-02-14 07:15:04 +01:00
|
|
|
@MENetworkEventSubscribe
|
2015-01-02 18:52:47 +01:00
|
|
|
public void chanRender( MENetworkChannelsChanged c )
|
2014-02-14 07:15:04 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.onNeighborChanged();
|
|
|
|
this.getHost().markForUpdate();
|
2014-02-14 07:15:04 +01:00
|
|
|
}
|
|
|
|
|
2014-09-28 20:34:00 +02:00
|
|
|
@Override
|
2014-02-14 07:15:04 +01:00
|
|
|
@MENetworkEventSubscribe
|
2015-01-02 18:52:47 +01:00
|
|
|
public void powerRender( MENetworkPowerStatusChange c )
|
2014-02-14 07:15:04 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.onNeighborChanged();
|
|
|
|
this.getHost().markForUpdate();
|
2014-02-14 07:15:04 +01:00
|
|
|
}
|
|
|
|
|
2015-03-26 11:20:31 +01:00
|
|
|
public TickRateModulation breakBlock( boolean modulate )
|
2014-02-14 05:27:15 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.isAccepting && this.proxy.isActive() )
|
2014-02-14 05:27:15 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-01-02 18:52:47 +01:00
|
|
|
final TileEntity te = this.getTile();
|
2015-01-03 02:53:14 +01:00
|
|
|
final WorldServer w = (WorldServer) te.getWorldObj();
|
2014-02-14 05:27:15 +01:00
|
|
|
|
2015-01-02 18:52:47 +01:00
|
|
|
final int x = te.xCoord + this.side.offsetX;
|
|
|
|
final int y = te.yCoord + this.side.offsetY;
|
|
|
|
final int z = te.zCoord + this.side.offsetZ;
|
2014-02-14 05:27:15 +01:00
|
|
|
|
2015-01-02 18:52:47 +01:00
|
|
|
final Block blk = w.getBlock( x, y, z );
|
2014-02-14 05:27:15 +01:00
|
|
|
|
2015-01-02 18:52:47 +01:00
|
|
|
final IEnergyGrid energy = this.proxy.getEnergy();
|
2014-02-14 05:27:15 +01:00
|
|
|
|
2015-01-02 18:52:47 +01:00
|
|
|
final Material mat = blk.getMaterial();
|
2015-01-03 02:53:14 +01:00
|
|
|
final boolean ignore = mat == Material.air || mat == Material.lava || mat == Material.water || mat.isLiquid() || blk == Blocks.bedrock || blk == Blocks.end_portal || blk == Blocks.end_portal_frame || blk == Blocks.command_block;
|
2014-02-14 05:27:15 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !ignore && !w.isAirBlock( x, y, z ) && w.blockExists( x, y, z ) && w.canMineBlock( Platform.getPlayer( w ), x, y, z ) )
|
2014-02-14 05:27:15 +01:00
|
|
|
{
|
2015-01-02 18:52:47 +01:00
|
|
|
final float hardness = blk.getBlockHardness( w, x, y, z );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( hardness >= 0.0 )
|
2014-02-14 05:27:15 +01:00
|
|
|
{
|
2015-01-02 18:52:47 +01:00
|
|
|
final ItemStack[] out = Platform.getBlockDrops( w, x, y, z );
|
2014-02-14 05:27:15 +01:00
|
|
|
|
2015-01-02 18:52:47 +01:00
|
|
|
float total = 1 + hardness;
|
2015-04-03 08:54:31 +02:00
|
|
|
for( final ItemStack is : out )
|
2015-01-02 18:52:47 +01:00
|
|
|
{
|
|
|
|
total += is.stackSize;
|
|
|
|
}
|
2014-03-15 07:58:21 +01:00
|
|
|
|
2015-01-02 18:52:47 +01:00
|
|
|
final boolean hasPower = energy.extractAEPower( total, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > total - 0.1;
|
|
|
|
final boolean canStore = this.canStoreItemStacks( out );
|
2014-02-14 07:15:04 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( hasPower && canStore )
|
2015-01-02 18:52:47 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( modulate )
|
2015-01-02 18:52:47 +01:00
|
|
|
{
|
2015-05-08 23:37:09 +02:00
|
|
|
w.setBlock( x, y, z, Platform.AIR_BLOCK, 0, 3 );
|
2015-02-26 22:33:23 +01:00
|
|
|
energy.extractAEPower( total, Actionable.MODULATE, PowerMultiplier.CONFIG );
|
|
|
|
|
|
|
|
final AxisAlignedBB box = AxisAlignedBB.getBoundingBox( x - 0.2, y - 0.2, z - 0.2, x + 1.2, y + 1.2, z + 1.2 );
|
2015-04-03 08:54:31 +02:00
|
|
|
for( final Object ei : w.getEntitiesWithinAABB( EntityItem.class, box ) )
|
2015-01-02 18:52:47 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ei instanceof EntityItem )
|
2015-02-26 22:33:23 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
final EntityItem entityItem = (EntityItem) ei;
|
2015-02-26 22:33:23 +01:00
|
|
|
this.storeEntityItem( entityItem );
|
|
|
|
}
|
2014-02-14 05:27:15 +01:00
|
|
|
}
|
2015-01-02 18:52:47 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( final ItemStack snaggedItem : out )
|
2014-02-14 05:27:15 +01:00
|
|
|
{
|
2015-02-26 22:33:23 +01:00
|
|
|
this.storeItemStack( snaggedItem );
|
2014-02-14 05:27:15 +01:00
|
|
|
}
|
2015-01-02 18:52:47 +01:00
|
|
|
|
2015-02-26 22:33:23 +01:00
|
|
|
ServerHelper.proxy.sendToAllNearExcept( null, x, y, z, 64, w, new PacketTransitionEffect( x, y, z, this.side, true ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.breaking = true;
|
|
|
|
TickHandler.INSTANCE.addCallable( this.tile.getWorldObj(), this );
|
|
|
|
}
|
2015-01-02 18:52:47 +01:00
|
|
|
return TickRateModulation.URGENT;
|
2014-02-14 05:27:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( final GridAccessException e1 )
|
2014-02-14 05:27:15 +01:00
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// nothing to do here :)
|
2015-01-02 18:52:47 +01:00
|
|
|
return TickRateModulation.IDLE;
|
2014-02-14 05:27:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-02 18:52:47 +01:00
|
|
|
public TickingRequest getTickingRequest( IGridNode node )
|
2014-02-14 05:27:15 +01:00
|
|
|
{
|
2014-03-17 20:59:50 +01:00
|
|
|
return new TickingRequest( TickRates.AnnihilationPlane.min, TickRates.AnnihilationPlane.max, false, true );
|
2014-02-14 05:27:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public TickRateModulation tickingRequest( IGridNode node, int ticksSinceLastCall )
|
2014-02-14 05:27:15 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.breaking )
|
2015-02-26 22:33:23 +01:00
|
|
|
{
|
|
|
|
return TickRateModulation.URGENT;
|
|
|
|
}
|
|
|
|
|
2015-01-02 18:52:47 +01:00
|
|
|
this.isAccepting = true;
|
2015-03-26 11:20:31 +01:00
|
|
|
return this.breakBlock( false );
|
2014-02-14 05:27:15 +01:00
|
|
|
}
|
|
|
|
|
2015-01-02 18:52:47 +01:00
|
|
|
/**
|
|
|
|
* Checks if the network can store the possible drops.
|
2015-02-03 12:04:13 +01:00
|
|
|
*
|
2015-01-02 18:52:47 +01:00
|
|
|
* It also sets isAccepting to false, if the item can not be stored.
|
2015-02-03 12:04:13 +01:00
|
|
|
*
|
2015-01-02 18:52:47 +01:00
|
|
|
* @param itemStacks an array of {@link ItemStack} to test
|
2015-01-03 02:53:14 +01:00
|
|
|
*
|
2015-01-02 18:52:47 +01:00
|
|
|
* @return true, if the network can store at least a single item of all drops or no drops are reported
|
|
|
|
*/
|
|
|
|
private boolean canStoreItemStacks( ItemStack[] itemStacks )
|
2014-02-14 05:27:15 +01:00
|
|
|
{
|
2015-01-02 18:52:47 +01:00
|
|
|
boolean canStore = itemStacks.length == 0;
|
|
|
|
|
2014-02-14 05:27:15 +01:00
|
|
|
try
|
|
|
|
{
|
2015-01-02 18:52:47 +01:00
|
|
|
final IStorageGrid storage = this.proxy.getStorage();
|
2014-02-14 05:27:15 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( final ItemStack itemStack : itemStacks )
|
2014-02-14 05:27:15 +01:00
|
|
|
{
|
2015-01-02 18:52:47 +01:00
|
|
|
final IAEItemStack itemToTest = AEItemStack.create( itemStack );
|
|
|
|
final IAEItemStack overflow = storage.getItemInventory().injectItems( itemToTest, Actionable.SIMULATE, this.mySrc );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( overflow == null || itemToTest.getStackSize() > overflow.getStackSize() )
|
2014-02-14 05:27:15 +01:00
|
|
|
{
|
2015-01-02 18:52:47 +01:00
|
|
|
canStore = true;
|
2014-02-14 05:27:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( final GridAccessException e )
|
2014-02-14 05:27:15 +01:00
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
2015-01-02 18:52:47 +01:00
|
|
|
|
|
|
|
this.isAccepting = canStore;
|
|
|
|
return canStore;
|
2014-02-14 05:27:15 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|