- 12
- 0
По отдельности PropertyEnum и PropertyDirection в коде блока работают отлично, но когда их объединяешь... в ванили примеров подобной ситуации нет (у одних PropertyBool + PropertyDirection (наблюдатель раздатчик, e.t.c), у других PropertyDirection + PropertyInteger (кокос)), лично я считаю, что напортачил с методом getMetaFromState
Java:
public class BaseCrys extends BlockDirectional {
public static final PropertyEnum<CrysType> VARIANT = PropertyEnum.<CrysType>create("variant", CrysType.class);
public BaseCrys(String name) {
super(Material.GLASS);
this.setUnlocalizedName(name);
this.blockHardness = 34;
this.blockResistance = 23;
this.setRegistryName(name);
this.lightOpacity = 0;
this.setHarvestLevel("pickaxe", 2);
this.setCreativeTab(Main.BLOCKTAB);
this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, CrysType.PHOENIX));
}
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withProperty(FACING, mirrorIn.mirror((EnumFacing)state.getValue(FACING)));
}
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
return true;
}
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
IBlockState iblockstate = worldIn.getBlockState(pos.offset(facing.getOpposite()));
if (iblockstate.getBlock() == BlocksRegister.BASECRYS)
{
EnumFacing enumfacing = (EnumFacing)iblockstate.getValue(FACING);
if (enumfacing == facing)
{
return this.getDefaultState().withProperty(FACING, facing.getOpposite());
}
}
return this.getDefaultState().withProperty(FACING, facing);
}
@Override
public boolean canSilkHarvest()
{
return true;
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING, VARIANT});
}
public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items) {
for (CrysType ecrys$enumtype : CrysType.values())
{
items.add(new ItemStack(this, 1, ecrys$enumtype.getMetadata()));
}
}
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(VARIANT, CrysType.byMetadata(meta)).withProperty(FACING, EnumFacing.getFront(meta));
}
public int getMetaFromState(IBlockState state)
{
int i = 0;
i = i | ((EnumFacing)state.getValue(FACING)).getIndex() + i | ((CrysType)state.getValue(VARIANT)).getMetadata();
return i;
}
public int damageDropped(IBlockState state)
{
return ((CrysType)state.getValue(VARIANT)).getMetadata();
}
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
@Override
public boolean isFullCube(IBlockState state)
{
return false;
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.TRANSLUCENT;
}
public Item getItemDropped (IBlockState state, Random rand, int fortune) {
return ItemsRegister.CRYSPIECE;
}
public int guantityDropped (Random random) {
return random.nextInt(12) + 4;
}
public int quantityDroppedWithBonus(int fortune, Random random)
{
return this.guantityDropped(random) + (fortune * 2);
}
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune) {
super.dropBlockAsItemWithChance(worldIn, pos, state, chance, fortune);
}
public int getExpDrop(IBlockState state, IBlockAccess world, BlockPos pos, int fortune)
{
return 7 * fortune + 5;
}
}