我正在编码我的第一部“我的世界”。我做了一根钢梁,它总是朝北。我想让它面对球员面对的任何方向。我尝试过多种方法,例如:
@Override
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}和
@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY,
float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
return super.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, placer, hand).withProperty(FACING, placer.getHorizontalFacing());
}这两样都不管用。我用的是小龙虾的模特儿,它的两边是定向的。我不知道这是否重要,但我决定把它包括进去。
发布于 2019-10-17 08:34:07
重写IForgeBlock#getStateForPlacement并返回由Block#getDefaultState获得的块的默认状态。
这方面的一个例子是:
@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing());
}您还需要重写Block#createBlockState以返回包含方向属性的BlockStateContainer:
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[] {FACING});
}https://stackoverflow.com/questions/58244154
复制相似问题