Continue mapping migration
This commit is contained in:
parent
99ade39404
commit
f03fd03bd0
499 changed files with 12567 additions and 12723 deletions
|
@ -7,87 +7,95 @@ import com.google.common.collect.Maps;
|
|||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
||||
import net.minecraft.world.level.block.AbstractBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.HorizontalFacingBlock;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.level.block.ShapeContext;
|
||||
import net.minecraft.world.item.ItemPlacementContext;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.state.property.DirectionProperty;
|
||||
import net.minecraft.util.BlockMirror;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.WorldView;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
||||
import net.minecraft.world.level.block.Mirror;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
|
||||
public class EndWallPlantBlock extends EndPlantBlock {
|
||||
private static final EnumMap<Direction, VoxelShape> SHAPES = Maps.newEnumMap(ImmutableMap.of(Direction.NORTH,
|
||||
Block.createCuboidShape(1, 1, 8, 15, 15, 16), Direction.SOUTH, Block.createCuboidShape(1, 1, 0, 15, 15, 8),
|
||||
Direction.WEST, Block.createCuboidShape(8, 1, 1, 16, 15, 15), Direction.EAST,
|
||||
Block.createCuboidShape(0, 1, 1, 8, 15, 15)));
|
||||
public static final DirectionProperty FACING = HorizontalFacingBlock.FACING;
|
||||
|
||||
private static final EnumMap<Direction, VoxelShape> SHAPES = Maps.newEnumMap(ImmutableMap.of(
|
||||
Direction.NORTH, Block.box(1, 1, 8, 15, 15, 16),
|
||||
Direction.SOUTH, Block.box(1, 1, 0, 15, 15, 8),
|
||||
Direction.WEST, Block.box(8, 1, 1, 16, 15, 15),
|
||||
Direction.EAST, Block.box(0, 1, 1, 8, 15, 15)));
|
||||
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
|
||||
|
||||
public EndWallPlantBlock() {
|
||||
this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS)
|
||||
.breakByHand(true).noCollision());
|
||||
this(FabricBlockSettings.of(Material.PLANT)
|
||||
.breakByTool(FabricToolTags.SHEARS)
|
||||
.breakByHand(true)
|
||||
.sound(SoundType.GRASS)
|
||||
.noCollission());
|
||||
}
|
||||
|
||||
|
||||
public EndWallPlantBlock(int light) {
|
||||
this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).sounds(SoundType.GRASS)
|
||||
.luminance(light).breakByHand(true).noCollision());
|
||||
this(FabricBlockSettings.of(Material.PLANT)
|
||||
.breakByTool(FabricToolTags.SHEARS)
|
||||
.breakByHand(true)
|
||||
.luminance(light)
|
||||
.sound(SoundType.GRASS)
|
||||
.noCollission());
|
||||
}
|
||||
|
||||
|
||||
public EndWallPlantBlock(Properties settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateManager) {
|
||||
stateManager.add(FACING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
|
||||
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
|
||||
return SHAPES.get(state.getValue(FACING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractBlock.OffsetType getOffsetType() {
|
||||
return AbstractBlock.OffsetType.NONE;
|
||||
public BlockBehaviour.OffsetType getOffsetType() {
|
||||
return BlockBehaviour.OffsetType.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
|
||||
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
|
||||
Direction direction = (Direction) state.getValue(FACING);
|
||||
BlockPos blockPos = pos.relative(direction.getOpposite());
|
||||
BlockState blockState = world.getBlockState(blockPos);
|
||||
return isSupport(world, blockPos, blockState, direction);
|
||||
}
|
||||
|
||||
public boolean isSupport(WorldView world, BlockPos pos, BlockState blockState, Direction direction) {
|
||||
return blockState.getMaterial().isSolid() && blockState.isSideSolidFullSquare(world, pos, direction);
|
||||
|
||||
public boolean isSupport(LevelReader world, BlockPos pos, BlockState blockState, Direction direction) {
|
||||
return blockState.getMaterial().isSolid() && blockState.isFaceSturdy(world, pos, direction);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
|
||||
BlockState blockState = this.defaultBlockState();
|
||||
WorldView worldView = ctx.getLevel();
|
||||
BlockPos blockPos = ctx.getBlockPos();
|
||||
Direction[] directions = ctx.getPlacementDirections();
|
||||
LevelReader worldView = ctx.getLevel();
|
||||
BlockPos blockPos = ctx.getClickedPos();
|
||||
Direction[] directions = ctx.getNearestLookingDirections();
|
||||
for (int i = 0; i < directions.length; ++i) {
|
||||
Direction direction = directions[i];
|
||||
if (direction.getAxis().isHorizontal()) {
|
||||
Direction direction2 = direction.getOpposite();
|
||||
blockState = blockState.with(FACING, direction2);
|
||||
if (blockState.canPlaceAt(worldView, blockPos)) {
|
||||
blockState = blockState.setValue(FACING, direction2);
|
||||
if (blockState.canSurvive(worldView, blockPos)) {
|
||||
return blockState;
|
||||
}
|
||||
}
|
||||
|
@ -96,22 +104,22 @@ public class EndWallPlantBlock extends EndPlantBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world,
|
||||
BlockPos pos, BlockPos neighborPos) {
|
||||
if (!canPlaceAt(state, world, pos)) {
|
||||
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
|
||||
if (!canSurvive(state, world, pos)) {
|
||||
return Blocks.AIR.defaultBlockState();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, Rotation rotation) {
|
||||
return BlocksHelper.rotateHorizontal(state, rotation, FACING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState mirror(BlockState state, BlockMirror mirror) {
|
||||
public BlockState mirror(BlockState state, Mirror mirror) {
|
||||
return BlocksHelper.mirrorHorizontal(state, mirror, FACING);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue