Continue mapping migration
This commit is contained in:
parent
99ade39404
commit
f03fd03bd0
499 changed files with 12567 additions and 12723 deletions
|
@ -1,48 +1,47 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
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.FluidFillable;
|
||||
import net.minecraft.world.level.block.ShapeContext;
|
||||
import net.minecraft.world.level.block.Waterloggable;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraft.world.item.ItemPlacementContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
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.LiquidBlockContainer;
|
||||
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
|
||||
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.BooleanProperty;
|
||||
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import ru.betterend.blocks.BlockProperties;
|
||||
import ru.betterend.client.render.ERenderLayer;
|
||||
import ru.betterend.interfaces.IRenderTypeable;
|
||||
import ru.betterend.patterns.Patterns;
|
||||
|
||||
public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable, FluidFillable, IRenderTypeable {
|
||||
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
|
||||
public class StalactiteBlock extends BlockBaseNotFull implements SimpleWaterloggedBlock, LiquidBlockContainer, IRenderTypeable {
|
||||
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
|
||||
public static final BooleanProperty IS_FLOOR = BlockProperties.IS_FLOOR;
|
||||
public static final IntegerProperty SIZE = BlockProperties.SIZE;
|
||||
private static final VoxelShape[] SHAPES;
|
||||
|
||||
public StalactiteBlock(Block source) {
|
||||
super(FabricBlockSettings.copy(source).nonOpaque());
|
||||
this.setDefaultState(
|
||||
getStateManager().defaultBlockState().with(SIZE, 0).with(IS_FLOOR, true).with(WATERLOGGED, false));
|
||||
super(FabricBlockSettings.copy(source).noOcclusion());
|
||||
this.registerDefaultState(getStateDefinition().any().setValue(SIZE, 0).setValue(IS_FLOOR, true).setValue(WATERLOGGED, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,137 +50,147 @@ public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable,
|
|||
}
|
||||
|
||||
@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[state.getValue(SIZE)];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
WorldView world = ctx.getLevel();
|
||||
BlockPos pos = ctx.getBlockPos();
|
||||
Direction dir = ctx.getSide();
|
||||
boolean water = world.getFluidState(pos).getFluid() == Fluids.WATER;
|
||||
|
||||
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
|
||||
LevelReader world = ctx.getLevel();
|
||||
BlockPos pos = ctx.getClickedPos();
|
||||
Direction dir = ctx.getClickedFace();
|
||||
boolean water = world.getFluidState(pos).getType() == Fluids.WATER;
|
||||
|
||||
if (dir == Direction.DOWN) {
|
||||
if (isThis(world, pos.up()) || sideCoversSmallSquare(world, pos.up(), Direction.DOWN)) {
|
||||
return getDefaultState().with(IS_FLOOR, false).with(WATERLOGGED, water);
|
||||
} else if (isThis(world, pos.below()) || sideCoversSmallSquare(world, pos.below(), Direction.UP)) {
|
||||
return getDefaultState().with(IS_FLOOR, true).with(WATERLOGGED, water);
|
||||
} else {
|
||||
if (isThis(world, pos.above()) || canSupportCenter(world, pos.above(), Direction.DOWN)) {
|
||||
return defaultBlockState().setValue(IS_FLOOR, false).setValue(WATERLOGGED, water);
|
||||
}
|
||||
else if (isThis(world, pos.below()) || canSupportCenter(world, pos.below(), Direction.UP)) {
|
||||
return defaultBlockState().setValue(IS_FLOOR, true).setValue(WATERLOGGED, water);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if (isThis(world, pos.below()) || sideCoversSmallSquare(world, pos.below(), Direction.UP)) {
|
||||
return getDefaultState().with(IS_FLOOR, true).with(WATERLOGGED, water);
|
||||
} else if (isThis(world, pos.up()) || sideCoversSmallSquare(world, pos.up(), Direction.DOWN)) {
|
||||
return getDefaultState().with(IS_FLOOR, false).with(WATERLOGGED, water);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (isThis(world, pos.below()) || canSupportCenter(world, pos.below(), Direction.UP)) {
|
||||
return defaultBlockState().setValue(IS_FLOOR, true).setValue(WATERLOGGED, water);
|
||||
}
|
||||
else if (isThis(world, pos.above()) || canSupportCenter(world, pos.above(), Direction.DOWN)) {
|
||||
return defaultBlockState().setValue(IS_FLOOR, false).setValue(WATERLOGGED, water);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaced(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
|
||||
boolean hasUp = isThis(world, pos.up());
|
||||
public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
|
||||
boolean hasUp = isThis(world, pos.above());
|
||||
boolean hasDown = isThis(world, pos.below());
|
||||
MutableBlockPos mut = new MutableBlockPos();
|
||||
if (hasUp && hasDown) {
|
||||
boolean floor = state.getValue(IS_FLOOR);
|
||||
BlockPos second = floor ? pos.up() : pos.below();
|
||||
BlockPos second = floor ? pos.above() : pos.below();
|
||||
BlockState bState = world.getBlockState(second);
|
||||
world.setBlockAndUpdate(pos, state.with(SIZE, 1).with(IS_FLOOR, floor));
|
||||
world.setBlockAndUpdate(second, bState.with(SIZE, 1).with(IS_FLOOR, !floor));
|
||||
|
||||
world.setBlockAndUpdate(pos, state.setValue(SIZE, 1).setValue(IS_FLOOR, floor));
|
||||
world.setBlockAndUpdate(second, bState.setValue(SIZE, 1).setValue(IS_FLOOR, !floor));
|
||||
|
||||
bState = state;
|
||||
int startSize = floor ? 1 : 2;
|
||||
mut.set(pos.getX(), pos.getY() + 1, pos.getZ());
|
||||
for (int i = 0; i < 8 && isThis(bState); i++) {
|
||||
world.setBlockAndUpdate(mut, bState.with(SIZE, startSize++).with(IS_FLOOR, false));
|
||||
world.setBlockAndUpdate(mut, bState.setValue(SIZE, startSize++).setValue(IS_FLOOR, false));
|
||||
mut.setY(mut.getY() + 1);
|
||||
bState = world.getBlockState(mut);
|
||||
}
|
||||
|
||||
|
||||
bState = state;
|
||||
startSize = floor ? 2 : 1;
|
||||
mut.set(pos.getX(), pos.getY() - 1, pos.getZ());
|
||||
for (int i = 0; i < 8 && isThis(bState); i++) {
|
||||
world.setBlockAndUpdate(mut, bState.with(SIZE, startSize++).with(IS_FLOOR, true));
|
||||
world.setBlockAndUpdate(mut, bState.setValue(SIZE, startSize++).setValue(IS_FLOOR, true));
|
||||
mut.setY(mut.getY() - 1);
|
||||
bState = world.getBlockState(mut);
|
||||
}
|
||||
} else if (hasDown) {
|
||||
}
|
||||
else if (hasDown) {
|
||||
mut.setX(pos.getX());
|
||||
mut.setZ(pos.getZ());
|
||||
for (int i = 1; i < 8; i++) {
|
||||
mut.setY(pos.getY() - i);
|
||||
if (isThis(world, mut)) {
|
||||
BlockState state2 = world.getBlockState(mut);
|
||||
int size = state2.get(SIZE);
|
||||
int size = state2.getValue(SIZE);
|
||||
if (size < i) {
|
||||
world.setBlockAndUpdate(mut, state2.with(SIZE, i).with(IS_FLOOR, true));
|
||||
} else {
|
||||
world.setBlockAndUpdate(mut, state2.setValue(SIZE, i).setValue(IS_FLOOR, true));
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (hasUp) {
|
||||
}
|
||||
else if (hasUp) {
|
||||
mut.setX(pos.getX());
|
||||
mut.setZ(pos.getZ());
|
||||
for (int i = 1; i < 8; i++) {
|
||||
mut.setY(pos.getY() + i);
|
||||
if (isThis(world, mut)) {
|
||||
BlockState state2 = world.getBlockState(mut);
|
||||
int size = state2.get(SIZE);
|
||||
int size = state2.getValue(SIZE);
|
||||
if (size < i) {
|
||||
world.setBlockAndUpdate(mut, state2.with(SIZE, i).with(IS_FLOOR, false));
|
||||
} else {
|
||||
world.setBlockAndUpdate(mut, state2.setValue(SIZE, i).setValue(IS_FLOOR, false));
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isThis(WorldView world, BlockPos pos) {
|
||||
|
||||
private boolean isThis(LevelReader world, BlockPos pos) {
|
||||
return isThis(world.getBlockState(pos));
|
||||
}
|
||||
|
||||
|
||||
private boolean isThis(BlockState state) {
|
||||
return state.getBlock() instanceof StalactiteBlock;
|
||||
}
|
||||
|
||||
|
||||
@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();
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
|
||||
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
|
||||
int size = state.getValue(SIZE);
|
||||
return checkUp(world, pos, size) || checkDown(world, pos, size);
|
||||
}
|
||||
|
||||
private boolean checkUp(BlockView world, BlockPos pos, int size) {
|
||||
BlockPos p = pos.up();
|
||||
|
||||
private boolean checkUp(BlockGetter world, BlockPos pos, int size) {
|
||||
BlockPos p = pos.above();
|
||||
BlockState state = world.getBlockState(p);
|
||||
return (isThis(state) && state.getValue(SIZE) >= size) || state.isFullCube(world, p);
|
||||
return (isThis(state) && state.getValue(SIZE) >= size) || state.isCollisionShapeFullBlock(world, p);
|
||||
}
|
||||
|
||||
private boolean checkDown(BlockView world, BlockPos pos, int size) {
|
||||
|
||||
private boolean checkDown(BlockGetter world, BlockPos pos, int size) {
|
||||
BlockPos p = pos.below();
|
||||
BlockState state = world.getBlockState(p);
|
||||
return (isThis(state) && state.getValue(SIZE) >= size) || state.isFullCube(world, p);
|
||||
return (isThis(state) && state.getValue(SIZE) >= size) || state.isCollisionShapeFullBlock(world, p);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getModelPattern(String block) {
|
||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||
|
@ -190,25 +199,25 @@ public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable,
|
|||
}
|
||||
return Patterns.createJson(Patterns.BLOCK_CROSS_SHADED, block);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResourceLocation statePatternId() {
|
||||
return Patterns.STATE_STALACTITE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) {
|
||||
public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryFillWithFluid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) {
|
||||
public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FluidState getFluidState(BlockState state) {
|
||||
return state.getValue(WATERLOGGED) ? Fluids.WATER.getStill(false) : Fluids.EMPTY.defaultBlockState();
|
||||
return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : Fluids.EMPTY.defaultFluidState();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -222,7 +231,7 @@ public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable,
|
|||
SHAPES = new VoxelShape[8];
|
||||
for (int i = 0; i < 8; i++) {
|
||||
int side = Mth.floor(Mth.lerp(i / 7F, start, end) * 8F + 0.5F);
|
||||
SHAPES[i] = Block.createCuboidShape(side, 0, side, 16 - side, 16, 16 - side);
|
||||
SHAPES[i] = Block.box(side, 0, side, 16 - side, 16, 16 - side);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue