2013-12-27 23:59:59 +01:00
|
|
|
package appeng.tile.grindstone;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
|
|
|
import net.minecraft.world.World;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.tiles.ICrankable;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.helpers.ICustomCollision;
|
|
|
|
import appeng.tile.AEBaseTile;
|
|
|
|
import appeng.tile.events.AETileEventHandler;
|
|
|
|
import appeng.tile.events.TileEventType;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
|
|
|
public class TileCrank extends AEBaseTile implements ICustomCollision
|
|
|
|
{
|
|
|
|
|
|
|
|
final int ticksPerRoation = 18;
|
|
|
|
|
|
|
|
// sided values..
|
|
|
|
public float visibleRotation = 0;
|
|
|
|
public int charge = 0;
|
|
|
|
|
|
|
|
public int hits = 0;
|
|
|
|
public int rotation = 0;
|
|
|
|
|
|
|
|
public TileCrank() {
|
2014-01-26 07:46:16 +01:00
|
|
|
addNewHandler( new AETileEventHandler( TileEventType.NETWORK, TileEventType.TICK ) {
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void Tick()
|
|
|
|
{
|
|
|
|
if ( rotation > 0 )
|
|
|
|
{
|
|
|
|
visibleRotation -= 360 / (ticksPerRoation);
|
|
|
|
charge++;
|
|
|
|
if ( charge >= ticksPerRoation )
|
|
|
|
{
|
|
|
|
charge -= ticksPerRoation;
|
|
|
|
ICrankable g = getGrinder();
|
|
|
|
if ( g != null )
|
|
|
|
g.applyTurn();
|
|
|
|
}
|
|
|
|
|
|
|
|
rotation--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public boolean readFromStream(ByteBuf data) throws java.io.IOException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
rotation = data.readInt();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void writeToStream(ByteBuf data) throws java.io.IOException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
data.writeInt( rotation );
|
|
|
|
}
|
|
|
|
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
public ICrankable getGrinder()
|
|
|
|
{
|
|
|
|
if ( Platform.isClient() )
|
|
|
|
return null;
|
|
|
|
|
|
|
|
ForgeDirection grinder = getUp().getOpposite();
|
2014-02-09 02:34:52 +01:00
|
|
|
TileEntity te = worldObj.getTileEntity( xCoord + grinder.offsetX, yCoord + grinder.offsetY, zCoord + grinder.offsetZ );
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( te instanceof ICrankable )
|
|
|
|
return (ICrankable) te;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setOrientation(ForgeDirection inForward, ForgeDirection inUp)
|
|
|
|
{
|
|
|
|
super.setOrientation( inForward, inUp );
|
2014-02-09 02:34:52 +01:00
|
|
|
getBlockType().onNeighborBlockChange( worldObj, xCoord, yCoord, zCoord, Platform.air );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void power()
|
|
|
|
{
|
|
|
|
if ( Platform.isClient() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( rotation < 3 )
|
|
|
|
{
|
|
|
|
ICrankable g = getGrinder();
|
|
|
|
if ( g != null )
|
|
|
|
{
|
|
|
|
if ( g.canTurn() )
|
|
|
|
{
|
|
|
|
hits = 0;
|
|
|
|
rotation += ticksPerRoation;
|
|
|
|
this.markForUpdate();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hits++;
|
|
|
|
if ( hits > 10 )
|
2014-02-09 02:34:52 +01:00
|
|
|
{
|
|
|
|
worldObj.func_147480_a( xCoord, yCoord, zCoord, false );
|
|
|
|
// worldObj.destroyBlock( xCoord, yCoord, zCoord, false );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-31 18:11:50 +01:00
|
|
|
public Iterable<AxisAlignedBB> getSelectedBoundingBoxsFromPool(World w, int x, int y, int z, Entity e, boolean isVisual)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
double xOff = -0.15 * getUp().offsetX;
|
|
|
|
double yOff = -0.15 * getUp().offsetY;
|
|
|
|
double zOff = -0.15 * getUp().offsetZ;
|
2014-02-06 05:36:10 +01:00
|
|
|
return Arrays
|
|
|
|
.asList( new AxisAlignedBB[] { AxisAlignedBB.getBoundingBox( xOff + 0.15, yOff + 0.15, zOff + 0.15, xOff + 0.85, yOff + 0.85, zOff + 0.85 ) } );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addCollidingBlockToList(World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e)
|
|
|
|
{
|
|
|
|
double xOff = -0.15 * getUp().offsetX;
|
|
|
|
double yOff = -0.15 * getUp().offsetY;
|
|
|
|
double zOff = -0.15 * getUp().offsetZ;
|
|
|
|
out.add( AxisAlignedBB.getAABBPool().getAABB( xOff + (double) 0.15, yOff + (double) 0.15, zOff + (double) 0.15,// ahh
|
|
|
|
xOff + (double) 0.85, yOff + (double) 0.85, zOff + (double) 0.85 ) );
|
|
|
|
}
|
2014-02-06 05:36:10 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean requiresTESR()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|