как создать физику блока

7,099
324
1,510
Скинь класс CustomBlockBenchBlock
 
package com.LockOriginalMods.bc.blocks;

import java.util.stream.Stream;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.IBooleanFunction;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;

public class CustomBlockBenchBlock extends BaseHorizontalBlock
{
private static final VoxelShape SHAPE = Stream.of(
Block.makeCuboidShape(0, 6, 0, 16, 8, 16),
Block.makeCuboidShape(4, 0, 4, 12, 1, 12),
Block.makeCuboidShape(6, 1, 6, 10, 2, 10),
Block.makeCuboidShape(10, 1, 10, 11, 5, 11),
Block.makeCuboidShape(10, 1, 5, 11, 5, 6),
Block.makeCuboidShape(5, 1, 5, 6, 5, 6),
Block.makeCuboidShape(5, 1, 10, 6, 5, 11),
Block.makeCuboidShape(7, 2, 7, 9, 4, 9),
Block.makeCuboidShape(6, 4, 6, 10, 5, 10),
Block.makeCuboidShape(1, 5, 1, 15, 6, 15)
).reduce((v1, v2) -> {return VoxelShapes.combineAndSimplify(v1, v2, IBooleanFunction.OR);}).get();

public CustomBlockBenchBlock(Properties properties) {
super(properties);
runCalculation(SHAPE);
}

@Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPES.get(state.get(HORIZONTAL_FACING));
}

}
Вам ещё надо BaseHorizontalBlock
public class BaseHorizontalBlock extends Block
{
protected static final Map<Direction, VoxelShape> SHAPES = new HashMap<Direction, VoxelShape>();

public static final DirectionProperty HORIZONTAL_FACING = BlockStateProperties.HORIZONTAL_FACING;

public BaseHorizontalBlock(Properties properties) {
super(properties);
this.setDefaultState(this.stateContainer.getBaseState().with(HORIZONTAL_FACING, Direction.NORTH));
}

@SuppressWarnings("deprecation")
@Override
public BlockState mirror(BlockState state, Mirror mirrorIn) {

return state.rotate(mirrorIn.toRotation(state.get(HORIZONTAL_FACING)));
}
@Override
public BlockState rotate(BlockState state, IWorld world, BlockPos pos, Rotation direction) {

return state.with(HORIZONTAL_FACING, direction.rotate(state.get(HORIZONTAL_FACING)));
}

@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {

return this.getDefaultState().with(HORIZONTAL_FACING, context.getPlacementHorizontalFacing().getOpposite());
}

@Override
protected void fillStateContainer(Builder<Block, BlockState> builder) {

super.fillStateContainer(builder);
builder.add(HORIZONTAL_FACING);
}

protected static void calculateShapes(Direction to, VoxelShape shape)
{
VoxelShape[] buffer = new VoxelShape[] { shape, VoxelShapes.empty() };

int times = (to.getHorizontalIndex() - Direction.NORTH.getHorizontalIndex() + 4) % 4;
for (int i = 0; i < times; i++)
{
buffer[0].forEachBox((minX, minY, minZ, maxX, maxY, maxZ) -> buffer[1] = VoxelShapes.or(buffer[1],
VoxelShapes.create(1 - maxZ, minY, maxX, 1 - minZ, maxY, maxX)));
buffer[0] = buffer[1];
buffer[1] = VoxelShapes.empty();
}
SHAPES.put(to, buffer[0]);
}

protected void runCalculation(VoxelShape shape)
{
for(Direction direction : Direction.values())
{
calculateShapes(direction, shape);
}
}
}
 
Сверху