|
13 | 13 | import net.minecraft.world.level.BlockGetter; |
14 | 14 | import net.minecraft.world.level.block.Blocks; |
15 | 15 | import net.minecraft.world.level.block.state.BlockState; |
| 16 | +import net.minecraft.world.phys.shapes.Shapes; |
16 | 17 | import net.minecraft.world.phys.shapes.VoxelShape; |
17 | 18 | import org.jetbrains.annotations.NotNull; |
18 | 19 | import org.jetbrains.annotations.Nullable; |
@@ -66,17 +67,28 @@ public RapierVoxelColliderBakery(@NotNull final BlockGetter blockGetter) { |
66 | 67 | return entry; |
67 | 68 | } |
68 | 69 |
|
69 | | - final VoxelShape shape; |
| 70 | + VoxelShape shape = Shapes.empty(); |
70 | 71 |
|
71 | | - this.level.setup(childState); |
72 | | - if (childState.getBlock() instanceof final BlockSubLevelCollisionShape extension) { |
73 | | - shape = extension.getSubLevelCollisionShape(this.level, childState); |
74 | | - } else { |
75 | | - shape = childState.getCollisionShape(this.level, BlockPos.ZERO, SableCollisionContext.get()); |
| 72 | + // if mods have complicated multiblocks, we catch it |
| 73 | + try { |
| 74 | + this.level.setup(childState); |
| 75 | + |
| 76 | + if (childState.getBlock() instanceof final BlockSubLevelCollisionShape extension) { |
| 77 | + shape = extension.getSubLevelCollisionShape(this.level, childState); |
| 78 | + } else { |
| 79 | + shape = childState.getCollisionShape(this.level, BlockPos.ZERO, SableCollisionContext.get()); |
| 80 | + } |
| 81 | + } catch (Exception e) { |
| 82 | + System.err.println("[Sable] Failed to get collision shape for block " |
| 83 | + + childState.getBlock().getDescriptionId() |
| 84 | + + ". Defaulting to empty shape to prevent crash."); |
| 85 | + e.printStackTrace(); |
| 86 | + shape = Shapes.empty(); |
| 87 | + } finally { |
| 88 | + this.level.setup(Blocks.AIR.defaultBlockState()); |
76 | 89 | } |
77 | | - this.level.setup(Blocks.AIR.defaultBlockState()); |
78 | 90 |
|
79 | | - if (shape.isEmpty()) { |
| 91 | + if (shape == null || shape.isEmpty()) { |
80 | 92 | return RapierVoxelColliderData.EMPTY; |
81 | 93 | } |
82 | 94 |
|
|
0 commit comments