Fix crash when placing an engine vertically

This commit is contained in:
mezz committed 2016-05-21 20:31:20 -07:00
1 parent 2dc7ae137e
commit c4c3f493be
2 files changed
+14 -12

No files matched your search

@@ -64,7 +64,7 @@ import forestry.core.utils.PlayerUtil;
public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> extends BlockForestry implements IItemModelRegister, ISpriteRegister, IStateMapperRegister {
/** use this instead of {@link BlockHorizontal#FACING} so the blocks rotate in a circle instead of NSWE order. */
public static final PropertyEnum<EnumFacing> FACING = PropertyEnum.create("facing", EnumFacing.class, EnumFacing.NORTH, EnumFacing.EAST, EnumFacing.SOUTH, EnumFacing.WEST);
public static final PropertyEnum<EnumFacing> FACING = PropertyEnum.create("facing", EnumFacing.class, EnumFacing.NORTH, EnumFacing.EAST, EnumFacing.SOUTH, EnumFacing.WEST, EnumFacing.DOWN, EnumFacing.UP);
private final boolean hasTESR;
private final boolean hasCustom;
@@ -175,20 +175,22 @@ public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> ext
public void rotateAfterPlacement(EntityPlayer player, World world, BlockPos pos, EnumFacing side) {
IBlockState state = world.getBlockState(pos);
EnumFacing facing = getPlacementRotation(player, world, pos, side);
world.setBlockState(pos, state.withProperty(FACING, facing));
}
protected EnumFacing getPlacementRotation(EntityPlayer player, World world, BlockPos pos, EnumFacing side) {
int l = MathHelper.floor_double(player.rotationYaw * 4F / 360F + 0.5D) & 3;
if (l == 0) {
state = state.withProperty(FACING, EnumFacing.NORTH);
}
if (l == 1) {
state = state.withProperty(FACING, EnumFacing.EAST);
return EnumFacing.EAST;
}
if (l == 2) {
state = state.withProperty(FACING, EnumFacing.SOUTH);
return EnumFacing.SOUTH;
}
if (l == 3) {
state = state.withProperty(FACING, EnumFacing.WEST);
return EnumFacing.WEST;
}
world.setBlockState(pos, state, 2);
return EnumFacing.NORTH;
}
@Override
@@ -237,12 +239,12 @@ public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> ext
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta));
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(FACING).getHorizontalIndex();
return state.getValue(FACING).getIndex();
}
@Override
@@ -125,7 +125,7 @@ public class BlockEngine extends BlockBase<BlockTypeEngine> {
EnumFacing orientation = EnumFacing.values()[i % 6];
if (isOrientedAtEnergyReciever(world, pos, orientation)) {
blockState = blockState.withProperty(FACING, orientation);
world.setBlockState(pos, blockState, 2);
world.setBlockState(pos, blockState);
return true;
}
}
@@ -138,7 +138,7 @@ public class BlockEngine extends BlockBase<BlockTypeEngine> {
if (isOrientedAtEnergyReciever(world, pos, orientation)) {
IBlockState blockState = world.getBlockState(pos);
blockState = blockState.withProperty(FACING, orientation);
world.setBlockState(pos, blockState, 2);
world.setBlockState(pos, blockState);
} else {
super.rotateAfterPlacement(player, world, pos, side);
rotate(world, pos);