Skip to content

Commit 3e41ca6

Browse files
committed
Merge remote-tracking branch 'upstream/master' into feat/26.1
# Conflicts: # core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java
2 parents 1d96860 + 855f97c commit 3e41ca6

10 files changed

Lines changed: 52 additions & 35 deletions

File tree

core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
import org.geysermc.geyser.entity.type.TNTEntity;
7474
import org.geysermc.geyser.entity.type.TextDisplayEntity;
7575
import org.geysermc.geyser.entity.type.ThrowableEggEntity;
76-
import org.geysermc.geyser.entity.type.ThrowableEntity;
76+
import org.geysermc.geyser.entity.type.ProjectileEntity;
7777
import org.geysermc.geyser.entity.type.ThrowableItemEntity;
7878
import org.geysermc.geyser.entity.type.ThrownPotionEntity;
7979
import org.geysermc.geyser.entity.type.TridentEntity;
@@ -259,7 +259,7 @@ public final class EntityDefinitions {
259259
public static final EntityDefinition<LeashKnotEntity> LEASH_KNOT;
260260
public static final EntityDefinition<LightningEntity> LIGHTNING_BOLT;
261261
public static final EntityDefinition<LlamaEntity> LLAMA;
262-
public static final EntityDefinition<ThrowableEntity> LLAMA_SPIT;
262+
public static final EntityDefinition<ProjectileEntity> LLAMA_SPIT;
263263
public static final EntityDefinition<MagmaCubeEntity> MAGMA_CUBE;
264264
public static final EntityDefinition<BoatEntity> MANGROVE_BOAT;
265265
public static final EntityDefinition<ChestBoatEntity> MANGROVE_CHEST_BOAT;
@@ -293,7 +293,7 @@ public final class EntityDefinitions {
293293
public static final EntityDefinition<SheepEntity> SHEEP;
294294
public static final EntityDefinition<ShulkerEntity> SHULKER;
295295
public static final EntityDefinition<SnifferEntity> SNIFFER;
296-
public static final EntityDefinition<ThrowableEntity> SHULKER_BULLET;
296+
public static final EntityDefinition<ProjectileEntity> SHULKER_BULLET;
297297
public static final EntityDefinition<MonsterEntity> SILVERFISH;
298298
public static final EntityDefinition<SkeletonEntity> SKELETON;
299299
public static final EntityDefinition<SkeletonHorseEntity> SKELETON_HORSE;
@@ -425,11 +425,11 @@ public final class EntityDefinitions {
425425
LIGHTNING_BOLT = EntityDefinition.inherited(LightningEntity::new, entityBase)
426426
.type(EntityType.LIGHTNING_BOLT)
427427
.build();
428-
LLAMA_SPIT = EntityDefinition.inherited(ThrowableEntity::new, entityBase)
428+
LLAMA_SPIT = EntityDefinition.inherited(ProjectileEntity::new, entityBase)
429429
.type(EntityType.LLAMA_SPIT)
430430
.heightAndWidth(0.25f)
431431
.build();
432-
SHULKER_BULLET = EntityDefinition.inherited(ThrowableEntity::new, entityBase)
432+
SHULKER_BULLET = EntityDefinition.inherited(ProjectileEntity::new, entityBase)
433433
.type(EntityType.SHULKER_BULLET)
434434
.heightAndWidth(0.3125f)
435435
.build();
@@ -535,7 +535,7 @@ public final class EntityDefinitions {
535535
EntityDefinition<AbstractArrowEntity> abstractArrowBase = EntityDefinition.inherited(AbstractArrowEntity::new, entityBase)
536536
.addTranslator(MetadataTypes.BYTE, AbstractArrowEntity::setArrowFlags)
537537
.addTranslator(null) // "Piercing level"
538-
.addTranslator(null) // If the arrow is in the ground
538+
.addTranslator(MetadataTypes.BOOLEAN, AbstractArrowEntity::setInGround) // If the arrow is in the ground
539539
.build();
540540
ARROW = EntityDefinition.inherited(ArrowEntity::new, abstractArrowBase)
541541
.type(EntityType.ARROW)

core/src/main/java/org/geysermc/geyser/entity/type/AbstractArrowEntity.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@
2828
import org.cloudburstmc.math.vector.Vector3f;
2929
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
3030
import org.geysermc.geyser.entity.spawn.EntitySpawnContext;
31+
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
3132
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
3233
import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType;
3334

34-
public class AbstractArrowEntity extends Entity {
35+
public class AbstractArrowEntity extends ProjectileEntity {
36+
37+
private boolean inGround;
3538

3639
public AbstractArrowEntity(EntitySpawnContext context) {
3740
super(context);
@@ -42,12 +45,24 @@ public AbstractArrowEntity(EntitySpawnContext context) {
4245
setMotion(motion);
4346
}
4447

48+
@Override
49+
public void tick() {
50+
if (inGround) {
51+
return;
52+
}
53+
super.tick();
54+
}
55+
4556
public void setArrowFlags(ByteEntityMetadata entityMetadata) {
4657
byte data = entityMetadata.getPrimitiveValue();
4758

4859
setFlag(EntityFlag.CRITICAL, (data & 0x01) == 0x01);
4960
}
5061

62+
public void setInGround(BooleanEntityMetadata entityMetadata) {
63+
this.inGround = entityMetadata.getPrimitiveValue();
64+
}
65+
5166
// Ignore the rotation sent by the Java server since the
5267
// Java client calculates the rotation from the motion
5368
@Override
@@ -62,6 +77,16 @@ public void setPitch(float pitch) {
6277
public void setHeadYaw(float headYaw) {
6378
}
6479

80+
@Override
81+
protected float getGravity() {
82+
return getFlag(EntityFlag.HAS_GRAVITY) ? 0.05f : 0f;
83+
}
84+
85+
@Override
86+
protected float getDrag() {
87+
return isInWater() ? 0.6f : 0.99f;
88+
}
89+
6590
@Override
6691
public void setMotion(Vector3f motion) {
6792
super.setMotion(motion);

core/src/main/java/org/geysermc/geyser/entity/type/DisplayBaseEntity.java

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,9 @@ public void setTranslation(EntityMetadata<Vector3f, ?> translationMeta) {
5050
return;
5151
}
5252

53-
// No more translation, remove the old
54-
if (Vector3f.ZERO.equals(this.baseTranslation)) {
55-
if (vehicle == null) {
56-
this.setRiderSeatPosition(this.baseTranslation);
57-
this.moveRelativeRaw(-oldTranslation.getX(), -oldTranslation.getY(), -oldTranslation.getZ(), yaw, pitch, headYaw, false);
58-
} else {
59-
EntityUtils.updateMountOffset(this, this.vehicle, true, true, 0, 1);
60-
this.updateBedrockMetadata();
61-
}
62-
return;
63-
}
64-
65-
// Use the diff between the old and new translation
66-
float xTranslation = oldTranslation.getX() - this.baseTranslation.getX();
67-
float yTranslation = oldTranslation.getY() - this.baseTranslation.getY();
68-
float zTranslation = oldTranslation.getZ() - this.baseTranslation.getZ();
69-
7053
if (this.vehicle == null) {
7154
this.setRiderSeatPosition(this.baseTranslation);
72-
this.moveRelativeRaw(xTranslation, yTranslation, zTranslation, yaw, pitch, headYaw, false);
55+
this.moveAbsoluteRaw(position, yaw, pitch, headYaw, onGround, true);
7356
} else {
7457
EntityUtils.updateMountOffset(this, this.vehicle, true, true, 0, 1);
7558
this.updateBedrockMetadata();
@@ -79,4 +62,9 @@ public void setTranslation(EntityMetadata<Vector3f, ?> translationMeta) {
7962
public Vector3f getTranslation() {
8063
return baseTranslation;
8164
}
65+
66+
@Override
67+
public Vector3f bedrockPosition() {
68+
return super.bedrockPosition().add(baseTranslation);
69+
}
8270
}

core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.cloudburstmc.math.vector.Vector3f;
2929
import org.geysermc.geyser.entity.spawn.EntitySpawnContext;
3030

31-
public class FireballEntity extends ThrowableEntity {
31+
public class FireballEntity extends ProjectileEntity {
3232
private final Vector3f acceleration;
3333

3434
/**

core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
import java.util.concurrent.ThreadLocalRandom;
4444

45-
public class FishingHookEntity extends ThrowableEntity {
45+
public class FishingHookEntity extends ProjectileEntity {
4646

4747
private boolean hooked = false;
4848
private boolean castByPlayer = false;

core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
import java.util.concurrent.CompletableFuture;
4343

44-
public class ItemEntity extends ThrowableEntity {
44+
public class ItemEntity extends ProjectileEntity {
4545
protected ItemData item;
4646

4747
private CompletableFuture<Integer> waterLevel = CompletableFuture.completedFuture(-1);

core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java renamed to core/src/main/java/org/geysermc/geyser/entity/type/ProjectileEntity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
/**
3838
* Used as a class for any object-like entity that moves as a projectile
3939
*/
40-
public class ThrowableEntity extends Entity implements Tickable {
40+
public class ProjectileEntity extends Entity implements Tickable {
4141

4242
protected Vector3f lastJavaPosition;
4343

44-
public ThrowableEntity(EntitySpawnContext context) {
44+
public ProjectileEntity(EntitySpawnContext context) {
4545
super(context);
4646
this.lastJavaPosition = position;
4747
}
@@ -58,7 +58,7 @@ public void tick() {
5858
moveAbsoluteImmediate(position.add(motion), getYaw(), getPitch(), getHeadYaw(), isOnGround(), false);
5959
float drag = getDrag();
6060
float gravity = getGravity();
61-
motion = motion.mul(drag).down(gravity);
61+
setMotion(motion.mul(drag).down(gravity));
6262
}
6363

6464
protected void moveAbsoluteImmediate(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) {

core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public void updateNameTag() {
181181
secondEntity.getDirtyMetadata().put(EntityDataTypes.HEIGHT, 0.0f);
182182
secondEntity.getDirtyMetadata().put(EntityDataTypes.HITBOX, NbtMap.EMPTY);
183183
}
184+
184185
/**
185186
* Calculates the Y offset needed to match Java Edition's text centering
186187
* behavior for multi-line text displays.

core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
/**
3636
* Used as a class for any projectile entity that looks like an item
3737
*/
38-
public class ThrowableItemEntity extends ThrowableEntity {
38+
public class ThrowableItemEntity extends ProjectileEntity {
3939
/**
4040
* Number of draw ticks since the entity was spawned by the Java server
4141
*/

core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -914,8 +914,8 @@ public int compare(GeyserCustomMappingData firstData, GeyserCustomMappingData se
914914
return second.priority() - first.priority();
915915
}
916916

917-
if (first.predicates().isEmpty() ^ second.predicates().isEmpty()) {
918-
// If one has no predicates, and the other has at least one, there's no need to check for range dispatch predicates.
917+
if (first.predicates().size() != second.predicates().size()) {
918+
// If predicate size differs, there's no need to check for range dispatch predicates.
919919
// Prefer the one with the most amount of predicates
920920
return second.predicates().size() - first.predicates().size();
921921
}
@@ -938,7 +938,10 @@ public int compare(GeyserCustomMappingData firstData, GeyserCustomMappingData se
938938
// If a similar predicate was found, check if they're negated
939939
// If they are, prefer the one with the lowest threshold
940940
// If they aren't, prefer the one with the highest threshold
941-
return (int) (negated ? threshold - other.get().threshold() : other.get().threshold() - threshold);
941+
double thresholdComparison = negated ? threshold - other.get().threshold() : other.get().threshold() - threshold;
942+
if (thresholdComparison != 0.0) {
943+
return thresholdComparison < 0 ? -1 : 1;
944+
}
942945
}
943946
}
944947
}

0 commit comments

Comments
 (0)