Stalactite enhancements (WIP)

This commit is contained in:
paulevsGitch 2021-03-09 15:54:51 +03:00
parent 7e73d9a31c
commit 0739e0580b
19 changed files with 272 additions and 43 deletions

View file

@ -102,8 +102,7 @@ public class EndSignBlock extends AbstractSignBlock implements BlockPatterned {
}
@Override
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer,
ItemStack itemStack) {
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
if (placer != null && placer instanceof PlayerEntity) {
ESignBlockEntity sign = (ESignBlockEntity) world.getBlockEntity(pos);
if (!world.isClient) {
@ -124,7 +123,7 @@ public class EndSignBlock extends AbstractSignBlock implements BlockPatterned {
}
return super.getStateForNeighborUpdate(state, facing, neighborState, world, pos, neighborPos);
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
if (!state.get(FLOOR)) {
@ -143,7 +142,8 @@ public class EndSignBlock extends AbstractSignBlock implements BlockPatterned {
return this.getDefaultState().with(FLOOR, true)
.with(ROTATION, MathHelper.floor((180.0 + ctx.getPlayerYaw() * 16.0 / 360.0) + 0.5 - 12) & 15)
.with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER);
} else if (ctx.getSide() != Direction.DOWN) {
}
else if (ctx.getSide() != Direction.DOWN) {
BlockState blockState = this.getDefaultState();
FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos());
WorldView worldView = ctx.getWorld();

View file

@ -109,7 +109,7 @@ public abstract class FeatureSaplingBlock extends BlockBaseNotFull implements Fe
block = block.split("/")[1];
return Patterns.createJson(Patterns.ITEM_BLOCK, block);
}
return Patterns.createJson(Patterns.BLOCK_SAPLING, block);
return Patterns.createJson(Patterns.BLOCK_CROSS, block);
}
@Override

View file

@ -4,11 +4,19 @@ import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FluidFillable;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.Waterloggable;
import net.minecraft.entity.LivingEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
@ -20,29 +28,62 @@ import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
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 {
public class StalactiteBlock extends BlockBaseNotFull implements Waterloggable, FluidFillable, IRenderTypeable {
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
public static final BooleanProperty IS_FLOOR = BlockProperties.IS_FLOOR;
public static final IntProperty SIZE = BlockProperties.SIZE;
private static final Mutable POS = new Mutable();
private static final VoxelShape[] SHAPES;
private final Block source;
public StalactiteBlock(Block source) {
super(FabricBlockSettings.copy(source).nonOpaque());
this.setDefaultState(getStateManager().getDefaultState().with(SIZE, 0));
this.source = source;
this.setDefaultState(getStateManager().getDefaultState().with(SIZE, 0).with(IS_FLOOR, true).with(WATERLOGGED, false));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
stateManager.add(SIZE);
stateManager.add(WATERLOGGED, IS_FLOOR, SIZE);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
return SHAPES[state.get(SIZE)];
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
WorldView worldView = ctx.getWorld();
BlockPos blockPos = ctx.getBlockPos();
Direction dir = ctx.getSide();
boolean water = worldView.getFluidState(blockPos).getFluid() == Fluids.WATER;
if (dir == Direction.UP) {
if (sideCoversSmallSquare(worldView, blockPos.up(), Direction.DOWN)) {
return getDefaultState().with(IS_FLOOR, false).with(WATERLOGGED, water);
}
else if (sideCoversSmallSquare(worldView, blockPos.down(), Direction.UP)) {
return getDefaultState().with(IS_FLOOR, true).with(WATERLOGGED, water);
}
else {
return null;
}
}
else {
if (sideCoversSmallSquare(worldView, blockPos.up(), Direction.DOWN)) {
return getDefaultState().with(IS_FLOOR, false).with(WATERLOGGED, water);
}
else if (sideCoversSmallSquare(worldView, blockPos.down(), Direction.UP)) {
return getDefaultState().with(IS_FLOOR, true).with(WATERLOGGED, water);
}
else {
return null;
}
}
}
@Override
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
@ -55,7 +96,7 @@ public class StalactiteBlock extends BlockBaseNotFull {
BlockState state2 = world.getBlockState(POS);
int size = state2.get(SIZE);
if (size < i) {
world.setBlockState(POS, state2.with(SIZE, i));
world.setBlockState(POS, state2.with(SIZE, i).with(IS_FLOOR, true));
}
else {
break;
@ -75,7 +116,7 @@ public class StalactiteBlock extends BlockBaseNotFull {
BlockState state2 = world.getBlockState(POS);
int size = state2.get(SIZE);
if (size < i) {
world.setBlockState(POS, state2.with(SIZE, i));
world.setBlockState(POS, state2.with(SIZE, i).with(IS_FLOOR, false));
}
else {
break;
@ -94,18 +135,29 @@ public class StalactiteBlock extends BlockBaseNotFull {
return Blocks.AIR.getDefaultState();
}
else {
if (checkUp(world, neighborPos, state.get(SIZE))) {
state = state.with(IS_FLOOR, false);
}
return state;
}
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
BlockState upState = world.getBlockState(pos.up());
BlockState downState = world.getBlockState(pos.down());
int size = state.get(SIZE);
boolean validUp = (upState.isOf(this) && upState.get(SIZE) >= size) || upState.isFullCube(world, pos.up());
boolean validDown = (downState.isOf(this) && downState.get(SIZE) >= size) || downState.isFullCube(world, pos.down());
return validUp || validDown;
return checkUp(world, pos, size) || checkDown(world, pos, size);
}
private boolean checkUp(BlockView world, BlockPos pos, int size) {
BlockPos p = pos.up();
BlockState state = world.getBlockState(p);
return (state.getBlock() instanceof StalactiteBlock && state.get(SIZE) >= size) || state.isFullCube(world, p);
}
private boolean checkDown(BlockView world, BlockPos pos, int size) {
BlockPos p = pos.down();
BlockState state = world.getBlockState(p);
return (state.getBlock() instanceof StalactiteBlock && state.get(SIZE) >= size) || state.isFullCube(world, p);
}
@Override
@ -114,15 +166,33 @@ public class StalactiteBlock extends BlockBaseNotFull {
if (block.contains("item")) {
return Patterns.createJson(Patterns.ITEM_GENERATED, "item/" + blockId.getPath());
}
blockId = Registry.BLOCK.getId(source);
int shape = Character.getNumericValue(block.charAt(block.lastIndexOf('_') + 1));
return Patterns.createJson(Patterns.BLOCKS_STALACTITE[shape], blockId.getNamespace() + ":block/" + blockId.getPath());
return Patterns.createJson(Patterns.BLOCK_CROSS_SHADED, block);
}
@Override
public Identifier statePatternId() {
return Patterns.STATE_STALACTITE;
}
@Override
public boolean canFillWithFluid(BlockView world, BlockPos pos, BlockState state, Fluid fluid) {
return false;
}
@Override
public boolean tryFillWithFluid(WorldAccess world, BlockPos pos, BlockState state, FluidState fluidState) {
return false;
}
@Override
public FluidState getFluidState(BlockState state) {
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : Fluids.EMPTY.getDefaultState();
}
@Override
public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT;
}
static {
SHAPES = new VoxelShape[8];

View file

@ -71,7 +71,8 @@ public class Patterns {
public final static Identifier BLOCK_DOOR_TOP_HINGE = BetterEnd.makeID("patterns/block/door_top_hinge.json");
public final static Identifier BLOCK_DOOR_BOTTOM = BetterEnd.makeID("patterns/block/door_bottom.json");
public final static Identifier BLOCK_DOOR_BOTTOM_HINGE = BetterEnd.makeID("patterns/block/door_bottom_hinge.json");
public final static Identifier BLOCK_SAPLING = BetterEnd.makeID("patterns/block/sapling.json");
public final static Identifier BLOCK_CROSS = BetterEnd.makeID("patterns/block/cross.json");
public final static Identifier BLOCK_CROSS_SHADED = BetterEnd.makeID("patterns/block/cross_shaded.json");
public final static Identifier BLOCK_GATE_CLOSED = BetterEnd.makeID("patterns/block/fence_gate_closed.json");
public final static Identifier BLOCK_GATE_CLOSED_WALL = BetterEnd.makeID("patterns/block/wall_gate_closed.json");
public final static Identifier BLOCK_GATE_OPEN = BetterEnd.makeID("patterns/block/fence_gate_open.json");
@ -105,17 +106,6 @@ public class Patterns {
public final static Identifier BLOCK_TOP_SIDE_BOTTOM = BetterEnd.makeID("patterns/block/top_side_bottom.json");
public final static Identifier BLOCK_PATH = BetterEnd.makeID("patterns/block/path.json");
public final static Identifier[] BLOCKS_STALACTITE = new Identifier[] {
BetterEnd.makeID("patterns/block/stalactite_0.json"),
BetterEnd.makeID("patterns/block/stalactite_1.json"),
BetterEnd.makeID("patterns/block/stalactite_2.json"),
BetterEnd.makeID("patterns/block/stalactite_3.json"),
BetterEnd.makeID("patterns/block/stalactite_4.json"),
BetterEnd.makeID("patterns/block/stalactite_5.json"),
BetterEnd.makeID("patterns/block/stalactite_6.json"),
BetterEnd.makeID("patterns/block/stalactite_7.json")
};
//Models Item
public final static Identifier ITEM_WALL = BetterEnd.makeID("patterns/item/pattern_wall.json");
public final static Identifier ITEM_FENCE = BetterEnd.makeID("patterns/item/pattern_fence.json");

View file

@ -4,6 +4,7 @@ import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.util.math.MathHelper;
@ -33,14 +34,14 @@ public class StalactiteFeature extends DefaultFeature {
}
Mutable mut = new Mutable().set(pos);
int height = random.nextInt(8);
int height = random.nextInt(8);
int dir = ceiling ? -1 : 1;
boolean stalagnate = false;
for (int i = 1; i <= height; i++) {
mut.setY(pos.getY() + i * dir);
BlockState state = world.getBlockState(mut);
if (!state.isAir()) {
if (!state.getMaterial().isReplaceable()) {
stalagnate = state.isIn(EndTags.GEN_TERRAIN);
height = i - 1;
break;
@ -51,7 +52,10 @@ public class StalactiteFeature extends DefaultFeature {
for (int i = 0; i < height; i++) {
mut.setY(pos.getY() + i * dir);
int size = stalagnate ? MathHelper.abs(i - center) + 1 : height - i - 1;
BlocksHelper.setWithoutUpdate(world, mut, block.getDefaultState().with(StalactiteBlock.SIZE, size));
boolean waterlogged = !world.getFluidState(mut).isEmpty();
BlockState base = block.getDefaultState().with(StalactiteBlock.SIZE, size).with(Properties.WATERLOGGED, waterlogged);
BlockState state = stalagnate ? base.with(StalactiteBlock.IS_FLOOR, dir > 0 ? i < center : i > center) : base.with(StalactiteBlock.IS_FLOOR, dir > 0);
BlocksHelper.setWithoutUpdate(world, mut, state);
}
return true;