1
1
package galena .oreganized .content .block ;
2
2
3
- import galena .oreganized .OreganizedConfig ;
4
3
import galena .oreganized .index .OBlocks ;
5
- import galena .oreganized .index .OEffects ;
6
- import galena .oreganized .index .OItems ;
7
4
import galena .oreganized .index .OTags ;
8
5
import net .minecraft .MethodsReturnNonnullByDefault ;
9
6
import net .minecraft .core .BlockPos ;
10
7
import net .minecraft .core .Direction ;
11
- import net .minecraft .server . level . ServerLevel ;
8
+ import net .minecraft .core . particles . ParticleTypes ;
12
9
import net .minecraft .sounds .SoundEvent ;
13
10
import net .minecraft .sounds .SoundEvents ;
14
- import net .minecraft .tags . BlockTags ;
11
+ import net .minecraft .sounds . SoundSource ;
15
12
import net .minecraft .tags .FluidTags ;
16
- import net .minecraft .util .RandomSource ;
17
- import net .minecraft .world .effect .MobEffectInstance ;
18
- import net .minecraft .world .effect .MobEffects ;
19
13
import net .minecraft .world .entity .Entity ;
20
14
import net .minecraft .world .entity .EquipmentSlot ;
21
15
import net .minecraft .world .entity .LivingEntity ;
22
16
import net .minecraft .world .entity .Mob ;
23
- import net .minecraft .world .item .context .BlockPlaceContext ;
24
17
import net .minecraft .world .level .BlockGetter ;
25
18
import net .minecraft .world .level .Level ;
26
- import net .minecraft .world .level .LevelAccessor ;
27
19
import net .minecraft .world .level .block .Block ;
28
- import net .minecraft .world .level .block .Blocks ;
29
20
import net .minecraft .world .level .block .LiquidBlock ;
30
21
import net .minecraft .world .level .block .state .BlockState ;
31
22
import net .minecraft .world .level .block .state .StateDefinition ;
48
39
@ MethodsReturnNonnullByDefault
49
40
public class MoltenLeadBlock extends LiquidBlock {
50
41
51
- private static final BooleanProperty MOVING = BooleanProperty .create ( "moving" );
42
+ public static final BooleanProperty MOVING = BooleanProperty .create ("moving" );
52
43
53
44
public static final VoxelShape STABLE_SHAPE = Block .box (0.0D , 0.0D , 0.0D , 16.0D , 8.0D , 16.0D );
54
45
@@ -58,74 +49,37 @@ public MoltenLeadBlock(Supplier<? extends FlowingFluid> fluid, Properties proper
58
49
}
59
50
60
51
@ Override
61
- protected void createBlockStateDefinition (StateDefinition .Builder <Block , BlockState > builder ) {
52
+ protected void createBlockStateDefinition (StateDefinition .Builder <Block , BlockState > builder ) {
62
53
super .createBlockStateDefinition (builder );
63
54
builder .add (MOVING );
64
55
}
65
56
66
- @ Override
67
- public BlockState updateShape (BlockState pState , Direction pDirection , BlockState neighbour , LevelAccessor pLevel , BlockPos pPos , BlockPos neighbourPos ) {
68
- if (pDirection == Direction .DOWN ){
69
- pLevel .scheduleTick ( pPos , this , 30 );
70
- }
71
- return super .updateShape ( pState , pDirection , neighbour , pLevel , pPos , neighbourPos );
72
- }
73
-
74
57
@ Nullable
75
58
@ Override
76
59
public BlockPathTypes getBlockPathType (BlockState state , BlockGetter world , BlockPos pos , @ Nullable Mob entity ) {
77
60
return BlockPathTypes .WALKABLE ;
78
61
}
79
62
80
63
@ Override
81
- public boolean canEntityDestroy ( BlockState state , BlockGetter world , BlockPos pos , Entity entity ){
82
- return false ;
83
- }
84
-
85
- @ Override
86
- public void onPlace ( BlockState pState , Level pLevel , BlockPos pPos , BlockState pOldState , boolean pIsMoving ){
87
- if (pIsMoving ){
88
- if (!pOldState .getFluidState ().is ( FluidTags .WATER )){
89
- scheduleFallingTick ( pLevel , pPos , 30 );
90
- pLevel .setBlock ( pPos , pState .setValue ( MOVING , true ) , 3 );
91
- }else {
92
- pLevel .levelEvent ( 1501 , pPos , 0 );
93
- pLevel .setBlock ( pPos , OBlocks .LEAD_BLOCK .get ().defaultBlockState () , 3 );
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 );
94
71
}
95
72
} else {
96
- if (!pOldState .getFluidState ().is ( FluidTags .WATER )){
97
- pLevel .setBlock ( pPos , pState .setValue ( MOVING , false ) , 3 );
98
- pLevel .scheduleTick ( pPos , this , 300 );
99
- }else {
100
- pLevel .levelEvent ( 1501 , pPos , 0 );
101
- pLevel .setBlock ( pPos , OBlocks .LEAD_BLOCK .get ().defaultBlockState () , 3 );
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 );
102
78
}
103
79
}
104
80
super .onPlace (pState , pLevel , pPos , pOldState , pIsMoving );
105
81
}
106
82
107
- @ Override
108
- public void tick (BlockState pState , ServerLevel pLevel , BlockPos pPos , RandomSource pRandom ){
109
- if (pLevel .getBlockState (pPos .below ()).getBlock () == Blocks .AIR || pLevel .getBlockState (pPos .below ()).is (BlockTags .REPLACEABLE )
110
- || pLevel .getBlockState (pPos .below ()).getFluidState ().is (FluidTags .WATER )
111
- || pLevel .getBlockState (pPos .below ()).is (BlockTags .SMALL_FLOWERS )
112
- || pLevel .getBlockState (pPos .below ()).is (BlockTags .TALL_FLOWERS )){
113
- pLevel .setBlock ( pPos , Blocks .AIR .defaultBlockState () , 67 );
114
- pLevel .setBlock ( pPos .below () , OBlocks .MOLTEN_LEAD .get ().defaultBlockState () , 67 );
115
- }
116
- }
117
-
118
- private boolean scheduleFallingTick ( LevelAccessor pLevel , BlockPos pPos , int pDelay ){
119
- if (pLevel .getBlockState ( pPos .below () ).getBlock () == Blocks .AIR || pLevel .getBlockState (pPos .below ()).is (BlockTags .REPLACEABLE )
120
- || pLevel .getBlockState ( pPos .below () ).getFluidState ().is (FluidTags .WATER )
121
- || pLevel .getBlockState ( pPos .below () ).is (BlockTags .SMALL_FLOWERS )
122
- || pLevel .getBlockState (pPos .below ()).is (BlockTags .TALL_FLOWERS )){
123
- pLevel .scheduleTick ( pPos , this , pDelay );
124
- return true ;
125
- }
126
- return false ;
127
- }
128
-
129
83
@ Override
130
84
public VoxelShape getCollisionShape (BlockState blockState , BlockGetter world , BlockPos blockPos , CollisionContext ctx ) {
131
85
if (ctx instanceof EntityCollisionContext eCtx && eCtx .getEntity () != null )
@@ -135,18 +89,40 @@ public VoxelShape getCollisionShape(BlockState blockState, BlockGetter world, Bl
135
89
}
136
90
137
91
@ Override
138
- public VoxelShape getShape (BlockState state , BlockGetter blockWorld , BlockPos pos , CollisionContext context ) {
139
- if (context .isHoldingItem (OItems .MOLTEN_LEAD_BUCKET .get ()))
140
- return blockWorld .getBlockState (pos .above ()) != state ? STABLE_SHAPE : Shapes .block ();
92
+ public void onRemove (BlockState state , Level level , BlockPos pos , BlockState replacedWith , boolean dropXp ) {
93
+ super .onRemove (state , level , pos , replacedWith , dropXp );
94
+
95
+ if (replacedWith .isAir () || !replacedWith .getFluidState ().isEmpty ()) return ;
141
96
142
- return Shapes . empty ( );
97
+ tryEscape ( state , level , pos );
143
98
}
144
99
145
- @ Override
146
- public boolean canBeReplaced (BlockState state , BlockPlaceContext context ) {
147
- return state .is (Blocks .LAVA );
100
+ private boolean tryEscape (BlockState state , Level level , BlockPos pos , Direction direction ) {
101
+ var adjancentPos = pos .relative (direction );
102
+ var adjacentState = level .getBlockState (adjancentPos );
103
+ if (adjacentState .canBeReplaced (getFluid ())) {
104
+ level .setBlockAndUpdate (adjancentPos , state );
105
+
106
+ getPickupSound ().ifPresent (sound -> {
107
+ level .playSound (null , pos , sound , SoundSource .BLOCKS , 1F , 1F );
108
+ });
109
+
110
+ return true ;
111
+ }
112
+
113
+ return false ;
148
114
}
149
115
116
+ private boolean tryEscape (BlockState state , Level level , BlockPos pos ) {
117
+ if (tryEscape (state , level , pos , Direction .DOWN )) return true ;
118
+ for (var direction : Direction .allShuffled (level .random )) {
119
+ if (direction .getAxis ().isHorizontal () && tryEscape (state , level , pos , direction )) {
120
+ return true ;
121
+ }
122
+ }
123
+
124
+ return false ;
125
+ }
150
126
151
127
@ Override
152
128
public void entityInside (BlockState state , Level world , BlockPos pos , Entity entity ) {
@@ -155,22 +131,16 @@ public void entityInside(BlockState state, Level world, BlockPos pos, Entity ent
155
131
entity .makeStuckInBlock (state , new Vec3 (0.9F , 1.0D , 0.9F ));
156
132
}
157
133
158
- if (entity instanceof LivingEntity living && living .isUsingItem () && living .getUseItemRemainingTicks () == 0 && living .getItemInHand (living .getUsedItemHand ()).isEdible ()) {
159
- if (!OreganizedConfig .COMMON .poisonInsteadOfStunning .get ()) {
160
- living .addEffect (new MobEffectInstance (OEffects .STUNNING .get (), 40 * 20 ));
161
- }
162
- living .addEffect (new MobEffectInstance (MobEffects .POISON , 200 ));
163
- }
164
134
entity .setSecondsOnFire (10 );
165
135
if (!world .isClientSide ) entity .setSharedFlagOnFire (true );
166
136
}
167
137
}
168
138
169
139
@ Override
170
140
public void fallOn (Level world , BlockState state , BlockPos pos , Entity entity , float fallDistance ) {
171
- if (!((double )fallDistance < 4.0D ) && entity instanceof LivingEntity living ) {
141
+ if (!((double ) fallDistance < 4.0D ) && entity instanceof LivingEntity living ) {
172
142
LivingEntity .Fallsounds fallSound = living .getFallSounds ();
173
- SoundEvent sound = (double )fallDistance < 7.0D ? fallSound .small () : fallSound .big ();
143
+ SoundEvent sound = (double ) fallDistance < 7.0D ? fallSound .small () : fallSound .big ();
174
144
entity .playSound (sound , 1.0F , 1.0F );
175
145
}
176
146
}
@@ -179,7 +149,7 @@ public static boolean isEntityLighterThanLead(Entity entity) {
179
149
if (entity .getType ().is (OTags .Entities .LIGHTER_THAN_LEAD )) {
180
150
return true ;
181
151
} else {
182
- return entity instanceof LivingEntity && (( LivingEntity ) entity ) .getItemBySlot (EquipmentSlot .FEET ).is (OTags .Items .LIGHTER_THAN_LEAD );
152
+ return entity instanceof LivingEntity living && living .getItemBySlot (EquipmentSlot .FEET ).is (OTags .Items .LIGHTER_THAN_LEAD );
183
153
}
184
154
}
185
155
0 commit comments