Skip to content

Commit b1d90fa

Browse files
committed
Correct typo of physics
1 parent cdb064f commit b1d90fa

6 files changed

Lines changed: 336 additions & 336 deletions

File tree

src/main/java/dev/manifold/ConstructManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import dev.manifold.network.packets.BreakInConstructC2SPacket;
88
import dev.manifold.network.packets.ConstructSectionDataS2CPacket;
99
import dev.manifold.network.packets.RemoveConstructS2CPacket;
10-
import dev.manifold.phyics.collision.ConstructCollisionManager;
10+
import dev.manifold.physics.collision.ConstructCollisionManager;
1111
import io.netty.buffer.Unpooled;
1212
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
1313
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
package dev.manifold.mixin;
2-
3-
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
4-
import dev.manifold.phyics.collision.RotatedCollisionHandler;
5-
import net.minecraft.world.entity.Entity;
6-
import net.minecraft.world.phys.AABB;
7-
import net.minecraft.world.phys.Vec3;
8-
import org.spongepowered.asm.mixin.Mixin;
9-
import org.spongepowered.asm.mixin.Shadow;
10-
import org.spongepowered.asm.mixin.injection.At;
11-
12-
@Mixin(Entity.class)
13-
public abstract class EntityMixin {
14-
@Shadow
15-
public abstract AABB getBoundingBox();
16-
17-
@ModifyReturnValue(
18-
method = "collide(Lnet/minecraft/world/phys/Vec3;)Lnet/minecraft/world/phys/Vec3;",
19-
at = @At("RETURN")
20-
)
21-
private Vec3 onCollideReturn(Vec3 original) {
22-
Entity self = (Entity) (Object) this;
23-
return RotatedCollisionHandler.collideWithConstructs(original, getBoundingBox());
24-
}
25-
}
26-
1+
package dev.manifold.mixin;
2+
3+
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
4+
import dev.manifold.physics.collision.RotatedCollisionHandler;
5+
import net.minecraft.world.entity.Entity;
6+
import net.minecraft.world.phys.AABB;
7+
import net.minecraft.world.phys.Vec3;
8+
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.Shadow;
10+
import org.spongepowered.asm.mixin.injection.At;
11+
12+
@Mixin(Entity.class)
13+
public abstract class EntityMixin {
14+
@Shadow
15+
public abstract AABB getBoundingBox();
16+
17+
@ModifyReturnValue(
18+
method = "collide(Lnet/minecraft/world/phys/Vec3;)Lnet/minecraft/world/phys/Vec3;",
19+
at = @At("RETURN")
20+
)
21+
private Vec3 onCollideReturn(Vec3 original) {
22+
Entity self = (Entity) (Object) this;
23+
return RotatedCollisionHandler.collideWithConstructs(original, getBoundingBox());
24+
}
25+
}
26+

src/main/java/dev/manifold/phyics/collision/ConstructCollisionManager.java renamed to src/main/java/dev/manifold/physics/collision/ConstructCollisionManager.java

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
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
}
Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
package dev.manifold.phyics.collision;
2-
3-
import net.minecraft.world.phys.AABB;
4-
import net.minecraft.world.phys.Vec3;
5-
import org.joml.Matrix3f;
6-
import org.joml.Vector3f;
7-
8-
public class OBB {
9-
public Vec3 center;
10-
public Vec3 halfSize;
11-
public Matrix3f rotation;
12-
13-
public OBB(Vec3 center, Vec3 halfSize, Matrix3f rotation) {
14-
this.center = center;
15-
this.halfSize = halfSize;
16-
this.rotation = new Matrix3f(rotation);
17-
}
18-
19-
public static OBB fromAABB(AABB box, Matrix3f rotation) {
20-
double centerX = (box.minX + box.maxX) / 2.0;
21-
double centerY = (box.minY + box.maxY) / 2.0;
22-
double centerZ = (box.minZ + box.maxZ) / 2.0;
23-
24-
double halfX = (box.maxX - box.minX) / 2.0;
25-
double halfY = (box.maxY - box.minY) / 2.0;
26-
double halfZ = (box.maxZ - box.minZ) / 2.0;
27-
28-
Vector3f localCenter = new Vector3f((float) centerX, (float) centerY, (float) centerZ);
29-
rotation.transform(localCenter);
30-
31-
Vec3 finalCenter = new Vec3(localCenter.x, localCenter.y, localCenter.z);
32-
return new OBB(finalCenter, new Vec3(halfX, halfY, halfZ), rotation);
33-
}
34-
35-
public OBB move(Vec3 origin) {
36-
this.center = this.center.add(origin);
37-
this.halfSize = this.halfSize.add(origin);
38-
return this;
39-
}
1+
package dev.manifold.physics.collision;
2+
3+
import net.minecraft.world.phys.AABB;
4+
import net.minecraft.world.phys.Vec3;
5+
import org.joml.Matrix3f;
6+
import org.joml.Vector3f;
7+
8+
public class OBB {
9+
public Vec3 center;
10+
public Vec3 halfSize;
11+
public Matrix3f rotation;
12+
13+
public OBB(Vec3 center, Vec3 halfSize, Matrix3f rotation) {
14+
this.center = center;
15+
this.halfSize = halfSize;
16+
this.rotation = new Matrix3f(rotation);
17+
}
18+
19+
public static OBB fromAABB(AABB box, Matrix3f rotation) {
20+
double centerX = (box.minX + box.maxX) / 2.0;
21+
double centerY = (box.minY + box.maxY) / 2.0;
22+
double centerZ = (box.minZ + box.maxZ) / 2.0;
23+
24+
double halfX = (box.maxX - box.minX) / 2.0;
25+
double halfY = (box.maxY - box.minY) / 2.0;
26+
double halfZ = (box.maxZ - box.minZ) / 2.0;
27+
28+
Vector3f localCenter = new Vector3f((float) centerX, (float) centerY, (float) centerZ);
29+
rotation.transform(localCenter);
30+
31+
Vec3 finalCenter = new Vec3(localCenter.x, localCenter.y, localCenter.z);
32+
return new OBB(finalCenter, new Vec3(halfX, halfY, halfZ), rotation);
33+
}
34+
35+
public OBB move(Vec3 origin) {
36+
this.center = this.center.add(origin);
37+
this.halfSize = this.halfSize.add(origin);
38+
return this;
39+
}
4040
}

0 commit comments

Comments
 (0)