3
3
import com .google .common .collect .Lists ;
4
4
import com .jme3 .bullet .collision .shapes .CollisionShape ;
5
5
import com .jme3 .bullet .objects .PhysicsRigidBody ;
6
+ import com .jme3 .math .Vector3f ;
6
7
import dev .lazurite .rayon .core .impl .RayonCoreCommon ;
7
8
import dev .lazurite .rayon .core .impl .physics .space .body .BlockRigidBody ;
8
9
import dev .lazurite .rayon .core .impl .physics .space .body .shape .BoundingBoxShape ;
@@ -118,16 +119,20 @@ public void load(TerrainLoading terrainLoading, Box box) {
118
119
119
120
BlockEntity blockEntity = world .getBlockEntity (blockPos );
120
121
121
- if (blockEntity != null ) {
122
- pattern = Disassembler .getBlockEntity (blockEntity , transformation );
123
- } else {
124
- pattern = Disassembler .getBlock (blockState , blockPos , world , transformation );
122
+ try {
123
+ if (blockEntity != null ) {
124
+ pattern = Disassembler .getBlockEntity (blockEntity , transformation );
125
+ } else {
126
+ pattern = Disassembler .getBlock (blockState , blockPos , world , transformation );
127
+ }
128
+ } catch (Exception e ) {
129
+ pattern = null ;
125
130
}
126
131
} else {
127
132
pattern = PatternBuffer .getBlockBuffer (world ).get (blockPos );
128
133
}
129
134
130
- if (pattern != null ) {
135
+ if (pattern != null && ! blockState . getBlock (). equals ( Blocks . GRASS_PATH ) ) {
131
136
if (body .getCollisionShape () instanceof PatternShape ) {
132
137
if (!pattern .equals (((PatternShape ) body .getCollisionShape ()).getPattern ())) {
133
138
body .setCollisionShape (new PatternShape (pattern ));
@@ -143,6 +148,15 @@ public void load(TerrainLoading terrainLoading, Box box) {
143
148
PatternBuffer .getBlockBuffer (world ).put (pattern );
144
149
}
145
150
}
151
+ } else {
152
+ VoxelShape voxel = blockState .getCollisionShape (world , blockPos );
153
+
154
+ if (!voxel .isEmpty ()) {
155
+ body .setCollisionShape (new BoundingBoxShape (voxel .getBoundingBox ()));
156
+ body .setPhysicsLocation (new Vector3f (blockPos .getX () + 0.5f , blockPos .getY () + (float ) voxel .getBoundingBox ().getCenter ().y , blockPos .getZ () + 0.5f ));
157
+ } else {
158
+ body .setCollisionShape (new BoundingBoxShape (new Box (-0.5f , -0.5f , -0.5f , 0.5f , 0.5f , 0.5f )));
159
+ }
146
160
}
147
161
} else if (body .getCollisionShape () instanceof PatternShape ) {
148
162
VoxelShape voxel = blockState .getCollisionShape (world , blockPos );
0 commit comments