1- package dev .manifold .phyics .collision ;
2-
3- import net .minecraft .core .BlockPos ;
4- import net .minecraft .world .level .Level ;
5- import net .minecraft .world .level .block .state .BlockState ;
6- import net .minecraft .world .phys .AABB ;
7- import net .minecraft .world .phys .shapes .VoxelShape ;
8-
9- import java .util .*;
10-
11- public class ConstructCollisionManager {
12- private final Map <UUID , List <CollisionEntry >> shapesByConstruct = new HashMap <>();
13-
14- public void updateCollision (UUID id , Level level , BlockPos origin , BlockPos min , BlockPos max ) {
15- List <CollisionEntry > shapes = new ArrayList <>();
16- for (BlockPos pos : BlockPos .betweenClosed (min .offset (origin ), max .offset (origin ))) {
17- BlockState state = level .getBlockState (pos );
18- if (!state .isAir ()) {
19- VoxelShape shape = state .getCollisionShape (level , pos );
20- if (!shape .isEmpty ()) {
21- double friction = state .getBlock ().getFriction ();
22- shapes .add (new CollisionEntry (
23- shape .move (pos .getX () - origin .getX (), pos .getY () - origin .getY (), pos .getZ () - origin .getZ ()),
24- shape .bounds ().move (pos .getX () - origin .getX (), pos .getY () - origin .getY (), pos .getZ () - origin .getZ ()),
25- friction
26- ));
27- }
28- }
29- }
30- shapesByConstruct .put (id , shapes );
31- }
32-
33- public void remove (UUID id ) {
34- shapesByConstruct .remove (id );
35- }
36-
37- public List <CollisionEntry > getCollisionShapesWithFriction (UUID id ) {
38- return shapesByConstruct .getOrDefault (id , List .of ());
39- }
40-
41- public static class CollisionEntry {
42- public final VoxelShape shape ;
43- public final AABB shapeBounds ;
44- public final double friction ;
45-
46- public CollisionEntry (VoxelShape shape , AABB bounds , double friction ) {
47- this .shape = shape ;
48- this .shapeBounds = bounds ;
49- this .friction = friction ;
50- }
51- }
1+ package dev .manifold .physics .collision ;
2+
3+ import net .minecraft .core .BlockPos ;
4+ import net .minecraft .world .level .Level ;
5+ import net .minecraft .world .level .block .state .BlockState ;
6+ import net .minecraft .world .phys .AABB ;
7+ import net .minecraft .world .phys .shapes .VoxelShape ;
8+
9+ import java .util .*;
10+
11+ public class ConstructCollisionManager {
12+ private final Map <UUID , List <CollisionEntry >> shapesByConstruct = new HashMap <>();
13+
14+ public void updateCollision (UUID id , Level level , BlockPos origin , BlockPos min , BlockPos max ) {
15+ List <CollisionEntry > shapes = new ArrayList <>();
16+ for (BlockPos pos : BlockPos .betweenClosed (min .offset (origin ), max .offset (origin ))) {
17+ BlockState state = level .getBlockState (pos );
18+ if (!state .isAir ()) {
19+ VoxelShape shape = state .getCollisionShape (level , pos );
20+ if (!shape .isEmpty ()) {
21+ double friction = state .getBlock ().getFriction ();
22+ shapes .add (new CollisionEntry (
23+ shape .move (pos .getX () - origin .getX (), pos .getY () - origin .getY (), pos .getZ () - origin .getZ ()),
24+ shape .bounds ().move (pos .getX () - origin .getX (), pos .getY () - origin .getY (), pos .getZ () - origin .getZ ()),
25+ friction
26+ ));
27+ }
28+ }
29+ }
30+ shapesByConstruct .put (id , shapes );
31+ }
32+
33+ public void remove (UUID id ) {
34+ shapesByConstruct .remove (id );
35+ }
36+
37+ public List <CollisionEntry > getCollisionShapesWithFriction (UUID id ) {
38+ return shapesByConstruct .getOrDefault (id , List .of ());
39+ }
40+
41+ public static class CollisionEntry {
42+ public final VoxelShape shape ;
43+ public final AABB shapeBounds ;
44+ public final double friction ;
45+
46+ public CollisionEntry (VoxelShape shape , AABB bounds , double friction ) {
47+ this .shape = shape ;
48+ this .shapeBounds = bounds ;
49+ this .friction = friction ;
50+ }
51+ }
5252}
0 commit comments