tcr/common/src/main/java/common/block/artificial/BlockStairs.java
2025-06-21 10:31:07 +02:00

880 lines
30 KiB
Java
Executable file

package common.block.artificial;
import java.util.Arrays;
import java.util.List;
import common.block.Block;
import common.block.Rotatable;
import common.block.Material;
import common.entity.Entity;
import common.entity.npc.EntityNPC;
import common.entity.types.EntityLiving;
import common.init.BlockRegistry;
import common.init.Blocks;
import common.item.CheatTab;
import common.model.BlockLayer;
import common.model.Model;
import common.model.ModelProvider;
import common.model.Transforms;
import common.properties.Property;
import common.properties.PropertyEnum;
import common.rng.Random;
import common.util.BlockPos;
import common.util.BoundingBox;
import common.util.Facing;
import common.util.HitPosition;
import common.util.Identifyable;
import common.util.Vec3;
import common.world.Explosion;
import common.world.IBlockAccess;
import common.world.IWorldAccess;
import common.world.AWorldClient;
import common.world.State;
import common.world.World;
import common.world.AWorldServer;
public class BlockStairs extends Block implements Rotatable
{
public static final PropertyEnum<BlockStairs.EnumHalf> HALF = PropertyEnum.<BlockStairs.EnumHalf>create("half", BlockStairs.EnumHalf.class);
public static final PropertyEnum<BlockStairs.EnumShape> SHAPE = PropertyEnum.<BlockStairs.EnumShape>create("shape", BlockStairs.EnumShape.class);
private static final int[][] field_150150_a = new int[][] {{4, 5}, {5, 7}, {6, 7}, {4, 6}, {0, 1}, {1, 3}, {2, 3}, {0, 2}};
private final Block modelBlock;
private final State modelState;
private final String downTex;
private final String upTex;
private boolean hasRaytraced;
private int rayTracePass;
public BlockStairs(State modelState)
{
this(modelState, null, null);
}
public BlockStairs(State modelState, String down, String up)
{
super(modelState.getBlock().getMaterial());
this.setDefaultState(this.getBaseState().withProperty(FACING, Facing.NORTH).withProperty(HALF, BlockStairs.EnumHalf.BOTTOM).withProperty(SHAPE, BlockStairs.EnumShape.STRAIGHT));
this.modelBlock = modelState.getBlock();
this.modelState = modelState;
this.setHardness(this.modelBlock.getRawHardness());
this.setResistance(this.modelBlock.getRawResistance() / 3.0F);
this.setStepSound(this.modelBlock.sound);
this.setLightOpacity(255);
this.setTab(modelState.getBlock().getMaterial() == Material.WOOD ? CheatTab.WOOD : CheatTab.BLOCKS);
this.downTex = down;
this.upTex = up;
}
public void setBlockBoundsBasedOnState(IWorldAccess worldIn, BlockPos pos)
{
if (this.hasRaytraced)
{
this.setBlockBounds(0.5F * (float)(this.rayTracePass % 2), 0.5F * (float)(this.rayTracePass / 4 % 2), 0.5F * (float)(this.rayTracePass / 2 % 2), 0.5F + 0.5F * (float)(this.rayTracePass % 2), 0.5F + 0.5F * (float)(this.rayTracePass / 4 % 2), 0.5F + 0.5F * (float)(this.rayTracePass / 2 % 2));
}
else
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube()
{
return false;
}
public boolean isFullCube()
{
return false;
}
/**
* Set the block bounds as the collision bounds for the stairs at the given position
*/
public void setBaseCollisionBounds(IBlockAccess worldIn, BlockPos pos)
{
if (worldIn.getState(pos).getValue(HALF) == BlockStairs.EnumHalf.TOP)
{
this.setBlockBounds(0.0F, 0.5F, 0.0F, 1.0F, 1.0F, 1.0F);
}
else
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
}
}
/**
* Checks if a block is stairs
*/
public static boolean isBlockStairs(Block blockIn)
{
return blockIn instanceof BlockStairs;
}
/**
* Check whether there is a stair block at the given position and it has the same properties as the given BlockState
*/
public static boolean isSameStair(IBlockAccess worldIn, BlockPos pos, State state)
{
State iblockstate = worldIn.getState(pos);
Block block = iblockstate.getBlock();
return isBlockStairs(block) && iblockstate.getValue(HALF) == state.getValue(HALF) && iblockstate.getValue(FACING) == state.getValue(FACING);
}
public int getOuterShape(IBlockAccess blockAccess, BlockPos pos)
{
State iblockstate = blockAccess.getState(pos);
Facing enumfacing = (Facing)iblockstate.getValue(FACING);
BlockStairs.EnumHalf blockstairs$enumhalf = (BlockStairs.EnumHalf)iblockstate.getValue(HALF);
boolean flag = blockstairs$enumhalf == BlockStairs.EnumHalf.TOP;
if (enumfacing == Facing.EAST)
{
State iblockstate1 = blockAccess.getState(pos.east());
Block block = iblockstate1.getBlock();
if (isBlockStairs(block) && blockstairs$enumhalf == iblockstate1.getValue(HALF))
{
Facing enumfacing1 = (Facing)iblockstate1.getValue(FACING);
if (enumfacing1 == Facing.NORTH && !isSameStair(blockAccess, pos.south(), iblockstate))
{
return flag ? 1 : 2;
}
if (enumfacing1 == Facing.SOUTH && !isSameStair(blockAccess, pos.north(), iblockstate))
{
return flag ? 2 : 1;
}
}
}
else if (enumfacing == Facing.WEST)
{
State iblockstate2 = blockAccess.getState(pos.west());
Block block1 = iblockstate2.getBlock();
if (isBlockStairs(block1) && blockstairs$enumhalf == iblockstate2.getValue(HALF))
{
Facing enumfacing2 = (Facing)iblockstate2.getValue(FACING);
if (enumfacing2 == Facing.NORTH && !isSameStair(blockAccess, pos.south(), iblockstate))
{
return flag ? 2 : 1;
}
if (enumfacing2 == Facing.SOUTH && !isSameStair(blockAccess, pos.north(), iblockstate))
{
return flag ? 1 : 2;
}
}
}
else if (enumfacing == Facing.SOUTH)
{
State iblockstate3 = blockAccess.getState(pos.south());
Block block2 = iblockstate3.getBlock();
if (isBlockStairs(block2) && blockstairs$enumhalf == iblockstate3.getValue(HALF))
{
Facing enumfacing3 = (Facing)iblockstate3.getValue(FACING);
if (enumfacing3 == Facing.WEST && !isSameStair(blockAccess, pos.east(), iblockstate))
{
return flag ? 2 : 1;
}
if (enumfacing3 == Facing.EAST && !isSameStair(blockAccess, pos.west(), iblockstate))
{
return flag ? 1 : 2;
}
}
}
else if (enumfacing == Facing.NORTH)
{
State iblockstate4 = blockAccess.getState(pos.north());
Block block3 = iblockstate4.getBlock();
if (isBlockStairs(block3) && blockstairs$enumhalf == iblockstate4.getValue(HALF))
{
Facing enumfacing4 = (Facing)iblockstate4.getValue(FACING);
if (enumfacing4 == Facing.WEST && !isSameStair(blockAccess, pos.east(), iblockstate))
{
return flag ? 1 : 2;
}
if (enumfacing4 == Facing.EAST && !isSameStair(blockAccess, pos.west(), iblockstate))
{
return flag ? 2 : 1;
}
}
}
return 0;
}
public int getInnerShape(IBlockAccess blockAccess, BlockPos pos)
{
State iblockstate = blockAccess.getState(pos);
Facing enumfacing = (Facing)iblockstate.getValue(FACING);
BlockStairs.EnumHalf blockstairs$enumhalf = (BlockStairs.EnumHalf)iblockstate.getValue(HALF);
boolean flag = blockstairs$enumhalf == BlockStairs.EnumHalf.TOP;
if (enumfacing == Facing.EAST)
{
State iblockstate1 = blockAccess.getState(pos.west());
Block block = iblockstate1.getBlock();
if (isBlockStairs(block) && blockstairs$enumhalf == iblockstate1.getValue(HALF))
{
Facing enumfacing1 = (Facing)iblockstate1.getValue(FACING);
if (enumfacing1 == Facing.NORTH && !isSameStair(blockAccess, pos.north(), iblockstate))
{
return flag ? 1 : 2;
}
if (enumfacing1 == Facing.SOUTH && !isSameStair(blockAccess, pos.south(), iblockstate))
{
return flag ? 2 : 1;
}
}
}
else if (enumfacing == Facing.WEST)
{
State iblockstate2 = blockAccess.getState(pos.east());
Block block1 = iblockstate2.getBlock();
if (isBlockStairs(block1) && blockstairs$enumhalf == iblockstate2.getValue(HALF))
{
Facing enumfacing2 = (Facing)iblockstate2.getValue(FACING);
if (enumfacing2 == Facing.NORTH && !isSameStair(blockAccess, pos.north(), iblockstate))
{
return flag ? 2 : 1;
}
if (enumfacing2 == Facing.SOUTH && !isSameStair(blockAccess, pos.south(), iblockstate))
{
return flag ? 1 : 2;
}
}
}
else if (enumfacing == Facing.SOUTH)
{
State iblockstate3 = blockAccess.getState(pos.north());
Block block2 = iblockstate3.getBlock();
if (isBlockStairs(block2) && blockstairs$enumhalf == iblockstate3.getValue(HALF))
{
Facing enumfacing3 = (Facing)iblockstate3.getValue(FACING);
if (enumfacing3 == Facing.WEST && !isSameStair(blockAccess, pos.west(), iblockstate))
{
return flag ? 2 : 1;
}
if (enumfacing3 == Facing.EAST && !isSameStair(blockAccess, pos.east(), iblockstate))
{
return flag ? 1 : 2;
}
}
}
else if (enumfacing == Facing.NORTH)
{
State iblockstate4 = blockAccess.getState(pos.south());
Block block3 = iblockstate4.getBlock();
if (isBlockStairs(block3) && blockstairs$enumhalf == iblockstate4.getValue(HALF))
{
Facing enumfacing4 = (Facing)iblockstate4.getValue(FACING);
if (enumfacing4 == Facing.WEST && !isSameStair(blockAccess, pos.west(), iblockstate))
{
return flag ? 1 : 2;
}
if (enumfacing4 == Facing.EAST && !isSameStair(blockAccess, pos.east(), iblockstate))
{
return flag ? 2 : 1;
}
}
}
return 0;
}
public boolean setBaseBlockBounds(IBlockAccess blockAccess, BlockPos pos)
{
State iblockstate = blockAccess.getState(pos);
Facing enumfacing = (Facing)iblockstate.getValue(FACING);
BlockStairs.EnumHalf blockstairs$enumhalf = (BlockStairs.EnumHalf)iblockstate.getValue(HALF);
boolean flag = blockstairs$enumhalf == BlockStairs.EnumHalf.TOP;
float f = 0.5F;
float f1 = 1.0F;
if (flag)
{
f = 0.0F;
f1 = 0.5F;
}
float f2 = 0.0F;
float f3 = 1.0F;
float f4 = 0.0F;
float f5 = 0.5F;
boolean flag1 = true;
if (enumfacing == Facing.EAST)
{
f2 = 0.5F;
f5 = 1.0F;
State iblockstate1 = blockAccess.getState(pos.east());
Block block = iblockstate1.getBlock();
if (isBlockStairs(block) && blockstairs$enumhalf == iblockstate1.getValue(HALF))
{
Facing enumfacing1 = (Facing)iblockstate1.getValue(FACING);
if (enumfacing1 == Facing.NORTH && !isSameStair(blockAccess, pos.south(), iblockstate))
{
f5 = 0.5F;
flag1 = false;
}
else if (enumfacing1 == Facing.SOUTH && !isSameStair(blockAccess, pos.north(), iblockstate))
{
f4 = 0.5F;
flag1 = false;
}
}
}
else if (enumfacing == Facing.WEST)
{
f3 = 0.5F;
f5 = 1.0F;
State iblockstate2 = blockAccess.getState(pos.west());
Block block1 = iblockstate2.getBlock();
if (isBlockStairs(block1) && blockstairs$enumhalf == iblockstate2.getValue(HALF))
{
Facing enumfacing2 = (Facing)iblockstate2.getValue(FACING);
if (enumfacing2 == Facing.NORTH && !isSameStair(blockAccess, pos.south(), iblockstate))
{
f5 = 0.5F;
flag1 = false;
}
else if (enumfacing2 == Facing.SOUTH && !isSameStair(blockAccess, pos.north(), iblockstate))
{
f4 = 0.5F;
flag1 = false;
}
}
}
else if (enumfacing == Facing.SOUTH)
{
f4 = 0.5F;
f5 = 1.0F;
State iblockstate3 = blockAccess.getState(pos.south());
Block block2 = iblockstate3.getBlock();
if (isBlockStairs(block2) && blockstairs$enumhalf == iblockstate3.getValue(HALF))
{
Facing enumfacing3 = (Facing)iblockstate3.getValue(FACING);
if (enumfacing3 == Facing.WEST && !isSameStair(blockAccess, pos.east(), iblockstate))
{
f3 = 0.5F;
flag1 = false;
}
else if (enumfacing3 == Facing.EAST && !isSameStair(blockAccess, pos.west(), iblockstate))
{
f2 = 0.5F;
flag1 = false;
}
}
}
else if (enumfacing == Facing.NORTH)
{
State iblockstate4 = blockAccess.getState(pos.north());
Block block3 = iblockstate4.getBlock();
if (isBlockStairs(block3) && blockstairs$enumhalf == iblockstate4.getValue(HALF))
{
Facing enumfacing4 = (Facing)iblockstate4.getValue(FACING);
if (enumfacing4 == Facing.WEST && !isSameStair(blockAccess, pos.east(), iblockstate))
{
f3 = 0.5F;
flag1 = false;
}
else if (enumfacing4 == Facing.EAST && !isSameStair(blockAccess, pos.west(), iblockstate))
{
f2 = 0.5F;
flag1 = false;
}
}
}
this.setBlockBounds(f2, f, f4, f3, f1, f5);
return flag1;
}
public boolean setCollisionBlockBounds(IBlockAccess blockAccess, BlockPos pos)
{
State iblockstate = blockAccess.getState(pos);
Facing enumfacing = (Facing)iblockstate.getValue(FACING);
BlockStairs.EnumHalf blockstairs$enumhalf = (BlockStairs.EnumHalf)iblockstate.getValue(HALF);
boolean flag = blockstairs$enumhalf == BlockStairs.EnumHalf.TOP;
float f = 0.5F;
float f1 = 1.0F;
if (flag)
{
f = 0.0F;
f1 = 0.5F;
}
float f2 = 0.0F;
float f3 = 0.5F;
float f4 = 0.5F;
float f5 = 1.0F;
boolean flag1 = false;
if (enumfacing == Facing.EAST)
{
State iblockstate1 = blockAccess.getState(pos.west());
Block block = iblockstate1.getBlock();
if (isBlockStairs(block) && blockstairs$enumhalf == iblockstate1.getValue(HALF))
{
Facing enumfacing1 = (Facing)iblockstate1.getValue(FACING);
if (enumfacing1 == Facing.NORTH && !isSameStair(blockAccess, pos.north(), iblockstate))
{
f4 = 0.0F;
f5 = 0.5F;
flag1 = true;
}
else if (enumfacing1 == Facing.SOUTH && !isSameStair(blockAccess, pos.south(), iblockstate))
{
f4 = 0.5F;
f5 = 1.0F;
flag1 = true;
}
}
}
else if (enumfacing == Facing.WEST)
{
State iblockstate2 = blockAccess.getState(pos.east());
Block block1 = iblockstate2.getBlock();
if (isBlockStairs(block1) && blockstairs$enumhalf == iblockstate2.getValue(HALF))
{
f2 = 0.5F;
f3 = 1.0F;
Facing enumfacing2 = (Facing)iblockstate2.getValue(FACING);
if (enumfacing2 == Facing.NORTH && !isSameStair(blockAccess, pos.north(), iblockstate))
{
f4 = 0.0F;
f5 = 0.5F;
flag1 = true;
}
else if (enumfacing2 == Facing.SOUTH && !isSameStair(blockAccess, pos.south(), iblockstate))
{
f4 = 0.5F;
f5 = 1.0F;
flag1 = true;
}
}
}
else if (enumfacing == Facing.SOUTH)
{
State iblockstate3 = blockAccess.getState(pos.north());
Block block2 = iblockstate3.getBlock();
if (isBlockStairs(block2) && blockstairs$enumhalf == iblockstate3.getValue(HALF))
{
f4 = 0.0F;
f5 = 0.5F;
Facing enumfacing3 = (Facing)iblockstate3.getValue(FACING);
if (enumfacing3 == Facing.WEST && !isSameStair(blockAccess, pos.west(), iblockstate))
{
flag1 = true;
}
else if (enumfacing3 == Facing.EAST && !isSameStair(blockAccess, pos.east(), iblockstate))
{
f2 = 0.5F;
f3 = 1.0F;
flag1 = true;
}
}
}
else if (enumfacing == Facing.NORTH)
{
State iblockstate4 = blockAccess.getState(pos.south());
Block block3 = iblockstate4.getBlock();
if (isBlockStairs(block3) && blockstairs$enumhalf == iblockstate4.getValue(HALF))
{
Facing enumfacing4 = (Facing)iblockstate4.getValue(FACING);
if (enumfacing4 == Facing.WEST && !isSameStair(blockAccess, pos.west(), iblockstate))
{
flag1 = true;
}
else if (enumfacing4 == Facing.EAST && !isSameStair(blockAccess, pos.east(), iblockstate))
{
f2 = 0.5F;
f3 = 1.0F;
flag1 = true;
}
}
}
if (flag1)
{
this.setBlockBounds(f2, f, f4, f3, f1, f5);
}
return flag1;
}
/**
* Add all collision boxes of this Block to the list that intersect with the given mask.
*/
public void addCollisionBoxesToList(World worldIn, BlockPos pos, State state, BoundingBox mask, List<BoundingBox> list, Entity collidingEntity)
{
this.setBaseCollisionBounds(worldIn, pos);
super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
boolean flag = this.setBaseBlockBounds(worldIn, pos);
super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
if (flag && this.setCollisionBlockBounds(worldIn, pos))
{
super.addCollisionBoxesToList(worldIn, pos, state, mask, list, collidingEntity);
}
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
public void randomDisplayTick(AWorldClient worldIn, BlockPos pos, State state, Random rand)
{
this.modelBlock.randomDisplayTick(worldIn, pos, state, rand);
}
public void onBlockClicked(World worldIn, BlockPos pos, EntityNPC playerIn)
{
this.modelBlock.onBlockClicked(worldIn, pos, playerIn);
}
/**
* Called when a player destroys this Block
*/
public void onBlockDestroyedByPlayer(World worldIn, BlockPos pos, State state)
{
this.modelBlock.onBlockDestroyedByPlayer(worldIn, pos, state);
}
public int getMixedBrightnessForBlock(IWorldAccess worldIn, BlockPos pos)
{
return this.modelBlock.getMixedBrightnessForBlock(worldIn, pos);
}
/**
* Returns how much this block can resist explosions from the passed in entity.
*/
public float getExplosionResistance(Entity exploder)
{
return this.modelBlock.getExplosionResistance(exploder);
}
public BlockLayer getBlockLayer()
{
return this.modelBlock.getBlockLayer();
}
/**
* How many world ticks before ticking
*/
public int tickRate(World worldIn, BlockPos pos)
{
return this.modelBlock.tickRate(worldIn, pos);
}
public BoundingBox getSelectedBoundingBox(World worldIn, BlockPos pos)
{
return this.modelBlock.getSelectedBoundingBox(worldIn, pos);
}
public Vec3 modifyAcceleration(World worldIn, BlockPos pos, Entity entityIn, Vec3 motion)
{
return this.modelBlock.modifyAcceleration(worldIn, pos, entityIn, motion);
}
/**
* Returns if this block is collidable (only used by Fire). Args: x, y, z
*/
public boolean isCollidable()
{
return this.modelBlock.isCollidable();
}
public boolean canCollideCheck(State state, boolean liquid)
{
return this.modelBlock.canCollideCheck(state, liquid);
}
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
return this.modelBlock.canPlaceBlockAt(worldIn, pos);
}
public void onBlockAdded(AWorldServer worldIn, BlockPos pos, State state)
{
this.onNeighborBlockChange(worldIn, pos, this.modelState, Blocks.air);
this.modelBlock.onBlockAdded(worldIn, pos, this.modelState);
}
public void onBlockRemoved(AWorldServer worldIn, BlockPos pos, State state)
{
this.modelBlock.onBlockRemoved(worldIn, pos, this.modelState);
}
/**
* Triggered whenever an entity collides with this block (enters into the block)
*/
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, Entity entityIn)
{
this.modelBlock.onEntityCollidedWithBlock(worldIn, pos, entityIn);
}
public void updateTick(AWorldServer worldIn, BlockPos pos, State state, Random rand)
{
this.modelBlock.updateTick(worldIn, pos, state, rand);
}
public boolean onBlockActivated(World worldIn, BlockPos pos, State state, EntityNPC playerIn, Facing side, float hitX, float hitY, float hitZ)
{
return this.modelBlock.onBlockActivated(worldIn, pos, this.modelState, playerIn, Facing.DOWN, 0.0F, 0.0F, 0.0F);
}
/**
* Called when this Block is destroyed by an Explosion
*/
public void onBlockDestroyedByExplosion(World worldIn, BlockPos pos, Explosion explosionIn, State prevState)
{
this.modelBlock.onBlockDestroyedByExplosion(worldIn, pos, explosionIn, prevState);
}
// /**
// * Get the MapColor for this Block and the given BlockState
// */
// public MapColor getMapColor(IBlockState state)
// {
// return this.modelBlock.getMapColor(this.modelState);
// }
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public State onBlockPlaced(World worldIn, BlockPos pos, Facing facing, float hitX, float hitY, float hitZ, int meta, EntityLiving placer)
{
State iblockstate = super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);
iblockstate = iblockstate.withProperty(FACING, placer.getHorizontalFacing()).withProperty(SHAPE, BlockStairs.EnumShape.STRAIGHT);
return facing != Facing.DOWN && (facing == Facing.UP || (double)hitY <= 0.5D) ? iblockstate.withProperty(HALF, BlockStairs.EnumHalf.BOTTOM) : iblockstate.withProperty(HALF, BlockStairs.EnumHalf.TOP);
}
/**
* Ray traces through the blocks collision from start vector to end vector returning a ray trace hit.
*/
public HitPosition collisionRayTrace(World worldIn, BlockPos pos, Vec3 start, Vec3 end)
{
HitPosition[] amovingobjectposition = new HitPosition[8];
State iblockstate = worldIn.getState(pos);
int i = ((Facing)iblockstate.getValue(FACING)).getHorizontalIndex();
boolean flag = iblockstate.getValue(HALF) == BlockStairs.EnumHalf.TOP;
int[] aint = field_150150_a[i + (flag ? 4 : 0)];
this.hasRaytraced = true;
for (int j = 0; j < 8; ++j)
{
this.rayTracePass = j;
if (Arrays.binarySearch(aint, j) < 0)
{
amovingobjectposition[j] = super.collisionRayTrace(worldIn, pos, start, end);
}
}
for (int k : aint)
{
amovingobjectposition[k] = null;
}
HitPosition movingobjectposition1 = null;
double d1 = 0.0D;
for (HitPosition movingobjectposition : amovingobjectposition)
{
if (movingobjectposition != null)
{
double d0 = movingobjectposition.vec.squareDistanceTo(end);
if (d0 > d1)
{
movingobjectposition1 = movingobjectposition;
d1 = d0;
}
}
}
return movingobjectposition1;
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public State getStateFromMeta(int meta)
{
State iblockstate = this.getState().withProperty(HALF, (meta & 4) > 0 ? BlockStairs.EnumHalf.TOP : BlockStairs.EnumHalf.BOTTOM);
iblockstate = iblockstate.withProperty(FACING, Facing.getFront(5 - (meta & 3)));
return iblockstate;
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(State state)
{
int i = 0;
if (state.getValue(HALF) == BlockStairs.EnumHalf.TOP)
{
i |= 4;
}
i = i | 5 - ((Facing)state.getValue(FACING)).getIndex();
return i;
}
/**
* Get the actual Block state of this Block at the given position. This applies properties not visible in the
* metadata, such as fence connections.
*/
public State getActualState(State state, IWorldAccess worldIn, BlockPos pos)
{
if (this.setBaseBlockBounds(worldIn, pos))
{
switch (this.getInnerShape(worldIn, pos))
{
case 0:
state = state.withProperty(SHAPE, BlockStairs.EnumShape.STRAIGHT);
break;
case 1:
state = state.withProperty(SHAPE, BlockStairs.EnumShape.INNER_RIGHT);
break;
case 2:
state = state.withProperty(SHAPE, BlockStairs.EnumShape.INNER_LEFT);
}
}
else
{
switch (this.getOuterShape(worldIn, pos))
{
case 0:
state = state.withProperty(SHAPE, BlockStairs.EnumShape.STRAIGHT);
break;
case 1:
state = state.withProperty(SHAPE, BlockStairs.EnumShape.OUTER_RIGHT);
break;
case 2:
state = state.withProperty(SHAPE, BlockStairs.EnumShape.OUTER_LEFT);
}
}
return state;
}
protected Property[] getProperties()
{
return new Property[] {FACING, HALF, SHAPE};
}
public Transforms getTransform() {
return Transforms.STAIRS;
}
public Model getModel(ModelProvider provider, String name, State state) {
String primary = this.modelBlock.getModel(provider, BlockRegistry.getNameFromBlock(this.modelBlock).toString(), this.modelState)
.getPrimary();
return provider.getModel(primary)
.stairs(state.getValue(HALF) == EnumHalf.TOP, state.getValue(SHAPE) == EnumShape.INNER_RIGHT ||
state.getValue(SHAPE) == EnumShape.INNER_LEFT, state.getValue(SHAPE) == EnumShape.OUTER_RIGHT ||
state.getValue(SHAPE) == EnumShape.OUTER_LEFT, state.getValue(SHAPE) == EnumShape.INNER_LEFT ||
state.getValue(SHAPE) == EnumShape.OUTER_LEFT, state.getValue(FACING),
this.downTex != null ? this.downTex : primary, this.upTex != null ? this.upTex : primary
// state.getBlock() == Blocks.quartz_stairs ? "quartz_block_bottom" :
// (state.getBlock() == Blocks.sandstone_stairs ? "sandstone_bottom" : (state.getBlock() == Blocks.black_quartz_stairs ? "black_quartz_block_bottom" : primary)),
// state.getBlock() == Blocks.quartz_stairs ? "quartz_top" :
// (state.getBlock() == Blocks.sandstone_stairs ? "sandstone_all" : (state.getBlock() == Blocks.black_quartz_stairs ? "black_quartz_top" : primary))
);
}
public static enum EnumHalf implements Identifyable
{
TOP("top"),
BOTTOM("bottom");
private final String name;
private EnumHalf(String name)
{
this.name = name;
}
public String toString()
{
return this.name;
}
public String getName()
{
return this.name;
}
}
public static enum EnumShape implements Identifyable
{
STRAIGHT("straight"),
INNER_LEFT("inner_left"),
INNER_RIGHT("inner_right"),
OUTER_LEFT("outer_left"),
OUTER_RIGHT("outer_right");
private final String name;
private EnumShape(String name)
{
this.name = name;
}
public String toString()
{
return this.name;
}
public String getName()
{
return this.name;
}
}
}