Отменить блокстату.

Сообщения
4,660
Лучшие ответы
44
Реакции
600
Версия Minecraft
1.12.2
Друзья, делаю стол на блокстейтах, типо как коннектящийся. Собственно при срабатывании того что слева стоит блок, не убирается дефолтное состояние.
Каким образом это можно исправить?
Java:
public class SovietTable extends BasicBlock{

    public static final PropertyBool DEFAULT = PropertyBool.create("default");
    public static final PropertyBool NORTH = PropertyBool.create("north");
    public static final PropertyBool EAST = PropertyBool.create("east");
    public static final PropertyBool SOUTH = PropertyBool.create("south");
    public static final PropertyBool WEST = PropertyBool.create("west");


    protected static final AxisAlignedBB[] AABB_BY_INDEX = new AxisAlignedBB[] {
            new AxisAlignedBB(0D, 0D, 0D, 1D, 1D, 1D),
            new AxisAlignedBB(0D, 0D, 0D, 1D, 1D, 1D),
            new AxisAlignedBB(0D, 0D, 0D, 1D, 1D, 1D),
            new AxisAlignedBB(0D, 0D, 0D, 1D, 1D, 1D),
            new AxisAlignedBB(0D, 0D, 0D, 1D, 1D, 1D),
            new AxisAlignedBB(0D, 0D, 0D, 1D, 1D, 1D),
            new AxisAlignedBB(0D, 0D, 0D, 1D, 1D, 1D),
            new AxisAlignedBB(0D, 0D, 0D, 1D, 1D, 1D),
            new AxisAlignedBB(0D, 0D, 0D, 1D, 1D, 1D),
            new AxisAlignedBB(0D, 0D, 0D, 1D, 1D, 1D),
            new AxisAlignedBB(0D, 0D, 0D, 1D, 1D, 1D),
            new AxisAlignedBB(0D, 0D, 0D, 1D, 1D, 1D),
            new AxisAlignedBB(0D, 0D, 0D, 1D, 1D, 1D),
            new AxisAlignedBB(0D, 0D, 0D, 1D, 1D, 1D),
            new AxisAlignedBB(0D, 0D, 0D, 1D, 1D, 1D),
            new AxisAlignedBB(0D, 0D, 0D, 1D, 1D, 1D)
    };
    protected static final AxisAlignedBB[] CLIP_AABB_BY_INDEX = new AxisAlignedBB[] {
            AABB_BY_INDEX[0].setMaxY(1.5D), AABB_BY_INDEX[1].setMaxY(1.5D),
            AABB_BY_INDEX[2].setMaxY(1.5D), AABB_BY_INDEX[3].setMaxY(1.5D),
            AABB_BY_INDEX[4].setMaxY(1.5D), AABB_BY_INDEX[5].setMaxY(1.5D),
            AABB_BY_INDEX[6].setMaxY(1.5D), AABB_BY_INDEX[7].setMaxY(1.5D),
            AABB_BY_INDEX[8].setMaxY(1.5D), AABB_BY_INDEX[9].setMaxY(1.5D),
            AABB_BY_INDEX[10].setMaxY(1.5D), AABB_BY_INDEX[11].setMaxY(1.5D),
            AABB_BY_INDEX[12].setMaxY(1.5D), AABB_BY_INDEX[13].setMaxY(1.5D),
            AABB_BY_INDEX[14].setMaxY(1.5D), AABB_BY_INDEX[15].setMaxY(1.5D)
    };


    public SovietTable(Material materialIn, String name, float hardness, float resistanse, SoundType soundtype) {
        super(materialIn, name, hardness, resistanse, soundtype);
        this.setDefaultState(this.blockState.getBaseState().withProperty(DEFAULT, Boolean.valueOf(false)));
    }
    @Override
    public boolean isFullCube(IBlockState state)
    {
        return false;
    }
    @Override
    public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
    {
        return false;
    }

    public boolean isOpaqueCube(IBlockState state)
    {
        return false;
    }
    @Override
    @SideOnly(Side.CLIENT)
    public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
    {
        return side == EnumFacing.DOWN ? super.shouldSideBeRendered(blockState, blockAccess, pos, side) : true;
    }
    @Override
    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
    {
        state = this.getActualState(state, source, pos);
        return AABB_BY_INDEX[getAABBIndex(state)];
    }

    private static int getAABBIndex(IBlockState state)
    {
        int i = 0;

        if (((Boolean)state.getValue(NORTH)).booleanValue())
        {
            i |= 1 << EnumFacing.NORTH.getHorizontalIndex();
        }

        if (((Boolean)state.getValue(EAST)).booleanValue())
        {
            i |= 1 << EnumFacing.EAST.getHorizontalIndex();
        }

        if (((Boolean)state.getValue(SOUTH)).booleanValue())
        {
            i |= 1 << EnumFacing.SOUTH.getHorizontalIndex();
        }

        if (((Boolean)state.getValue(WEST)).booleanValue())
        {
            i |= 1 << EnumFacing.WEST.getHorizontalIndex();
        }

        return i;
    }
    @Override
    public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean p_185477_7_)
    {
        if (!p_185477_7_)
        {
            state = this.getActualState(state, worldIn, pos);
        }

        addCollisionBoxToList(pos, entityBox, collidingBoxes, CLIP_AABB_BY_INDEX[getAABBIndex(state)]);
    }

    private boolean canConnectTo(IBlockAccess worldIn, BlockPos pos, EnumFacing p_176253_3_)
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();
        BlockFaceShape blockfaceshape = iblockstate.getBlockFaceShape(worldIn, pos, p_176253_3_);
        boolean flag = blockfaceshape == BlockFaceShape.MIDDLE_POLE_THICK || blockfaceshape == BlockFaceShape.MIDDLE_POLE && block instanceof BlockFenceGate;
        return  blockfaceshape == BlockFaceShape.SOLID || flag;
    }
    @Override
    public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState();
    }
    @Override
    public int getMetaFromState(IBlockState state)
    {
        return 0;
    }
    @Override
    public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
    {



        boolean connectNorth =  canWallConnectTo(worldIn, pos, EnumFacing.NORTH);
        boolean connectEast = canWallConnectTo(worldIn, pos, EnumFacing.EAST);
        boolean connectSouth = canWallConnectTo(worldIn, pos, EnumFacing.SOUTH);
        boolean connectWest = canWallConnectTo(worldIn, pos, EnumFacing.WEST);

        boolean connectAngleNW =  connectNorth && connectWest;
        boolean connectAngleNE =  connectNorth && connectEast;
        boolean connectAngleSW =  connectSouth && connectWest;
        boolean connectAngleSE =  connectSouth && connectEast;

        return state
                .withProperty(DEFAULT, Boolean.valueOf(!connectAngleNW))
                .withProperty(NORTH, Boolean.valueOf(connectNorth))
                .withProperty(EAST, Boolean.valueOf(connectEast))
                .withProperty(SOUTH, Boolean.valueOf(connectSouth))
                .withProperty(WEST, Boolean.valueOf(connectWest))
                ;
    }
    @Override
    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {DEFAULT, NORTH, EAST, WEST, SOUTH});
    }
    @Override
    public BlockFaceShape getBlockFaceShape(IBlockAccess p_193383_1_, IBlockState p_193383_2_, BlockPos p_193383_3_, EnumFacing p_193383_4_)
    {
        return p_193383_4_ != EnumFacing.UP && p_193383_4_ != EnumFacing.DOWN ? BlockFaceShape.MIDDLE_POLE_THICK : BlockFaceShape.CENTER_BIG;
    }



    @Override
    public boolean canBeConnectedTo(IBlockAccess world, BlockPos pos, EnumFacing facing)
    {
        Block connector = world.getBlockState(pos.offset(facing)).getBlock();
        return connector instanceof SovietTable || connector instanceof BlockFenceGate;
    }

    private boolean canWallConnectTo(IBlockAccess world, BlockPos pos, EnumFacing facing)
    {
        BlockPos other = pos.offset(facing);
        Block block = world.getBlockState(other).getBlock();
        return block.canBeConnectedTo(world, other, facing.getOpposite()) || canConnectTo(world, other, facing.getOpposite());
    }



}
JSON:
{
    "multipart": [
        {   "when": { "default": "true" },
            "apply": { "model": "soviet:table_full" }
        },
        {   "when": { "north": "true" },
            "apply": { "model": "soviet:table_north", "uvlock": true }
        },
        {   "when": { "east": "true" },
            "apply": { "model": "soviet:table_east", "uvlock": true }
        },
        {   "when": { "south": "true" },
            "apply": { "model": "soviet:table_south","uvlock": true }
        }
    ]
}
2018-02-04_22.46.01.png
 
Последнее редактирование:
Сверху