pick 97420a31d The big reformat of 2020
This commit is contained in:
@@ -18,12 +18,8 @@
|
||||
|
||||
package appeng.block.grindstone;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.api.implementations.tiles.ICrankable;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.core.stats.AeStats;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.tile.grindstone.TileCrank;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRenderType;
|
||||
import net.minecraft.block.BlockState;
|
||||
@@ -47,137 +43,122 @@ import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import appeng.api.implementations.tiles.ICrankable;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.core.stats.AeStats;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.tile.grindstone.TileCrank;
|
||||
|
||||
public class BlockCrank extends AEBaseTileBlock<TileCrank> {
|
||||
|
||||
public class BlockCrank extends AEBaseTileBlock<TileCrank>
|
||||
{
|
||||
public BlockCrank(Properties props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
public BlockCrank(Properties props) {
|
||||
super(props);
|
||||
}
|
||||
@Override
|
||||
public ActionResultType onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockRayTraceResult hit) {
|
||||
if (player instanceof FakePlayer || player == null) {
|
||||
this.dropCrank(w, pos);
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand, final @Nullable ItemStack heldItem, final BlockRayTraceResult hit)
|
||||
{
|
||||
if( player instanceof FakePlayer || player == null )
|
||||
{
|
||||
this.dropCrank( w, pos );
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
final TileCrank tile = this.getTileEntity(w, pos);
|
||||
if (tile != null) {
|
||||
if (tile.power()) {
|
||||
AeStats.TurnedCranks.addToPlayer(player, 1);
|
||||
}
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
|
||||
final TileCrank tile = this.getTileEntity( w, pos );
|
||||
if( tile != null )
|
||||
{
|
||||
if( tile.power() )
|
||||
{
|
||||
AeStats.TurnedCranks.addToPlayer( player, 1 );
|
||||
}
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
private void dropCrank(final World world, final BlockPos pos) {
|
||||
world.destroyBlock(pos, true);
|
||||
world.notifyBlockUpdate(pos, this.getDefaultState(), world.getBlockState(pos), 3);
|
||||
}
|
||||
|
||||
private void dropCrank( final World world, final BlockPos pos )
|
||||
{
|
||||
world.destroyBlock( pos, true );
|
||||
world.notifyBlockUpdate( pos, this.getDefaultState(), world.getBlockState( pos ), 3 );
|
||||
}
|
||||
@Override
|
||||
public void onBlockPlacedBy(final World world, final BlockPos pos, final BlockState state,
|
||||
final LivingEntity placer, final ItemStack stack) {
|
||||
final AEBaseTile tile = this.getTileEntity(world, pos);
|
||||
if (tile != null) {
|
||||
final Direction mnt = this.findCrankable(world, pos);
|
||||
Direction forward = Direction.UP;
|
||||
if (mnt == Direction.UP || mnt == Direction.DOWN) {
|
||||
forward = Direction.SOUTH;
|
||||
}
|
||||
tile.setOrientation(forward, mnt.getOpposite());
|
||||
} else {
|
||||
this.dropCrank(world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy( final World world, final BlockPos pos, final BlockState state, final LivingEntity placer, final ItemStack stack )
|
||||
{
|
||||
final AEBaseTile tile = this.getTileEntity( world, pos );
|
||||
if( tile != null )
|
||||
{
|
||||
final Direction mnt = this.findCrankable( world, pos );
|
||||
Direction forward = Direction.UP;
|
||||
if( mnt == Direction.UP || mnt == Direction.DOWN )
|
||||
{
|
||||
forward = Direction.SOUTH;
|
||||
}
|
||||
tile.setOrientation( forward, mnt.getOpposite() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.dropCrank( world, pos );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean isValidOrientation(final IWorld w, final BlockPos pos, final Direction forward, final Direction up) {
|
||||
final TileEntity te = w.getTileEntity(pos);
|
||||
return !(te instanceof TileCrank) || this.isCrankable(w, pos, up.getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidOrientation( final IWorld w, final BlockPos pos, final Direction forward, final Direction up )
|
||||
{
|
||||
final TileEntity te = w.getTileEntity( pos );
|
||||
return !( te instanceof TileCrank ) || this.isCrankable( w, pos, up.getOpposite() );
|
||||
}
|
||||
private Direction findCrankable(final IBlockReader world, final BlockPos pos) {
|
||||
for (final Direction dir : Direction.values()) {
|
||||
if (this.isCrankable(world, pos, dir)) {
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Direction findCrankable( final IBlockReader world, final BlockPos pos )
|
||||
{
|
||||
for( final Direction dir : Direction.values() )
|
||||
{
|
||||
if( this.isCrankable( world, pos, dir ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private boolean isCrankable(final IBlockReader world, final BlockPos pos, final Direction offset) {
|
||||
final BlockPos o = pos.offset(offset);
|
||||
final TileEntity te = world.getTileEntity(o);
|
||||
|
||||
private boolean isCrankable( final IBlockReader world, final BlockPos pos, final Direction offset )
|
||||
{
|
||||
final BlockPos o = pos.offset( offset );
|
||||
final TileEntity te = world.getTileEntity( o );
|
||||
return te instanceof ICrankable && ((ICrankable) te).canCrankAttach(offset.getOpposite());
|
||||
}
|
||||
|
||||
return te instanceof ICrankable && ( (ICrankable) te ).canCrankAttach( offset.getOpposite() );
|
||||
}
|
||||
@Override
|
||||
public BlockRenderType getRenderType(BlockState state) {
|
||||
return BlockRenderType.ENTITYBLOCK_ANIMATED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderType getRenderType(BlockState state )
|
||||
{
|
||||
return BlockRenderType.ENTITYBLOCK_ANIMATED;
|
||||
}
|
||||
@Override
|
||||
public void neighborChanged(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos,
|
||||
boolean isMoving) {
|
||||
final AEBaseTile tile = this.getTileEntity(world, pos);
|
||||
if (tile != null) {
|
||||
if (!this.isCrankable(world, pos, tile.getUp().getOpposite())) {
|
||||
this.dropCrank(world, pos);
|
||||
}
|
||||
} else {
|
||||
this.dropCrank(world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborChanged(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) {
|
||||
final AEBaseTile tile = this.getTileEntity( world, pos );
|
||||
if( tile != null )
|
||||
{
|
||||
if( !this.isCrankable( world, pos, tile.getUp().getOpposite() ) )
|
||||
{
|
||||
this.dropCrank( world, pos );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.dropCrank( world, pos );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean isValidPosition(BlockState state, IWorldReader w, BlockPos pos) {
|
||||
return this.findCrankable(w, pos) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidPosition(BlockState state, IWorldReader w, BlockPos pos)
|
||||
{
|
||||
return this.findCrankable( w, pos ) != null;
|
||||
}
|
||||
private Direction getUp(IBlockReader world, BlockPos pos) {
|
||||
TileCrank crank = getTileEntity(world, pos);
|
||||
return crank != null ? crank.getUp() : null;
|
||||
}
|
||||
|
||||
private Direction getUp(IBlockReader world, BlockPos pos) {
|
||||
TileCrank crank = getTileEntity(world, pos);
|
||||
return crank != null ? crank.getUp() : null;
|
||||
}
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context) {
|
||||
Direction up = getUp(world, pos);
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, IBlockReader world, BlockPos pos, ISelectionContext context) {
|
||||
Direction up = getUp(world, pos);
|
||||
if (up == null) {
|
||||
return VoxelShapes.empty();
|
||||
} else {
|
||||
// FIXME: Cache per direction, and build it 'precise', not just from AABB
|
||||
final double xOff = -0.15 * up.getXOffset();
|
||||
final double yOff = -0.15 * up.getYOffset();
|
||||
final double zOff = -0.15 * up.getZOffset();
|
||||
return VoxelShapes.create(
|
||||
new AxisAlignedBB(xOff + 0.15, yOff + 0.15, zOff + 0.15, xOff + 0.85, yOff + 0.85, zOff + 0.85));
|
||||
}
|
||||
|
||||
if (up == null) {
|
||||
return VoxelShapes.empty();
|
||||
} else {
|
||||
// FIXME: Cache per direction, and build it 'precise', not just from AABB
|
||||
final double xOff = -0.15 * up.getXOffset();
|
||||
final double yOff = -0.15 * up.getYOffset();
|
||||
final double zOff = -0.15 * up.getZOffset();
|
||||
return VoxelShapes.create(new AxisAlignedBB(xOff + 0.15, yOff + 0.15, zOff + 0.15, xOff + 0.85, yOff + 0.85, zOff + 0.85));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,8 @@
|
||||
|
||||
package appeng.block.grindstone;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerGrinder;
|
||||
import appeng.tile.grindstone.TileGrinder;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -33,27 +29,29 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.container.ContainerOpener;
|
||||
import appeng.container.implementations.ContainerGrinder;
|
||||
import appeng.tile.grindstone.TileGrinder;
|
||||
|
||||
public class BlockGrinder extends AEBaseTileBlock<TileGrinder> {
|
||||
|
||||
public class BlockGrinder extends AEBaseTileBlock<TileGrinder>
|
||||
{
|
||||
public BlockGrinder(Properties props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
public BlockGrinder(Properties props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResultType onActivated(final World w, final BlockPos pos, final PlayerEntity p, final Hand hand, final @Nullable ItemStack heldItem, final BlockRayTraceResult hit)
|
||||
{
|
||||
final TileGrinder tg = this.getTileEntity( w, pos );
|
||||
if( tg != null && !p.isCrouching() )
|
||||
{
|
||||
if (p instanceof ServerPlayerEntity) {
|
||||
ContainerOpener.openContainer(ContainerGrinder.TYPE, p, ContainerLocator.forTileEntitySide(tg, hit.getFace()));
|
||||
}
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
@Override
|
||||
public ActionResultType onActivated(final World w, final BlockPos pos, final PlayerEntity p, final Hand hand,
|
||||
final @Nullable ItemStack heldItem, final BlockRayTraceResult hit) {
|
||||
final TileGrinder tg = this.getTileEntity(w, pos);
|
||||
if (tg != null && !p.isCrouching()) {
|
||||
if (p instanceof ServerPlayerEntity) {
|
||||
ContainerOpener.openContainer(ContainerGrinder.TYPE, p,
|
||||
ContainerLocator.forTileEntitySide(tg, hit.getFace()));
|
||||
}
|
||||
return ActionResultType.SUCCESS;
|
||||
}
|
||||
return ActionResultType.PASS;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user