forked from ethanicusss/AstralAdditions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDroptusBlock.java
More file actions
115 lines (101 loc) · 4.47 KB
/
DroptusBlock.java
File metadata and controls
115 lines (101 loc) · 4.47 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.github.ethanicuss.astraladditions.blocks;
import com.github.ethanicuss.astraladditions.registry.ModBlocks;
import com.github.ethanicuss.astraladditions.registry.ModData;
import net.minecraft.block.*;
import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.server.world.ServerWorld;
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.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import java.util.Random;
public class DroptusBlock extends Block {
public static final IntProperty AGE = Properties.AGE_2;
public static final BooleanProperty LIT = Properties.LIT;
protected static final VoxelShape OUTLINE_SHAPE_0 = Block.createCuboidShape(5.0, 8.0, 5.0, 11.0, 16.0, 11.0);
protected static final VoxelShape OUTLINE_SHAPE_1 = Block.createCuboidShape(3.0, 0.0, 3.0, 13.0, 16.0, 13.0);
protected static final VoxelShape OUTLINE_SHAPE_2 = Block.createCuboidShape(1.0, 0.0, 1.0, 15.0, 16.0, 15.0);
public DroptusBlock(AbstractBlock.Settings settings) {
super(settings);
this.setDefaultState((BlockState)((BlockState)this.stateManager.getDefaultState()).with(AGE, 0));
this.setDefaultState((BlockState)((BlockState)this.stateManager.getDefaultState()).with(LIT, false));
}
@Override
public boolean hasRandomTicks(BlockState state) {
return state.get(AGE) < 3;
}
@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
int j = state.get(AGE);
if (j < 2) {
world.setBlockState(pos, (BlockState)state.with(AGE, j + 1), Block.NOTIFY_LISTENERS);
if (j == 1){
world.setBlockState(pos, (BlockState)state.with(LIT, true).with(AGE, 2), Block.NOTIFY_LISTENERS);
return;
}
}
int i = 1;
while (world.getBlockState(pos.up(i)).isOf(this)) {
++i;
}
BlockPos blockPos = pos.down();
if (i < 4) {
if (world.getBlockState(blockPos).isAir()) {
world.setBlockState(blockPos, this.getDefaultState());
}
}
}
@Override
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (!state.canPlaceAt(world, pos)) {
world.breakBlock(pos, true);
}
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (!state.canPlaceAt(world, pos)) {
world.createAndScheduleBlockTick(pos, this, 1);
}
return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
if (!world.getBlockState(pos).isAir() && !world.getBlockState(pos).isOf(ModBlocks.BULBA_BLOCK)){
return false;
}
BlockState blockState2 = world.getBlockState(pos.up());
return ((blockState2.isOf(ModBlocks.BULBA_BLOCK) && blockState2.get(AGE) != 0) || blockState2.isOf(ModBlocks.MOONSET_CRYSTAL_BLOCK) || blockState2.isIn(ModData.BULBA_GROWABLE));
}
@Override
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return switch (state.get(AGE)) {
case 0 -> OUTLINE_SHAPE_0;
case 1 -> OUTLINE_SHAPE_1;
case 2 -> OUTLINE_SHAPE_2;
default -> OUTLINE_SHAPE_2;
};
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return switch (state.get(AGE)) {
case 0 -> OUTLINE_SHAPE_0;
case 1 -> OUTLINE_SHAPE_1;
case 2 -> OUTLINE_SHAPE_2;
default -> OUTLINE_SHAPE_2;
};
}
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(AGE);
builder.add(LIT);
}
@Override
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
return false;
}
}