pick 97420a31d The big reformat of 2020

This commit is contained in:
yueh
2020-06-16 21:41:28 +02:00
parent 5304b3febe
commit 5225ea426b
2252 changed files with 95466 additions and 118582 deletions
@@ -18,14 +18,12 @@
package appeng.block.misc;
import java.util.EnumMap;
import java.util.Map;
import java.util.Random;
import javax.annotation.Nullable;
import appeng.api.util.IOrientable;
import appeng.api.util.IOrientableBlock;
import appeng.block.AEBaseBlock;
import appeng.client.render.effects.LightningFX;
import appeng.core.AEConfig;
import appeng.core.AppEng;
import appeng.helpers.MetaRotation;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
@@ -49,170 +47,162 @@ import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import javax.annotation.Nullable;
import java.util.EnumMap;
import java.util.Map;
import java.util.Random;
import appeng.api.util.IOrientable;
import appeng.api.util.IOrientableBlock;
import appeng.block.AEBaseBlock;
import appeng.client.render.effects.LightningFX;
import appeng.core.AEConfig;
import appeng.core.AppEng;
import appeng.helpers.MetaRotation;
public class BlockQuartzFixture extends AEBaseBlock implements IOrientableBlock {
public class BlockQuartzFixture extends AEBaseBlock implements IOrientableBlock
{
// Cache VoxelShapes for each facing
private static final Map<Direction, VoxelShape> SHAPES;
// Cache VoxelShapes for each facing
private static final Map<Direction, VoxelShape> SHAPES;
static {
SHAPES = new EnumMap<>(Direction.class);
static {
SHAPES = new EnumMap<>(Direction.class);
for (Direction facing : Direction.values()) {
final double xOff = -0.3 * facing.getXOffset();
final double yOff = -0.3 * facing.getYOffset();
final double zOff = -0.3 * facing.getZOffset();
VoxelShape shape = VoxelShapes
.create(new AxisAlignedBB(xOff + 0.3, yOff + 0.3, zOff + 0.3, xOff + 0.7, yOff + 0.7, zOff + 0.7));
SHAPES.put(facing, shape);
}
}
for (Direction facing : Direction.values()) {
final double xOff = -0.3 * facing.getXOffset();
final double yOff = -0.3 * facing.getYOffset();
final double zOff = -0.3 * facing.getZOffset();
VoxelShape shape = VoxelShapes.create(new AxisAlignedBB(xOff + 0.3, yOff + 0.3, zOff + 0.3, xOff + 0.7, yOff + 0.7, zOff + 0.7));
SHAPES.put(facing, shape);
}
}
// Cannot use the vanilla FACING property here because it excludes facing DOWN
public static final DirectionProperty FACING = BlockStateProperties.FACING;
// Cannot use the vanilla FACING property here because it excludes facing DOWN
public static final DirectionProperty FACING = BlockStateProperties.FACING;
// Used to alternate between two variants of the fixture on adjacent blocks
public static final BooleanProperty ODD = BooleanProperty.create("odd");
// Used to alternate between two variants of the fixture on adjacent blocks
public static final BooleanProperty ODD = BooleanProperty.create( "odd" );
public BlockQuartzFixture() {
super(defaultProps(Material.MISCELLANEOUS).doesNotBlockMovement().hardnessAndResistance(0).lightValue(14)
.sound(SoundType.GLASS));
public BlockQuartzFixture()
{
super(defaultProps(Material.MISCELLANEOUS).doesNotBlockMovement().hardnessAndResistance(0).lightValue(14).sound(SoundType.GLASS));
this.setDefaultState(getDefaultState().with(FACING, Direction.UP).with(ODD, false));
this.setFullSize(false);
this.setOpaque(false);
}
this.setDefaultState( getDefaultState().with( FACING, Direction.UP ).with( ODD, false ) );
this.setFullSize( false );
this.setOpaque( false );
}
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
builder.add(FACING, ODD);
}
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
builder.add(FACING, ODD);
}
// For reference, see WallTorchBlock
@Nullable
public BlockState getStateForPlacement(BlockItemUseContext context) {
BlockState blockstate = super.getStateForPlacement(context);
BlockPos pos = context.getPos();
// For reference, see WallTorchBlock
@Nullable
public BlockState getStateForPlacement(BlockItemUseContext context) {
BlockState blockstate = super.getStateForPlacement(context);
BlockPos pos = context.getPos();
// Set the even/odd property
boolean oddPlacement = ((pos.getX() + pos.getY() + pos.getZ()) % 2) != 0;
blockstate = blockstate.with(ODD, oddPlacement);
// Set the even/odd property
boolean oddPlacement = ( ( pos.getX() + pos.getY() + pos.getZ() ) % 2 ) != 0;
blockstate = blockstate.with( ODD, oddPlacement );
IWorldReader iworldreader = context.getWorld();
Direction[] adirection = context.getNearestLookingDirections();
IWorldReader iworldreader = context.getWorld();
Direction[] adirection = context.getNearestLookingDirections();
for (Direction direction : adirection) {
if (canPlaceAt(iworldreader, pos, direction)) {
return blockstate.with(FACING, direction.getOpposite());
}
}
for(Direction direction : adirection) {
if (canPlaceAt(iworldreader, pos, direction)) {
return blockstate.with(FACING, direction.getOpposite());
}
}
return null;
}
return null;
}
// Break the fixture if the block it is attached to is changed so that it could
// no longer be placed
@Override
public BlockState updatePostPlacement(BlockState state, Direction facing, BlockState facingState, IWorld worldIn,
BlockPos pos, BlockPos facingPos) {
Direction fixtureFacing = state.get(FACING);
if (facing.getOpposite() == fixtureFacing && !canPlaceAt(worldIn, pos, facing)) {
return Blocks.AIR.getDefaultState();
}
return state;
}
// Break the fixture if the block it is attached to is changed so that it could no longer be placed
@Override
public BlockState updatePostPlacement(BlockState state, Direction facing, BlockState facingState, IWorld worldIn, BlockPos pos, BlockPos facingPos) {
Direction fixtureFacing = state.get(FACING);
if (facing.getOpposite() == fixtureFacing && !canPlaceAt(worldIn, pos, facing)) {
return Blocks.AIR.getDefaultState();
}
return state;
}
@Override
public boolean isValidOrientation(final IWorld w, final BlockPos pos, final Direction forward, final Direction up) {
// FIXME: I think this entire method -> not required, but not sure... are quartz
// fixtures rotateable???
return this.canPlaceAt(w, pos, up.getOpposite());
}
@Override
public boolean isValidOrientation( final IWorld w, final BlockPos pos, final Direction forward, final Direction up )
{
// FIXME: I think this entire method -> not required, but not sure... are quartz fixtures rotateable???
return this.canPlaceAt( w, pos, up.getOpposite() );
}
private boolean canPlaceAt(final IWorldReader w, final BlockPos pos, final Direction dir) {
final BlockPos test = pos.offset(dir);
BlockState blockstate = w.getBlockState(test);
return blockstate.isSolidSide(w, test, dir.getOpposite());
}
private boolean canPlaceAt( final IWorldReader w, final BlockPos pos, final Direction dir )
{
final BlockPos test = pos.offset( dir );
BlockState blockstate = w.getBlockState(test);
return blockstate.isSolidSide(w, test, dir.getOpposite());
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
Direction facing = state.get(FACING);
return SHAPES.get(facing);
}
@Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
Direction facing = state.get(FACING);
return SHAPES.get(facing);
}
@Override
@OnlyIn(Dist.CLIENT)
public void animateTick(final BlockState state, final World w, final BlockPos pos, final Random r) {
if (!AEConfig.instance().isEnableEffects()) {
return;
}
@Override
@OnlyIn( Dist.CLIENT )
public void animateTick( final BlockState state, final World w, final BlockPos pos, final Random r )
{
if( !AEConfig.instance().isEnableEffects() )
{
return;
}
if (r.nextFloat() < 0.98) {
return;
}
if( r.nextFloat() < 0.98 )
{
return;
}
final Direction up = this.getOrientable(w, pos).getUp();
final double xOff = -0.3 * up.getXOffset();
final double yOff = -0.3 * up.getYOffset();
final double zOff = -0.3 * up.getZOffset();
for (int bolts = 0; bolts < 3; bolts++) {
if (AppEng.proxy.shouldAddParticles(r)) {
w.addParticle(LightningFX.TYPE, xOff + 0.5 + pos.getX(), yOff + 0.5 + pos.getY(),
zOff + 0.5 + pos.getZ(), 0, 0, 0);
}
}
}
final Direction up = this.getOrientable( w, pos ).getUp();
final double xOff = -0.3 * up.getXOffset();
final double yOff = -0.3 * up.getYOffset();
final double zOff = -0.3 * up.getZOffset();
for( int bolts = 0; bolts < 3; bolts++ )
{
if( AppEng.proxy.shouldAddParticles( r ) )
{
w.addParticle(LightningFX.TYPE, xOff + 0.5 + pos.getX(), yOff + 0.5 + pos.getY(), zOff + 0.5 + pos.getZ(), 0, 0, 0);
}
}
}
// FIXME: Replaced by the postPlaceupdate stuff above, but check item drops!
@Override
public void neighborChanged(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos,
boolean isMoving) {
final Direction up = this.getOrientable(world, pos).getUp();
if (!this.canPlaceAt(world, pos, up.getOpposite())) {
this.dropTorch(world, pos);
}
}
// FIXME: Replaced by the postPlaceupdate stuff above, but check item drops!
@Override
public void neighborChanged( BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving )
{
final Direction up = this.getOrientable( world, pos ).getUp();
if( !this.canPlaceAt( world, pos, up.getOpposite() ) )
{
this.dropTorch( world, pos );
}
}
private void dropTorch(final World w, final BlockPos pos) {
final BlockState prev = w.getBlockState(pos);
w.destroyBlock(pos, true);
w.notifyBlockUpdate(pos, prev, w.getBlockState(pos), 3);
}
private void dropTorch( final World w, final BlockPos pos )
{
final BlockState prev = w.getBlockState( pos );
w.destroyBlock( pos, true );
w.notifyBlockUpdate( pos, prev, w.getBlockState( pos ), 3 );
}
@Override
public boolean isValidPosition(BlockState state, IWorldReader w, BlockPos pos) {
for (final Direction dir : Direction.values()) {
if (this.canPlaceAt(w, pos, dir)) {
return true;
}
}
return false;
}
@Override
public boolean isValidPosition(BlockState state, IWorldReader w, BlockPos pos)
{
for( final Direction dir : Direction.values() )
{
if( this.canPlaceAt( w, pos, dir ) )
{
return true;
}
}
return false;
}
@Override
public IOrientable getOrientable(final IBlockReader w, final BlockPos pos) {
return new MetaRotation(w, pos, FACING);
}
@Override
public IOrientable getOrientable( final IBlockReader w, final BlockPos pos )
{
return new MetaRotation( w, pos, FACING );
}
@Override
public boolean isOpaque()
{
return false;
}
@Override
public boolean isOpaque() {
return false;
}
}