-
Notifications
You must be signed in to change notification settings - Fork 18
/
BlockPath.java
96 lines (83 loc) · 3.35 KB
/
BlockPath.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package knightminer.inspirations.building.block;
import knightminer.inspirations.common.Config;
import knightminer.inspirations.common.block.HidableBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.material.Material;
import net.minecraft.block.material.MaterialColor;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.World;
import net.minecraftforge.common.ToolType;
import javax.annotation.Nonnull;
public class BlockPath extends HidableBlock {
private final VoxelShape shape;
private final VoxelShape collShape;
public BlockPath(VoxelShape shape, MaterialColor mapColor) {
super(Block.Properties.create(Material.ROCK, mapColor)
.hardnessAndResistance(1.5F, 10F)
.harvestTool(ToolType.PICKAXE).harvestLevel(0),
Config.enablePath::get
);
// Each path has a different shape, but use the bounding box for collisions.
this.shape = shape;
this.collShape = VoxelShapes.create(shape.getBoundingBox());
}
/* Block Shape */
public static final VoxelShape SHAPE_ROUND = VoxelShapes.or(
Block.makeCuboidShape(1, 0, 5, 15, 1, 11),
Block.makeCuboidShape(5, 0, 1, 11, 1, 15),
Block.makeCuboidShape(2, 0, 3, 14, 1, 13),
Block.makeCuboidShape(3, 0, 2, 13, 1, 14)
).simplify();
public static final VoxelShape SHAPE_TILE = VoxelShapes.or(
Block.makeCuboidShape(1, 0, 1, 7, 1, 7),
Block.makeCuboidShape(9, 0, 1, 15, 1, 7),
Block.makeCuboidShape(9, 0, 9, 15, 1, 15),
Block.makeCuboidShape(1, 0, 9, 7, 1, 15)
);
public static final VoxelShape SHAPE_BRICK = VoxelShapes.or(
Block.makeCuboidShape(0, 0, 0, 3, 1, 3),
Block.makeCuboidShape(4, 0, 0, 7, 1, 7),
Block.makeCuboidShape(0, 0, 4, 3, 1, 11),
Block.makeCuboidShape(12, 0, 8, 15, 1, 15),
Block.makeCuboidShape(8, 0, 0, 11, 1, 3),
Block.makeCuboidShape(8, 0, 12, 11, 1, 16),
Block.makeCuboidShape(12, 0, 0, 16, 1, 3),
Block.makeCuboidShape(8, 0, 4, 15, 1, 7),
Block.makeCuboidShape(4, 0, 8, 11, 1, 11),
Block.makeCuboidShape(0, 0, 12, 7, 1, 15)
);
// There's multiple variants for these, just use a square.
public static final VoxelShape SHAPE_ROCK = Block.makeCuboidShape(.5, 0, .5, 15.5, 1, 15.5);
@Nonnull
@Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return shape;
}
@Nonnull
@Override
public VoxelShape getCollisionShape(@Nonnull BlockState state, @Nonnull IBlockReader world, @Nonnull BlockPos pos, ISelectionContext context) {
return collShape;
}
/* Solid surface below */
@Override
public boolean isValidPosition(BlockState state, IWorldReader world, BlockPos pos) {
return super.isValidPosition(state, world, pos) && this.canBlockStay(world, pos);
}
private boolean canBlockStay(IWorldReader world, BlockPos pos) {
BlockPos down = pos.down();
return Block.hasSolidSide(world.getBlockState(down), world, pos, Direction.UP);
}
@Override
public void neighborChanged(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos, boolean p_220069_6_) {
if (!this.canBlockStay(world, pos)) {
world.destroyBlock(pos, true);
}
}
}