1
1
package galena .oreganized .content .block ;
2
2
3
+ import galena .oreganized .OreganizedConfig ;
3
4
import galena .oreganized .index .OBlocks ;
5
+ import galena .oreganized .index .OItems ;
4
6
import galena .oreganized .index .OTags ;
5
7
import net .minecraft .MethodsReturnNonnullByDefault ;
6
8
import net .minecraft .core .BlockPos ;
7
9
import net .minecraft .core .Direction ;
8
- import net .minecraft .core . particles . ParticleTypes ;
10
+ import net .minecraft .server . level . ServerLevel ;
9
11
import net .minecraft .sounds .SoundEvent ;
10
12
import net .minecraft .sounds .SoundEvents ;
11
13
import net .minecraft .sounds .SoundSource ;
12
14
import net .minecraft .tags .FluidTags ;
15
+ import net .minecraft .util .RandomSource ;
13
16
import net .minecraft .world .entity .Entity ;
14
17
import net .minecraft .world .entity .EquipmentSlot ;
15
18
import net .minecraft .world .entity .LivingEntity ;
16
19
import net .minecraft .world .entity .Mob ;
17
20
import net .minecraft .world .level .BlockGetter ;
18
21
import net .minecraft .world .level .Level ;
22
+ import net .minecraft .world .level .LevelAccessor ;
19
23
import net .minecraft .world .level .block .Block ;
20
24
import net .minecraft .world .level .block .LiquidBlock ;
21
25
import net .minecraft .world .level .block .state .BlockState ;
22
26
import net .minecraft .world .level .block .state .StateDefinition ;
23
27
import net .minecraft .world .level .block .state .properties .BooleanProperty ;
24
28
import net .minecraft .world .level .material .FlowingFluid ;
29
+ import net .minecraft .world .level .material .Fluid ;
25
30
import net .minecraft .world .level .pathfinder .BlockPathTypes ;
26
31
import net .minecraft .world .level .pathfinder .PathComputationType ;
27
32
import net .minecraft .world .phys .Vec3 ;
39
44
@ MethodsReturnNonnullByDefault
40
45
public class MoltenLeadBlock extends LiquidBlock {
41
46
42
- public static final BooleanProperty MOVING = BooleanProperty .create ("moving" );
43
-
44
47
public static final VoxelShape STABLE_SHAPE = Block .box (0.0D , 0.0D , 0.0D , 16.0D , 8.0D , 16.0D );
45
48
49
+ public static final BooleanProperty WAITING = BooleanProperty .create ("waiting" );
50
+
46
51
public MoltenLeadBlock (Supplier <? extends FlowingFluid > fluid , Properties properties ) {
47
52
super (fluid , properties .noCollission ().strength (-1.0F , 3600000.0F ).noLootTable ().lightLevel ((state ) -> 8 ));
48
- this .registerDefaultState (this .stateDefinition .any ().setValue (MOVING , false ));
49
- }
50
-
51
- @ Override
52
- protected void createBlockStateDefinition (StateDefinition .Builder <Block , BlockState > builder ) {
53
- super .createBlockStateDefinition (builder );
54
- builder .add (MOVING );
53
+ registerDefaultState (defaultBlockState ().setValue (WAITING , true ));
55
54
}
56
55
57
56
@ Nullable
@@ -61,23 +60,29 @@ public BlockPathTypes getBlockPathType(BlockState state, BlockGetter world, Bloc
61
60
}
62
61
63
62
@ Override
64
- public void onPlace (BlockState pState , Level pLevel , BlockPos pPos , BlockState pOldState , boolean pIsMoving ) {
65
- if (pIsMoving ) {
66
- if (!pOldState .getFluidState ().is (FluidTags .WATER )) {
67
- pLevel .setBlock (pPos , pState .setValue (MOVING , true ), 3 );
68
- } else {
69
- pLevel .levelEvent (1501 , pPos , 0 );
70
- pLevel .setBlock (pPos , OBlocks .LEAD_BLOCK .get ().defaultBlockState (), 3 );
71
- }
72
- } else {
73
- if (!pOldState .getFluidState ().is (FluidTags .WATER )) {
74
- pLevel .setBlock (pPos , pState .setValue (MOVING , false ), 3 );
75
- } else {
76
- pLevel .levelEvent (1501 , pPos , 0 );
77
- pLevel .setBlock (pPos , OBlocks .LEAD_BLOCK .get ().defaultBlockState (), 3 );
63
+ protected void createBlockStateDefinition (StateDefinition .Builder <Block , BlockState > builder ) {
64
+ super .createBlockStateDefinition (builder );
65
+ builder .add (WAITING );
66
+ }
67
+
68
+ @ Override
69
+ public void onPlace (BlockState state , Level level , BlockPos pos , BlockState oldState , boolean isMoving ) {
70
+ if (state .getFluidState ().isSource ()) {
71
+ var oldFluid = oldState .getFluidState ();
72
+ if (oldFluid .is (FluidTags .WATER )) {
73
+ level .levelEvent (1501 , pos , 0 );
74
+ level .setBlock (pos , OBlocks .LEAD_BLOCK .get ().defaultBlockState (), 3 );
75
+ } else if (oldFluid .is (FluidTags .LAVA )) {
76
+ LeadOreBlock .spawnCloud (level , pos , 2F );
77
+ level .setBlockAndUpdate (pos , oldState );
78
78
}
79
79
}
80
- super .onPlace (pState , pLevel , pPos , pOldState , pIsMoving );
80
+
81
+ if (state .getValue (WAITING )) {
82
+ level .scheduleTick (pos , state .getBlock (), OreganizedConfig .COMMON .moltenLeadDelay .get ());
83
+ }
84
+
85
+ super .onPlace (state , level , pos , oldState , isMoving );
81
86
}
82
87
83
88
@ Override
@@ -88,13 +93,28 @@ public VoxelShape getCollisionShape(BlockState blockState, BlockGetter world, Bl
88
93
return super .getCollisionShape (blockState , world , blockPos , ctx );
89
94
}
90
95
96
+ @ Override
97
+ public VoxelShape getShape (BlockState state , BlockGetter level , BlockPos pos , CollisionContext context ) {
98
+ if (context .isHoldingItem (OItems .MOLTEN_LEAD_BUCKET .get ()))
99
+ return level .getBlockState (pos .above ()).is (this ) ? Shapes .block () : STABLE_SHAPE ;
100
+
101
+ return Shapes .empty ();
102
+ }
103
+
104
+ @ Override
105
+ public boolean canBeReplaced (BlockState state , Fluid fluid ) {
106
+ if (getFluid () == fluid ) return false ;
107
+ return super .canBeReplaced (state , fluid );
108
+ }
109
+
91
110
@ Override
92
111
public void onRemove (BlockState state , Level level , BlockPos pos , BlockState replacedWith , boolean dropXp ) {
93
112
super .onRemove (state , level , pos , replacedWith , dropXp );
94
113
95
114
if (replacedWith .isAir () || !replacedWith .getFluidState ().isEmpty ()) return ;
115
+ if (replacedWith .is (OBlocks .LEAD_BLOCK .get ())) return ;
96
116
97
- tryEscape (state , level , pos );
117
+ if ( state . getFluidState (). isSource ()) tryEscape (state , level , pos );
98
118
}
99
119
100
120
private boolean tryEscape (BlockState state , Level level , BlockPos pos , Direction direction ) {
@@ -121,7 +141,7 @@ private boolean tryEscape(BlockState state, Level level, BlockPos pos) {
121
141
}
122
142
}
123
143
124
- return false ;
144
+ return tryEscape ( state , level , pos , Direction . UP ) ;
125
145
}
126
146
127
147
@ Override
@@ -138,9 +158,9 @@ public void entityInside(BlockState state, Level world, BlockPos pos, Entity ent
138
158
139
159
@ Override
140
160
public void fallOn (Level world , BlockState state , BlockPos pos , Entity entity , float fallDistance ) {
141
- if (!(( double ) fallDistance < 4.0D ) && entity instanceof LivingEntity living ) {
161
+ if (fallDistance >= 4.0D && entity instanceof LivingEntity living ) {
142
162
LivingEntity .Fallsounds fallSound = living .getFallSounds ();
143
- SoundEvent sound = ( double ) fallDistance < 7.0D ? fallSound .small () : fallSound .big ();
163
+ SoundEvent sound = fallDistance < 7.0D ? fallSound .small () : fallSound .big ();
144
164
entity .playSound (sound , 1.0F , 1.0F );
145
165
}
146
166
}
@@ -153,6 +173,37 @@ public static boolean isEntityLighterThanLead(Entity entity) {
153
173
}
154
174
}
155
175
176
+ public static boolean shouldWait (LevelAccessor level , BlockPos pos ) {
177
+ var belowPos = pos .below ();
178
+ var belowState = level .getBlockState (belowPos );
179
+ return belowState .isFaceSturdy (level , belowPos , Direction .UP );
180
+ }
181
+
182
+ @ Override
183
+ public void neighborChanged (BlockState state , Level level , BlockPos pos , Block block , BlockPos neighborPos , boolean moving ) {
184
+ super .neighborChanged (state , level , pos , block , neighborPos , moving );
185
+
186
+ var waiting = state .getValue (WAITING );
187
+ var shouldWait = shouldWait (level , pos );
188
+
189
+ if (waiting == shouldWait ) return ;
190
+
191
+ if (shouldWait ) {
192
+ level .setBlockAndUpdate (pos , state .setValue (WAITING , true ));
193
+ } else {
194
+ level .scheduleTick (pos , state .getBlock (), OreganizedConfig .COMMON .moltenLeadDelay .get ());
195
+ }
196
+ }
197
+
198
+ @ Override
199
+ public void tick (BlockState state , ServerLevel level , BlockPos pos , RandomSource random ) {
200
+ super .tick (state , level , pos , random );
201
+
202
+ if (!shouldWait (level , pos )) {
203
+ level .setBlockAndUpdate (pos , state .setValue (WAITING , false ));
204
+ }
205
+ }
206
+
156
207
@ Override
157
208
public Optional <SoundEvent > getPickupSound () {
158
209
return Optional .of (SoundEvents .BUCKET_FILL_LAVA );
0 commit comments