Neon oasis (WIP)

This commit is contained in:
paulevsGitch 2021-03-21 06:37:42 +03:00
parent 4ceda82bfb
commit 12447f783f
16 changed files with 202 additions and 63 deletions

View file

@ -1,5 +1,9 @@
package ru.betterend.blocks;
import java.util.EnumMap;
import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
@ -34,13 +38,10 @@ public class NeonCactusBlock extends BlockBaseNotFull implements Waterloggable,
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
public static final DirectionProperty FACING = Properties.FACING;
private static final VoxelShape MEDIUM_X = Block.createCuboidShape(0, 2, 2, 16, 14, 14);
private static final VoxelShape MEDIUM_Y = Block.createCuboidShape(2, 0, 2, 14, 16, 14);
private static final VoxelShape MEDIUM_Z = Block.createCuboidShape(2, 2, 0, 14, 14, 16);
private static final VoxelShape SMALL_X = Block.createCuboidShape(0, 4, 4, 16, 12, 12);
private static final VoxelShape SMALL_Y = Block.createCuboidShape(4, 0, 4, 12, 16, 12);
private static final VoxelShape SMALL_Z = Block.createCuboidShape(4, 4, 0, 12, 12, 16);
private static final EnumMap<Direction, VoxelShape> MEDIUM_SHAPES_OPEN = Maps.newEnumMap(Direction.class);
private static final EnumMap<Direction, VoxelShape> SMALL_SHAPES_OPEN = Maps.newEnumMap(Direction.class);
private static final EnumMap<Axis, VoxelShape> MEDIUM_SHAPES = Maps.newEnumMap(Axis.class);
private static final EnumMap<Axis, VoxelShape> SMALL_SHAPES = Maps.newEnumMap(Axis.class);
public NeonCactusBlock() {
super(FabricBlockSettings.copyOf(Blocks.CACTUS).luminance(state -> {
@ -50,6 +51,7 @@ public class NeonCactusBlock extends BlockBaseNotFull implements Waterloggable,
}
return shape == TripleShape.MIDDLE ? 13 : 10;
}));
setDefaultState(getDefaultState().with(WATERLOGGED, false).with(FACING, Direction.UP).with(SHAPE, TripleShape.TOP));
}
@Override
@ -99,18 +101,38 @@ public class NeonCactusBlock extends BlockBaseNotFull implements Waterloggable,
if (shape == TripleShape.BOTTOM) {
return VoxelShapes.fullCube();
}
Axis dir = state.get(FACING).getAxis();
if (shape == TripleShape.MIDDLE) {
if (dir == Axis.Y) {
return MEDIUM_Y;
}
return dir == Axis.X ? MEDIUM_X : MEDIUM_Z;
Direction dir = state.get(FACING);
BlockState next = view.getBlockState(pos.offset(dir));
if (next.isOf(this)) {
Axis axis = dir.getAxis();
return shape == TripleShape.MIDDLE ? MEDIUM_SHAPES.get(axis) : SMALL_SHAPES.get(axis);
}
else {
if (dir == Axis.Y) {
return SMALL_Y;
}
return dir == Axis.X ? SMALL_X : SMALL_Z;
return shape == TripleShape.MIDDLE ? MEDIUM_SHAPES_OPEN.get(dir) : SMALL_SHAPES_OPEN.get(dir);
}
}
static {
MEDIUM_SHAPES.put(Axis.X, Block.createCuboidShape(0, 2, 2, 16, 14, 14));
MEDIUM_SHAPES.put(Axis.Y, Block.createCuboidShape(2, 0, 2, 14, 16, 14));
MEDIUM_SHAPES.put(Axis.Z, Block.createCuboidShape(2, 2, 0, 14, 14, 16));
SMALL_SHAPES.put(Axis.X, Block.createCuboidShape(0, 4, 4, 16, 12, 12));
SMALL_SHAPES.put(Axis.Y, Block.createCuboidShape(4, 0, 4, 12, 16, 12));
SMALL_SHAPES.put(Axis.Z, Block.createCuboidShape(4, 4, 0, 12, 12, 16));
MEDIUM_SHAPES_OPEN.put(Direction.UP, Block.createCuboidShape(2, 0, 2, 14, 14, 14));
MEDIUM_SHAPES_OPEN.put(Direction.DOWN, Block.createCuboidShape(2, 2, 2, 14, 16, 14));
MEDIUM_SHAPES_OPEN.put(Direction.NORTH, Block.createCuboidShape(2, 2, 2, 14, 14, 16));
MEDIUM_SHAPES_OPEN.put(Direction.SOUTH, Block.createCuboidShape(2, 2, 0, 14, 14, 14));
MEDIUM_SHAPES_OPEN.put(Direction.WEST, Block.createCuboidShape(2, 2, 2, 16, 14, 14));
MEDIUM_SHAPES_OPEN.put(Direction.EAST, Block.createCuboidShape(0, 2, 2, 14, 14, 14));
SMALL_SHAPES_OPEN.put(Direction.UP, Block.createCuboidShape(4, 0, 4, 12, 12, 12));
SMALL_SHAPES_OPEN.put(Direction.DOWN, Block.createCuboidShape(4, 4, 4, 12, 16, 12));
SMALL_SHAPES_OPEN.put(Direction.NORTH, Block.createCuboidShape(4, 4, 4, 12, 12, 16));
SMALL_SHAPES_OPEN.put(Direction.SOUTH, Block.createCuboidShape(4, 4, 0, 12, 12, 12));
SMALL_SHAPES_OPEN.put(Direction.WEST, Block.createCuboidShape(4, 4, 4, 16, 12, 12));
SMALL_SHAPES_OPEN.put(Direction.EAST, Block.createCuboidShape(0, 4, 4, 12, 12, 12));
}
}