1.20 Minecraft Forge Bed 模型未衬有边界框

问题描述 投票:0回答:1

另一个问题。我的床模型未与边界框正确对齐。当朝南或朝东时,IT 工作正常,但朝北或朝西时,该街区将向东或向南移动一个街区。所以模型和块边界不对齐。

边界块和模型的图像未正确对齐。

我的代码是:

package io.github.magikpups.testing.block;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.BedBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;

import java.awt.*;

public class advhopebed extends HorizontalDirectionalBlock {

    public static final VoxelShape SHAPE_N = Shapes.box(0, 0, 0,
            1, 0.55, 2);
    public static final VoxelShape SHAPE_S = Shapes.box(0, 0, 0,
            1, 0.55, 2);
    public static final VoxelShape SHAPE_E = Shapes.box(0, 0, 0,
            2, 0.55, 1);
    public static final VoxelShape SHAPE_W = Shapes.box(0, 0, 0,
            2, 0.55, 1);

    public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;

    public advhopebed(Properties properties) {
        super(properties);
        this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
    }

    @Override

    public VoxelShape getShape(BlockState state, BlockGetter getter, BlockPos pos, CollisionContext context) {
        Direction direction = state.getValue(FACING);
        switch(state.getValue(FACING)) {
            case EAST:
                return SHAPE_E;
            case SOUTH:
                return SHAPE_S;
            case WEST:
                return SHAPE_W;
            default:
                return SHAPE_N;
        }
    }

    public BlockState getStateForPlacement(BlockPlaceContext context) {
        return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
    }

    @Override
    protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
        super.createBlockStateDefinition(builder);
        builder.add(FACING);
    }
}

我尝试对体素形状进行更多的修改,看看这是否是问题所在,并尝试对块形状进行修改。据我所知,这可能与方向或面向有关,但我还没有弄清楚它到底是如何工作的。

我查看了其他使用床的代码,但我找不到为什么我的边界框与他们的如此不同。

minecraft minecraft-forge
1个回答
0
投票

在不和谐的人的帮助下解决了这个问题。

必须改变我的体素形状,我知道但不明白如何改变。这是更新的体素形状代码。

public static final VoxelShape SHAPE_N = Shapes.box(0, 0, 0,
            1, 0.55, 2);
    public static final VoxelShape SHAPE_S = Shapes.box(0, 0, -1,
            1, 0.55, 1);
    public static final VoxelShape SHAPE_E = Shapes.box(-1, 0, 0,
            1, 0.55, 1);
    public static final VoxelShape SHAPE_W = Shapes.box(0, 0, 0,
            2, 0.55, 1);

现在所有模型都适合模型盒

© www.soinside.com 2019 - 2024. All rights reserved.