mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-23 00:21:26 +01:00
Item pickup fix (#1216)
This commit is contained in:
parent
9181c52e6b
commit
4feac211c7
@ -203,7 +203,7 @@ public class LivingEntity extends Entity implements EquipmentHandler {
|
|||||||
// Items picking
|
// Items picking
|
||||||
if (canPickupItem() && itemPickupCooldown.isReady(time)) {
|
if (canPickupItem() && itemPickupCooldown.isReady(time)) {
|
||||||
itemPickupCooldown.refreshLastUpdate(time);
|
itemPickupCooldown.refreshLastUpdate(time);
|
||||||
final Point loweredPosition = position.sub(0, -.5, 0);
|
final Point loweredPosition = position.sub(0, .5, 0);
|
||||||
this.instance.getEntityTracker().nearbyEntities(position, expandedBoundingBox.width(),
|
this.instance.getEntityTracker().nearbyEntities(position, expandedBoundingBox.width(),
|
||||||
EntityTracker.Target.ITEMS, itemEntity -> {
|
EntityTracker.Target.ITEMS, itemEntity -> {
|
||||||
if (this instanceof Player player && !itemEntity.isViewer(player)) return;
|
if (this instanceof Player player && !itemEntity.isViewer(player)) return;
|
||||||
|
@ -333,7 +333,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
// Experience orb pickup
|
// Experience orb pickup
|
||||||
if (experiencePickupCooldown.isReady(time)) {
|
if (experiencePickupCooldown.isReady(time)) {
|
||||||
experiencePickupCooldown.refreshLastUpdate(time);
|
experiencePickupCooldown.refreshLastUpdate(time);
|
||||||
final Point loweredPosition = position.sub(0, -.5, 0);
|
final Point loweredPosition = position.sub(0, .5, 0);
|
||||||
this.instance.getEntityTracker().nearbyEntities(position, expandedBoundingBox.width(),
|
this.instance.getEntityTracker().nearbyEntities(position, expandedBoundingBox.width(),
|
||||||
EntityTracker.Target.EXPERIENCE_ORBS, experienceOrb -> {
|
EntityTracker.Target.EXPERIENCE_ORBS, experienceOrb -> {
|
||||||
if (expandedBoundingBox.intersectEntity(loweredPosition, experienceOrb)) {
|
if (expandedBoundingBox.intersectEntity(loweredPosition, experienceOrb)) {
|
||||||
|
@ -4,6 +4,10 @@ import net.minestom.server.api.Env;
|
|||||||
import net.minestom.server.api.EnvTest;
|
import net.minestom.server.api.EnvTest;
|
||||||
import net.minestom.server.collision.BoundingBox;
|
import net.minestom.server.collision.BoundingBox;
|
||||||
import net.minestom.server.coordinate.Pos;
|
import net.minestom.server.coordinate.Pos;
|
||||||
|
import net.minestom.server.event.item.PickupItemEvent;
|
||||||
|
import net.minestom.server.instance.Instance;
|
||||||
|
import net.minestom.server.item.ItemStack;
|
||||||
|
import net.minestom.server.item.Material;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
@ -48,4 +52,31 @@ public class EntityBoundingBoxIntegrationTest {
|
|||||||
player.setPose(Entity.Pose.FALL_FLYING);
|
player.setPose(Entity.Pose.FALL_FLYING);
|
||||||
assertEquals(0.4, player.getEyeHeight());
|
assertEquals(0.4, player.getEyeHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void pickupItem(Env env) {
|
||||||
|
final var instance = env.createFlatInstance();
|
||||||
|
final var listener = env.listen(PickupItemEvent.class);
|
||||||
|
final var spawnPos = new Pos(0, 42, 0);
|
||||||
|
final var entity = new LivingEntity(EntityType.ZOMBIE);
|
||||||
|
entity.setCanPickupItem(true);
|
||||||
|
entity.setInstance(instance, spawnPos).join();
|
||||||
|
|
||||||
|
var time = System.currentTimeMillis();
|
||||||
|
|
||||||
|
dropItem(instance, spawnPos);
|
||||||
|
listener.followup();
|
||||||
|
entity.update(time += 1_000L);
|
||||||
|
|
||||||
|
dropItem(instance, spawnPos.sub(.5));
|
||||||
|
listener.followup();
|
||||||
|
entity.update(time += 1_000L);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dropItem(final Instance instance, final Pos position) {
|
||||||
|
final var entity = new ItemEntity(ItemStack.of(Material.STONE));
|
||||||
|
entity.hasPhysics = false;
|
||||||
|
entity.setNoGravity(true);
|
||||||
|
entity.setInstance(instance, position).join();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user