-
Notifications
You must be signed in to change notification settings - Fork 18
/
BlockBlockCrop.java
102 lines (86 loc) · 2.82 KB
/
BlockBlockCrop.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
97
98
99
100
101
102
package knightminer.inspirations.tweaks.block;
import knightminer.inspirations.common.Config;
import knightminer.inspirations.common.IHidable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.CropsBlock;
import net.minecraft.state.IntegerProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.util.Direction;
import net.minecraft.util.IItemProvider;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.World;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.common.PlantType;
import net.minecraftforge.registries.IRegistryDelegate;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public abstract class BlockBlockCrop extends CropsBlock implements IHidable, IPlantable {
protected IRegistryDelegate<Block> block;
protected PlantType type;
protected final VoxelShape[] shape;
public static final IntegerProperty SMALL_AGE = IntegerProperty.create("age", 0, 6);
public BlockBlockCrop(Block block, PlantType type, VoxelShape[] shape, Block.Properties props) {
super(props);
this.block = block.delegate;
this.shape = shape;
this.type = type;
}
@Override
public boolean isEnabled() {
return Config.enableMoreSeeds.get();
}
@Override
public boolean isValidPosition(@Nonnull BlockState state, IWorldReader world, BlockPos pos) {
BlockState soil = world.getBlockState(pos.down());
return soil.canSustainPlant(world, pos, Direction.UP, this);
}
/* Age logic */
@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
builder.add(getAgeProperty());
// No super, we want a different age size!
}
@Nonnull
@Override
public IntegerProperty getAgeProperty() {
return SMALL_AGE;
}
@Nonnull
@Override
public BlockState withAge(int age) {
if(age == getMaxAge()) {
return block.get().getDefaultState();
}
return super.withAge(age);
}
@Override
public boolean isMaxAge(BlockState state) {
// never get to max age, our max is the block
return false;
}
@Nonnull
@Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return shape[this.getAge(state)];
}
@Nonnull
@Override
public VoxelShape getRaytraceShape(@Nonnull BlockState state, @Nonnull IBlockReader world, @Nonnull BlockPos pos) {
return shape[this.getAge(state)];
}
/* Crop drops */
@Nonnull
@Override
protected abstract IItemProvider getSeedsItem();
@Override
public PlantType getPlantType(IBlockReader world, BlockPos pos) {
return type;
}
}