Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
480a7dc
Fix entity position desync when spawned in an 8 block radius from wor…
Am-Gone Aug 20, 2024
b0b31d4
Update API for swept entity <-> entity collisions (#2343)
iam4722202468 Aug 21, 2024
b05bfd9
Move EntityCollisionResult to its own class (#2345)
iam4722202468 Aug 21, 2024
6b660a4
Return directional information from entity collision (#2346)
iam4722202468 Aug 21, 2024
a521c4e
fix entity collisions (#2348)
DasBabyPixel Aug 22, 2024
b832db7
Ability to get collision shape position from PhysicsResult (#2355)
DasBabyPixel Aug 26, 2024
789befe
Coordinate limit to prevent potential overflow
TheMode Aug 26, 2024
8f46913
fix some jcstress files
TheMode Aug 28, 2024
65f75bb
clear remaining hephaistos usage
TheMode Aug 28, 2024
b1ad94c
Make BoundingBox/ShapeImpl records (#2371)
TheMode Sep 3, 2024
a3dec12
Use a single int for all block states (#2373)
TheMode Sep 3, 2024
5ec42c6
Light cleanup (#2372)
TheMode Sep 3, 2024
b1c34cc
record namespace (#2374)
TheMode Sep 3, 2024
61f7b61
Add EquipmentSlot.BODY (#2325)
TogAr2 Sep 3, 2024
2d92fa6
unused cache
TheMode Sep 3, 2024
f591566
Implement Graph Cache in CommandManager (#2360)
kermandev Sep 3, 2024
4553d3c
update dependencies
TheMode Sep 4, 2024
c24f3a5
Remove caffeine dependency from EventNode (#2375)
TheMode Sep 4, 2024
6e0ee02
Remove mojang utils cache
TheMode Sep 4, 2024
3172039
fix team visibility (#2186)
bea4dev Sep 6, 2024
1b85254
Fix chunks not being refreshed when view distance updates (#2197)
GreatWyrm Sep 6, 2024
b0bad7e
give more control of collisions to the entities colliding (#2350)
DasBabyPixel Sep 6, 2024
c509804
Playsound exclude (#2381)
Minikloon Sep 7, 2024
af7e357
fix: saturation not working in food item component (#2382)
SLH335 Sep 7, 2024
11ed85a
fix missing inversion in DataComponentMap#diff handling for removed e…
Floweynt Sep 7, 2024
7ce047b
More Vec operator, more min/max methods
TheMode Sep 8, 2024
cc9f125
Merge branch 'master' of https://github.com/Minestom/Minestom
TheMeinerLP Sep 9, 2024
826361d
Remove no longer exists methods
TheMeinerLP Sep 9, 2024
31d44e9
Disable failed test
TheMeinerLP Sep 9, 2024
5aa77a1
Improve AtomicReference handling
theEvilReaper Sep 9, 2024
eaba762
Fix test execution when loading chunk outside of the main thread
theEvilReaper Sep 9, 2024
8ad882e
Improve AtomicReference handling in some tests
theEvilReaper Sep 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added gradle/libs.versions.toml
Empty file.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package net.minestom.server.tag;

import org.jglrxavpok.hephaistos.nbt.NBT;
import net.kyori.adventure.nbt.CompoundBinaryTag;
import org.openjdk.jcstress.annotations.*;
import org.openjdk.jcstress.infra.results.L_Result;

import java.util.Map;

import static net.kyori.adventure.nbt.IntBinaryTag.intBinaryTag;
import static org.openjdk.jcstress.annotations.Expect.ACCEPTABLE;

@JCStressTest
Expand All @@ -30,9 +31,9 @@ public void actor2() {
@Arbiter
public void arbiter(L_Result r) {
var compound = handler.asCompound();
if (compound.equals(NBT.Compound(Map.of("path", NBT.Compound(Map.of("key", NBT.Int(1))))))) {
if (compound.equals(CompoundBinaryTag.from(Map.of("path", CompoundBinaryTag.from(Map.of("key", intBinaryTag(1))))))) {
r.r1 = "actor1";
} else if (compound.equals(NBT.Compound(Map.of("path", NBT.Compound(Map.of("key", NBT.Int(5))))))) {
} else if (compound.equals(CompoundBinaryTag.from(Map.of("path", CompoundBinaryTag.from(Map.of("key", intBinaryTag(5))))))) {
r.r1 = "actor2";
} else {
r.r1 = compound;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package net.minestom.server.tag;

import org.jglrxavpok.hephaistos.nbt.NBT;
import net.kyori.adventure.nbt.CompoundBinaryTag;
import org.openjdk.jcstress.annotations.*;
import org.openjdk.jcstress.infra.results.L_Result;

import java.util.Map;

import static net.kyori.adventure.nbt.IntBinaryTag.intBinaryTag;
import static org.openjdk.jcstress.annotations.Expect.ACCEPTABLE;

@JCStressTest
Expand All @@ -31,9 +32,9 @@ public void actor2() {
@Arbiter
public void arbiter(L_Result r) {
var compound = handler.asCompound();
if (compound.equals(NBT.Compound(Map.of("path", NBT.Int(1))))) {
if (compound.equals(CompoundBinaryTag.from(Map.of("path", intBinaryTag(1))))) {
r.r1 = "tag";
} else if (compound.equals(NBT.Compound(Map.of("path", NBT.Compound(Map.of("key", NBT.Int(5))))))) {
} else if (compound.equals(CompoundBinaryTag.from(Map.of("path", CompoundBinaryTag.from(Map.of("key", intBinaryTag(5))))))) {
r.r1 = "tag_path";
} else {
r.r1 = compound;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package net.minestom.server.tag;

import org.jglrxavpok.hephaistos.nbt.NBT;
import org.jglrxavpok.hephaistos.nbt.mutable.MutableNBTCompound;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

Expand All @@ -24,8 +23,8 @@ public class TagReadBenchmark {
TagHandler tagHandler;
Tag<String> secondTag;

MutableNBTCompound concurrentCompound;
MutableNBTCompound compound;
Map<String, String> map;
Map<String, String> concurrentMap;

@Setup
public void setup() {
Expand All @@ -34,11 +33,11 @@ public void setup() {
if (present) tagHandler.setTag(TAG, "value");
secondTag = Tag.String("key");
// Concurrent map benchmark
this.concurrentCompound = new MutableNBTCompound(new ConcurrentHashMap<>());
if (present) concurrentCompound.set("key", NBT.String("value"));
map = new HashMap<>();
if (present) map.put("key", "value");
// Hash map benchmark
this.compound = new MutableNBTCompound(new HashMap<>());
if (present) compound.set("key", NBT.String("value"));
concurrentMap = new ConcurrentHashMap<>();
if (present) concurrentMap.put("key", "value");
}

@Benchmark
Expand All @@ -57,12 +56,12 @@ public void readNewTag(Blackhole blackhole) {
}

@Benchmark
public void readConcurrentCompound(Blackhole blackhole) {
blackhole.consume(concurrentCompound.getString("key"));
public void readConcurrentMap(Blackhole blackhole) {
blackhole.consume(concurrentMap.get("key"));
}

@Benchmark
public void readCompound(Blackhole blackhole) {
blackhole.consume(compound.getString("key"));
public void readMap(Blackhole blackhole) {
blackhole.consume(map.get("key"));
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package net.minestom.server.tag;

import org.jglrxavpok.hephaistos.nbt.NBT;
import org.jglrxavpok.hephaistos.nbt.mutable.MutableNBTCompound;
import org.openjdk.jmh.annotations.*;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

Expand All @@ -20,8 +19,8 @@ public class TagWriteBenchmark {
TagHandler tagHandler;
Tag<String> secondTag;

MutableNBTCompound concurrentCompound;
MutableNBTCompound compound;
Map<String, String> map;
Map<String, String> concurrentMap;

@Setup
public void setup() {
Expand All @@ -30,11 +29,11 @@ public void setup() {
tagHandler.setTag(TAG, "value");
secondTag = Tag.String("key");
// Concurrent map benchmark
this.concurrentCompound = new MutableNBTCompound(new ConcurrentHashMap<>());
concurrentCompound.set("key", NBT.String("value"));
map = new HashMap<>();
map.put("key", "value");
// Hash map benchmark
this.compound = new MutableNBTCompound(new HashMap<>());
compound.set("key", NBT.String("value"));
concurrentMap = new ConcurrentHashMap<>();
concurrentMap.put("key", "value");
}

@Benchmark
Expand All @@ -53,12 +52,12 @@ public void writeNewTag() {
}

@Benchmark
public void writeConcurrentCompound() {
concurrentCompound.setString("key", "value");
public void writeConcurrentMap() {
concurrentMap.put("key", "value");
}

@Benchmark
public void writeCompound() {
compound.setString("key", "value");
public void writeMap() {
map.put("key", "value");
}
}
32 changes: 14 additions & 18 deletions src/main/java/net/minestom/server/collision/BlockCollision.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import net.minestom.server.coordinate.Pos;
import net.minestom.server.coordinate.Vec;
import net.minestom.server.entity.Entity;
import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.GameMode;
import net.minestom.server.entity.Player;
import net.minestom.server.entity.metadata.other.ArmorStandMeta;
import net.minestom.server.instance.Instance;
import net.minestom.server.instance.block.Block;
import net.minestom.server.utils.block.BlockIterator;
Expand All @@ -29,7 +26,7 @@ static PhysicsResult handlePhysics(@NotNull BoundingBox boundingBox,
if (velocity.isZero()) {
// TODO should return a constant
return new PhysicsResult(entityPosition, Vec.ZERO, false, false, false, false,
velocity, new Point[3], new Shape[3], false, SweepResult.NO_COLLISION);
velocity, new Point[3], new Shape[3], new Point[3], false, SweepResult.NO_COLLISION);
}
// Fast-exit using cache
final PhysicsResult cachedResult = cachedPhysics(velocity, entityPosition, getter, lastPhysicsResult);
Expand All @@ -42,18 +39,11 @@ static PhysicsResult handlePhysics(@NotNull BoundingBox boundingBox,

static Entity canPlaceBlockAt(Instance instance, Point blockPos, Block b) {
for (Entity entity : instance.getNearbyEntities(blockPos, 3)) {
final EntityType type = entity.getEntityType();
if (!entity.hasCollision() || type == EntityType.ITEM || type == EntityType.ARROW)
continue;
// Marker Armor Stands should not prevent block placement
if (entity.getEntityMeta() instanceof ArmorStandMeta armorStandMeta && armorStandMeta.isMarker())
if (!entity.preventBlockPlacement())
continue;

final boolean intersects;
if (entity instanceof Player) {
// Ignore spectators
if (((Player) entity).getGameMode() == GameMode.SPECTATOR)
continue;
// Need to move player slightly away from block we're placing.
// If player is at block 40 we cannot place a block at block 39 with side length 1 because the block will be in [39, 40]
// For this reason we subtract a small amount from the player position
Expand All @@ -70,16 +60,18 @@ static Entity canPlaceBlockAt(Instance instance, Point blockPos, Block b) {
private static PhysicsResult cachedPhysics(Vec velocity, Pos entityPosition,
Block.Getter getter, PhysicsResult lastPhysicsResult) {
if (lastPhysicsResult != null && lastPhysicsResult.collisionShapes()[1] instanceof ShapeImpl shape) {
Block collisionBlockY = shape.block();
var currentBlock = getter.getBlock(lastPhysicsResult.collisionPoints()[1].sub(0, Vec.EPSILON, 0), Block.Getter.Condition.TYPE);
var lastBlockBoxes = shape.collisionBoundingBoxes();
var currentBlockBoxes = ((ShapeImpl) currentBlock.registry().collisionShape()).collisionBoundingBoxes();

// Fast exit if entity hasn't moved
if (lastPhysicsResult.collisionY()
&& velocity.y() == lastPhysicsResult.originalDelta().y()
// Check block below to fast exit gravity
&& getter.getBlock(lastPhysicsResult.collisionPoints()[1].sub(0, Vec.EPSILON, 0), Block.Getter.Condition.TYPE) == collisionBlockY
&& currentBlockBoxes.equals(lastBlockBoxes)
&& velocity.x() == 0 && velocity.z() == 0
&& entityPosition.samePoint(lastPhysicsResult.newPosition())
&& collisionBlockY != Block.AIR) {
&& !lastBlockBoxes.isEmpty()) {
return lastPhysicsResult;
}
}
Expand All @@ -90,12 +82,13 @@ private static PhysicsResult stepPhysics(@NotNull BoundingBox boundingBox,
@NotNull Vec velocity, @NotNull Pos entityPosition,
@NotNull Block.Getter getter, boolean singleCollision) {
// Allocate once and update values
SweepResult finalResult = new SweepResult(1 - Vec.EPSILON, 0, 0, 0, null, 0, 0, 0);
SweepResult finalResult = new SweepResult(1 - Vec.EPSILON, 0, 0, 0, null, 0, 0, 0, 0, 0, 0);

boolean foundCollisionX = false, foundCollisionY = false, foundCollisionZ = false;

Point[] collidedPoints = new Point[3];
Shape[] collisionShapes = new Shape[3];
Point[] collisionShapePositions = new Point[3];

boolean hasCollided = false;

Expand All @@ -114,18 +107,21 @@ private static PhysicsResult stepPhysics(@NotNull BoundingBox boundingBox,
if (result.collisionX()) {
foundCollisionX = true;
collisionShapes[0] = finalResult.collidedShape;
collisionShapePositions[0] = new Vec(finalResult.collidedShapeX, finalResult.collidedShapeY, finalResult.collidedShapeZ);
collidedPoints[0] = new Vec(finalResult.collidedPositionX, finalResult.collidedPositionY, finalResult.collidedPositionZ);
hasCollided = true;
if (singleCollision) break;
} else if (result.collisionZ()) {
foundCollisionZ = true;
collisionShapes[2] = finalResult.collidedShape;
collisionShapePositions[2] = new Vec(finalResult.collidedShapeX, finalResult.collidedShapeY, finalResult.collidedShapeZ);
collidedPoints[2] = new Vec(finalResult.collidedPositionX, finalResult.collidedPositionY, finalResult.collidedPositionZ);
hasCollided = true;
if (singleCollision) break;
} else if (result.collisionY()) {
foundCollisionY = true;
collisionShapes[1] = finalResult.collidedShape;
collisionShapePositions[1] = new Vec(finalResult.collidedShapeX, finalResult.collidedShapeY, finalResult.collidedShapeZ);
collidedPoints[1] = new Vec(finalResult.collidedPositionX, finalResult.collidedPositionY, finalResult.collidedPositionZ);
hasCollided = true;
if (singleCollision) break;
Expand All @@ -148,7 +144,7 @@ private static PhysicsResult stepPhysics(@NotNull BoundingBox boundingBox,

return new PhysicsResult(result.newPosition(), new Vec(newDeltaX, newDeltaY, newDeltaZ),
newDeltaY == 0 && velocity.y() < 0,
foundCollisionX, foundCollisionY, foundCollisionZ, velocity, collidedPoints, collisionShapes, hasCollided, finalResult);
foundCollisionX, foundCollisionY, foundCollisionZ, velocity, collidedPoints, collisionShapes, collisionShapePositions, hasCollided, finalResult);
}

private static PhysicsResult computePhysics(@NotNull BoundingBox boundingBox,
Expand Down Expand Up @@ -185,7 +181,7 @@ private static PhysicsResult computePhysics(@NotNull BoundingBox boundingBox,

return new PhysicsResult(finalPos, new Vec(remainingX, remainingY, remainingZ),
collisionY, collisionX, collisionY, collisionZ,
Vec.ZERO, null, null, false, finalResult);
Vec.ZERO, null, null, null, false, finalResult);
}

private static boolean isDiagonal(Vec velocity) {
Expand Down
Loading