9
9
import net .minecraft .world .entity .Entity ;
10
10
import net .minecraft .world .entity .LivingEntity ;
11
11
import net .minecraft .world .entity .item .FallingBlockEntity ;
12
+ import net .minecraft .world .level .BlockGetter ;
12
13
import net .minecraft .world .level .Level ;
14
+ import net .minecraft .world .level .block .Block ;
13
15
import net .minecraft .world .level .block .FallingBlock ;
14
16
import net .minecraft .world .level .block .state .BlockState ;
15
17
import net .minecraft .world .phys .Vec3 ;
18
+ import net .minecraft .world .phys .shapes .CollisionContext ;
19
+ import net .minecraft .world .phys .shapes .EntityCollisionContext ;
20
+ import net .minecraft .world .phys .shapes .Shapes ;
21
+ import net .minecraft .world .phys .shapes .VoxelShape ;
16
22
import net .minecraftforge .client .extensions .common .IClientBlockExtensions ;
17
23
18
24
import java .util .function .Consumer ;
19
25
20
26
public class BonePileBlock extends FallingBlock {
21
27
28
+ protected static final VoxelShape SHAPE = Block .box (0.0 , 0.0 , 0.0 , 16.0 , 13.0 , 16.0 );
29
+
30
+ private static StatePredicate ALWAYS = (s , l , p ) -> true ;
31
+
22
32
public BonePileBlock (Properties properties ) {
23
- super (properties );
33
+ super (properties .isRedstoneConductor (ALWAYS ).isSuffocating (ALWAYS ).isViewBlocking (ALWAYS ).noParticlesOnBreak ());
34
+ }
35
+
36
+ public VoxelShape getCollisionShape (BlockState state , BlockGetter level , BlockPos pos , CollisionContext context ) {
37
+ // For particles
38
+ if (context instanceof EntityCollisionContext ec && (ec .getEntity () == null || ec .getEntity () instanceof FallingBlockEntity )) return Shapes .block ();
39
+ return SHAPE ;
40
+ }
41
+
42
+ public VoxelShape getBlockSupportShape (BlockState state , BlockGetter level , BlockPos pos ) {
43
+ return Shapes .block ();
44
+ }
45
+
46
+ public VoxelShape getVisualShape (BlockState state , BlockGetter level , BlockPos pos , CollisionContext context ) {
47
+ return Shapes .block ();
24
48
}
25
49
26
50
@ Override
27
51
public void onLand (Level level , BlockPos pos , BlockState state , BlockState other , FallingBlockEntity entity ) {
28
52
super .onLand (level , pos , state , other , entity );
29
- if (!entity .isSilent ()) level .playSound (null , pos , OSoundEvents .BONE_PILE_FALL .get (), SoundSource .BLOCKS , 1F , 1F );
53
+ if (!entity .isSilent ())
54
+ level .playSound (null , pos , OSoundEvents .BONE_PILE_FALL .get (), SoundSource .BLOCKS , 1F , 1F );
30
55
particles (level , Vec3 .atCenterOf (pos ), 10 );
31
56
}
32
57
33
58
@ Override
34
59
public boolean addLandingEffects (BlockState state , ServerLevel level , BlockPos pos , BlockState other , LivingEntity entity , int numberOfParticles ) {
35
- particles (level , entity .position (), numberOfParticles / 2 );
60
+ particles (level , entity .position (). add ( 0 , 0.2 , 0.0 ) , numberOfParticles / 2 );
36
61
return true ;
37
62
}
38
63
39
64
@ Override
40
65
public boolean addRunningEffects (BlockState state , Level level , BlockPos pos , Entity entity ) {
41
- var vec = entity .position ();
42
- level .addParticle (OParticleTypes .BONE_FRAGMENT .get (), vec .x , vec .y , vec .z , level .random .nextDouble () - 0.5 , level .random .nextDouble () - 0.5 , level .random .nextDouble () - 0.5 );
66
+ var vec = entity .position ().add (0 , 0.2 , 0.0 );
67
+ var speed = entity .isSprinting () ? 0.5F : 0.2F ;
68
+ var halfSpeed = speed / 2 ;
69
+ level .addParticle (OParticleTypes .BONE_FRAGMENT .get (), vec .x , vec .y , vec .z , level .random .nextDouble () * speed - halfSpeed , level .random .nextDouble () * speed - halfSpeed , level .random .nextDouble () * speed - halfSpeed );
43
70
return true ;
44
71
}
45
72
@@ -50,11 +77,11 @@ public void initializeClient(Consumer<IClientBlockExtensions> consumer) {
50
77
51
78
private void particles (Level level , Vec3 vec , int numberOfParticles ) {
52
79
if (level instanceof ServerLevel serverLevel ) {
53
- serverLevel .sendParticles (OParticleTypes .BONE_FRAGMENT .get (), vec .x , vec .y , vec .z , numberOfParticles , level . random . nextDouble () - 0.5 , level . random . nextDouble () - 0.5 , level . random . nextDouble () - 0.5 , 0.0 );
80
+ serverLevel .sendParticles (OParticleTypes .BONE_FRAGMENT .get (), vec .x , vec .y , vec .z , numberOfParticles , 0.35 , 0.35 , 0.35 , 0.1 );
54
81
} else for (int i = 0 ; i < numberOfParticles ; i ++) {
55
82
level .addParticle (OParticleTypes .BONE_FRAGMENT .get (),
56
83
vec .x + level .random .nextDouble () - 0.5 , vec .y + level .random .nextDouble () - 0.5 , vec .z + level .random .nextDouble () - 0.5 ,
57
- level .random .nextDouble () - 0.5 , level .random .nextDouble () - 0.5 , level .random .nextDouble () - 0.5
84
+ level .random .nextDouble () * 0.3 - 0.15 , level .random .nextDouble () * 0.3 - 0.15 , level .random .nextDouble () * 0.3 - 0.15
58
85
);
59
86
}
60
87
}
0 commit comments