Skip to content

Commit 21db9db

Browse files
committed
Rewrite blocks in Java
Fixed bugs / code adjusted to match vanilla: - BenchBlock.rotate: not working for CLOCKWISE_90 - ChimneyBlock.onUse, SofaBlock.onUse, TableLampBlock.onUse: returning ActionResult.SUCCESS on the server
1 parent 4fd7fa7 commit 21db9db

File tree

77 files changed

+3574
-3130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3574
-3130
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package juuxel.adorn.block;
2+
3+
import juuxel.adorn.lib.AdornTags;
4+
import net.minecraft.block.Block;
5+
import net.minecraft.block.BlockState;
6+
import net.minecraft.block.MapColor;
7+
import net.minecraft.block.ShapeContext;
8+
import net.minecraft.block.Waterloggable;
9+
import net.minecraft.entity.ai.pathing.NavigationType;
10+
import net.minecraft.fluid.FluidState;
11+
import net.minecraft.fluid.Fluids;
12+
import net.minecraft.item.ItemPlacementContext;
13+
import net.minecraft.state.StateManager;
14+
import net.minecraft.state.property.BooleanProperty;
15+
import net.minecraft.state.property.Properties;
16+
import net.minecraft.util.math.BlockPos;
17+
import net.minecraft.util.math.Direction;
18+
import net.minecraft.util.shape.VoxelShape;
19+
import net.minecraft.world.BlockView;
20+
import net.minecraft.world.WorldAccess;
21+
22+
public abstract class AbstractChimneyBlock extends Block implements Waterloggable {
23+
public static final BooleanProperty CONNECTED = BooleanProperty.of("connected");
24+
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
25+
private static final VoxelShape TOP_SHAPE = createCuboidShape(4.0, 0.0, 4.0, 12.0, 12.0, 12.0);
26+
private static final VoxelShape MIDDLE_SHAPE = createCuboidShape(5.0, 0.0, 5.0, 11.0, 16.0, 11.0);
27+
28+
public AbstractChimneyBlock(Settings settings) {
29+
super(settings);
30+
setDefaultState(getDefaultState()
31+
.with(CONNECTED, false)
32+
.with(WATERLOGGED, false));
33+
}
34+
35+
@Override
36+
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
37+
super.appendProperties(builder);
38+
builder.add(CONNECTED, WATERLOGGED);
39+
}
40+
41+
@Override
42+
public BlockState getPlacementState(ItemPlacementContext ctx) {
43+
return updateConnections(
44+
getDefaultState().with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER),
45+
ctx.getWorld().getBlockState(ctx.getBlockPos().up())
46+
);
47+
}
48+
49+
private BlockState updateConnections(BlockState state, BlockState neighborState) {
50+
return state.with(CONNECTED, neighborState.isIn(AdornTags.CHIMNEYS.block()));
51+
}
52+
53+
@Override
54+
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
55+
if (state.get(WATERLOGGED)) {
56+
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
57+
}
58+
59+
return direction == Direction.UP ? updateConnections(state, neighborState) : state;
60+
}
61+
62+
@Override
63+
public FluidState getFluidState(BlockState state) {
64+
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
65+
}
66+
67+
@Override
68+
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
69+
return state.get(CONNECTED) ? MIDDLE_SHAPE : TOP_SHAPE;
70+
}
71+
72+
@Override
73+
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
74+
return false;
75+
}
76+
77+
public static Settings createBlockSettings(MapColor color) {
78+
return createBlockSettings(color, 2f);
79+
}
80+
81+
public static Settings createBlockSettings(MapColor color, float hardness) {
82+
return Settings.create()
83+
.mapColor(color)
84+
.solid()
85+
.requiresTool()
86+
.strength(hardness, 6f)
87+
.ticksRandomly()
88+
.nonOpaque();
89+
}
90+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package juuxel.adorn.block;
2+
3+
import juuxel.adorn.block.variant.BlockVariant;
4+
import juuxel.adorn.util.Shapes;
5+
import net.minecraft.block.Block;
6+
import net.minecraft.block.BlockState;
7+
import net.minecraft.block.ShapeContext;
8+
import net.minecraft.item.ItemPlacementContext;
9+
import net.minecraft.sound.BlockSoundGroup;
10+
import net.minecraft.sound.SoundEvents;
11+
import net.minecraft.state.StateManager;
12+
import net.minecraft.state.property.DirectionProperty;
13+
import net.minecraft.state.property.Properties;
14+
import net.minecraft.util.BlockMirror;
15+
import net.minecraft.util.BlockRotation;
16+
import net.minecraft.util.math.BlockPos;
17+
import net.minecraft.util.math.Direction;
18+
import net.minecraft.util.shape.VoxelShape;
19+
import net.minecraft.world.BlockView;
20+
21+
import java.util.Map;
22+
23+
public abstract class AbstractKitchenCounterBlock extends Block {
24+
public static final DirectionProperty FACING = Properties.HORIZONTAL_FACING;
25+
public static final BlockSoundGroup SOUND_GROUP = new BlockSoundGroup(
26+
1.0F, 1.0F,
27+
SoundEvents.BLOCK_WOOD_BREAK,
28+
SoundEvents.BLOCK_STONE_STEP,
29+
SoundEvents.BLOCK_WOOD_PLACE,
30+
SoundEvents.BLOCK_WOOD_HIT,
31+
SoundEvents.BLOCK_STONE_FALL
32+
);
33+
protected static final Map<Direction, VoxelShape> SHAPES = Shapes.mergeIntoShapeMap(
34+
Shapes.buildShapeRotationsFromNorth(
35+
0, 0, 2,
36+
16, 12, 16
37+
),
38+
createCuboidShape(
39+
0.0, 12.0, 0.0,
40+
16.0, 16.0, 16.0
41+
)
42+
);
43+
44+
public AbstractKitchenCounterBlock(Settings settings) {
45+
super(settings);
46+
}
47+
48+
public AbstractKitchenCounterBlock(BlockVariant variant) {
49+
this(variant.createSettings().sounds(SOUND_GROUP));
50+
}
51+
52+
@Override
53+
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
54+
super.appendProperties(builder);
55+
builder.add(FACING);
56+
}
57+
58+
@Override
59+
public BlockState getPlacementState(ItemPlacementContext ctx) {
60+
return getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing().getOpposite());
61+
}
62+
63+
@Override
64+
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
65+
return SHAPES.get(state.get(FACING));
66+
}
67+
68+
@Override
69+
public BlockState mirror(BlockState state, BlockMirror mirror) {
70+
return state.rotate(mirror.getRotation(state.get(FACING)));
71+
}
72+
73+
@Override
74+
public BlockState rotate(BlockState state, BlockRotation rotation) {
75+
return state.with(FACING, rotation.rotate(state.get(FACING)));
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package juuxel.adorn.block;
2+
3+
import net.minecraft.block.Block;
4+
import net.minecraft.block.BlockState;
5+
import net.minecraft.block.ShapeContext;
6+
import net.minecraft.block.Waterloggable;
7+
import net.minecraft.entity.ai.pathing.NavigationType;
8+
import net.minecraft.fluid.FluidState;
9+
import net.minecraft.fluid.Fluids;
10+
import net.minecraft.item.ItemPlacementContext;
11+
import net.minecraft.state.StateManager;
12+
import net.minecraft.state.property.BooleanProperty;
13+
import net.minecraft.state.property.Properties;
14+
import net.minecraft.util.math.BlockPos;
15+
import net.minecraft.util.math.Direction;
16+
import net.minecraft.util.shape.VoxelShape;
17+
import net.minecraft.world.BlockView;
18+
import net.minecraft.world.WorldAccess;
19+
20+
public abstract class AbstractTableBlock extends CarpetedBlock implements Waterloggable {
21+
public static final BooleanProperty NORTH = Properties.NORTH;
22+
public static final BooleanProperty EAST = Properties.EAST;
23+
public static final BooleanProperty SOUTH = Properties.SOUTH;
24+
public static final BooleanProperty WEST = Properties.WEST;
25+
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
26+
27+
public AbstractTableBlock(Settings settings) {
28+
super(settings);
29+
setDefaultState(getDefaultState().with(WATERLOGGED, false));
30+
}
31+
32+
protected abstract boolean canConnectTo(BlockState state, Direction sideOfSelf);
33+
34+
@Override
35+
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
36+
super.appendProperties(builder);
37+
builder.add(NORTH, EAST, SOUTH, WEST, WATERLOGGED);
38+
}
39+
40+
@Override
41+
public BlockState getPlacementState(ItemPlacementContext ctx) {
42+
return updateConnections(
43+
super.getPlacementState(ctx)
44+
.with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER),
45+
ctx.getWorld(),
46+
ctx.getBlockPos()
47+
);
48+
}
49+
50+
@Override
51+
public FluidState getFluidState(BlockState state) {
52+
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
53+
}
54+
55+
@Override
56+
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
57+
if (state.get(WATERLOGGED)) {
58+
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
59+
}
60+
61+
return updateConnections(super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos), world, pos);
62+
}
63+
64+
private BlockState updateConnections(BlockState state, WorldAccess world, BlockPos pos) {
65+
return state.with(NORTH, canConnectTo(world.getBlockState(pos.offset(Direction.NORTH)), Direction.NORTH))
66+
.with(EAST, canConnectTo(world.getBlockState(pos.offset(Direction.EAST)), Direction.EAST))
67+
.with(SOUTH, canConnectTo(world.getBlockState(pos.offset(Direction.SOUTH)), Direction.SOUTH))
68+
.with(WEST, canConnectTo(world.getBlockState(pos.offset(Direction.WEST)), Direction.WEST));
69+
}
70+
71+
@Override
72+
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
73+
return getShapeForKey(
74+
Bits.buildTableState(
75+
state.get(NORTH), state.get(EAST), state.get(SOUTH), state.get(WEST),
76+
isCarpetingEnabled() && state.get(CARPET).isPresent()
77+
)
78+
);
79+
}
80+
81+
protected abstract VoxelShape getShapeForKey(byte key);
82+
83+
@Override
84+
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
85+
return false;
86+
}
87+
}

0 commit comments

Comments
 (0)