From 5a7bf1ba8492321d3685164bb60c8dd6a6388033 Mon Sep 17 00:00:00 2001 From: Eclipse Date: Fri, 24 Oct 2025 08:28:10 +0000 Subject: [PATCH 01/62] Start working on custom entity API (for real this time) --- .../geyser/api/entity/JavaEntityType.java | 41 ++++++++ .../context/entity/EntitySpawnContext.java | 42 ++++++++ .../geysermc/geyser/api/util/Identifier.java | 2 + .../geyser/entity/EntityDefinition.java | 96 ++++++++++++++++++- .../geysermc/geyser/impl/IdentifierImpl.java | 3 +- 5 files changed, 179 insertions(+), 5 deletions(-) create mode 100644 api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java create mode 100644 api/src/main/java/org/geysermc/geyser/api/predicate/context/entity/EntitySpawnContext.java diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java new file mode 100644 index 00000000000..70b4d5b857c --- /dev/null +++ b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.api.entity; + +import org.geysermc.geyser.api.util.Identifier; + +public interface JavaEntityType { + + Identifier javaIdentifier(); + + int javaId(); + + boolean isUnregistered(); + + default boolean is(Identifier identifier) { + return javaIdentifier().equals(identifier); + } +} diff --git a/api/src/main/java/org/geysermc/geyser/api/predicate/context/entity/EntitySpawnContext.java b/api/src/main/java/org/geysermc/geyser/api/predicate/context/entity/EntitySpawnContext.java new file mode 100644 index 00000000000..8072e25fcf8 --- /dev/null +++ b/api/src/main/java/org/geysermc/geyser/api/predicate/context/entity/EntitySpawnContext.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.api.predicate.context.entity; + +import org.geysermc.geyser.api.entity.JavaEntityType; +import org.geysermc.geyser.api.predicate.context.MinecraftPredicateContext; + +import java.util.UUID; + +public interface EntitySpawnContext extends MinecraftPredicateContext { + + JavaEntityType entityType(); + + int entityId(); + + UUID entityUuid(); + + int data(); +} diff --git a/api/src/main/java/org/geysermc/geyser/api/util/Identifier.java b/api/src/main/java/org/geysermc/geyser/api/util/Identifier.java index e82a695d1fa..b7910fa762b 100644 --- a/api/src/main/java/org/geysermc/geyser/api/util/Identifier.java +++ b/api/src/main/java/org/geysermc/geyser/api/util/Identifier.java @@ -28,6 +28,8 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.api.GeyserApi; +// TODO: using static Identifiers, both in API and by API users, is not really possible at the moment, since providers have to be registered first, which probably won't have happened +// when a class's clinit is run /** * An identifying object for representing unique objects. * This identifier consists of two parts: diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java index 284ac442554..cb2d4f7c4ac 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java @@ -41,6 +41,7 @@ import java.util.List; import java.util.Locale; +import java.util.Objects; import java.util.function.BiConsumer; /** @@ -48,11 +49,32 @@ * metadata translators needed to translate the properties sent from the server. The translators are structured in such * a way that inserting a new one (for example in version updates) is convenient. * - * @param identifier the Bedrock identifier of this entity * @param the entity type this definition represents */ -public record EntityDefinition(EntityFactory factory, EntityType entityType, String identifier, - float width, float height, float offset, GeyserEntityProperties registeredProperties, List> translators) { +public final class EntityDefinition { + private final EntityFactory factory; + private final EntityType entityType; + private final String identifier; + private final float width; + private final float height; + private final float offset; + private final GeyserEntityProperties registeredProperties; + private final List> translators; + + /** + * @param identifier the Bedrock identifier of this entity + */ + public EntityDefinition(EntityFactory factory, EntityType entityType, String identifier, + float width, float height, float offset, GeyserEntityProperties registeredProperties, List> translators) { + this.factory = factory; + this.entityType = entityType; + this.identifier = identifier; + this.width = width; + this.height = height; + this.offset = offset; + this.registeredProperties = registeredProperties; + this.translators = translators; + } public static Builder inherited(EntityFactory factory, EntityDefinition parent) { return new Builder<>(factory, parent.entityType, parent.identifier, parent.width, parent.height, parent.offset, new ObjectArrayList<>(parent.translators)); @@ -81,6 +103,72 @@ public void translateMetadata(T entity, EntityMetadata factory() { + return factory; + } + + public EntityType entityType() { + return entityType; + } + + public String identifier() { + return identifier; + } + + public float width() { + return width; + } + + public float height() { + return height; + } + + public float offset() { + return offset; + } + + public GeyserEntityProperties registeredProperties() { + return registeredProperties; + } + + public List> translators() { + return translators; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) return true; + if (obj == null || obj.getClass() != this.getClass()) return false; + var that = (EntityDefinition) obj; + return Objects.equals(this.factory, that.factory) && + Objects.equals(this.entityType, that.entityType) && + Objects.equals(this.identifier, that.identifier) && + Float.floatToIntBits(this.width) == Float.floatToIntBits(that.width) && + Float.floatToIntBits(this.height) == Float.floatToIntBits(that.height) && + Float.floatToIntBits(this.offset) == Float.floatToIntBits(that.offset) && + Objects.equals(this.registeredProperties, that.registeredProperties) && + Objects.equals(this.translators, that.translators); + } + + @Override + public int hashCode() { + return Objects.hash(factory, entityType, identifier, width, height, offset, registeredProperties, translators); + } + + @Override + public String toString() { + return "EntityDefinition[" + + "factory=" + factory + ", " + + "entityType=" + entityType + ", " + + "identifier=" + identifier + ", " + + "width=" + width + ", " + + "height=" + height + ", " + + "offset=" + offset + ", " + + "registeredProperties=" + registeredProperties + ", " + + "translators=" + translators + ']'; + } + + @Setter @Accessors(fluent = true, chain = true) public static class Builder { @@ -155,7 +243,7 @@ public EntityDefinition build() { /** * @param register whether to register this entity in the Registries for entity types. Generally this should be - * set to false if we're not expecting this entity to spawn from the network. + * set to false if we're not expecting this entity to spawn from the network. */ public EntityDefinition build(boolean register) { if (identifier == null && type != null) { diff --git a/core/src/main/java/org/geysermc/geyser/impl/IdentifierImpl.java b/core/src/main/java/org/geysermc/geyser/impl/IdentifierImpl.java index ca03246658e..3f2429b1662 100644 --- a/core/src/main/java/org/geysermc/geyser/impl/IdentifierImpl.java +++ b/core/src/main/java/org/geysermc/geyser/impl/IdentifierImpl.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.impl; import net.kyori.adventure.key.Key; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.api.util.Identifier; import org.geysermc.geyser.util.MinecraftKey; @@ -59,7 +60,7 @@ public String path() { } @Override - public String toString() { + public @NonNull String toString() { return identifier.toString(); } } From f4156c61f60a62ff93addc7d5c6de3a051923e07 Mon Sep 17 00:00:00 2001 From: Eclipse Date: Fri, 24 Oct 2025 11:59:39 +0200 Subject: [PATCH 02/62] Split EntityDefinition up into EntityDefinition and VanillaEntityDefinition, create GeyserEntityType, target custom entities MCPL --- .../geyser/entity/EntityDefinition.java | 147 +-- .../geyser/entity/EntityDefinitions.java | 924 +++++++++--------- .../geyser/entity/GeyserEntityType.java | 95 ++ .../entity/VanillaEntityDefinition.java | 155 +++ .../entity/type/AbstractArrowEntity.java | 4 +- .../geysermc/geyser/entity/type/Entity.java | 5 +- .../geyser/entity/type/ItemFrameEntity.java | 5 +- .../geyser/entity/type/ThrowableEntity.java | 52 +- .../entity/type/ThrownPotionEntity.java | 4 +- .../entity/vehicle/VehicleComponent.java | 4 +- .../geysermc/geyser/impl/IdentifierImpl.java | 5 +- .../item/hashing/DataComponentHashers.java | 4 +- .../geyser/item/hashing/MinecraftHasher.java | 4 + .../geyser/item/hashing/RegistryHasher.java | 5 +- .../geysermc/geyser/registry/Registries.java | 5 +- .../cache/registry/JavaRegistries.java | 45 +- .../java/entity/JavaAddEntityTranslator.java | 15 +- .../entity/JavaSetPassengersTranslator.java | 12 +- .../org/geysermc/geyser/util/EntityUtils.java | 234 ++--- .../geysermc/geyser/util/StatisticsUtils.java | 20 +- .../network/ScoreboardIssueTests.java | 6 +- gradle/libs.versions.toml | 2 +- 22 files changed, 984 insertions(+), 768 deletions(-) create mode 100644 core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java create mode 100644 core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java index cb2d4f7c4ac..85341491509 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java @@ -26,22 +26,22 @@ package org.geysermc.geyser.entity; import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import lombok.AccessLevel; +import lombok.EqualsAndHashCode; +import lombok.Getter; import lombok.Setter; +import lombok.ToString; import lombok.experimental.Accessors; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.entity.factory.EntityFactory; import org.geysermc.geyser.entity.properties.GeyserEntityProperties; import org.geysermc.geyser.entity.properties.type.PropertyType; import org.geysermc.geyser.entity.type.Entity; -import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.translator.entity.EntityMetadataTranslator; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataType; -import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; import java.util.List; -import java.util.Locale; -import java.util.Objects; import java.util.function.BiConsumer; /** @@ -51,9 +51,13 @@ * * @param the entity type this definition represents */ -public final class EntityDefinition { +@Getter +@Accessors(fluent = true) +@EqualsAndHashCode +@ToString +public class EntityDefinition { private final EntityFactory factory; - private final EntityType entityType; + private final GeyserEntityType entityType; private final String identifier; private final float width; private final float height; @@ -64,7 +68,7 @@ public final class EntityDefinition { /** * @param identifier the Bedrock identifier of this entity */ - public EntityDefinition(EntityFactory factory, EntityType entityType, String identifier, + public EntityDefinition(EntityFactory factory, GeyserEntityType entityType, String identifier, float width, float height, float offset, GeyserEntityProperties registeredProperties, List> translators) { this.factory = factory; this.entityType = entityType; @@ -76,14 +80,6 @@ public EntityDefinition(EntityFactory factory, EntityType entityType, String this.translators = translators; } - public static Builder inherited(EntityFactory factory, EntityDefinition parent) { - return new Builder<>(factory, parent.entityType, parent.identifier, parent.width, parent.height, parent.offset, new ObjectArrayList<>(parent.translators)); - } - - public static Builder builder(EntityFactory factory) { - return new Builder<>(factory); - } - @SuppressWarnings("unchecked") public void translateMetadata(T entity, EntityMetadata> metadata) { EntityMetadataTranslator>> translator = (EntityMetadataTranslator>>) this.translators.get(metadata.getId()); @@ -103,90 +99,27 @@ public void translateMetadata(T entity, EntityMetadata factory() { - return factory; - } - - public EntityType entityType() { - return entityType; - } - - public String identifier() { - return identifier; - } - - public float width() { - return width; - } - - public float height() { - return height; - } - - public float offset() { - return offset; - } - - public GeyserEntityProperties registeredProperties() { - return registeredProperties; - } - - public List> translators() { - return translators; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) return true; - if (obj == null || obj.getClass() != this.getClass()) return false; - var that = (EntityDefinition) obj; - return Objects.equals(this.factory, that.factory) && - Objects.equals(this.entityType, that.entityType) && - Objects.equals(this.identifier, that.identifier) && - Float.floatToIntBits(this.width) == Float.floatToIntBits(that.width) && - Float.floatToIntBits(this.height) == Float.floatToIntBits(that.height) && - Float.floatToIntBits(this.offset) == Float.floatToIntBits(that.offset) && - Objects.equals(this.registeredProperties, that.registeredProperties) && - Objects.equals(this.translators, that.translators); - } - - @Override - public int hashCode() { - return Objects.hash(factory, entityType, identifier, width, height, offset, registeredProperties, translators); - } - - @Override - public String toString() { - return "EntityDefinition[" + - "factory=" + factory + ", " + - "entityType=" + entityType + ", " + - "identifier=" + identifier + ", " + - "width=" + width + ", " + - "height=" + height + ", " + - "offset=" + offset + ", " + - "registeredProperties=" + registeredProperties + ", " + - "translators=" + translators + ']'; - } - - @Setter @Accessors(fluent = true, chain = true) - public static class Builder { - private final EntityFactory factory; - private EntityType type; - private String identifier; - private float width; - private float height; - private float offset = 0.00001f; - private GeyserEntityProperties.Builder propertiesBuilder; - private final List> translators; - - private Builder(EntityFactory factory) { + public static abstract class Builder { + protected final EntityFactory factory; + @Setter(AccessLevel.NONE) + protected GeyserEntityType type; + + protected String identifier; + protected float width; + protected float height; + protected float offset = 0.00001f; + @Setter(AccessLevel.NONE) + protected GeyserEntityProperties.Builder propertiesBuilder; + protected final List> translators; + + protected Builder(EntityFactory factory) { this.factory = factory; translators = new ObjectArrayList<>(); } - public Builder(EntityFactory factory, EntityType type, String identifier, float width, float height, float offset, List> translators) { + protected Builder(EntityFactory factory, GeyserEntityType type, String identifier, float width, float height, float offset, List> translators) { this.factory = factory; this.type = type; this.identifier = identifier; @@ -210,15 +143,6 @@ public Builder offset(float offset) { return this; } - /** - * Resets the identifier as well - */ - public Builder type(EntityType type) { - this.type = type; - identifier = null; - return this; - } - public Builder property(PropertyType propertyType) { if (this.propertiesBuilder == null) { this.propertiesBuilder = new GeyserEntityProperties.Builder(this.identifier); @@ -238,24 +162,11 @@ public Builder addTranslator(EntityMetadataTranslator translator) { } public EntityDefinition build() { - return build(true); - } - - /** - * @param register whether to register this entity in the Registries for entity types. Generally this should be - * set to false if we're not expecting this entity to spawn from the network. - */ - public EntityDefinition build(boolean register) { if (identifier == null && type != null) { - identifier = "minecraft:" + type.name().toLowerCase(Locale.ROOT); - } - GeyserEntityProperties registeredProperties = propertiesBuilder == null ? new GeyserEntityProperties() : propertiesBuilder.build(); - EntityDefinition definition = new EntityDefinition<>(factory, type, identifier, width, height, offset, registeredProperties, translators); - if (register && definition.entityType() != null) { - Registries.ENTITY_DEFINITIONS.get().putIfAbsent(definition.entityType(), definition); - Registries.JAVA_ENTITY_IDENTIFIERS.get().putIfAbsent("minecraft:" + type.name().toLowerCase(Locale.ROOT), definition); + identifier = type.javaIdentifier().toString(); } - return definition; + GeyserEntityProperties registeredProperties = propertiesBuilder == null ? null : propertiesBuilder.build(); + return new EntityDefinition<>(factory, type, identifier, width, height, offset, registeredProperties, translators); } } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java index a0eec898343..0e85bdf4d2c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java @@ -170,174 +170,174 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataTypes; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.FloatEntityMetadata; -import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import java.util.Collection; import java.util.List; import java.util.Objects; public final class EntityDefinitions { - public static final EntityDefinition ACACIA_BOAT; - public static final EntityDefinition ACACIA_CHEST_BOAT; - public static final EntityDefinition ALLAY; - public static final EntityDefinition AREA_EFFECT_CLOUD; - public static final EntityDefinition ARMADILLO; - public static final EntityDefinition ARMOR_STAND; - public static final EntityDefinition ARROW; - public static final EntityDefinition AXOLOTL; - public static final EntityDefinition BAMBOO_RAFT; - public static final EntityDefinition BAMBOO_CHEST_RAFT; - public static final EntityDefinition BAT; - public static final EntityDefinition BEE; - public static final EntityDefinition BIRCH_BOAT; - public static final EntityDefinition BIRCH_CHEST_BOAT; - public static final EntityDefinition BLAZE; - public static final EntityDefinition BOGGED; - public static final EntityDefinition BREEZE; - public static final EntityDefinition BREEZE_WIND_CHARGE; - public static final EntityDefinition CAMEL; - public static final EntityDefinition CAT; - public static final EntityDefinition CAVE_SPIDER; - public static final EntityDefinition CHERRY_BOAT; - public static final EntityDefinition CHERRY_CHEST_BOAT; - public static final EntityDefinition CHEST_MINECART; - public static final EntityDefinition CHICKEN; - public static final EntityDefinition COD; - public static final EntityDefinition COPPER_GOLEM; - public static final EntityDefinition COMMAND_BLOCK_MINECART; - public static final EntityDefinition COW; - public static final EntityDefinition CREAKING; - public static final EntityDefinition CREEPER; - public static final EntityDefinition DARK_OAK_BOAT; - public static final EntityDefinition DARK_OAK_CHEST_BOAT; - public static final EntityDefinition DOLPHIN; - public static final EntityDefinition DONKEY; - public static final EntityDefinition DRAGON_FIREBALL; - public static final EntityDefinition DROWNED; - public static final EntityDefinition EGG; - public static final EntityDefinition ELDER_GUARDIAN; - public static final EntityDefinition ENDERMAN; - public static final EntityDefinition ENDERMITE; - public static final EntityDefinition ENDER_DRAGON; - public static final EntityDefinition ENDER_PEARL; - public static final EntityDefinition END_CRYSTAL; - public static final EntityDefinition EVOKER; - public static final EntityDefinition EVOKER_FANGS; - public static final EntityDefinition EXPERIENCE_BOTTLE; - public static final EntityDefinition EXPERIENCE_ORB; - public static final EntityDefinition EYE_OF_ENDER; - public static final EntityDefinition FALLING_BLOCK; - public static final EntityDefinition FIREBALL; - public static final EntityDefinition FIREWORK_ROCKET; - public static final EntityDefinition FISHING_BOBBER; - public static final EntityDefinition FOX; - public static final EntityDefinition FROG; - public static final EntityDefinition FURNACE_MINECART; // Not present on Bedrock - public static final EntityDefinition GHAST; - public static final EntityDefinition GIANT; - public static final EntityDefinition GLOW_ITEM_FRAME; - public static final EntityDefinition GLOW_SQUID; - public static final EntityDefinition GOAT; - public static final EntityDefinition GUARDIAN; - public static final EntityDefinition HAPPY_GHAST; - public static final EntityDefinition HOGLIN; - public static final EntityDefinition HOPPER_MINECART; - public static final EntityDefinition HORSE; - public static final EntityDefinition HUSK; - public static final EntityDefinition ILLUSIONER; // Not present on Bedrock - public static final EntityDefinition INTERACTION; - public static final EntityDefinition IRON_GOLEM; - public static final EntityDefinition ITEM; - public static final EntityDefinition ITEM_FRAME; - public static final EntityDefinition JUNGLE_BOAT; - public static final EntityDefinition JUNGLE_CHEST_BOAT; - public static final EntityDefinition LEASH_KNOT; - public static final EntityDefinition LIGHTNING_BOLT; - public static final EntityDefinition LLAMA; - public static final EntityDefinition LLAMA_SPIT; - public static final EntityDefinition MAGMA_CUBE; - public static final EntityDefinition MANGROVE_BOAT; - public static final EntityDefinition MANGROVE_CHEST_BOAT; - public static final EntityDefinition MANNEQUIN; - public static final EntityDefinition MINECART; - public static final EntityDefinition MOOSHROOM; - public static final EntityDefinition MULE; - public static final EntityDefinition OAK_BOAT; - public static final EntityDefinition OAK_CHEST_BOAT; - public static final EntityDefinition OCELOT; - public static final EntityDefinition PAINTING; - public static final EntityDefinition PALE_OAK_BOAT; - public static final EntityDefinition PALE_OAK_CHEST_BOAT; - public static final EntityDefinition PANDA; - public static final EntityDefinition PARROT; - public static final EntityDefinition PHANTOM; - public static final EntityDefinition PIG; - public static final EntityDefinition PIGLIN; - public static final EntityDefinition PIGLIN_BRUTE; - public static final EntityDefinition PILLAGER; - public static final EntityDefinition PLAYER; - public static final EntityDefinition POLAR_BEAR; - public static final EntityDefinition SPLASH_POTION; - public static final EntityDefinition LINGERING_POTION; - public static final EntityDefinition PUFFERFISH; - public static final EntityDefinition RABBIT; - public static final EntityDefinition RAVAGER; - public static final EntityDefinition SALMON; - public static final EntityDefinition SHEEP; - public static final EntityDefinition SHULKER; - public static final EntityDefinition SNIFFER; - public static final EntityDefinition SHULKER_BULLET; - public static final EntityDefinition SILVERFISH; - public static final EntityDefinition SKELETON; - public static final EntityDefinition SKELETON_HORSE; - public static final EntityDefinition SLIME; - public static final EntityDefinition SMALL_FIREBALL; - public static final EntityDefinition SNOWBALL; - public static final EntityDefinition SNOW_GOLEM; - public static final EntityDefinition SPAWNER_MINECART; // Not present on Bedrock - public static final EntityDefinition SPECTRAL_ARROW; - public static final EntityDefinition SPIDER; - public static final EntityDefinition SPRUCE_BOAT; - public static final EntityDefinition SPRUCE_CHEST_BOAT; - public static final EntityDefinition SQUID; - public static final EntityDefinition STRAY; - public static final EntityDefinition STRIDER; - public static final EntityDefinition TADPOLE; - public static final EntityDefinition TEXT_DISPLAY; - public static final EntityDefinition TNT; - public static final EntityDefinition TNT_MINECART; - public static final EntityDefinition TRADER_LLAMA; - public static final EntityDefinition TRIDENT; - public static final EntityDefinition TROPICAL_FISH; - public static final EntityDefinition TURTLE; - public static final EntityDefinition VEX; - public static final EntityDefinition VILLAGER; - public static final EntityDefinition VINDICATOR; - public static final EntityDefinition WANDERING_TRADER; - public static final EntityDefinition WARDEN; - public static final EntityDefinition WIND_CHARGE; - public static final EntityDefinition WITCH; - public static final EntityDefinition WITHER; - public static final EntityDefinition WITHER_SKELETON; - public static final EntityDefinition WITHER_SKULL; - public static final EntityDefinition WOLF; - public static final EntityDefinition ZOGLIN; - public static final EntityDefinition ZOMBIE; - public static final EntityDefinition ZOMBIE_HORSE; - public static final EntityDefinition ZOMBIE_VILLAGER; - public static final EntityDefinition ZOMBIFIED_PIGLIN; + public static final VanillaEntityDefinition ACACIA_BOAT; + public static final VanillaEntityDefinition ACACIA_CHEST_BOAT; + public static final VanillaEntityDefinition ALLAY; + public static final VanillaEntityDefinition AREA_EFFECT_CLOUD; + public static final VanillaEntityDefinition ARMADILLO; + public static final VanillaEntityDefinition ARMOR_STAND; + public static final VanillaEntityDefinition ARROW; + public static final VanillaEntityDefinition AXOLOTL; + public static final VanillaEntityDefinition BAMBOO_RAFT; + public static final VanillaEntityDefinition BAMBOO_CHEST_RAFT; + public static final VanillaEntityDefinition BAT; + public static final VanillaEntityDefinition BEE; + public static final VanillaEntityDefinition BIRCH_BOAT; + public static final VanillaEntityDefinition BIRCH_CHEST_BOAT; + public static final VanillaEntityDefinition BLAZE; + public static final VanillaEntityDefinition BOGGED; + public static final VanillaEntityDefinition BREEZE; + public static final VanillaEntityDefinition BREEZE_WIND_CHARGE; + public static final VanillaEntityDefinition CAMEL; + public static final VanillaEntityDefinition CAT; + public static final VanillaEntityDefinition CAVE_SPIDER; + public static final VanillaEntityDefinition CHERRY_BOAT; + public static final VanillaEntityDefinition CHERRY_CHEST_BOAT; + public static final VanillaEntityDefinition CHEST_MINECART; + public static final VanillaEntityDefinition CHICKEN; + public static final VanillaEntityDefinition COD; + public static final VanillaEntityDefinition COPPER_GOLEM; + public static final VanillaEntityDefinition COMMAND_BLOCK_MINECART; + public static final VanillaEntityDefinition COW; + public static final VanillaEntityDefinition CREAKING; + public static final VanillaEntityDefinition CREEPER; + public static final VanillaEntityDefinition DARK_OAK_BOAT; + public static final VanillaEntityDefinition DARK_OAK_CHEST_BOAT; + public static final VanillaEntityDefinition DOLPHIN; + public static final VanillaEntityDefinition DONKEY; + public static final VanillaEntityDefinition DRAGON_FIREBALL; + public static final VanillaEntityDefinition DROWNED; + public static final VanillaEntityDefinition EGG; + public static final VanillaEntityDefinition ELDER_GUARDIAN; + public static final VanillaEntityDefinition ENDERMAN; + public static final VanillaEntityDefinition ENDERMITE; + public static final VanillaEntityDefinition ENDER_DRAGON; + public static final VanillaEntityDefinition ENDER_PEARL; + public static final VanillaEntityDefinition END_CRYSTAL; + public static final VanillaEntityDefinition EVOKER; + public static final VanillaEntityDefinition EVOKER_FANGS; + public static final VanillaEntityDefinition EXPERIENCE_BOTTLE; + public static final VanillaEntityDefinition EXPERIENCE_ORB; + public static final VanillaEntityDefinition EYE_OF_ENDER; + public static final VanillaEntityDefinition FALLING_BLOCK; + public static final VanillaEntityDefinition FIREBALL; + public static final VanillaEntityDefinition FIREWORK_ROCKET; + public static final VanillaEntityDefinition FISHING_BOBBER; + public static final VanillaEntityDefinition FOX; + public static final VanillaEntityDefinition FROG; + public static final VanillaEntityDefinition FURNACE_MINECART; // Not present on Bedrock + public static final VanillaEntityDefinition GHAST; + public static final VanillaEntityDefinition GIANT; + public static final VanillaEntityDefinition GLOW_ITEM_FRAME; + public static final VanillaEntityDefinition GLOW_SQUID; + public static final VanillaEntityDefinition GOAT; + public static final VanillaEntityDefinition GUARDIAN; + public static final VanillaEntityDefinition HAPPY_GHAST; + public static final VanillaEntityDefinition HOGLIN; + public static final VanillaEntityDefinition HOPPER_MINECART; + public static final VanillaEntityDefinition HORSE; + public static final VanillaEntityDefinition HUSK; + public static final VanillaEntityDefinition ILLUSIONER; // Not present on Bedrock + public static final VanillaEntityDefinition INTERACTION; + public static final VanillaEntityDefinition IRON_GOLEM; + public static final VanillaEntityDefinition ITEM; + public static final VanillaEntityDefinition ITEM_FRAME; + public static final VanillaEntityDefinition JUNGLE_BOAT; + public static final VanillaEntityDefinition JUNGLE_CHEST_BOAT; + public static final VanillaEntityDefinition LEASH_KNOT; + public static final VanillaEntityDefinition LIGHTNING_BOLT; + public static final VanillaEntityDefinition LLAMA; + public static final VanillaEntityDefinition LLAMA_SPIT; + public static final VanillaEntityDefinition MAGMA_CUBE; + public static final VanillaEntityDefinition MANGROVE_BOAT; + public static final VanillaEntityDefinition MANGROVE_CHEST_BOAT; + public static final VanillaEntityDefinition MANNEQUIN; + public static final VanillaEntityDefinition MINECART; + public static final VanillaEntityDefinition MOOSHROOM; + public static final VanillaEntityDefinition MULE; + public static final VanillaEntityDefinition OAK_BOAT; + public static final VanillaEntityDefinition OAK_CHEST_BOAT; + public static final VanillaEntityDefinition OCELOT; + public static final VanillaEntityDefinition PAINTING; + public static final VanillaEntityDefinition PALE_OAK_BOAT; + public static final VanillaEntityDefinition PALE_OAK_CHEST_BOAT; + public static final VanillaEntityDefinition PANDA; + public static final VanillaEntityDefinition PARROT; + public static final VanillaEntityDefinition PHANTOM; + public static final VanillaEntityDefinition PIG; + public static final VanillaEntityDefinition PIGLIN; + public static final VanillaEntityDefinition PIGLIN_BRUTE; + public static final VanillaEntityDefinition PILLAGER; + public static final VanillaEntityDefinition PLAYER; + public static final VanillaEntityDefinition POLAR_BEAR; + public static final VanillaEntityDefinition SPLASH_POTION; + public static final VanillaEntityDefinition LINGERING_POTION; + public static final VanillaEntityDefinition PUFFERFISH; + public static final VanillaEntityDefinition RABBIT; + public static final VanillaEntityDefinition RAVAGER; + public static final VanillaEntityDefinition SALMON; + public static final VanillaEntityDefinition SHEEP; + public static final VanillaEntityDefinition SHULKER; + public static final VanillaEntityDefinition SNIFFER; + public static final VanillaEntityDefinition SHULKER_BULLET; + public static final VanillaEntityDefinition SILVERFISH; + public static final VanillaEntityDefinition SKELETON; + public static final VanillaEntityDefinition SKELETON_HORSE; + public static final VanillaEntityDefinition SLIME; + public static final VanillaEntityDefinition SMALL_FIREBALL; + public static final VanillaEntityDefinition SNOWBALL; + public static final VanillaEntityDefinition SNOW_GOLEM; + public static final VanillaEntityDefinition SPAWNER_MINECART; // Not present on Bedrock + public static final VanillaEntityDefinition SPECTRAL_ARROW; + public static final VanillaEntityDefinition SPIDER; + public static final VanillaEntityDefinition SPRUCE_BOAT; + public static final VanillaEntityDefinition SPRUCE_CHEST_BOAT; + public static final VanillaEntityDefinition SQUID; + public static final VanillaEntityDefinition STRAY; + public static final VanillaEntityDefinition STRIDER; + public static final VanillaEntityDefinition TADPOLE; + public static final VanillaEntityDefinition TEXT_DISPLAY; + public static final VanillaEntityDefinition TNT; + public static final VanillaEntityDefinition TNT_MINECART; + public static final VanillaEntityDefinition TRADER_LLAMA; + public static final VanillaEntityDefinition TRIDENT; + public static final VanillaEntityDefinition TROPICAL_FISH; + public static final VanillaEntityDefinition TURTLE; + public static final VanillaEntityDefinition VEX; + public static final VanillaEntityDefinition VILLAGER; + public static final VanillaEntityDefinition VINDICATOR; + public static final VanillaEntityDefinition WANDERING_TRADER; + public static final VanillaEntityDefinition WARDEN; + public static final VanillaEntityDefinition WIND_CHARGE; + public static final VanillaEntityDefinition WITCH; + public static final VanillaEntityDefinition WITHER; + public static final VanillaEntityDefinition WITHER_SKELETON; + public static final VanillaEntityDefinition WITHER_SKULL; + public static final VanillaEntityDefinition WOLF; + public static final VanillaEntityDefinition ZOGLIN; + public static final VanillaEntityDefinition ZOMBIE; + public static final VanillaEntityDefinition ZOMBIE_HORSE; + public static final VanillaEntityDefinition ZOMBIE_VILLAGER; + public static final VanillaEntityDefinition ZOMBIFIED_PIGLIN; /** * Is not sent over the network */ - public static final EntityDefinition ENDER_DRAGON_PART; + public static final VanillaEntityDefinition ENDER_DRAGON_PART; /** * Special Bedrock type */ - public static final EntityDefinition WITHER_SKULL_DANGEROUS; + public static final VanillaEntityDefinition WITHER_SKULL_DANGEROUS; static { - EntityDefinition entityBase = EntityDefinition.builder(Entity::new) + EntityDefinition entityBase = VanillaEntityDefinition.builder(Entity::new) .addTranslator(MetadataTypes.BYTE, Entity::setFlags) .addTranslator(MetadataTypes.INT, Entity::setAir) // Air/bubbles .addTranslator(MetadataTypes.OPTIONAL_COMPONENT, Entity::setDisplayName) @@ -350,89 +350,89 @@ public final class EntityDefinitions { // Extends entity { - AREA_EFFECT_CLOUD = EntityDefinition.inherited(AreaEffectCloudEntity::new, entityBase) - .type(EntityType.AREA_EFFECT_CLOUD) + AREA_EFFECT_CLOUD = VanillaEntityDefinition.inherited(AreaEffectCloudEntity::new, entityBase) + .type(BuiltinEntityType.AREA_EFFECT_CLOUD) .height(0.5f).width(1.0f) .addTranslator(MetadataTypes.FLOAT, AreaEffectCloudEntity::setRadius) .addTranslator(null) // Waiting .addTranslator(MetadataTypes.PARTICLE, AreaEffectCloudEntity::setParticle) .build(); - DRAGON_FIREBALL = EntityDefinition.inherited(FireballEntity::new, entityBase) - .type(EntityType.DRAGON_FIREBALL) + DRAGON_FIREBALL = VanillaEntityDefinition.inherited(FireballEntity::new, entityBase) + .type(BuiltinEntityType.DRAGON_FIREBALL) .heightAndWidth(1.0f) .build(); - END_CRYSTAL = EntityDefinition.inherited(EnderCrystalEntity::new, entityBase) - .type(EntityType.END_CRYSTAL) + END_CRYSTAL = VanillaEntityDefinition.inherited(EnderCrystalEntity::new, entityBase) + .type(BuiltinEntityType.END_CRYSTAL) .heightAndWidth(2.0f) .identifier("minecraft:ender_crystal") .addTranslator(MetadataTypes.OPTIONAL_BLOCK_POS, EnderCrystalEntity::setBlockTarget) .addTranslator(MetadataTypes.BOOLEAN, (enderCrystalEntity, entityMetadata) -> enderCrystalEntity.setFlag(EntityFlag.SHOW_BOTTOM, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) // There is a base located on the ender crystal .build(); - EXPERIENCE_ORB = EntityDefinition.inherited(ExpOrbEntity::new, entityBase) - .type(EntityType.EXPERIENCE_ORB) + EXPERIENCE_ORB = VanillaEntityDefinition.inherited(ExpOrbEntity::new, entityBase) + .type(BuiltinEntityType.EXPERIENCE_ORB) .addTranslator(null) // int determining xb orb texture .identifier("minecraft:xp_orb") .build(); - EVOKER_FANGS = EntityDefinition.inherited(EvokerFangsEntity::new, entityBase) - .type(EntityType.EVOKER_FANGS) + EVOKER_FANGS = VanillaEntityDefinition.inherited(EvokerFangsEntity::new, entityBase) + .type(BuiltinEntityType.EVOKER_FANGS) .height(0.8f).width(0.5f) .identifier("minecraft:evocation_fang") .build(); - EYE_OF_ENDER = EntityDefinition.inherited(EnderEyeEntity::new, entityBase) - .type(EntityType.EYE_OF_ENDER) + EYE_OF_ENDER = VanillaEntityDefinition.inherited(EnderEyeEntity::new, entityBase) + .type(BuiltinEntityType.EYE_OF_ENDER) .heightAndWidth(0.25f) .identifier("minecraft:eye_of_ender_signal") .addTranslator(null) // Item .build(); - FALLING_BLOCK = EntityDefinition.inherited(null, entityBase) - .type(EntityType.FALLING_BLOCK) + FALLING_BLOCK = VanillaEntityDefinition.inherited(null, entityBase) + .type(BuiltinEntityType.FALLING_BLOCK) .heightAndWidth(0.98f) .addTranslator(null) // "start block position" .build(); - FIREWORK_ROCKET = EntityDefinition.inherited(FireworkEntity::new, entityBase) - .type(EntityType.FIREWORK_ROCKET) + FIREWORK_ROCKET = VanillaEntityDefinition.inherited(FireworkEntity::new, entityBase) + .type(BuiltinEntityType.FIREWORK_ROCKET) .heightAndWidth(0.25f) .identifier("minecraft:fireworks_rocket") .addTranslator(MetadataTypes.ITEM_STACK, FireworkEntity::setFireworkItem) .addTranslator(MetadataTypes.OPTIONAL_UNSIGNED_INT, FireworkEntity::setPlayerGliding) .addTranslator(null) // Shot at angle .build(); - FISHING_BOBBER = EntityDefinition.inherited(null, entityBase) - .type(EntityType.FISHING_BOBBER) + FISHING_BOBBER = VanillaEntityDefinition.inherited(null, entityBase) + .type(BuiltinEntityType.FISHING_BOBBER) .identifier("minecraft:fishing_hook") .addTranslator(MetadataTypes.INT, FishingHookEntity::setHookedEntity) .addTranslator(null) // Biting TODO check .build(); - ITEM = EntityDefinition.inherited(ItemEntity::new, entityBase) - .type(EntityType.ITEM) + ITEM = VanillaEntityDefinition.inherited(ItemEntity::new, entityBase) + .type(BuiltinEntityType.ITEM) .heightAndWidth(0.25f) .offset(0.125f) .addTranslator(MetadataTypes.ITEM_STACK, ItemEntity::setItem) .build(); - LEASH_KNOT = EntityDefinition.inherited(LeashKnotEntity::new, entityBase) - .type(EntityType.LEASH_KNOT) + LEASH_KNOT = VanillaEntityDefinition.inherited(LeashKnotEntity::new, entityBase) + .type(BuiltinEntityType.LEASH_KNOT) .height(0.5f).width(0.375f) .build(); - LIGHTNING_BOLT = EntityDefinition.inherited(LightningEntity::new, entityBase) - .type(EntityType.LIGHTNING_BOLT) + LIGHTNING_BOLT = VanillaEntityDefinition.inherited(LightningEntity::new, entityBase) + .type(BuiltinEntityType.LIGHTNING_BOLT) .build(); - LLAMA_SPIT = EntityDefinition.inherited(ThrowableEntity::new, entityBase) - .type(EntityType.LLAMA_SPIT) + LLAMA_SPIT = VanillaEntityDefinition.inherited(ThrowableEntity::new, entityBase) + .type(BuiltinEntityType.LLAMA_SPIT) .heightAndWidth(0.25f) .build(); - SHULKER_BULLET = EntityDefinition.inherited(ThrowableEntity::new, entityBase) - .type(EntityType.SHULKER_BULLET) + SHULKER_BULLET = VanillaEntityDefinition.inherited(ThrowableEntity::new, entityBase) + .type(BuiltinEntityType.SHULKER_BULLET) .heightAndWidth(0.3125f) .build(); - TNT = EntityDefinition.inherited(TNTEntity::new, entityBase) - .type(EntityType.TNT) + TNT = VanillaEntityDefinition.inherited(TNTEntity::new, entityBase) + .type(BuiltinEntityType.TNT) .heightAndWidth(0.98f) .offset(0.49f) .addTranslator(MetadataTypes.INT, TNTEntity::setFuseLength) .build(); - EntityDefinition displayBase = EntityDefinition.inherited(DisplayBaseEntity::new, entityBase) + VanillaEntityDefinition displayBase = VanillaEntityDefinition.inherited(DisplayBaseEntity::new, entityBase) .addTranslator(null) // Interpolation delay .addTranslator(null) // Transformation interpolation duration .addTranslator(null) // Position/Rotation interpolation duration @@ -449,8 +449,8 @@ public final class EntityDefinitions { .addTranslator(null) // Height .addTranslator(null) // Glow color override .build(); - TEXT_DISPLAY = EntityDefinition.inherited(TextDisplayEntity::new, displayBase) - .type(EntityType.TEXT_DISPLAY) + TEXT_DISPLAY = VanillaEntityDefinition.inherited(TextDisplayEntity::new, displayBase) + .type(BuiltinEntityType.TEXT_DISPLAY) .identifier("minecraft:armor_stand") .offset(-0.5f) .addTranslator(MetadataTypes.COMPONENT, TextDisplayEntity::setText) @@ -460,8 +460,8 @@ public final class EntityDefinitions { .addTranslator(null) // Bit mask .build(); - INTERACTION = EntityDefinition.inherited(InteractionEntity::new, entityBase) - .type(EntityType.INTERACTION) + INTERACTION = VanillaEntityDefinition.inherited(InteractionEntity::new, entityBase) + .type(BuiltinEntityType.INTERACTION) .heightAndWidth(1.0f) // default size until server specifies otherwise .identifier("minecraft:armor_stand") .addTranslator(MetadataTypes.FLOAT, InteractionEntity::setWidth) @@ -469,105 +469,105 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.BOOLEAN, InteractionEntity::setResponse) .build(); - EntityDefinition fireballBase = EntityDefinition.inherited(FireballEntity::new, entityBase) + VanillaEntityDefinition fireballBase = VanillaEntityDefinition.inherited(FireballEntity::new, entityBase) .addTranslator(null) // Item .build(); - FIREBALL = EntityDefinition.inherited(FireballEntity::new, fireballBase) - .type(EntityType.FIREBALL) + FIREBALL = VanillaEntityDefinition.inherited(FireballEntity::new, fireballBase) + .type(BuiltinEntityType.FIREBALL) .heightAndWidth(1.0f) .build(); - SMALL_FIREBALL = EntityDefinition.inherited(FireballEntity::new, fireballBase) - .type(EntityType.SMALL_FIREBALL) + SMALL_FIREBALL = VanillaEntityDefinition.inherited(FireballEntity::new, fireballBase) + .type(BuiltinEntityType.SMALL_FIREBALL) .heightAndWidth(0.3125f) .build(); - EntityDefinition throwableItemBase = EntityDefinition.inherited(ThrowableItemEntity::new, entityBase) + VanillaEntityDefinition throwableItemBase = VanillaEntityDefinition.inherited(ThrowableItemEntity::new, entityBase) .addTranslator(MetadataTypes.ITEM_STACK, ThrowableItemEntity::setItem) .build(); - EGG = EntityDefinition.inherited(ThrowableEggEntity::new, throwableItemBase) - .type(EntityType.EGG) + EGG = VanillaEntityDefinition.inherited(ThrowableEggEntity::new, throwableItemBase) + .type(BuiltinEntityType.EGG) .heightAndWidth(0.25f) .property(TemperatureVariantAnimal.TEMPERATE_VARIANT_PROPERTY) .build(); - ENDER_PEARL = EntityDefinition.inherited(ThrowableItemEntity::new, throwableItemBase) - .type(EntityType.ENDER_PEARL) + ENDER_PEARL = VanillaEntityDefinition.inherited(ThrowableItemEntity::new, throwableItemBase) + .type(BuiltinEntityType.ENDER_PEARL) .heightAndWidth(0.25f) .build(); - EXPERIENCE_BOTTLE = EntityDefinition.inherited(ThrowableItemEntity::new, throwableItemBase) - .type(EntityType.EXPERIENCE_BOTTLE) + EXPERIENCE_BOTTLE = VanillaEntityDefinition.inherited(ThrowableItemEntity::new, throwableItemBase) + .type(BuiltinEntityType.EXPERIENCE_BOTTLE) .heightAndWidth(0.25f) .identifier("minecraft:xp_bottle") .build(); - SPLASH_POTION = EntityDefinition.inherited(ThrownPotionEntity::new, throwableItemBase) - .type(EntityType.SPLASH_POTION) + SPLASH_POTION = VanillaEntityDefinition.inherited(ThrownPotionEntity::new, throwableItemBase) + .type(BuiltinEntityType.SPLASH_POTION) .heightAndWidth(0.25f) .identifier("minecraft:splash_potion") .build(); - LINGERING_POTION = EntityDefinition.inherited(ThrownPotionEntity::new, throwableItemBase) - .type(EntityType.LINGERING_POTION) + LINGERING_POTION = VanillaEntityDefinition.inherited(ThrownPotionEntity::new, throwableItemBase) + .type(BuiltinEntityType.LINGERING_POTION) .heightAndWidth(0.25f) .identifier("minecraft:splash_potion") .build(); - SNOWBALL = EntityDefinition.inherited(ThrowableItemEntity::new, throwableItemBase) - .type(EntityType.SNOWBALL) + SNOWBALL = VanillaEntityDefinition.inherited(ThrowableItemEntity::new, throwableItemBase) + .type(BuiltinEntityType.SNOWBALL) .heightAndWidth(0.25f) .build(); EntityFactory windChargeSupplier = AbstractWindChargeEntity::new; - BREEZE_WIND_CHARGE = EntityDefinition.inherited(windChargeSupplier, entityBase) - .type(EntityType.BREEZE_WIND_CHARGE) + BREEZE_WIND_CHARGE = VanillaEntityDefinition.inherited(windChargeSupplier, entityBase) + .type(BuiltinEntityType.BREEZE_WIND_CHARGE) .identifier("minecraft:breeze_wind_charge_projectile") .heightAndWidth(0.3125f) .build(); - WIND_CHARGE = EntityDefinition.inherited(windChargeSupplier, entityBase) - .type(EntityType.WIND_CHARGE) + WIND_CHARGE = VanillaEntityDefinition.inherited(windChargeSupplier, entityBase) + .type(BuiltinEntityType.WIND_CHARGE) .identifier("minecraft:wind_charge_projectile") .heightAndWidth(0.3125f) .build(); - EntityDefinition abstractArrowBase = EntityDefinition.inherited(AbstractArrowEntity::new, entityBase) + VanillaEntityDefinition abstractArrowBase = VanillaEntityDefinition.inherited(AbstractArrowEntity::new, entityBase) .addTranslator(MetadataTypes.BYTE, AbstractArrowEntity::setArrowFlags) .addTranslator(null) // "Piercing level" .addTranslator(null) // If the arrow is in the ground .build(); - ARROW = EntityDefinition.inherited(ArrowEntity::new, abstractArrowBase) - .type(EntityType.ARROW) + ARROW = VanillaEntityDefinition.inherited(ArrowEntity::new, abstractArrowBase) + .type(BuiltinEntityType.ARROW) .heightAndWidth(0.25f) .addTranslator(MetadataTypes.INT, ArrowEntity::setPotionEffectColor) .build(); - SPECTRAL_ARROW = EntityDefinition.inherited(abstractArrowBase.factory(), abstractArrowBase) - .type(EntityType.SPECTRAL_ARROW) + SPECTRAL_ARROW = VanillaEntityDefinition.inherited(abstractArrowBase.factory(), abstractArrowBase) + .type(BuiltinEntityType.SPECTRAL_ARROW) .heightAndWidth(0.25f) .identifier("minecraft:arrow") .build(); - TRIDENT = EntityDefinition.inherited(TridentEntity::new, abstractArrowBase) // TODO remove class - .type(EntityType.TRIDENT) + TRIDENT = VanillaEntityDefinition.inherited(TridentEntity::new, abstractArrowBase) // TODO remove class + .type(BuiltinEntityType.TRIDENT) .identifier("minecraft:thrown_trident") .addTranslator(null) // Loyalty .addTranslator(MetadataTypes.BOOLEAN, (tridentEntity, entityMetadata) -> tridentEntity.setFlag(EntityFlag.ENCHANTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .build(); - EntityDefinition hangingEntityBase = EntityDefinition.inherited(null, entityBase) + VanillaEntityDefinition hangingEntityBase = VanillaEntityDefinition.inherited(null, entityBase) .addTranslator(MetadataTypes.DIRECTION, HangingEntity::setDirectionMetadata) .build(); - PAINTING = EntityDefinition.inherited(PaintingEntity::new, hangingEntityBase) - .type(EntityType.PAINTING) + PAINTING = VanillaEntityDefinition.inherited(PaintingEntity::new, hangingEntityBase) + .type(BuiltinEntityType.PAINTING) .addTranslator(MetadataTypes.PAINTING_VARIANT, PaintingEntity::setPaintingType) .build(); // Item frames are handled differently as they are blocks, not items, in Bedrock - ITEM_FRAME = EntityDefinition.inherited(ItemFrameEntity::new, hangingEntityBase) - .type(EntityType.ITEM_FRAME) + ITEM_FRAME = VanillaEntityDefinition.inherited(ItemFrameEntity::new, hangingEntityBase) + .type(BuiltinEntityType.ITEM_FRAME) .addTranslator(MetadataTypes.ITEM_STACK, ItemFrameEntity::setItemInFrame) .addTranslator(MetadataTypes.INT, ItemFrameEntity::setItemRotation) .build(); - GLOW_ITEM_FRAME = EntityDefinition.inherited(ITEM_FRAME.factory(), ITEM_FRAME) - .type(EntityType.GLOW_ITEM_FRAME) + GLOW_ITEM_FRAME = VanillaEntityDefinition.inherited(ITEM_FRAME.factory(), ITEM_FRAME) + .type(BuiltinEntityType.GLOW_ITEM_FRAME) .build(); - MINECART = EntityDefinition.inherited(MinecartEntity::new, entityBase) - .type(EntityType.MINECART) + MINECART = VanillaEntityDefinition.inherited(MinecartEntity::new, entityBase) + .type(BuiltinEntityType.MINECART) .height(0.7f).width(0.98f) .offset(0.35f) .addTranslator(MetadataTypes.INT, (minecartEntity, entityMetadata) -> minecartEntity.getDirtyMetadata().put(EntityDataTypes.STRUCTURAL_INTEGRITY, entityMetadata.getValue())) @@ -578,42 +578,42 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.OPTIONAL_BLOCK_STATE, MinecartEntity::setCustomBlock) .addTranslator(MetadataTypes.INT, MinecartEntity::setCustomBlockOffset) .build(); - CHEST_MINECART = EntityDefinition.inherited(MINECART.factory(), MINECART) - .type(EntityType.CHEST_MINECART) + CHEST_MINECART = VanillaEntityDefinition.inherited(MINECART.factory(), MINECART) + .type(BuiltinEntityType.CHEST_MINECART) .build(); - COMMAND_BLOCK_MINECART = EntityDefinition.inherited(CommandBlockMinecartEntity::new, MINECART) - .type(EntityType.COMMAND_BLOCK_MINECART) + COMMAND_BLOCK_MINECART = VanillaEntityDefinition.inherited(CommandBlockMinecartEntity::new, MINECART) + .type(BuiltinEntityType.COMMAND_BLOCK_MINECART) .addTranslator(MetadataTypes.STRING, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityDataTypes.COMMAND_BLOCK_NAME, entityMetadata.getValue())) .addTranslator(MetadataTypes.COMPONENT, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityDataTypes.COMMAND_BLOCK_LAST_OUTPUT, MessageTranslator.convertMessage(entityMetadata.getValue()))) .build(); - FURNACE_MINECART = EntityDefinition.inherited(FurnaceMinecartEntity::new, MINECART) - .type(EntityType.FURNACE_MINECART) + FURNACE_MINECART = VanillaEntityDefinition.inherited(FurnaceMinecartEntity::new, MINECART) + .type(BuiltinEntityType.FURNACE_MINECART) .identifier("minecraft:minecart") .addTranslator(MetadataTypes.BOOLEAN, FurnaceMinecartEntity::setHasFuel) .build(); - HOPPER_MINECART = EntityDefinition.inherited(MINECART.factory(), MINECART) - .type(EntityType.HOPPER_MINECART) + HOPPER_MINECART = VanillaEntityDefinition.inherited(MINECART.factory(), MINECART) + .type(BuiltinEntityType.HOPPER_MINECART) .build(); - SPAWNER_MINECART = EntityDefinition.inherited(SpawnerMinecartEntity::new, MINECART) - .type(EntityType.SPAWNER_MINECART) + SPAWNER_MINECART = VanillaEntityDefinition.inherited(SpawnerMinecartEntity::new, MINECART) + .type(BuiltinEntityType.SPAWNER_MINECART) .identifier("minecraft:minecart") .build(); - TNT_MINECART = EntityDefinition.inherited(MINECART.factory(), MINECART) - .type(EntityType.TNT_MINECART) + TNT_MINECART = VanillaEntityDefinition.inherited(MINECART.factory(), MINECART) + .type(BuiltinEntityType.TNT_MINECART) .build(); - WITHER_SKULL = EntityDefinition.inherited(WitherSkullEntity::new, entityBase) - .type(EntityType.WITHER_SKULL) + WITHER_SKULL = VanillaEntityDefinition.inherited(WitherSkullEntity::new, entityBase) + .type(BuiltinEntityType.WITHER_SKULL) .heightAndWidth(0.3125f) .addTranslator(MetadataTypes.BOOLEAN, WitherSkullEntity::setDangerous) .build(); - WITHER_SKULL_DANGEROUS = EntityDefinition.inherited(WITHER_SKULL.factory(), WITHER_SKULL) + WITHER_SKULL_DANGEROUS = VanillaEntityDefinition.inherited(WITHER_SKULL.factory(), WITHER_SKULL) .build(false); } // Boats { - EntityDefinition boatBase = EntityDefinition.inherited(null, entityBase) + VanillaEntityDefinition boatBase = VanillaEntityDefinition.inherited(null, entityBase) .height(0.6f).width(1.6f) .offset(0.35f) .addTranslator(MetadataTypes.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityDataTypes.HURT_TICKS, entityMetadata.getValue())) // Time since last hit @@ -626,33 +626,33 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityDataTypes.BOAT_BUBBLE_TIME, entityMetadata.getValue())) // May not actually do anything .build(); - ACACIA_BOAT = buildBoat(boatBase, EntityType.ACACIA_BOAT, BoatEntity.BoatVariant.ACACIA); - BAMBOO_RAFT = buildBoat(boatBase, EntityType.BAMBOO_RAFT, BoatEntity.BoatVariant.BAMBOO); - BIRCH_BOAT = buildBoat(boatBase, EntityType.BIRCH_BOAT, BoatEntity.BoatVariant.BIRCH); - CHERRY_BOAT = buildBoat(boatBase, EntityType.CHERRY_BOAT, BoatEntity.BoatVariant.CHERRY); - DARK_OAK_BOAT = buildBoat(boatBase, EntityType.DARK_OAK_BOAT, BoatEntity.BoatVariant.DARK_OAK); - JUNGLE_BOAT = buildBoat(boatBase, EntityType.JUNGLE_BOAT, BoatEntity.BoatVariant.JUNGLE); - MANGROVE_BOAT = buildBoat(boatBase, EntityType.MANGROVE_BOAT, BoatEntity.BoatVariant.MANGROVE); - OAK_BOAT = buildBoat(boatBase, EntityType.OAK_BOAT, BoatEntity.BoatVariant.OAK); - SPRUCE_BOAT = buildBoat(boatBase, EntityType.SPRUCE_BOAT, BoatEntity.BoatVariant.SPRUCE); - PALE_OAK_BOAT = buildBoat(boatBase, EntityType.PALE_OAK_BOAT, BoatEntity.BoatVariant.PALE_OAK); + ACACIA_BOAT = buildBoat(boatBase, BuiltinEntityType.ACACIA_BOAT, BoatEntity.BoatVariant.ACACIA); + BAMBOO_RAFT = buildBoat(boatBase, BuiltinEntityType.BAMBOO_RAFT, BoatEntity.BoatVariant.BAMBOO); + BIRCH_BOAT = buildBoat(boatBase, BuiltinEntityType.BIRCH_BOAT, BoatEntity.BoatVariant.BIRCH); + CHERRY_BOAT = buildBoat(boatBase, BuiltinEntityType.CHERRY_BOAT, BoatEntity.BoatVariant.CHERRY); + DARK_OAK_BOAT = buildBoat(boatBase, BuiltinEntityType.DARK_OAK_BOAT, BoatEntity.BoatVariant.DARK_OAK); + JUNGLE_BOAT = buildBoat(boatBase, BuiltinEntityType.JUNGLE_BOAT, BoatEntity.BoatVariant.JUNGLE); + MANGROVE_BOAT = buildBoat(boatBase, BuiltinEntityType.MANGROVE_BOAT, BoatEntity.BoatVariant.MANGROVE); + OAK_BOAT = buildBoat(boatBase, BuiltinEntityType.OAK_BOAT, BoatEntity.BoatVariant.OAK); + SPRUCE_BOAT = buildBoat(boatBase, BuiltinEntityType.SPRUCE_BOAT, BoatEntity.BoatVariant.SPRUCE); + PALE_OAK_BOAT = buildBoat(boatBase, BuiltinEntityType.PALE_OAK_BOAT, BoatEntity.BoatVariant.PALE_OAK); - EntityDefinition chestBoatBase = EntityDefinition.inherited(null, boatBase) + VanillaEntityDefinition chestBoatBase = VanillaEntityDefinition.inherited(null, boatBase) .build(); - ACACIA_CHEST_BOAT = buildChestBoat(chestBoatBase, EntityType.ACACIA_CHEST_BOAT, BoatEntity.BoatVariant.ACACIA); - BAMBOO_CHEST_RAFT = buildChestBoat(chestBoatBase, EntityType.BAMBOO_CHEST_RAFT, BoatEntity.BoatVariant.BAMBOO); - BIRCH_CHEST_BOAT = buildChestBoat(chestBoatBase, EntityType.BIRCH_CHEST_BOAT, BoatEntity.BoatVariant.BIRCH); - CHERRY_CHEST_BOAT = buildChestBoat(chestBoatBase, EntityType.CHERRY_CHEST_BOAT, BoatEntity.BoatVariant.CHERRY); - DARK_OAK_CHEST_BOAT = buildChestBoat(chestBoatBase, EntityType.DARK_OAK_CHEST_BOAT, BoatEntity.BoatVariant.DARK_OAK); - JUNGLE_CHEST_BOAT = buildChestBoat(chestBoatBase, EntityType.JUNGLE_CHEST_BOAT, BoatEntity.BoatVariant.JUNGLE); - MANGROVE_CHEST_BOAT = buildChestBoat(chestBoatBase, EntityType.MANGROVE_CHEST_BOAT, BoatEntity.BoatVariant.MANGROVE); - OAK_CHEST_BOAT = buildChestBoat(chestBoatBase, EntityType.OAK_CHEST_BOAT, BoatEntity.BoatVariant.OAK); - SPRUCE_CHEST_BOAT = buildChestBoat(chestBoatBase, EntityType.SPRUCE_CHEST_BOAT, BoatEntity.BoatVariant.SPRUCE); - PALE_OAK_CHEST_BOAT = buildChestBoat(chestBoatBase, EntityType.PALE_OAK_CHEST_BOAT, BoatEntity.BoatVariant.PALE_OAK); + ACACIA_CHEST_BOAT = buildChestBoat(chestBoatBase, BuiltinEntityType.ACACIA_CHEST_BOAT, BoatEntity.BoatVariant.ACACIA); + BAMBOO_CHEST_RAFT = buildChestBoat(chestBoatBase, BuiltinEntityType.BAMBOO_CHEST_RAFT, BoatEntity.BoatVariant.BAMBOO); + BIRCH_CHEST_BOAT = buildChestBoat(chestBoatBase, BuiltinEntityType.BIRCH_CHEST_BOAT, BoatEntity.BoatVariant.BIRCH); + CHERRY_CHEST_BOAT = buildChestBoat(chestBoatBase, BuiltinEntityType.CHERRY_CHEST_BOAT, BoatEntity.BoatVariant.CHERRY); + DARK_OAK_CHEST_BOAT = buildChestBoat(chestBoatBase, BuiltinEntityType.DARK_OAK_CHEST_BOAT, BoatEntity.BoatVariant.DARK_OAK); + JUNGLE_CHEST_BOAT = buildChestBoat(chestBoatBase, BuiltinEntityType.JUNGLE_CHEST_BOAT, BoatEntity.BoatVariant.JUNGLE); + MANGROVE_CHEST_BOAT = buildChestBoat(chestBoatBase, BuiltinEntityType.MANGROVE_CHEST_BOAT, BoatEntity.BoatVariant.MANGROVE); + OAK_CHEST_BOAT = buildChestBoat(chestBoatBase, BuiltinEntityType.OAK_CHEST_BOAT, BoatEntity.BoatVariant.OAK); + SPRUCE_CHEST_BOAT = buildChestBoat(chestBoatBase, BuiltinEntityType.SPRUCE_CHEST_BOAT, BoatEntity.BoatVariant.SPRUCE); + PALE_OAK_CHEST_BOAT = buildChestBoat(chestBoatBase, BuiltinEntityType.PALE_OAK_CHEST_BOAT, BoatEntity.BoatVariant.PALE_OAK); } - EntityDefinition livingEntityBase = EntityDefinition.inherited(LivingEntity::new, entityBase) + VanillaEntityDefinition livingEntityBase = VanillaEntityDefinition.inherited(LivingEntity::new, entityBase) .addTranslator(MetadataTypes.BYTE, LivingEntity::setLivingEntityFlags) .addTranslator(MetadataTypes.FLOAT, LivingEntity::setHealth) .addTranslator(MetadataTypes.PARTICLES, LivingEntity::setParticles) @@ -663,8 +663,8 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.OPTIONAL_BLOCK_POS, LivingEntity::setBedPosition) .build(); - ARMOR_STAND = EntityDefinition.inherited(ArmorStandEntity::new, livingEntityBase) - .type(EntityType.ARMOR_STAND) + ARMOR_STAND = VanillaEntityDefinition.inherited(ArmorStandEntity::new, livingEntityBase) + .type(BuiltinEntityType.ARMOR_STAND) .height(1.975f).width(0.5f) .addTranslator(MetadataTypes.BYTE, ArmorStandEntity::setArmorStandFlags) .addTranslator(MetadataTypes.ROTATIONS, ArmorStandEntity::setHeadRotation) @@ -675,61 +675,61 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.ROTATIONS, ArmorStandEntity::setRightLegRotation) .build(); - EntityDefinition avatarEntityBase = EntityDefinition.inherited(null, livingEntityBase) + VanillaEntityDefinition avatarEntityBase = VanillaEntityDefinition.inherited(null, livingEntityBase) .height(1.8f).width(0.6f) .offset(1.62f) .addTranslator(null) // Player main hand .addTranslator(MetadataTypes.BYTE, AvatarEntity::setSkinVisibility) .build(); - MANNEQUIN = EntityDefinition.inherited(MannequinEntity::new, avatarEntityBase) - .type(EntityType.MANNEQUIN) + MANNEQUIN = VanillaEntityDefinition.inherited(MannequinEntity::new, avatarEntityBase) + .type(BuiltinEntityType.MANNEQUIN) .addTranslator(MetadataTypes.RESOLVABLE_PROFILE, MannequinEntity::setProfile) .addTranslator(null) // Immovable .addTranslator(MetadataTypes.OPTIONAL_COMPONENT, MannequinEntity::setDescription) .build(); - PLAYER = EntityDefinition.inherited(null, avatarEntityBase) - .type(EntityType.PLAYER) + PLAYER = VanillaEntityDefinition.inherited(null, avatarEntityBase) + .type(BuiltinEntityType.PLAYER) .addTranslator(MetadataTypes.FLOAT, PlayerEntity::setAbsorptionHearts) .addTranslator(null) // Player score .addTranslator(MetadataTypes.OPTIONAL_UNSIGNED_INT, PlayerEntity::setLeftParrot) .addTranslator(MetadataTypes.OPTIONAL_UNSIGNED_INT, PlayerEntity::setRightParrot) .build(); - EntityDefinition mobEntityBase = EntityDefinition.inherited(MobEntity::new, livingEntityBase) + VanillaEntityDefinition mobEntityBase = VanillaEntityDefinition.inherited(MobEntity::new, livingEntityBase) .addTranslator(MetadataTypes.BYTE, MobEntity::setMobFlags) .build(); // Extends mob { - ALLAY = EntityDefinition.inherited(AllayEntity::new, mobEntityBase) - .type(EntityType.ALLAY) + ALLAY = VanillaEntityDefinition.inherited(AllayEntity::new, mobEntityBase) + .type(BuiltinEntityType.ALLAY) .height(0.6f).width(0.35f) .addTranslator(MetadataTypes.BOOLEAN, AllayEntity::setDancing) .addTranslator(MetadataTypes.BOOLEAN, AllayEntity::setCanDuplicate) .build(); - BAT = EntityDefinition.inherited(BatEntity::new, mobEntityBase) - .type(EntityType.BAT) + BAT = VanillaEntityDefinition.inherited(BatEntity::new, mobEntityBase) + .type(BuiltinEntityType.BAT) .height(0.9f).width(0.5f) .addTranslator(MetadataTypes.BYTE, BatEntity::setBatFlags) .build(); - BOGGED = EntityDefinition.inherited(BoggedEntity::new, mobEntityBase) - .type(EntityType.BOGGED) + BOGGED = VanillaEntityDefinition.inherited(BoggedEntity::new, mobEntityBase) + .type(BuiltinEntityType.BOGGED) .height(1.99f).width(0.6f) .addTranslator(MetadataTypes.BOOLEAN, BoggedEntity::setSheared) .build(); - BLAZE = EntityDefinition.inherited(BlazeEntity::new, mobEntityBase) - .type(EntityType.BLAZE) + BLAZE = VanillaEntityDefinition.inherited(BlazeEntity::new, mobEntityBase) + .type(BuiltinEntityType.BLAZE) .height(1.8f).width(0.6f) .addTranslator(MetadataTypes.BYTE, BlazeEntity::setBlazeFlags) .build(); - BREEZE = EntityDefinition.inherited(BreezeEntity::new, mobEntityBase) - .type(EntityType.BREEZE) + BREEZE = VanillaEntityDefinition.inherited(BreezeEntity::new, mobEntityBase) + .type(BuiltinEntityType.BREEZE) .height(1.77f).width(0.6f) .build(); - COPPER_GOLEM = EntityDefinition.inherited(CopperGolemEntity::new, mobEntityBase) - .type(EntityType.COPPER_GOLEM) + COPPER_GOLEM = VanillaEntityDefinition.inherited(CopperGolemEntity::new, mobEntityBase) + .type(BuiltinEntityType.COPPER_GOLEM) .height(0.49f).width(0.98f) .addTranslator(MetadataTypes.WEATHERING_COPPER_STATE, CopperGolemEntity::setWeatheringState) .addTranslator(MetadataTypes.COPPER_GOLEM_STATE, CopperGolemEntity::setGolemState) @@ -737,8 +737,8 @@ public final class EntityDefinitions { .property(CopperGolemEntity.HAS_FLOWER_PROPERTY) .property(CopperGolemEntity.OXIDATION_LEVEL_STATE_ENUM_PROPERTY) .build(); - CREAKING = EntityDefinition.inherited(CreakingEntity::new, mobEntityBase) - .type(EntityType.CREAKING) + CREAKING = VanillaEntityDefinition.inherited(CreakingEntity::new, mobEntityBase) + .type(BuiltinEntityType.CREAKING) .height(2.7f).width(0.9f) .addTranslator(MetadataTypes.BOOLEAN, CreakingEntity::setCanMove) .addTranslator(MetadataTypes.BOOLEAN, CreakingEntity::setActive) @@ -747,331 +747,331 @@ public final class EntityDefinitions { .property(CreakingEntity.STATE_PROPERTY) .property(CreakingEntity.SWAYING_TICKS_PROPERTY) .build(); - CREEPER = EntityDefinition.inherited(CreeperEntity::new, mobEntityBase) - .type(EntityType.CREEPER) + CREEPER = VanillaEntityDefinition.inherited(CreeperEntity::new, mobEntityBase) + .type(BuiltinEntityType.CREEPER) .height(1.7f).width(0.6f) .offset(1.62f) .addTranslator(MetadataTypes.INT, CreeperEntity::setSwelling) .addTranslator(MetadataTypes.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.POWERED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .addTranslator(MetadataTypes.BOOLEAN, CreeperEntity::setIgnited) .build(); - ENDERMAN = EntityDefinition.inherited(EndermanEntity::new, mobEntityBase) - .type(EntityType.ENDERMAN) + ENDERMAN = VanillaEntityDefinition.inherited(EndermanEntity::new, mobEntityBase) + .type(BuiltinEntityType.ENDERMAN) .height(2.9f).width(0.6f) .addTranslator(MetadataTypes.OPTIONAL_BLOCK_STATE, EndermanEntity::setCarriedBlock) .addTranslator(MetadataTypes.BOOLEAN, EndermanEntity::setScreaming) .addTranslator(MetadataTypes.BOOLEAN, EndermanEntity::setAngry) .build(); - ENDERMITE = EntityDefinition.inherited(MonsterEntity::new, mobEntityBase) - .type(EntityType.ENDERMITE) + ENDERMITE = VanillaEntityDefinition.inherited(MonsterEntity::new, mobEntityBase) + .type(BuiltinEntityType.ENDERMITE) .height(0.3f).width(0.4f) .build(); - ENDER_DRAGON = EntityDefinition.inherited(EnderDragonEntity::new, mobEntityBase) - .type(EntityType.ENDER_DRAGON) + ENDER_DRAGON = VanillaEntityDefinition.inherited(EnderDragonEntity::new, mobEntityBase) + .type(BuiltinEntityType.ENDER_DRAGON) .addTranslator(MetadataTypes.INT, EnderDragonEntity::setPhase) .build(); - GHAST = EntityDefinition.inherited(GhastEntity::new, mobEntityBase) - .type(EntityType.GHAST) + GHAST = VanillaEntityDefinition.inherited(GhastEntity::new, mobEntityBase) + .type(BuiltinEntityType.GHAST) .heightAndWidth(4.0f) .addTranslator(MetadataTypes.BOOLEAN, GhastEntity::setGhastAttacking) .build(); - GIANT = EntityDefinition.inherited(GiantEntity::new, mobEntityBase) - .type(EntityType.GIANT) + GIANT = VanillaEntityDefinition.inherited(GiantEntity::new, mobEntityBase) + .type(BuiltinEntityType.GIANT) .height(1.8f).width(1.6f) .offset(1.62f) .identifier("minecraft:zombie") .build(); - IRON_GOLEM = EntityDefinition.inherited(IronGolemEntity::new, mobEntityBase) - .type(EntityType.IRON_GOLEM) + IRON_GOLEM = VanillaEntityDefinition.inherited(IronGolemEntity::new, mobEntityBase) + .type(BuiltinEntityType.IRON_GOLEM) .height(2.7f).width(1.4f) .addTranslator(null) // "is player created", which doesn't seem to do anything clientside .build(); - PHANTOM = EntityDefinition.inherited(PhantomEntity::new, mobEntityBase) - .type(EntityType.PHANTOM) + PHANTOM = VanillaEntityDefinition.inherited(PhantomEntity::new, mobEntityBase) + .type(BuiltinEntityType.PHANTOM) .height(0.5f).width(0.9f) .offset(0.6f) .addTranslator(MetadataTypes.INT, PhantomEntity::setPhantomScale) .build(); - SILVERFISH = EntityDefinition.inherited(MonsterEntity::new, mobEntityBase) - .type(EntityType.SILVERFISH) + SILVERFISH = VanillaEntityDefinition.inherited(MonsterEntity::new, mobEntityBase) + .type(BuiltinEntityType.SILVERFISH) .height(0.3f).width(0.4f) .build(); - SHULKER = EntityDefinition.inherited(ShulkerEntity::new, mobEntityBase) - .type(EntityType.SHULKER) + SHULKER = VanillaEntityDefinition.inherited(ShulkerEntity::new, mobEntityBase) + .type(BuiltinEntityType.SHULKER) .heightAndWidth(1f) .addTranslator(MetadataTypes.DIRECTION, ShulkerEntity::setAttachedFace) .addTranslator(MetadataTypes.BYTE, ShulkerEntity::setShulkerHeight) .addTranslator(MetadataTypes.BYTE, ShulkerEntity::setShulkerColor) .build(); - SKELETON = EntityDefinition.inherited(SkeletonEntity::new, mobEntityBase) - .type(EntityType.SKELETON) + SKELETON = VanillaEntityDefinition.inherited(SkeletonEntity::new, mobEntityBase) + .type(BuiltinEntityType.SKELETON) .height(1.8f).width(0.6f) .offset(1.62f) .addTranslator(MetadataTypes.BOOLEAN, SkeletonEntity::setConvertingToStray) .build(); - SNOW_GOLEM = EntityDefinition.inherited(SnowGolemEntity::new, mobEntityBase) - .type(EntityType.SNOW_GOLEM) + SNOW_GOLEM = VanillaEntityDefinition.inherited(SnowGolemEntity::new, mobEntityBase) + .type(BuiltinEntityType.SNOW_GOLEM) .height(1.9f).width(0.7f) .addTranslator(MetadataTypes.BYTE, SnowGolemEntity::setSnowGolemFlags) .build(); - SPIDER = EntityDefinition.inherited(SpiderEntity::new, mobEntityBase) - .type(EntityType.SPIDER) + SPIDER = VanillaEntityDefinition.inherited(SpiderEntity::new, mobEntityBase) + .type(BuiltinEntityType.SPIDER) .height(0.9f).width(1.4f) .offset(1f) .addTranslator(MetadataTypes.BYTE, SpiderEntity::setSpiderFlags) .build(); - CAVE_SPIDER = EntityDefinition.inherited(SpiderEntity::new, SPIDER) - .type(EntityType.CAVE_SPIDER) + CAVE_SPIDER = VanillaEntityDefinition.inherited(SpiderEntity::new, SPIDER) + .type(BuiltinEntityType.CAVE_SPIDER) .height(0.5f).width(0.7f) .build(); - STRAY = EntityDefinition.inherited(AbstractSkeletonEntity::new, mobEntityBase) - .type(EntityType.STRAY) + STRAY = VanillaEntityDefinition.inherited(AbstractSkeletonEntity::new, mobEntityBase) + .type(BuiltinEntityType.STRAY) .height(1.8f).width(0.6f) .offset(1.62f) .build(); - VEX = EntityDefinition.inherited(VexEntity::new, mobEntityBase) - .type(EntityType.VEX) + VEX = VanillaEntityDefinition.inherited(VexEntity::new, mobEntityBase) + .type(BuiltinEntityType.VEX) .height(0.8f).width(0.4f) .addTranslator(MetadataTypes.BYTE, VexEntity::setVexFlags) .build(); - WARDEN = EntityDefinition.inherited(WardenEntity::new, mobEntityBase) - .type(EntityType.WARDEN) + WARDEN = VanillaEntityDefinition.inherited(WardenEntity::new, mobEntityBase) + .type(BuiltinEntityType.WARDEN) .height(2.9f).width(0.9f) .addTranslator(MetadataTypes.INT, WardenEntity::setAngerLevel) .build(); - WITHER = EntityDefinition.inherited(WitherEntity::new, mobEntityBase) - .type(EntityType.WITHER) + WITHER = VanillaEntityDefinition.inherited(WitherEntity::new, mobEntityBase) + .type(BuiltinEntityType.WITHER) .height(3.5f).width(0.9f) .addTranslator(MetadataTypes.INT, WitherEntity::setTarget1) .addTranslator(MetadataTypes.INT, WitherEntity::setTarget2) .addTranslator(MetadataTypes.INT, WitherEntity::setTarget3) .addTranslator(MetadataTypes.INT, WitherEntity::setInvulnerableTicks) .build(); - WITHER_SKELETON = EntityDefinition.inherited(AbstractSkeletonEntity::new, mobEntityBase) - .type(EntityType.WITHER_SKELETON) + WITHER_SKELETON = VanillaEntityDefinition.inherited(AbstractSkeletonEntity::new, mobEntityBase) + .type(BuiltinEntityType.WITHER_SKELETON) .height(2.4f).width(0.7f) .build(); - ZOGLIN = EntityDefinition.inherited(ZoglinEntity::new, mobEntityBase) - .type(EntityType.ZOGLIN) + ZOGLIN = VanillaEntityDefinition.inherited(ZoglinEntity::new, mobEntityBase) + .type(BuiltinEntityType.ZOGLIN) .height(1.4f).width(1.3965f) .addTranslator(MetadataTypes.BOOLEAN, ZoglinEntity::setBaby) .build(); - ZOMBIE = EntityDefinition.inherited(ZombieEntity::new, mobEntityBase) - .type(EntityType.ZOMBIE) + ZOMBIE = VanillaEntityDefinition.inherited(ZombieEntity::new, mobEntityBase) + .type(BuiltinEntityType.ZOMBIE) .height(1.8f).width(0.6f) .offset(1.62f) .addTranslator(MetadataTypes.BOOLEAN, ZombieEntity::setZombieBaby) .addTranslator(null) // "set special type", doesn't do anything .addTranslator(MetadataTypes.BOOLEAN, ZombieEntity::setConvertingToDrowned) .build(); - ZOMBIE_VILLAGER = EntityDefinition.inherited(ZombieVillagerEntity::new, ZOMBIE) - .type(EntityType.ZOMBIE_VILLAGER) + ZOMBIE_VILLAGER = VanillaEntityDefinition.inherited(ZombieVillagerEntity::new, ZOMBIE) + .type(BuiltinEntityType.ZOMBIE_VILLAGER) .height(1.8f).width(0.6f) .offset(1.62f) .identifier("minecraft:zombie_villager_v2") .addTranslator(MetadataTypes.BOOLEAN, ZombieVillagerEntity::setTransforming) .addTranslator(MetadataTypes.VILLAGER_DATA, ZombieVillagerEntity::setZombieVillagerData) .build(); - ZOMBIFIED_PIGLIN = EntityDefinition.inherited(ZombifiedPiglinEntity::new, ZOMBIE) //TODO test how zombie entity metadata is handled? - .type(EntityType.ZOMBIFIED_PIGLIN) + ZOMBIFIED_PIGLIN = VanillaEntityDefinition.inherited(ZombifiedPiglinEntity::new, ZOMBIE) //TODO test how zombie entity metadata is handled? + .type(BuiltinEntityType.ZOMBIFIED_PIGLIN) .height(1.95f).width(0.6f) .offset(1.62f) .identifier("minecraft:zombie_pigman") .build(); - DROWNED = EntityDefinition.inherited(ZOMBIE.factory(), ZOMBIE) - .type(EntityType.DROWNED) + DROWNED = VanillaEntityDefinition.inherited(ZOMBIE.factory(), ZOMBIE) + .type(BuiltinEntityType.DROWNED) .height(1.95f).width(0.6f) .build(); - HUSK = EntityDefinition.inherited(ZOMBIE.factory(), ZOMBIE) - .type(EntityType.HUSK) + HUSK = VanillaEntityDefinition.inherited(ZOMBIE.factory(), ZOMBIE) + .type(BuiltinEntityType.HUSK) .build(); - GUARDIAN = EntityDefinition.inherited(GuardianEntity::new, mobEntityBase) - .type(EntityType.GUARDIAN) + GUARDIAN = VanillaEntityDefinition.inherited(GuardianEntity::new, mobEntityBase) + .type(BuiltinEntityType.GUARDIAN) .heightAndWidth(0.85f) .addTranslator(null) // Moving //TODO .addTranslator(MetadataTypes.INT, GuardianEntity::setGuardianTarget) .build(); - ELDER_GUARDIAN = EntityDefinition.inherited(ElderGuardianEntity::new, GUARDIAN) - .type(EntityType.ELDER_GUARDIAN) + ELDER_GUARDIAN = VanillaEntityDefinition.inherited(ElderGuardianEntity::new, GUARDIAN) + .type(BuiltinEntityType.ELDER_GUARDIAN) .heightAndWidth(1.9975f) .build(); - SLIME = EntityDefinition.inherited(SlimeEntity::new, mobEntityBase) - .type(EntityType.SLIME) + SLIME = VanillaEntityDefinition.inherited(SlimeEntity::new, mobEntityBase) + .type(BuiltinEntityType.SLIME) .heightAndWidth(0.51f) .addTranslator(MetadataTypes.INT, SlimeEntity::setSlimeScale) .build(); - MAGMA_CUBE = EntityDefinition.inherited(MagmaCubeEntity::new, SLIME) - .type(EntityType.MAGMA_CUBE) + MAGMA_CUBE = VanillaEntityDefinition.inherited(MagmaCubeEntity::new, SLIME) + .type(BuiltinEntityType.MAGMA_CUBE) .build(); - EntityDefinition abstractFishEntityBase = EntityDefinition.inherited(AbstractFishEntity::new, mobEntityBase) + VanillaEntityDefinition abstractFishEntityBase = VanillaEntityDefinition.inherited(AbstractFishEntity::new, mobEntityBase) .addTranslator(null) // From bucket .build(); - COD = EntityDefinition.inherited(abstractFishEntityBase.factory(), abstractFishEntityBase) - .type(EntityType.COD) + COD = VanillaEntityDefinition.inherited(abstractFishEntityBase.factory(), abstractFishEntityBase) + .type(BuiltinEntityType.COD) .height(0.25f).width(0.5f) .build(); - PUFFERFISH = EntityDefinition.inherited(PufferFishEntity::new, abstractFishEntityBase) - .type(EntityType.PUFFERFISH) + PUFFERFISH = VanillaEntityDefinition.inherited(PufferFishEntity::new, abstractFishEntityBase) + .type(BuiltinEntityType.PUFFERFISH) .heightAndWidth(0.7f) .addTranslator(MetadataTypes.INT, PufferFishEntity::setPufferfishSize) .build(); - SALMON = EntityDefinition.inherited(abstractFishEntityBase.factory(), abstractFishEntityBase) - .type(EntityType.SALMON) + SALMON = VanillaEntityDefinition.inherited(abstractFishEntityBase.factory(), abstractFishEntityBase) + .type(BuiltinEntityType.SALMON) .height(0.5f).width(0.7f) .addTranslator(null) // Scale/variant - TODO .build(); - TADPOLE = EntityDefinition.inherited(TadpoleEntity::new, abstractFishEntityBase) - .type(EntityType.TADPOLE) + TADPOLE = VanillaEntityDefinition.inherited(TadpoleEntity::new, abstractFishEntityBase) + .type(BuiltinEntityType.TADPOLE) .height(0.3f).width(0.4f) .build(); - TROPICAL_FISH = EntityDefinition.inherited(TropicalFishEntity::new, abstractFishEntityBase) - .type(EntityType.TROPICAL_FISH) + TROPICAL_FISH = VanillaEntityDefinition.inherited(TropicalFishEntity::new, abstractFishEntityBase) + .type(BuiltinEntityType.TROPICAL_FISH) .heightAndWidth(0.6f) .identifier("minecraft:tropicalfish") .addTranslator(MetadataTypes.INT, TropicalFishEntity::setFishVariant) .build(); - EntityDefinition abstractPiglinEntityBase = EntityDefinition.inherited(BasePiglinEntity::new, mobEntityBase) + VanillaEntityDefinition abstractPiglinEntityBase = VanillaEntityDefinition.inherited(BasePiglinEntity::new, mobEntityBase) .addTranslator(MetadataTypes.BOOLEAN, BasePiglinEntity::setImmuneToZombification) .build(); - PIGLIN = EntityDefinition.inherited(PiglinEntity::new, abstractPiglinEntityBase) - .type(EntityType.PIGLIN) + PIGLIN = VanillaEntityDefinition.inherited(PiglinEntity::new, abstractPiglinEntityBase) + .type(BuiltinEntityType.PIGLIN) .height(1.95f).width(0.6f) .addTranslator(MetadataTypes.BOOLEAN, PiglinEntity::setBaby) .addTranslator(MetadataTypes.BOOLEAN, PiglinEntity::setChargingCrossbow) .addTranslator(MetadataTypes.BOOLEAN, PiglinEntity::setDancing) .build(); - PIGLIN_BRUTE = EntityDefinition.inherited(abstractPiglinEntityBase.factory(), abstractPiglinEntityBase) - .type(EntityType.PIGLIN_BRUTE) + PIGLIN_BRUTE = VanillaEntityDefinition.inherited(abstractPiglinEntityBase.factory(), abstractPiglinEntityBase) + .type(BuiltinEntityType.PIGLIN_BRUTE) .height(1.95f).width(0.6f) .build(); - EntityDefinition raidParticipantEntityBase = EntityDefinition.inherited(RaidParticipantEntity::new, mobEntityBase) + VanillaEntityDefinition raidParticipantEntityBase = VanillaEntityDefinition.inherited(RaidParticipantEntity::new, mobEntityBase) .addTranslator(null) // Celebrating //TODO .build(); - EntityDefinition spellcasterEntityBase = EntityDefinition.inherited(SpellcasterIllagerEntity::new, raidParticipantEntityBase) + VanillaEntityDefinition spellcasterEntityBase = VanillaEntityDefinition.inherited(SpellcasterIllagerEntity::new, raidParticipantEntityBase) .addTranslator(MetadataTypes.BYTE, SpellcasterIllagerEntity::setSpellType) .build(); - EVOKER = EntityDefinition.inherited(spellcasterEntityBase.factory(), spellcasterEntityBase) - .type(EntityType.EVOKER) + EVOKER = VanillaEntityDefinition.inherited(spellcasterEntityBase.factory(), spellcasterEntityBase) + .type(BuiltinEntityType.EVOKER) .height(1.95f).width(0.6f) .identifier("minecraft:evocation_illager") .build(); - ILLUSIONER = EntityDefinition.inherited(spellcasterEntityBase.factory(), spellcasterEntityBase) - .type(EntityType.ILLUSIONER) + ILLUSIONER = VanillaEntityDefinition.inherited(spellcasterEntityBase.factory(), spellcasterEntityBase) + .type(BuiltinEntityType.ILLUSIONER) .height(1.95f).width(0.6f) .identifier("minecraft:evocation_illager") .build(); - PILLAGER = EntityDefinition.inherited(PillagerEntity::new, raidParticipantEntityBase) - .type(EntityType.PILLAGER) + PILLAGER = VanillaEntityDefinition.inherited(PillagerEntity::new, raidParticipantEntityBase) + .type(BuiltinEntityType.PILLAGER) .height(1.8f).width(0.6f) .offset(1.62f) .addTranslator(MetadataTypes.BOOLEAN, PillagerEntity::setChargingCrossbow) .build(); - RAVAGER = EntityDefinition.inherited(RavagerEntity::new, raidParticipantEntityBase) - .type(EntityType.RAVAGER) + RAVAGER = VanillaEntityDefinition.inherited(RavagerEntity::new, raidParticipantEntityBase) + .type(BuiltinEntityType.RAVAGER) .height(1.9f).width(1.2f) .build(); - VINDICATOR = EntityDefinition.inherited(VindicatorEntity::new, raidParticipantEntityBase) - .type(EntityType.VINDICATOR) + VINDICATOR = VanillaEntityDefinition.inherited(VindicatorEntity::new, raidParticipantEntityBase) + .type(BuiltinEntityType.VINDICATOR) .height(1.8f).width(0.6f) .offset(1.62f) .build(); - WITCH = EntityDefinition.inherited(raidParticipantEntityBase.factory(), raidParticipantEntityBase) - .type(EntityType.WITCH) + WITCH = VanillaEntityDefinition.inherited(raidParticipantEntityBase.factory(), raidParticipantEntityBase) + .type(BuiltinEntityType.WITCH) .height(1.8f).width(0.6f) .offset(1.62f) .addTranslator(null) // Using item .build(); } - EntityDefinition ageableEntityBase = EntityDefinition.inherited(AgeableEntity::new, mobEntityBase) + VanillaEntityDefinition ageableEntityBase = VanillaEntityDefinition.inherited(AgeableEntity::new, mobEntityBase) .addTranslator(MetadataTypes.BOOLEAN, AgeableEntity::setBaby) .build(); // Extends ageable { - ARMADILLO = EntityDefinition.inherited(ArmadilloEntity::new, ageableEntityBase) - .type(EntityType.ARMADILLO) + ARMADILLO = VanillaEntityDefinition.inherited(ArmadilloEntity::new, ageableEntityBase) + .type(BuiltinEntityType.ARMADILLO) .height(0.65f).width(0.7f) .property(ArmadilloEntity.STATE_PROPERTY) .addTranslator(MetadataTypes.ARMADILLO_STATE, ArmadilloEntity::setArmadilloState) .build(); - AXOLOTL = EntityDefinition.inherited(AxolotlEntity::new, ageableEntityBase) - .type(EntityType.AXOLOTL) + AXOLOTL = VanillaEntityDefinition.inherited(AxolotlEntity::new, ageableEntityBase) + .type(BuiltinEntityType.AXOLOTL) .height(0.42f).width(0.7f) .addTranslator(MetadataTypes.INT, AxolotlEntity::setVariant) .addTranslator(MetadataTypes.BOOLEAN, AxolotlEntity::setPlayingDead) .addTranslator(null) // From bucket .build(); - BEE = EntityDefinition.inherited(BeeEntity::new, ageableEntityBase) - .type(EntityType.BEE) + BEE = VanillaEntityDefinition.inherited(BeeEntity::new, ageableEntityBase) + .type(BuiltinEntityType.BEE) .heightAndWidth(0.6f) .property(BeeEntity.NECTAR_PROPERTY) .addTranslator(MetadataTypes.BYTE, BeeEntity::setBeeFlags) .addTranslator(MetadataTypes.INT, BeeEntity::setAngerTime) .build(); - CHICKEN = EntityDefinition.inherited(ChickenEntity::new, ageableEntityBase) - .type(EntityType.CHICKEN) + CHICKEN = VanillaEntityDefinition.inherited(ChickenEntity::new, ageableEntityBase) + .type(BuiltinEntityType.CHICKEN) .height(0.7f).width(0.4f) .property(TemperatureVariantAnimal.TEMPERATE_VARIANT_PROPERTY) .addTranslator(MetadataTypes.CHICKEN_VARIANT, ChickenEntity::setVariant) .build(); - COW = EntityDefinition.inherited(CowEntity::new, ageableEntityBase) - .type(EntityType.COW) + COW = VanillaEntityDefinition.inherited(CowEntity::new, ageableEntityBase) + .type(BuiltinEntityType.COW) .height(1.4f).width(0.9f) .property(TemperatureVariantAnimal.TEMPERATE_VARIANT_PROPERTY) .addTranslator(MetadataTypes.COW_VARIANT, CowEntity::setVariant) .build(); - FOX = EntityDefinition.inherited(FoxEntity::new, ageableEntityBase) - .type(EntityType.FOX) + FOX = VanillaEntityDefinition.inherited(FoxEntity::new, ageableEntityBase) + .type(BuiltinEntityType.FOX) .height(0.7f).width(0.6f) .addTranslator(MetadataTypes.INT, FoxEntity::setFoxVariant) .addTranslator(MetadataTypes.BYTE, FoxEntity::setFoxFlags) .addTranslator(null) // Trusted player 1 .addTranslator(null) // Trusted player 2 .build(); - FROG = EntityDefinition.inherited(FrogEntity::new, ageableEntityBase) - .type(EntityType.FROG) + FROG = VanillaEntityDefinition.inherited(FrogEntity::new, ageableEntityBase) + .type(BuiltinEntityType.FROG) .heightAndWidth(0.5f) .addTranslator(MetadataTypes.FROG_VARIANT, FrogEntity::setVariant) .addTranslator(MetadataTypes.OPTIONAL_UNSIGNED_INT, FrogEntity::setTongueTarget) .build(); - HAPPY_GHAST = EntityDefinition.inherited(HappyGhastEntity::new, ageableEntityBase) - .type(EntityType.HAPPY_GHAST) + HAPPY_GHAST = VanillaEntityDefinition.inherited(HappyGhastEntity::new, ageableEntityBase) + .type(BuiltinEntityType.HAPPY_GHAST) .heightAndWidth(4f) .property(HappyGhastEntity.CAN_MOVE_PROPERTY) .addTranslator(null) // Is leash holder .addTranslator(MetadataTypes.BOOLEAN, HappyGhastEntity::setStaysStill) .build(); - HOGLIN = EntityDefinition.inherited(HoglinEntity::new, ageableEntityBase) - .type(EntityType.HOGLIN) + HOGLIN = VanillaEntityDefinition.inherited(HoglinEntity::new, ageableEntityBase) + .type(BuiltinEntityType.HOGLIN) .height(1.4f).width(1.3965f) .addTranslator(MetadataTypes.BOOLEAN, HoglinEntity::setImmuneToZombification) .build(); - GOAT = EntityDefinition.inherited(GoatEntity::new, ageableEntityBase) - .type(EntityType.GOAT) + GOAT = VanillaEntityDefinition.inherited(GoatEntity::new, ageableEntityBase) + .type(BuiltinEntityType.GOAT) .height(1.3f).width(0.9f) .addTranslator(MetadataTypes.BOOLEAN, GoatEntity::setScreamer) .addTranslator(MetadataTypes.BOOLEAN, GoatEntity::setHasLeftHorn) .addTranslator(MetadataTypes.BOOLEAN, GoatEntity::setHasRightHorn) .build(); - MOOSHROOM = EntityDefinition.inherited(MooshroomEntity::new, ageableEntityBase) - .type(EntityType.MOOSHROOM) + MOOSHROOM = VanillaEntityDefinition.inherited(MooshroomEntity::new, ageableEntityBase) + .type(BuiltinEntityType.MOOSHROOM) .height(1.4f).width(0.9f) .addTranslator(MetadataTypes.INT, MooshroomEntity::setMooshroomVariant) .build(); - OCELOT = EntityDefinition.inherited(OcelotEntity::new, ageableEntityBase) - .type(EntityType.OCELOT) + OCELOT = VanillaEntityDefinition.inherited(OcelotEntity::new, ageableEntityBase) + .type(BuiltinEntityType.OCELOT) .height(0.7f).width(0.6f) .addTranslator(MetadataTypes.BOOLEAN, (ocelotEntity, entityMetadata) -> ocelotEntity.setFlag(EntityFlag.TRUSTING, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .build(); - PANDA = EntityDefinition.inherited(PandaEntity::new, ageableEntityBase) - .type(EntityType.PANDA) + PANDA = VanillaEntityDefinition.inherited(PandaEntity::new, ageableEntityBase) + .type(BuiltinEntityType.PANDA) .height(1.25f).width(1.125f) .addTranslator(null) // Unhappy counter .addTranslator(null) // Sneeze counter @@ -1080,42 +1080,42 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.BYTE, PandaEntity::setHiddenGene) .addTranslator(MetadataTypes.BYTE, PandaEntity::setPandaFlags) .build(); - PIG = EntityDefinition.inherited(PigEntity::new, ageableEntityBase) - .type(EntityType.PIG) + PIG = VanillaEntityDefinition.inherited(PigEntity::new, ageableEntityBase) + .type(BuiltinEntityType.PIG) .heightAndWidth(0.9f) .property(TemperatureVariantAnimal.TEMPERATE_VARIANT_PROPERTY) .addTranslator(MetadataTypes.INT, PigEntity::setBoost) .addTranslator(MetadataTypes.PIG_VARIANT, PigEntity::setVariant) .build(); - POLAR_BEAR = EntityDefinition.inherited(PolarBearEntity::new, ageableEntityBase) - .type(EntityType.POLAR_BEAR) + POLAR_BEAR = VanillaEntityDefinition.inherited(PolarBearEntity::new, ageableEntityBase) + .type(BuiltinEntityType.POLAR_BEAR) .height(1.4f).width(1.3f) .addTranslator(MetadataTypes.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.STANDING, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .build(); - RABBIT = EntityDefinition.inherited(RabbitEntity::new, ageableEntityBase) - .type(EntityType.RABBIT) + RABBIT = VanillaEntityDefinition.inherited(RabbitEntity::new, ageableEntityBase) + .type(BuiltinEntityType.RABBIT) .height(0.5f).width(0.4f) .addTranslator(MetadataTypes.INT, RabbitEntity::setRabbitVariant) .build(); - SHEEP = EntityDefinition.inherited(SheepEntity::new, ageableEntityBase) - .type(EntityType.SHEEP) + SHEEP = VanillaEntityDefinition.inherited(SheepEntity::new, ageableEntityBase) + .type(BuiltinEntityType.SHEEP) .height(1.3f).width(0.9f) .addTranslator(MetadataTypes.BYTE, SheepEntity::setSheepFlags) .build(); - SNIFFER = EntityDefinition.inherited(SnifferEntity::new, ageableEntityBase) - .type(EntityType.SNIFFER) + SNIFFER = VanillaEntityDefinition.inherited(SnifferEntity::new, ageableEntityBase) + .type(BuiltinEntityType.SNIFFER) .height(1.75f).width(1.9f) .addTranslator(MetadataTypes.SNIFFER_STATE, SnifferEntity::setSnifferState) .addTranslator(null) // Integer, drop seed at tick .build(); - STRIDER = EntityDefinition.inherited(StriderEntity::new, ageableEntityBase) - .type(EntityType.STRIDER) + STRIDER = VanillaEntityDefinition.inherited(StriderEntity::new, ageableEntityBase) + .type(BuiltinEntityType.STRIDER) .height(1.7f).width(0.9f) .addTranslator(MetadataTypes.INT, StriderEntity::setBoost) .addTranslator(MetadataTypes.BOOLEAN, StriderEntity::setCold) .build(); - TURTLE = EntityDefinition.inherited(TurtleEntity::new, ageableEntityBase) - .type(EntityType.TURTLE) + TURTLE = VanillaEntityDefinition.inherited(TurtleEntity::new, ageableEntityBase) + .type(BuiltinEntityType.TURTLE) .height(0.4f).width(1.2f) .addTranslator(null) // Home position .addTranslator(MetadataTypes.BOOLEAN, TurtleEntity::setPregnant) @@ -1125,18 +1125,18 @@ public final class EntityDefinitions { .addTranslator(null) // Travelling .build(); - EntityDefinition abstractVillagerEntityBase = EntityDefinition.inherited(AbstractMerchantEntity::new, ageableEntityBase) + VanillaEntityDefinition abstractVillagerEntityBase = VanillaEntityDefinition.inherited(AbstractMerchantEntity::new, ageableEntityBase) .addTranslator(null) // Unhappy ticks .build(); - VILLAGER = EntityDefinition.inherited(VillagerEntity::new, abstractVillagerEntityBase) - .type(EntityType.VILLAGER) + VILLAGER = VanillaEntityDefinition.inherited(VillagerEntity::new, abstractVillagerEntityBase) + .type(BuiltinEntityType.VILLAGER) .height(1.8f).width(0.6f) .offset(1.62f) .identifier("minecraft:villager_v2") .addTranslator(MetadataTypes.VILLAGER_DATA, VillagerEntity::setVillagerData) .build(); - WANDERING_TRADER = EntityDefinition.inherited(abstractVillagerEntityBase.factory(), abstractVillagerEntityBase) - .type(EntityType.WANDERING_TRADER) + WANDERING_TRADER = VanillaEntityDefinition.inherited(abstractVillagerEntityBase.factory(), abstractVillagerEntityBase) + .type(BuiltinEntityType.WANDERING_TRADER) .height(1.8f).width(0.6f) .offset(1.62f) .build(); @@ -1144,90 +1144,90 @@ public final class EntityDefinitions { // Water creatures (AgeableWaterCreature) { - DOLPHIN = EntityDefinition.inherited(DolphinEntity::new, ageableEntityBase) - .type(EntityType.DOLPHIN) + DOLPHIN = VanillaEntityDefinition.inherited(DolphinEntity::new, ageableEntityBase) + .type(BuiltinEntityType.DOLPHIN) .height(0.6f).width(0.9f) //TODO check .addTranslator(null) // treasure position .addTranslator(null) // "got fish" .addTranslator(null) // "moistness level" .build(); - SQUID = EntityDefinition.inherited(SquidEntity::new, ageableEntityBase) - .type(EntityType.SQUID) + SQUID = VanillaEntityDefinition.inherited(SquidEntity::new, ageableEntityBase) + .type(BuiltinEntityType.SQUID) .heightAndWidth(0.8f) .build(); - GLOW_SQUID = EntityDefinition.inherited(GlowSquidEntity::new, SQUID) - .type(EntityType.GLOW_SQUID) + GLOW_SQUID = VanillaEntityDefinition.inherited(GlowSquidEntity::new, SQUID) + .type(BuiltinEntityType.GLOW_SQUID) .addTranslator(null) // Set dark ticks remaining, possible TODO .build(); } // Horses { - EntityDefinition abstractHorseEntityBase = EntityDefinition.inherited(AbstractHorseEntity::new, ageableEntityBase) + VanillaEntityDefinition abstractHorseEntityBase = VanillaEntityDefinition.inherited(AbstractHorseEntity::new, ageableEntityBase) .addTranslator(MetadataTypes.BYTE, AbstractHorseEntity::setHorseFlags) .build(); - CAMEL = EntityDefinition.inherited(CamelEntity::new, abstractHorseEntityBase) - .type(EntityType.CAMEL) + CAMEL = VanillaEntityDefinition.inherited(CamelEntity::new, abstractHorseEntityBase) + .type(BuiltinEntityType.CAMEL) .height(2.375f).width(1.7f) .addTranslator(MetadataTypes.BOOLEAN, CamelEntity::setDashing) .addTranslator(MetadataTypes.LONG, CamelEntity::setLastPoseTick) .build(); - HORSE = EntityDefinition.inherited(HorseEntity::new, abstractHorseEntityBase) - .type(EntityType.HORSE) + HORSE = VanillaEntityDefinition.inherited(HorseEntity::new, abstractHorseEntityBase) + .type(BuiltinEntityType.HORSE) .height(1.6f).width(1.3965f) .addTranslator(MetadataTypes.INT, HorseEntity::setHorseVariant) .build(); - SKELETON_HORSE = EntityDefinition.inherited(SkeletonHorseEntity::new, abstractHorseEntityBase) - .type(EntityType.SKELETON_HORSE) + SKELETON_HORSE = VanillaEntityDefinition.inherited(SkeletonHorseEntity::new, abstractHorseEntityBase) + .type(BuiltinEntityType.SKELETON_HORSE) .height(1.6f).width(1.3965f) .build(); - ZOMBIE_HORSE = EntityDefinition.inherited(ZombieHorseEntity::new, abstractHorseEntityBase) - .type(EntityType.ZOMBIE_HORSE) + ZOMBIE_HORSE = VanillaEntityDefinition.inherited(ZombieHorseEntity::new, abstractHorseEntityBase) + .type(BuiltinEntityType.ZOMBIE_HORSE) .height(1.6f).width(1.3965f) .build(); - EntityDefinition chestedHorseEntityBase = EntityDefinition.inherited(ChestedHorseEntity::new, abstractHorseEntityBase) + VanillaEntityDefinition chestedHorseEntityBase = VanillaEntityDefinition.inherited(ChestedHorseEntity::new, abstractHorseEntityBase) .addTranslator(MetadataTypes.BOOLEAN, (horseEntity, entityMetadata) -> horseEntity.setFlag(EntityFlag.CHESTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .build(); - DONKEY = EntityDefinition.inherited(chestedHorseEntityBase.factory(), chestedHorseEntityBase) - .type(EntityType.DONKEY) + DONKEY = VanillaEntityDefinition.inherited(chestedHorseEntityBase.factory(), chestedHorseEntityBase) + .type(BuiltinEntityType.DONKEY) .height(1.6f).width(1.3965f) .build(); - MULE = EntityDefinition.inherited(chestedHorseEntityBase.factory(), chestedHorseEntityBase) - .type(EntityType.MULE) + MULE = VanillaEntityDefinition.inherited(chestedHorseEntityBase.factory(), chestedHorseEntityBase) + .type(BuiltinEntityType.MULE) .height(1.6f).width(1.3965f) .build(); - LLAMA = EntityDefinition.inherited(LlamaEntity::new, chestedHorseEntityBase) - .type(EntityType.LLAMA) + LLAMA = VanillaEntityDefinition.inherited(LlamaEntity::new, chestedHorseEntityBase) + .type(BuiltinEntityType.LLAMA) .height(1.87f).width(0.9f) .addTranslator(MetadataTypes.INT, LlamaEntity::setStrength) .addTranslator(MetadataTypes.INT, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityDataTypes.VARIANT, entityMetadata.getValue())) .build(); - TRADER_LLAMA = EntityDefinition.inherited(TraderLlamaEntity::new, LLAMA) - .type(EntityType.TRADER_LLAMA) + TRADER_LLAMA = VanillaEntityDefinition.inherited(TraderLlamaEntity::new, LLAMA) + .type(BuiltinEntityType.TRADER_LLAMA) .identifier("minecraft:llama") .build(); } - EntityDefinition tameableEntityBase = EntityDefinition.inherited(null, ageableEntityBase) // No factory, is abstract + VanillaEntityDefinition tameableEntityBase = VanillaEntityDefinition.inherited(null, ageableEntityBase) // No factory, is abstract .addTranslator(MetadataTypes.BYTE, TameableEntity::setTameableFlags) .addTranslator(MetadataTypes.OPTIONAL_LIVING_ENTITY_REFERENCE, TameableEntity::setOwner) .build(); - CAT = EntityDefinition.inherited(CatEntity::new, tameableEntityBase) - .type(EntityType.CAT) + CAT = VanillaEntityDefinition.inherited(CatEntity::new, tameableEntityBase) + .type(BuiltinEntityType.CAT) .height(0.35f).width(0.3f) .addTranslator(MetadataTypes.CAT_VARIANT, CatEntity::setVariant) .addTranslator(MetadataTypes.BOOLEAN, CatEntity::setResting) .addTranslator(null) // "resting state one" //TODO .addTranslator(MetadataTypes.INT, CatEntity::setCollarColor) .build(); - PARROT = EntityDefinition.inherited(ParrotEntity::new, tameableEntityBase) - .type(EntityType.PARROT) + PARROT = VanillaEntityDefinition.inherited(ParrotEntity::new, tameableEntityBase) + .type(BuiltinEntityType.PARROT) .height(0.9f).width(0.5f) .addTranslator(MetadataTypes.INT, (parrotEntity, entityMetadata) -> parrotEntity.getDirtyMetadata().put(EntityDataTypes.VARIANT, entityMetadata.getValue())) // Parrot color .build(); - WOLF = EntityDefinition.inherited(WolfEntity::new, tameableEntityBase) - .type(EntityType.WOLF) + WOLF = VanillaEntityDefinition.inherited(WolfEntity::new, tameableEntityBase) + .type(BuiltinEntityType.WOLF) .height(0.85f).width(0.6f) .property(WolfEntity.SOUND_VARIANT) // "Begging" on wiki.vg, "Interested" in Nukkit - the tilt of the head @@ -1239,25 +1239,25 @@ public final class EntityDefinitions { .build(); // As of 1.18 these don't track entity data at all - ENDER_DRAGON_PART = EntityDefinition.builder(null) + ENDER_DRAGON_PART = VanillaEntityDefinition.builder(null) .identifier("minecraft:armor_stand") // Emulated .build(false); // Never sent over the network Registries.JAVA_ENTITY_IDENTIFIERS.get().put("minecraft:marker", null); // We don't need an entity definition for this as it is never sent over the network } - private static EntityDefinition buildBoat(EntityDefinition base, EntityType entityType, BoatEntity.BoatVariant variant) { - return EntityDefinition.inherited((session, javaId, bedrockId, uuid, definition, position, motion, yaw, pitch, headYaw) -> + private static VanillaEntityDefinition buildBoat(VanillaEntityDefinition base, BuiltinEntityType BuiltinEntityType, BoatEntity.BoatVariant variant) { + return VanillaEntityDefinition.inherited((session, javaId, bedrockId, uuid, definition, position, motion, yaw, pitch, headYaw) -> new BoatEntity(session, javaId, bedrockId, uuid, definition, position, motion, yaw, variant), base) - .type(entityType) + .type(BuiltinEntityType) .identifier("minecraft:boat") .build(); } - private static EntityDefinition buildChestBoat(EntityDefinition base, EntityType entityType, BoatEntity.BoatVariant variant) { - return EntityDefinition.inherited((session, javaId, bedrockId, uuid, definition, position, motion, yaw, pitch, headYaw) -> + private static VanillaEntityDefinition buildChestBoat(VanillaEntityDefinition base, BuiltinEntityType BuiltinEntityType, BoatEntity.BoatVariant variant) { + return VanillaEntityDefinition.inherited((session, javaId, bedrockId, uuid, definition, position, motion, yaw, pitch, headYaw) -> new ChestBoatEntity(session, javaId, bedrockId, uuid, definition, position, motion, yaw, variant), base) - .type(entityType) + .type(BuiltinEntityType) .identifier("minecraft:chest_boat") .build(); } @@ -1345,13 +1345,13 @@ public Collection> properties(@NonNull Identifier identi } } - private static void registerProperty(Identifier entityType, PropertyType property) { - var definition = Registries.JAVA_ENTITY_IDENTIFIERS.get(entityType.toString()); + private static void registerProperty(Identifier BuiltinEntityType, PropertyType property) { + var definition = Registries.JAVA_ENTITY_IDENTIFIERS.get(BuiltinEntityType.toString()); if (definition == null) { - throw new IllegalArgumentException("Unknown entity type: " + entityType); + throw new IllegalArgumentException("Unknown entity type: " + BuiltinEntityType); } - definition.registeredProperties().add(entityType.toString(), property); + definition.registeredProperties().add(BuiltinEntityType.toString(), property); } private EntityDefinitions() { diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java new file mode 100644 index 00000000000..2209c5687a3 --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.entity; + +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import net.kyori.adventure.key.Key; +import org.geysermc.geyser.Constants; +import org.geysermc.geyser.api.entity.JavaEntityType; +import org.geysermc.geyser.api.util.Identifier; +import org.geysermc.geyser.util.MinecraftKey; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; + +import java.util.EnumMap; +import java.util.Locale; +import java.util.Map; + +public record GeyserEntityType(Identifier javaIdentifier, int javaId) implements JavaEntityType { + private static final Map VANILLA = new EnumMap<>(BuiltinEntityType.class); + private static final Int2ObjectMap CUSTOM = new Int2ObjectOpenHashMap<>(); + + private GeyserEntityType(BuiltinEntityType builtin) { + this(Identifier.of(builtin.name().toLowerCase(Locale.ROOT)), builtin.id()); + } + + private GeyserEntityType(int javaId) { + this(Identifier.of(Constants.GEYSER_CUSTOM_NAMESPACE, "unregistered_sadface"), javaId); + } + + @Override + public boolean isUnregistered() { + return javaIdentifier.namespace().equals(Constants.GEYSER_CUSTOM_NAMESPACE) && javaIdentifier.path().equals("unregistered_sadface"); + } + + public boolean is(EntityType type) { + return javaId == type.id(); + } + + public static GeyserEntityType ofVanilla(BuiltinEntityType builtin) { + return VANILLA.computeIfAbsent(builtin, GeyserEntityType::new); + } + + public static GeyserEntityType of(int javaId) { + if (javaId >= 0 && javaId < BuiltinEntityType.VALUES.length) { + return ofVanilla(BuiltinEntityType.VALUES[javaId]); + } + + GeyserEntityType type = CUSTOM.get(javaId); + return type == null ? new GeyserEntityType(javaId) : type; + } + + // TODO improve this + public static GeyserEntityType of(Key javaKey) { + Identifier identifier = MinecraftKey.keyToIdentifier(javaKey); + for (GeyserEntityType builtin : VANILLA.values()) { + if (builtin.javaIdentifier.equals(identifier)) { + return builtin; + } + } + for (GeyserEntityType custom : CUSTOM.values()) { + if (custom.javaIdentifier.equals(identifier)) { + return custom; + } + } + return null; + } + + public static GeyserEntityType of(EntityType type) { + return type instanceof BuiltinEntityType builtin ? ofVanilla(builtin) : of(type.id()); + } +} diff --git a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java new file mode 100644 index 00000000000..1d08631d178 --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.entity; + +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Accessors; +import org.geysermc.geyser.entity.factory.EntityFactory; +import org.geysermc.geyser.entity.properties.GeyserEntityProperties; +import org.geysermc.geyser.entity.properties.type.PropertyType; +import org.geysermc.geyser.entity.type.Entity; +import org.geysermc.geyser.registry.Registries; +import org.geysermc.geyser.translator.entity.EntityMetadataTranslator; +import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; +import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataType; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; + +import java.util.List; +import java.util.function.BiConsumer; + +@Getter +@Accessors(fluent = true) +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class VanillaEntityDefinition extends EntityDefinition { + private final BuiltinEntityType builtinType; + + /** + * @param identifier the Bedrock identifier of this entity + */ + public VanillaEntityDefinition(EntityFactory factory, GeyserEntityType entityType, String identifier, + float width, float height, float offset, GeyserEntityProperties registeredProperties, List> translators, + BuiltinEntityType builtinType) { + super(factory, entityType, identifier, width, height, offset, registeredProperties, translators); + this.builtinType = builtinType; + } + + public static Builder inherited(EntityFactory factory, EntityDefinition parent) { + return new Builder<>(factory, parent.entityType(), parent.identifier(), parent.width(), parent.height(), parent.offset(), new ObjectArrayList<>(parent.translators())); + } + + public static Builder builder(EntityFactory factory) { + return new Builder<>(factory); + } + + public static class Builder extends EntityDefinition.Builder { + private BuiltinEntityType builtinType; + + private Builder(EntityFactory factory) { + super(factory); + } + + public Builder(EntityFactory factory, GeyserEntityType type, String identifier, float width, float height, float offset, List> entityMetadataTranslators) { + super(factory, type, identifier, width, height, offset, entityMetadataTranslators); + } + + /** + * Resets the identifier as well + */ + public Builder type(BuiltinEntityType type) { + this.type = GeyserEntityType.ofVanilla(type); + builtinType = type; + identifier(null); + return this; + } + + @Override + public Builder identifier(String identifier) { + return (Builder) super.identifier(identifier); + } + + @Override + public Builder width(float width) { + return (Builder) super.width(width); + } + + @Override + public Builder height(float height) { + return (Builder) super.height(height); + } + + @Override + public Builder heightAndWidth(float value) { + return (Builder) super.heightAndWidth(value); + } + + @Override + public Builder offset(float offset) { + return (Builder) super.offset(offset); + } + + @Override + public Builder property(PropertyType propertyType) { + return (Builder) super.property(propertyType); + } + + @Override + public >> Builder addTranslator(MetadataType type, BiConsumer translateFunction) { + return (Builder) super.addTranslator(type, translateFunction); + } + + @Override + public Builder addTranslator(EntityMetadataTranslator translator) { + return (Builder) super.addTranslator(translator); + } + + @Override + public VanillaEntityDefinition build() { + return build(true); + } + + /** + * @param register whether to register this entity in the Registries for entity types. Generally this should be + * set to false if we're not expecting this entity to spawn from the network. + */ + // TODO fix code duplication + public VanillaEntityDefinition build(boolean register) { + if (identifier == null && type != null) { + identifier = type.javaIdentifier().toString(); + } + GeyserEntityProperties registeredProperties = propertiesBuilder == null ? null : propertiesBuilder.build(); + VanillaEntityDefinition definition = new VanillaEntityDefinition<>(factory, type, identifier, width, height, offset, registeredProperties, translators, builtinType); + if (register && definition.entityType() != null) { + Registries.ENTITY_DEFINITIONS.get().putIfAbsent(definition.entityType(), definition); + Registries.JAVA_ENTITY_IDENTIFIERS.get().putIfAbsent(type.javaIdentifier().toString(), definition); + } + return definition; + } + } +} diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/AbstractArrowEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/AbstractArrowEntity.java index 1cc746d7ad8..fe62b3407f4 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/AbstractArrowEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/AbstractArrowEntity.java @@ -26,7 +26,7 @@ package org.geysermc.geyser.entity.type; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; -import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.EntityDefinition; @@ -40,7 +40,7 @@ public AbstractArrowEntity(GeyserSession session, int entityId, long geyserId, U super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); // Set the correct texture if using the resource pack - setFlag(EntityFlag.BRIBED, definition.entityType() == EntityType.SPECTRAL_ARROW); + setFlag(EntityFlag.BRIBED, definition.entityType().is(BuiltinEntityType.SPECTRAL_ARROW)); setMotion(motion); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index f82b09fe2b2..88141066116 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -43,6 +43,7 @@ import org.cloudburstmc.protocol.bedrock.packet.MoveEntityDeltaPacket; import org.cloudburstmc.protocol.bedrock.packet.RemoveEntityPacket; import org.cloudburstmc.protocol.bedrock.packet.SetEntityDataPacket; +import org.geysermc.geyser.api.entity.JavaEntityType; import org.geysermc.geyser.api.entity.property.BatchPropertyUpdater; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.entity.type.GeyserEntity; @@ -221,8 +222,8 @@ public void spawnEntity() { flagsDirty = false; if (session.getGeyser().config().debugMode() && PRINT_ENTITY_SPAWN_DEBUG) { - EntityType type = definition.entityType(); - String name = type != null ? type.name() : getClass().getSimpleName(); + JavaEntityType type = definition.entityType(); + String name = type != null ? type.javaIdentifier().toString() : getClass().getSimpleName(); session.getGeyser().getLogger().debug("Spawned entity " + name + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")"); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java index 8208f7525ee..e836a58db0d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java @@ -43,6 +43,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; @@ -176,7 +177,7 @@ private NbtMap getDefaultTag() { builder.putInt("y", bedrockPosition.getY()); builder.putInt("z", bedrockPosition.getZ()); builder.putByte("isMovable", (byte) 1); - builder.putString("id", this.definition.entityType() == EntityType.GLOW_ITEM_FRAME ? "GlowItemFrame" : "ItemFrame"); + builder.putString("id", this.definition.entityType().is(BuiltinEntityType.GLOW_ITEM_FRAME) ? "GlowItemFrame" : "ItemFrame"); return builder.build(); } @@ -222,7 +223,7 @@ public InteractionResult interact(Hand hand) { private BlockDefinition buildBlockDefinition(Direction direction) { NbtMapBuilder blockBuilder = NbtMap.builder() - .putString("name", this.definition.entityType() == EntityType.GLOW_ITEM_FRAME ? "minecraft:glow_frame" : "minecraft:frame"); + .putString("name", this.definition.entityType().is(BuiltinEntityType.GLOW_ITEM_FRAME) ? "minecraft:glow_frame" : "minecraft:frame"); NbtMapBuilder statesBuilder = NbtMap.builder() .putInt("facing_direction", direction.ordinal()) .putByte("item_frame_map_bit", (byte) 0) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java index 85abc1c40a1..ec1581ec7fa 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java @@ -31,9 +31,10 @@ import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; import org.cloudburstmc.protocol.bedrock.packet.MoveEntityDeltaPacket; import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.level.block.BlockStateValues; import org.geysermc.geyser.session.GeyserSession; -import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import java.util.UUID; @@ -119,20 +120,17 @@ protected void moveAbsoluteImmediate(Vector3f position, float yaw, float pitch, */ protected float getGravity() { if (getFlag(EntityFlag.HAS_GRAVITY)) { - switch (definition.entityType()) { - case LINGERING_POTION, SPLASH_POTION: - return 0.05f; - case EXPERIENCE_BOTTLE: - return 0.07f; - case FIREBALL: - case SHULKER_BULLET: - return 0; - case SNOWBALL: - case EGG: - case ENDER_PEARL: - return 0.03f; - case LLAMA_SPIT: - return 0.06f; + GeyserEntityType type = definition.entityType(); + if (type.is(BuiltinEntityType.LINGERING_POTION) || type.is(BuiltinEntityType.SPLASH_POTION)) { + return 0.05f; + } else if (type.is(BuiltinEntityType.EXPERIENCE_BOTTLE)) { + return 0.07f; + } else if (type.is(BuiltinEntityType.FIREBALL) || type.is(BuiltinEntityType.SHULKER_BULLET)) { + return 0; + } else if (type.is(BuiltinEntityType.SNOWBALL) || type.is(BuiltinEntityType.EGG) || type.is(BuiltinEntityType.ENDER_PEARL)) { + return 0.03f; + } else if (type.is(BuiltinEntityType.LLAMA_SPIT)) { + return 0.06f; } } return 0; @@ -145,20 +143,14 @@ protected float getDrag() { if (isInWater()) { return 0.8f; } else { - switch (definition.entityType()) { - case LINGERING_POTION, SPLASH_POTION: - case EXPERIENCE_BOTTLE: - case SNOWBALL: - case EGG: - case ENDER_PEARL: - case LLAMA_SPIT: - return 0.99f; - case FIREBALL: - case SMALL_FIREBALL: - case DRAGON_FIREBALL: - return 0.95f; - case SHULKER_BULLET: - return 1; + GeyserEntityType type = definition.entityType(); + if (type.is(BuiltinEntityType.LINGERING_POTION) || type.is(BuiltinEntityType.SPLASH_POTION) || type.is(BuiltinEntityType.EXPERIENCE_BOTTLE) + || type.is(BuiltinEntityType.SNOWBALL) || type.is(BuiltinEntityType.EGG) || type.is(BuiltinEntityType.ENDER_PEARL) || type.is(BuiltinEntityType.LLAMA_SPIT)) { + return 0.99f; + } else if (type.is(BuiltinEntityType.FIREBALL) || type.is(BuiltinEntityType.SMALL_FIREBALL) || type.is(BuiltinEntityType.DRAGON_FIREBALL)) { + return 0.95f; + } else if (type.is(BuiltinEntityType.SHULKER_BULLET)) { + return 1; } } return 1; @@ -174,7 +166,7 @@ protected boolean isInWater() { @Override public void despawnEntity() { - if (definition.entityType() == EntityType.ENDER_PEARL) { + if (definition.entityType().is(BuiltinEntityType.ENDER_PEARL)) { LevelEventPacket particlePacket = new LevelEventPacket(); particlePacket.setType(LevelEvent.PARTICLE_TELEPORT); particlePacket.setPosition(position); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java index 84c2cb7312b..2d9d2af0d7e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java @@ -33,7 +33,7 @@ import org.geysermc.geyser.inventory.item.Potion; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; -import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents; @@ -72,7 +72,7 @@ public void setItem(EntityMetadata entityMetadata) { } } - boolean isLingering = definition.entityType() == EntityType.LINGERING_POTION; + boolean isLingering = definition.entityType().is(BuiltinEntityType.LINGERING_POTION); setFlag(EntityFlag.LINGERING, isLingering); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java index 64796d052bf..c85547dee56 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java +++ b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java @@ -56,7 +56,7 @@ import org.geysermc.geyser.util.MathUtils; import org.geysermc.mcprotocollib.protocol.data.game.entity.Effect; import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.AttributeType; -import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundMoveVehiclePacket; public class VehicleComponent { @@ -218,7 +218,7 @@ protected ObjectDoublePair updateFluidMovement(VehicleContext ctx) { double lavaHeight = getFluidHeightAndApplyMovement(ctx, iter, Fluid.LAVA, vehicle.getSession().getDimensionType().ultrawarm() ? 0.007 : 0.007 / 3, min.getY()); // Apply upward motion if the vehicle is a Strider, and it is submerged in lava - if (lavaHeight > 0 && vehicle.getDefinition().entityType() == EntityType.STRIDER) { + if (lavaHeight > 0 && vehicle.getDefinition().entityType().is(BuiltinEntityType.STRIDER)) { Vector3i blockPos = ctx.centerPos().toInt(); if (!CollisionManager.FLUID_COLLISION.isBelow(blockPos.getY(), boundingBox) || ctx.getBlock(blockPos.up()).is(Blocks.LAVA)) { vehicle.setMotion(vehicle.getMotion().mul(0.5f).add(0, 0.05f, 0)); diff --git a/core/src/main/java/org/geysermc/geyser/impl/IdentifierImpl.java b/core/src/main/java/org/geysermc/geyser/impl/IdentifierImpl.java index 3f2429b1662..ef06bd67360 100644 --- a/core/src/main/java/org/geysermc/geyser/impl/IdentifierImpl.java +++ b/core/src/main/java/org/geysermc/geyser/impl/IdentifierImpl.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.impl; +import net.kyori.adventure.key.InvalidKeyException; import net.kyori.adventure.key.Key; import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.api.util.Identifier; @@ -39,8 +40,8 @@ public static IdentifierImpl of(String namespace, String value) throws IllegalAr Objects.requireNonNull(value, "value cannot be null!"); try { return new IdentifierImpl(MinecraftKey.key(namespace, value)); - } catch (Throwable e) { - throw new IllegalArgumentException(e.getMessage()); + } catch (InvalidKeyException exception) { + throw new IllegalArgumentException(exception); } } diff --git a/core/src/main/java/org/geysermc/geyser/item/hashing/DataComponentHashers.java b/core/src/main/java/org/geysermc/geyser/item/hashing/DataComponentHashers.java index d45ea5ffca9..d4b12b793a2 100644 --- a/core/src/main/java/org/geysermc/geyser/item/hashing/DataComponentHashers.java +++ b/core/src/main/java/org/geysermc/geyser/item/hashing/DataComponentHashers.java @@ -49,7 +49,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.AttributeType; import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.ModifierOperation; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.GlobalPos; -import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import org.geysermc.mcprotocollib.protocol.data.game.item.HashedStack; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; import org.geysermc.mcprotocollib.protocol.data.game.item.component.BlockStateProperties; @@ -484,7 +484,7 @@ public static void testHashing(GeyserSession session) { false, true, false, false, false, new CustomSound("testing_equippable", false, 10.0F)), -1145684769); testHash(session, DataComponentTypes.EQUIPPABLE, new Equippable(EquipmentSlot.BODY, BuiltinSound.ENTITY_BREEZE_WIND_BURST, null, MinecraftKey.key("testing"), - new HolderSet(new int[]{EntityType.ACACIA_BOAT.ordinal()}), false, true, false, false, + new HolderSet(new int[]{BuiltinEntityType.ACACIA_BOAT.ordinal()}), false, true, false, false, true, BuiltinSound.BLOCK_NETHERITE_BLOCK_PLACE), -115079770); testHash(session, DataComponentTypes.EQUIPPABLE, new Equippable(EquipmentSlot.HELMET, BuiltinSound.ITEM_ARMOR_EQUIP_GENERIC, null, null, null, true, true, true, false, diff --git a/core/src/main/java/org/geysermc/geyser/item/hashing/MinecraftHasher.java b/core/src/main/java/org/geysermc/geyser/item/hashing/MinecraftHasher.java index 9ae55bb2d2b..41943f59358 100644 --- a/core/src/main/java/org/geysermc/geyser/item/hashing/MinecraftHasher.java +++ b/core/src/main/java/org/geysermc/geyser/item/hashing/MinecraftHasher.java @@ -31,9 +31,11 @@ import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.nbt.NbtList; import org.cloudburstmc.nbt.NbtMap; +import org.geysermc.geyser.api.util.Identifier; import org.geysermc.geyser.inventory.item.DyeColor; import org.geysermc.geyser.item.components.Rarity; import org.geysermc.geyser.session.cache.registry.JavaRegistryProvider; +import org.geysermc.geyser.util.MinecraftKey; import org.geysermc.mcprotocollib.auth.GameProfile; import org.geysermc.mcprotocollib.protocol.data.game.entity.EquipmentSlot; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.GlobalPos; @@ -125,6 +127,8 @@ public interface MinecraftHasher { MinecraftHasher KEY_REMOVAL = STRING.cast(key -> '!' + key.asString()); + MinecraftHasher IDENTIFIER = KEY.cast(MinecraftKey::identifierToKey); + MinecraftHasher UUID = INT_ARRAY.cast(uuid -> { long mostSignificant = uuid.getMostSignificantBits(); long leastSignificant = uuid.getLeastSignificantBits(); diff --git a/core/src/main/java/org/geysermc/geyser/item/hashing/RegistryHasher.java b/core/src/main/java/org/geysermc/geyser/item/hashing/RegistryHasher.java index f25d4348091..fd6b3b17928 100644 --- a/core/src/main/java/org/geysermc/geyser/item/hashing/RegistryHasher.java +++ b/core/src/main/java/org/geysermc/geyser/item/hashing/RegistryHasher.java @@ -27,6 +27,7 @@ import com.google.common.hash.HashCode; import net.kyori.adventure.key.Key; +import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.inventory.item.Potion; import org.geysermc.geyser.item.hashing.data.ConsumeEffectType; import org.geysermc.geyser.item.hashing.data.FireworkExplosionShape; @@ -108,9 +109,9 @@ public interface RegistryHasher extends MinecraftHasher { RegistryHasher ITEM = registry(JavaRegistries.ITEM); - RegistryHasher ENTITY_TYPE = enumIdRegistry(EntityType.values()); + RegistryHasher ENTITY_TYPE = registry(JavaRegistries.ENTITY_TYPE); - MinecraftHasher ENTITY_TYPE_KEY = enumRegistry(); + MinecraftHasher ENTITY_TYPE_KEY = IDENTIFIER.cast(type -> GeyserEntityType.of(type).javaIdentifier()); MinecraftHasher BLOCK_ENTITY_TYPE_KEY = enumRegistry(); diff --git a/core/src/main/java/org/geysermc/geyser/registry/Registries.java b/core/src/main/java/org/geysermc/geyser/registry/Registries.java index 5aed0d5a517..e20efc1926e 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/Registries.java +++ b/core/src/main/java/org/geysermc/geyser/registry/Registries.java @@ -29,6 +29,7 @@ import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; import net.kyori.adventure.key.Key; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtMapBuilder; @@ -36,6 +37,7 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.PotionMixData; import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket; import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.api.entity.JavaEntityType; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.recipe.GeyserRecipe; import org.geysermc.geyser.item.type.Item; @@ -123,7 +125,8 @@ public final class Registries { /** * A map containing all entity types and their respective Geyser definitions */ - public static final SimpleMappedRegistry> ENTITY_DEFINITIONS = SimpleMappedRegistry.create(RegistryLoaders.empty(() -> new EnumMap<>(EntityType.class))); + // Is a Reference2ObjectMap since GeyserEntityType, the implementation of JavaEntityType, only ever keeps one instance per registered entity type + public static final SimpleMappedRegistry> ENTITY_DEFINITIONS = SimpleMappedRegistry.create(RegistryLoaders.empty(Reference2ObjectOpenHashMap::new)); /** * A registry holding a list of all the known entity properties to be sent to the client after start game. diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/registry/JavaRegistries.java b/core/src/main/java/org/geysermc/geyser/session/cache/registry/JavaRegistries.java index b6e80bf179e..d52c7408e2c 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/registry/JavaRegistries.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/registry/JavaRegistries.java @@ -29,6 +29,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.protocol.bedrock.data.TrimMaterial; import org.cloudburstmc.protocol.bedrock.data.TrimPattern; +import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.entity.type.living.animal.FrogEntity; import org.geysermc.geyser.entity.type.living.animal.farm.TemperatureVariantAnimal; import org.geysermc.geyser.entity.type.living.animal.tameable.CatEntity; @@ -47,14 +48,12 @@ import org.geysermc.geyser.session.dialog.Dialog; import org.geysermc.geyser.util.MinecraftKey; import org.geysermc.mcprotocollib.protocol.data.game.chat.ChatType; -import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import java.util.Locale; import java.util.Objects; import java.util.Optional; +import java.util.function.Function; /** * Stores {@link JavaRegistryKey} for Java registries that are used for loading of data-driven objects, tags, or both. Read {@link JavaRegistryKey} for more information on how to use one. @@ -68,14 +67,7 @@ public class JavaRegistries { .findFirst()); public static final JavaRegistryKey ITEM = createHardcoded("item", Registries.JAVA_ITEMS, Item::javaId, Item::javaKey, key -> Optional.ofNullable(Registries.JAVA_ITEM_IDENTIFIERS.get(key.asString()))); - public static JavaRegistryKey ENTITY_TYPE = createHardcoded("entity_type", Arrays.asList(EntityType.values()), EntityType::ordinal, - type -> MinecraftKey.key(type.name().toLowerCase(Locale.ROOT)), key -> { - try { - return Optional.of(EntityType.valueOf(key.value().toUpperCase(Locale.ROOT))); - } catch (IllegalArgumentException exception) { - return Optional.empty(); // Non-existent entity type - } - }); + public static JavaRegistryKey ENTITY_TYPE = create("entity_type", new EntityTypeLookup()); public static final JavaRegistryKey CHAT_TYPE = create("chat_type"); public static final JavaRegistryKey DIMENSION_TYPE = create("dimension_type"); @@ -170,6 +162,37 @@ public Optional> entry(JavaRegistryProvider registries, Jav } } + // Not the neatest solution... + private record EntityTypeLookup() implements JavaRegistryKey.RegistryLookup { + + @Override + public Optional> entry(JavaRegistryProvider registries, JavaRegistryKey registry, int networkId) { + return lookup(GeyserEntityType::of, networkId); + } + + @Override + public Optional> entry(JavaRegistryProvider registries, JavaRegistryKey registry, Key key) { + return lookup(GeyserEntityType::of, key); + } + + @Override + public Optional> entry(JavaRegistryProvider registries, JavaRegistryKey registry, GeyserEntityType object) { + return lookup(Function.identity(), object); + } + + private static Optional> lookup(Function getter, T value) { + GeyserEntityType type = getter.apply(value); + if (type == null || type.isUnregistered()) { + return Optional.empty(); + } + return Optional.of(wrap(type)); + } + + private static RegistryEntryData wrap(GeyserEntityType type) { + return new RegistryEntryData<>(type.javaId(), MinecraftKey.identifierToKey(type.javaIdentifier()), type); + } + } + private static class RegistryCacheLookup implements JavaRegistryKey.RegistryLookup { @Override diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java index 0de2c3ff6a6..b39785c20e1 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java @@ -28,6 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.FallingBlockEntity; import org.geysermc.geyser.entity.type.FishingHookEntity; @@ -45,6 +46,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.object.FallingBlockData; import org.geysermc.mcprotocollib.protocol.data.game.entity.object.ProjectileData; import org.geysermc.mcprotocollib.protocol.data.game.entity.object.WardenData; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundAddEntityPacket; @@ -55,9 +57,10 @@ public class JavaAddEntityTranslator extends PacketTranslator definition = Registries.ENTITY_DEFINITIONS.get(packet.getType()); + GeyserEntityType type = GeyserEntityType.of(packet.getType()); + EntityDefinition definition = Registries.ENTITY_DEFINITIONS.get(type); if (definition == null) { - session.getGeyser().getLogger().debug("Could not find an entity definition with type " + packet.getType()); + session.getGeyser().getLogger().warning("Could not find an entity definition with type " + type); return; } @@ -67,7 +70,7 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) float pitch = packet.getPitch(); float headYaw = packet.getHeadYaw(); - if (packet.getType() == EntityType.PLAYER) { + if (type.is(BuiltinEntityType.PLAYER)) { PlayerEntity entity; if (packet.getUuid().equals(session.getPlayerEntity().getUuid())) { @@ -102,10 +105,10 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) } Entity entity; - if (packet.getType() == EntityType.FALLING_BLOCK) { + if (type.is(BuiltinEntityType.FALLING_BLOCK)) { entity = new FallingBlockEntity(session, packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), packet.getUuid(), position, motion, yaw, pitch, headYaw, ((FallingBlockData) packet.getData()).getId()); - } else if (packet.getType() == EntityType.FISHING_BOBBER) { + } else if (type.is(BuiltinEntityType.FISHING_BOBBER)) { // Fishing bobbers need the owner for the line int ownerEntityId = ((ProjectileData) packet.getData()).getOwnerId(); Entity owner = session.getEntityCache().getEntityByJavaId(ownerEntityId); @@ -126,7 +129,7 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) } } - if (packet.getType() == EntityType.WARDEN) { + if (type.is(BuiltinEntityType.WARDEN)) { WardenData wardenData = (WardenData) packet.getData(); if (wardenData.isEmerging()) { entity.setPose(Pose.EMERGING); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java index e8f99fbeadb..67c36620d38 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java @@ -26,17 +26,18 @@ package org.geysermc.geyser.translator.protocol.java.entity; import org.checkerframework.checker.nullness.qual.NonNull; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityLinkData; import org.cloudburstmc.protocol.bedrock.packet.SetEntityLinkPacket; import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.vehicle.ClientVehicle; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.Translator; import org.geysermc.geyser.util.EntityUtils; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundSetPassengersPacket; import java.util.ArrayList; @@ -125,11 +126,10 @@ public void translate(GeyserSession session, ClientboundSetPassengersPacket pack entity.setPassengers(newPassengers); - switch (entity.getDefinition().entityType()) { - case HORSE, SKELETON_HORSE, DONKEY, MULE, RAVAGER -> { - entity.getDirtyMetadata().put(EntityDataTypes.SEAT_ROTATION_OFFSET_DEGREES, 181.0f); - entity.updateBedrockMetadata(); - } + GeyserEntityType type = entity.getDefinition().entityType(); + if (type.is(BuiltinEntityType.HORSE) || type.is(BuiltinEntityType.SKELETON_HORSE) || type.is(BuiltinEntityType.DONKEY) || type.is(BuiltinEntityType.MULE) || type.is(BuiltinEntityType.RAVAGER)) { + entity.getDirtyMetadata().put(EntityDataTypes.SEAT_ROTATION_OFFSET_DEGREES, 181.0f); + entity.updateBedrockMetadata(); } } } diff --git a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java index 915db8b3a49..0b58b14cdf6 100644 --- a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java @@ -32,7 +32,9 @@ import org.cloudburstmc.protocol.bedrock.data.GameType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.api.util.Identifier; import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.entity.type.BoatEntity; import org.geysermc.geyser.entity.type.ChestBoatEntity; import org.geysermc.geyser.entity.type.Entity; @@ -50,7 +52,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.Effect; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import org.geysermc.mcprotocollib.protocol.data.game.item.component.Equippable; import java.util.Locale; @@ -106,61 +108,73 @@ private static float getMountedHeightOffset(Entity mount) { float height = mount.getBoundingBoxHeight(); float mountedHeightOffset = height * 0.75f; - switch (mount.getDefinition().entityType()) { - case CAMEL -> { - boolean isBaby = mount.getFlag(EntityFlag.BABY); - mountedHeightOffset = height - (isBaby ? 0.35f : 0.6f); - } - case CAVE_SPIDER, CHICKEN, SPIDER -> mountedHeightOffset = height * 0.5f; - case DONKEY, MULE -> mountedHeightOffset -= 0.25f; - case TRADER_LLAMA, LLAMA -> mountedHeightOffset = height * 0.6f; - case MINECART, HOPPER_MINECART, TNT_MINECART, CHEST_MINECART, FURNACE_MINECART, SPAWNER_MINECART, - COMMAND_BLOCK_MINECART -> mountedHeightOffset = 0; - case BAMBOO_RAFT, BAMBOO_CHEST_RAFT -> mountedHeightOffset = 0.25f; - case HOGLIN, ZOGLIN -> { - boolean isBaby = mount.getFlag(EntityFlag.BABY); - mountedHeightOffset = height - (isBaby ? 0.2f : 0.15f); - } - case PIGLIN -> mountedHeightOffset = height * 0.92f; - case PHANTOM -> mountedHeightOffset = height * 0.35f; - case RAVAGER -> mountedHeightOffset = 2.1f; - case SKELETON_HORSE -> mountedHeightOffset -= 0.1875f; - case SNIFFER -> mountedHeightOffset = 1.8f; - case STRIDER -> mountedHeightOffset = height - 0.19f; + GeyserEntityType type = mount.getDefinition().entityType(); + if (type.is(BuiltinEntityType.CAMEL)) { + boolean isBaby = mount.getFlag(EntityFlag.BABY); + mountedHeightOffset = height - (isBaby ? 0.35f : 0.6f); + } else if (type.is(BuiltinEntityType.CAVE_SPIDER) || type.is(BuiltinEntityType.CHICKEN) || type.is(BuiltinEntityType.SPIDER)) { + mountedHeightOffset = height * 0.5f; + } else if (type.is(BuiltinEntityType.DONKEY) || type.is(BuiltinEntityType.MULE)) { + mountedHeightOffset -= 0.25f; + } else if (type.is(BuiltinEntityType.TRADER_LLAMA) || type.is(BuiltinEntityType.LLAMA)) { + mountedHeightOffset = height * 0.6f; + } else if (type.is(BuiltinEntityType.MINECART) || type.is(BuiltinEntityType.HOPPER_MINECART) || type.is(BuiltinEntityType.TNT_MINECART) + || type.is(BuiltinEntityType.CHEST_MINECART) || type.is(BuiltinEntityType.FURNACE_MINECART) + || type.is(BuiltinEntityType.SPAWNER_MINECART) || type.is(BuiltinEntityType.COMMAND_BLOCK_MINECART)) { + mountedHeightOffset = 0; + } else if (type.is(BuiltinEntityType.BAMBOO_RAFT) || type.is(BuiltinEntityType.BAMBOO_CHEST_RAFT)) { + mountedHeightOffset = 0.25f; + } else if (type.is(BuiltinEntityType.HOGLIN) || type.is(BuiltinEntityType.ZOGLIN)) { + boolean isBaby = mount.getFlag(EntityFlag.BABY); + mountedHeightOffset = height - (isBaby ? 0.2f : 0.15f); + } else if (type.is(BuiltinEntityType.PIGLIN)) { + mountedHeightOffset = height * 0.92f; + } else if (type.is(BuiltinEntityType.PHANTOM)) { + mountedHeightOffset = height * 0.35f; + } else if (type.is(BuiltinEntityType.RAVAGER)) { + mountedHeightOffset = 2.1f; + } else if (type.is(BuiltinEntityType.SKELETON_HORSE)) { + mountedHeightOffset -= 0.1875f; + } else if (type.is(BuiltinEntityType.SNIFFER)) { + mountedHeightOffset = 1.8f; + } else if (type.is(BuiltinEntityType.STRIDER)) { + mountedHeightOffset = height - 0.19f; } return mountedHeightOffset; } private static float getHeightOffset(Entity passenger) { boolean isBaby; - switch (passenger.getDefinition().entityType()) { - case ALLAY, VEX: - return 0.4f; - case SKELETON, STRAY, WITHER_SKELETON: - return -0.6f; - case ARMOR_STAND: - if (((ArmorStandEntity) passenger).isMarker()) { - return 0.0f; - } else { - return 0.1f; - } - case ENDERMITE, SILVERFISH: + GeyserEntityType type = passenger.getDefinition().entityType(); + if (type.is(BuiltinEntityType.ALLAY) || type.is(BuiltinEntityType.VEX)) { + return 0.4f; + } else if (type.is(BuiltinEntityType.SKELETON) || type.is(BuiltinEntityType.STRAY) || type.is(BuiltinEntityType.WITHER_SKELETON)) { + return -0.6f; + } else if (type.is(BuiltinEntityType.ARMOR_STAND)) { + if (((ArmorStandEntity) passenger).isMarker()) { + return 0.0f; + } else { return 0.1f; - case PIGLIN, PIGLIN_BRUTE, ZOMBIFIED_PIGLIN: - isBaby = passenger.getFlag(EntityFlag.BABY); - return isBaby ? -0.05f : -0.45f; - case DROWNED, HUSK, ZOMBIE_VILLAGER, ZOMBIE: - isBaby = passenger.getFlag(EntityFlag.BABY); - return isBaby ? 0.0f : -0.45f; - case EVOKER, ILLUSIONER, PILLAGER, RAVAGER, VINDICATOR, WITCH: - return -0.45f; - case PLAYER: - return -0.35f; - case SHULKER: - Entity vehicle = passenger.getVehicle(); - if (vehicle instanceof BoatEntity || vehicle.getDefinition() == EntityDefinitions.MINECART) { - return 0.1875f - getMountedHeightOffset(vehicle); - } + } + } else if (type.is(BuiltinEntityType.ENDERMITE) || type.is(BuiltinEntityType.SILVERFISH)) { + return 0.1f; + } else if (type.is(BuiltinEntityType.PIGLIN) || type.is(BuiltinEntityType.PIGLIN_BRUTE) || type.is(BuiltinEntityType.ZOMBIFIED_PIGLIN)) { + isBaby = passenger.getFlag(EntityFlag.BABY); + return isBaby ? -0.05f : -0.45f; + } else if (type.is(BuiltinEntityType.DROWNED) || type.is(BuiltinEntityType.HUSK) || type.is(BuiltinEntityType.ZOMBIE_VILLAGER) + || type.is(BuiltinEntityType.ZOMBIE)) { + isBaby = passenger.getFlag(EntityFlag.BABY); + return isBaby ? 0.0f : -0.45f; + } else if (type.is(BuiltinEntityType.EVOKER) || type.is(BuiltinEntityType.ILLUSIONER) || type.is(BuiltinEntityType.PILLAGER) + || type.is(BuiltinEntityType.RAVAGER) || type.is(BuiltinEntityType.VINDICATOR) || type.is(BuiltinEntityType.WITCH)) { + return -0.45f; + } else if (type.is(BuiltinEntityType.PLAYER)) { + return -0.35f; + } else if (type.is(BuiltinEntityType.SHULKER)) { + Entity vehicle = passenger.getVehicle(); + if (vehicle instanceof BoatEntity || vehicle.getDefinition() == EntityDefinitions.MINECART) { + return 0.1875f - getMountedHeightOffset(vehicle); + } } if (passenger instanceof AnimalEntity) { return 0.14f; @@ -181,57 +195,55 @@ public static void updateMountOffset(Entity passenger, Entity mount, boolean rid float xOffset = 0; float yOffset = mountedHeightOffset + heightOffset; float zOffset = 0; - switch (mount.getDefinition().entityType()) { - case CAMEL -> { - zOffset = 0.5f; - if (passengers > 1) { - if (!rider) { - zOffset = -0.7f; - } - if (passenger instanceof AnimalEntity) { - zOffset += 0.2f; - } + GeyserEntityType mountType = mount.getDefinition().entityType(); + if (mountType.is(BuiltinEntityType.CAMEL)) { + zOffset = 0.5f; + if (passengers > 1) { + if (!rider) { + zOffset = -0.7f; } - if (mount.getFlag(EntityFlag.SITTING)) { - if (mount.getFlag(EntityFlag.BABY)) { - yOffset += CamelEntity.SITTING_HEIGHT_DIFFERENCE * 0.5f; - } else { - yOffset += CamelEntity.SITTING_HEIGHT_DIFFERENCE; - } + if (passenger instanceof AnimalEntity) { + zOffset += 0.2f; } } - case CHICKEN -> zOffset = -0.1f; - case TRADER_LLAMA, LLAMA -> zOffset = -0.3f; - case TEXT_DISPLAY -> { - if (passenger instanceof TextDisplayEntity textDisplay) { - Vector3f displayTranslation = textDisplay.getTranslation(); - if (displayTranslation == null) { - return; - } - - xOffset = displayTranslation.getX(); - yOffset = displayTranslation.getY() + 0.2f; - zOffset = displayTranslation.getZ(); + if (mount.getFlag(EntityFlag.SITTING)) { + if (mount.getFlag(EntityFlag.BABY)) { + yOffset += CamelEntity.SITTING_HEIGHT_DIFFERENCE * 0.5f; + } else { + yOffset += CamelEntity.SITTING_HEIGHT_DIFFERENCE; } } - case PLAYER -> { - if (passenger instanceof TextDisplayEntity textDisplay) { - Vector3f displayTranslation = textDisplay.getTranslation(); - int lines = textDisplay.getLineCount(); - if (displayTranslation != null && lines != 0) { - float multiplier = .1414f; - xOffset = displayTranslation.getX(); - yOffset += displayTranslation.getY() + multiplier * lines; - zOffset = displayTranslation.getZ(); - } + } else if (mountType.is(BuiltinEntityType.CHICKEN)) { + zOffset = -0.1f; + } else if (mountType.is(BuiltinEntityType.TRADER_LLAMA) || mountType.is(BuiltinEntityType.LLAMA)) { + zOffset = -0.3f; + } else if (mountType.is(BuiltinEntityType.TEXT_DISPLAY)) { + if (passenger instanceof TextDisplayEntity textDisplay) { + Vector3f displayTranslation = textDisplay.getTranslation(); + if (displayTranslation == null) { + return; } + + xOffset = displayTranslation.getX(); + yOffset = displayTranslation.getY() + 0.2f; + zOffset = displayTranslation.getZ(); } - case HAPPY_GHAST -> { - int seatingIndex = Math.min(index, 4); - xOffset = HappyGhastEntity.X_OFFSETS[seatingIndex]; - yOffset = 3.4f; - zOffset = HappyGhastEntity.Z_OFFSETS[seatingIndex]; + } else if (mountType.is(BuiltinEntityType.PLAYER)) { + if (passenger instanceof TextDisplayEntity textDisplay) { + Vector3f displayTranslation = textDisplay.getTranslation(); + int lines = textDisplay.getLineCount(); + if (displayTranslation != null && lines != 0) { + float multiplier = .1414f; + xOffset = displayTranslation.getX(); + yOffset += displayTranslation.getY() + multiplier * lines; + zOffset = displayTranslation.getZ(); + } } + } else if (mountType.is(BuiltinEntityType.HAPPY_GHAST)) { + int seatingIndex = Math.min(index, 4); + xOffset = HappyGhastEntity.X_OFFSETS[seatingIndex]; + yOffset = 3.4f; + zOffset = HappyGhastEntity.Z_OFFSETS[seatingIndex]; } if (mount instanceof ChestBoatEntity) { xOffset = 0.15F; @@ -244,26 +256,31 @@ public static void updateMountOffset(Entity passenger, Entity mount, boolean rid } } } + /* * Bedrock Differences * Zoglin & Hoglin seem to be taller in Bedrock edition * Horses are tinier * Players, Minecarts, and Boats have different origins */ - if (mount.getDefinition().entityType() == EntityType.PLAYER) { + GeyserEntityType passengerType = passenger.getDefinition().entityType(); + if (mountType.is(BuiltinEntityType.PLAYER)) { yOffset -= EntityDefinitions.PLAYER.offset(); } - if (passenger.getDefinition().entityType() == EntityType.PLAYER) { + if (passengerType.is(BuiltinEntityType.PLAYER)) { yOffset += EntityDefinitions.PLAYER.offset(); } - switch (mount.getDefinition().entityType()) { - case MINECART, HOPPER_MINECART, TNT_MINECART, CHEST_MINECART, FURNACE_MINECART, SPAWNER_MINECART, - COMMAND_BLOCK_MINECART -> yOffset -= mount.getDefinition().height() * 0.5f; + if (mountType.is(BuiltinEntityType.MINECART) || mountType.is(BuiltinEntityType.HOPPER_MINECART) || mountType.is(BuiltinEntityType.TNT_MINECART) + || mountType.is(BuiltinEntityType.CHEST_MINECART) || mountType.is(BuiltinEntityType.FURNACE_MINECART) + || mountType.is(BuiltinEntityType.SPAWNER_MINECART) || mountType.is(BuiltinEntityType.COMMAND_BLOCK_MINECART)) { + yOffset -= mount.getDefinition().height() * 0.5f; } - switch (passenger.getDefinition().entityType()) { - case MINECART, HOPPER_MINECART, TNT_MINECART, CHEST_MINECART, FURNACE_MINECART, SPAWNER_MINECART, - COMMAND_BLOCK_MINECART, SHULKER -> yOffset += passenger.getDefinition().height() * 0.5f; - case FALLING_BLOCK -> yOffset += 0.995f; + if (passengerType.is(BuiltinEntityType.MINECART) || passengerType.is(BuiltinEntityType.HOPPER_MINECART) || passengerType.is(BuiltinEntityType.TNT_MINECART) + || passengerType.is(BuiltinEntityType.CHEST_MINECART) || passengerType.is(BuiltinEntityType.FURNACE_MINECART) || passengerType.is(BuiltinEntityType.SPAWNER_MINECART) + || passengerType.is(BuiltinEntityType.COMMAND_BLOCK_MINECART) || passengerType.is(BuiltinEntityType.SHULKER)) { + yOffset += passenger.getDefinition().height() * 0.5f; + } else if (passengerType.is(BuiltinEntityType.FALLING_BLOCK)) { + yOffset += 0.995f; } if (mount instanceof BoatEntity) { yOffset -= mount.getDefinition().height() * 0.5f; @@ -340,25 +357,24 @@ public static String translatedEntityName(@NonNull Key type, @NonNull GeyserSess return translatedEntityName(type.namespace(), type.value(), session); } - public static String translatedEntityName(@Nullable EntityType type, @NonNull GeyserSession session) { - if (type == EntityType.PLAYER) { - return "Player"; // the player's name is always shown instead - } + public static String translatedEntityName(@Nullable GeyserEntityType type, @NonNull GeyserSession session) { // default fallback value as used in Minecraft Java if (type == null) { return "entity.unregistered_sadface"; + } else if (type.is(BuiltinEntityType.PLAYER)) { + return "Player"; // the player's name is always shown instead } // this works at least with all 1.20.5 entities, except the killer bunny since that's not an entity type. - String typeName = type.name().toLowerCase(Locale.ROOT); - return translatedEntityName("minecraft", typeName, session); + Identifier typeName = type.javaIdentifier(); + return translatedEntityName(typeName.namespace(), typeName.path(), session); } - public static boolean equipmentUsableByEntity(GeyserSession session, Equippable equippable, EntityType entity) { + public static boolean equipmentUsableByEntity(GeyserSession session, Equippable equippable, GeyserEntityType entity) { if (equippable.allowedEntities() == null) { return true; } - GeyserHolderSet holderSet = GeyserHolderSet.fromHolderSet(JavaRegistries.ENTITY_TYPE, equippable.allowedEntities()); + GeyserHolderSet holderSet = GeyserHolderSet.fromHolderSet(JavaRegistries.ENTITY_TYPE, equippable.allowedEntities()); return holderSet.contains(session, entity); } diff --git a/core/src/main/java/org/geysermc/geyser/util/StatisticsUtils.java b/core/src/main/java/org/geysermc/geyser/util/StatisticsUtils.java index 9847c0cfc0e..05fea186949 100644 --- a/core/src/main/java/org/geysermc/geyser/util/StatisticsUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/StatisticsUtils.java @@ -28,6 +28,7 @@ import it.unimi.dsi.fastutil.objects.Object2IntMap; import org.geysermc.cumulus.form.SimpleForm; import org.geysermc.cumulus.util.FormImage; +import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.level.block.type.Block; import org.geysermc.geyser.registry.BlockRegistries; @@ -35,7 +36,16 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.text.MinecraftLocale; -import org.geysermc.mcprotocollib.protocol.data.game.statistic.*; +import org.geysermc.mcprotocollib.protocol.data.game.statistic.BreakBlockStatistic; +import org.geysermc.mcprotocollib.protocol.data.game.statistic.BreakItemStatistic; +import org.geysermc.mcprotocollib.protocol.data.game.statistic.CraftItemStatistic; +import org.geysermc.mcprotocollib.protocol.data.game.statistic.CustomStatistic; +import org.geysermc.mcprotocollib.protocol.data.game.statistic.DropItemStatistic; +import org.geysermc.mcprotocollib.protocol.data.game.statistic.KillEntityStatistic; +import org.geysermc.mcprotocollib.protocol.data.game.statistic.KilledByEntityStatistic; +import org.geysermc.mcprotocollib.protocol.data.game.statistic.PickupItemStatistic; +import org.geysermc.mcprotocollib.protocol.data.game.statistic.Statistic; +import org.geysermc.mcprotocollib.protocol.data.game.statistic.UseItemStatistic; import java.util.ArrayList; import java.util.List; @@ -157,8 +167,8 @@ public static void buildAndSendStatisticsMenu(GeyserSession session) { for (Object2IntMap.Entry entry : session.getStatistics().object2IntEntrySet()) { if (entry.getKey() instanceof KillEntityStatistic statistic) { - String entityName = statistic.getEntity().name().toLowerCase(Locale.ROOT); - content.add("entity.minecraft." + entityName + ": " + entry.getIntValue()); + GeyserEntityType type = GeyserEntityType.of(statistic.getEntity()); + content.add(EntityUtils.translatedEntityName(type, session) + ": " + entry.getIntValue()); } } break; @@ -167,8 +177,8 @@ public static void buildAndSendStatisticsMenu(GeyserSession session) { for (Object2IntMap.Entry entry : session.getStatistics().object2IntEntrySet()) { if (entry.getKey() instanceof KilledByEntityStatistic statistic) { - String entityName = statistic.getEntity().name().toLowerCase(Locale.ROOT); - content.add("entity.minecraft." + entityName + ": " + entry.getIntValue()); + GeyserEntityType type = GeyserEntityType.of(statistic.getEntity()); + content.add(EntityUtils.translatedEntityName(type, session) + ": " + entry.getIntValue()); } } break; diff --git a/core/src/test/java/org/geysermc/geyser/scoreboard/network/ScoreboardIssueTests.java b/core/src/test/java/org/geysermc/geyser/scoreboard/network/ScoreboardIssueTests.java index fcb05c92d80..b0cabce967f 100644 --- a/core/src/test/java/org/geysermc/geyser/scoreboard/network/ScoreboardIssueTests.java +++ b/core/src/test/java/org/geysermc/geyser/scoreboard/network/ScoreboardIssueTests.java @@ -46,7 +46,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ObjectEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode; -import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import org.geysermc.mcprotocollib.protocol.data.game.scoreboard.CollisionRule; import org.geysermc.mcprotocollib.protocol.data.game.scoreboard.NameTagVisibility; import org.geysermc.mcprotocollib.protocol.data.game.scoreboard.TeamAction; @@ -152,7 +152,7 @@ void nameNotUpdating() { setPlayerTeamTranslator, new ClientboundSetPlayerTeamPacket("npc_team_1297", TeamAction.ADD_PLAYER, new String[]{ "1297" })); - context.translate(addEntityTranslator, new ClientboundAddEntityPacket(1297, npcUuid, EntityType.PLAYER, 1, 2, 3, 4, 5, 6)); + context.translate(addEntityTranslator, new ClientboundAddEntityPacket(1297, npcUuid, BuiltinEntityType.PLAYER, 1, 2, 3, 4, 5, 6)); // then it updates the displayed skin parts, which isn't relevant for us assertNextPacketMatch(context, AddPlayerPacket.class, packet -> { @@ -171,7 +171,7 @@ void nameNotUpdating() { var hologramUuid = UUID.fromString("b1586291-5f68-44dc-847d-6c123c5b8cbf"); context.translate( addEntityTranslator, - new ClientboundAddEntityPacket(1298, hologramUuid, EntityType.ARMOR_STAND, 6, 5, 4, 3, 2, 1)); + new ClientboundAddEntityPacket(1298, hologramUuid, BuiltinEntityType.ARMOR_STAND, 6, 5, 4, 3, 2, 1)); assertNextPacketMatch(context, AddEntityPacket.class, packet -> { assertEquals(4, packet.getRuntimeEntityId()); diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f95fd6f73e4..74484cfe0ab 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -18,7 +18,7 @@ protocol-common = "3.0.0.Beta11-20251105.180808-2" protocol-codec = "3.0.0.Beta11-20251105.180808-3" raknet = "1.0.0.CR3-20251031.125212-22" minecraftauth = "5.0.0" -mcprotocollib = "1.21.9-20251029.184056-18" +mcprotocollib = "1.21.9-custom-entities-SNAPSHOT" adventure = "4.25.0" adventure-platform = "4.4.1" junit = "5.9.2" From 0b8678e2f2004be7e03f49bd5f38f1f0371e9630 Mon Sep 17 00:00:00 2001 From: Eclipse Date: Fri, 24 Oct 2025 10:10:49 +0000 Subject: [PATCH 03/62] Allow creating custom entity types from API --- .../geyser/api/entity/JavaEntityType.java | 11 ++++- .../geyser/entity/GeyserEntityType.java | 42 ++++++++++++++----- .../loader/ProviderRegistryLoader.java | 5 +++ 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java index 70b4d5b857c..50a06539b23 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java @@ -25,6 +25,9 @@ package org.geysermc.geyser.api.entity; +import org.checkerframework.checker.index.qual.NonNegative; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.geysermc.geyser.api.GeyserApi; import org.geysermc.geyser.api.util.Identifier; public interface JavaEntityType { @@ -35,7 +38,11 @@ public interface JavaEntityType { boolean isUnregistered(); - default boolean is(Identifier identifier) { - return javaIdentifier().equals(identifier); + default boolean is(Identifier javaIdentifier) { + return javaIdentifier().equals(javaIdentifier); + } + + static JavaEntityType create(@NonNull Identifier javaIdentifier, @NonNegative int javaId) { + return GeyserApi.api().provider(JavaEntityType.class, javaIdentifier, javaId); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java index 2209c5687a3..1871d7f3786 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java @@ -27,7 +27,12 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.kyori.adventure.key.Key; +import org.checkerframework.checker.index.qual.NonNegative; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.Constants; import org.geysermc.geyser.api.entity.JavaEntityType; import org.geysermc.geyser.api.util.Identifier; @@ -38,10 +43,12 @@ import java.util.EnumMap; import java.util.Locale; import java.util.Map; +import java.util.Objects; public record GeyserEntityType(Identifier javaIdentifier, int javaId) implements JavaEntityType { private static final Map VANILLA = new EnumMap<>(BuiltinEntityType.class); private static final Int2ObjectMap CUSTOM = new Int2ObjectOpenHashMap<>(); + private static final Object2ObjectMap CUSTOM_BY_IDENTIFIER = new Object2ObjectOpenHashMap<>(); private GeyserEntityType(BuiltinEntityType builtin) { this(Identifier.of(builtin.name().toLowerCase(Locale.ROOT)), builtin.id()); @@ -73,23 +80,36 @@ public static GeyserEntityType of(int javaId) { return type == null ? new GeyserEntityType(javaId) : type; } - // TODO improve this + @Nullable public static GeyserEntityType of(Key javaKey) { - Identifier identifier = MinecraftKey.keyToIdentifier(javaKey); - for (GeyserEntityType builtin : VANILLA.values()) { - if (builtin.javaIdentifier.equals(identifier)) { - return builtin; + if (javaKey.namespace().equals(Key.MINECRAFT_NAMESPACE)) { + try { + return ofVanilla(BuiltinEntityType.valueOf(javaKey.value().toUpperCase(Locale.ROOT))); + } catch (IllegalArgumentException exception) { + return null; } } - for (GeyserEntityType custom : CUSTOM.values()) { - if (custom.javaIdentifier.equals(identifier)) { - return custom; - } - } - return null; + return CUSTOM_BY_IDENTIFIER.get(MinecraftKey.keyToIdentifier(javaKey)); } public static GeyserEntityType of(EntityType type) { return type instanceof BuiltinEntityType builtin ? ofVanilla(builtin) : of(type.id()); } + + public static GeyserEntityType createCustom(@NonNull Identifier javaIdentifier, @NonNegative int javaId) { + Objects.requireNonNull(javaIdentifier, "javaIdentifier may not be null"); + if (javaIdentifier.vanilla()) { + throw new IllegalArgumentException("Cannot register custom entity type in vanilla namespace!" + javaIdentifier); + } else if (javaId < 0) { + throw new IllegalArgumentException("Invalid ID (may not be below zero): " + javaId); + } else if (javaId < BuiltinEntityType.VALUES.length) { + throw new IllegalArgumentException("Invalid ID (conflicts with vanilla entity type): " + javaId); + } else if (CUSTOM.containsKey(javaId) || CUSTOM_BY_IDENTIFIER.containsKey(javaIdentifier)) { + throw new IllegalArgumentException("Custom entity type with identifier " + javaIdentifier + " and ID " + javaId + " conflicts with existing custom entity type"); + } + GeyserEntityType type = new GeyserEntityType(javaIdentifier, javaId); + CUSTOM.put(javaId, type); + CUSTOM_BY_IDENTIFIER.put(javaIdentifier, type); + return type; + } } diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java index 48e08cc9c60..3d2426b5650 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java @@ -34,6 +34,7 @@ import org.geysermc.geyser.api.block.custom.component.MaterialInstance; import org.geysermc.geyser.api.block.custom.nonvanilla.JavaBlockState; import org.geysermc.geyser.api.command.Command; +import org.geysermc.geyser.api.entity.JavaEntityType; import org.geysermc.geyser.api.event.EventRegistrar; import org.geysermc.geyser.api.extension.Extension; import org.geysermc.geyser.api.item.custom.CustomItemData; @@ -45,6 +46,7 @@ import org.geysermc.geyser.api.pack.option.SubpackOption; import org.geysermc.geyser.api.pack.option.UrlFallbackOption; import org.geysermc.geyser.api.util.Identifier; +import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.event.GeyserEventRegistrar; import org.geysermc.geyser.extension.command.GeyserExtensionCommand; import org.geysermc.geyser.impl.IdentifierImpl; @@ -109,6 +111,9 @@ public Map, ProviderSupplier> load(Map, ProviderSupplier> prov providers.put(CameraFade.Builder.class, args -> new GeyserCameraFade.Builder()); providers.put(CameraPosition.Builder.class, args -> new GeyserCameraPosition.Builder()); + // entities + providers.put(JavaEntityType.class, args -> GeyserEntityType.createCustom((Identifier) args[0], (int) args[1])); + return providers; } } From d843745ded97b06e9b19c10f066fb4429d64e232 Mon Sep 17 00:00:00 2001 From: Eclipse Date: Sat, 25 Oct 2025 10:52:02 +0200 Subject: [PATCH 04/62] Further refactor EntityDefinition, create a Base class --- .../geyser/api/entity/JavaEntityType.java | 4 + .../geyser/entity/EntityDefinition.java | 119 ++++++--------- .../geyser/entity/EntityDefinitionBase.java | 139 ++++++++++++++++++ .../geyser/entity/EntityDefinitions.java | 58 ++++---- .../geyser/entity/GeyserEntityType.java | 22 ++- .../entity/VanillaEntityDefinition.java | 47 ++---- .../geysermc/geyser/entity/type/Entity.java | 3 +- .../loader/ProviderRegistryLoader.java | 2 +- .../TrialSpawnerBlockEntityTranslator.java | 2 +- .../entity/JavaSetEquipmentTranslator.java | 2 +- 10 files changed, 259 insertions(+), 139 deletions(-) create mode 100644 core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBase.java diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java index 50a06539b23..454aa27350f 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java @@ -42,6 +42,10 @@ default boolean is(Identifier javaIdentifier) { return javaIdentifier().equals(javaIdentifier); } + static JavaEntityType ofVanilla(@NonNull Identifier javaIdentifier) { + return GeyserApi.api().provider(JavaEntityType.class, javaIdentifier); + } + static JavaEntityType create(@NonNull Identifier javaIdentifier, @NonNegative int javaId) { return GeyserApi.api().provider(JavaEntityType.class, javaIdentifier, javaId); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java index 85341491509..4311b564e2b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java @@ -25,14 +25,12 @@ package org.geysermc.geyser.entity; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; import lombok.AccessLevel; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; -import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.entity.factory.EntityFactory; import org.geysermc.geyser.entity.properties.GeyserEntityProperties; import org.geysermc.geyser.entity.properties.type.PropertyType; @@ -53,120 +51,99 @@ */ @Getter @Accessors(fluent = true) -@EqualsAndHashCode -@ToString -public class EntityDefinition { +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public abstract class EntityDefinition extends EntityDefinitionBase { private final EntityFactory factory; private final GeyserEntityType entityType; - private final String identifier; - private final float width; - private final float height; - private final float offset; + private final String bedrockIdentifier; private final GeyserEntityProperties registeredProperties; - private final List> translators; - /** - * @param identifier the Bedrock identifier of this entity - */ - public EntityDefinition(EntityFactory factory, GeyserEntityType entityType, String identifier, + public EntityDefinition(EntityFactory factory, GeyserEntityType entityType, String bedrockIdentifier, float width, float height, float offset, GeyserEntityProperties registeredProperties, List> translators) { + super(width, height, offset, translators); this.factory = factory; this.entityType = entityType; - this.identifier = identifier; - this.width = width; - this.height = height; - this.offset = offset; + this.bedrockIdentifier = bedrockIdentifier; this.registeredProperties = registeredProperties; - this.translators = translators; - } - - @SuppressWarnings("unchecked") - public void translateMetadata(T entity, EntityMetadata> metadata) { - EntityMetadataTranslator>> translator = (EntityMetadataTranslator>>) this.translators.get(metadata.getId()); - if (translator == null) { - // This can safely happen; it means we don't translate this entity metadata - return; - } - - if (translator.acceptedType() != metadata.getType()) { - GeyserImpl.getInstance().getLogger().warning("Metadata ID " + metadata.getId() + " was received with type " + metadata.getType() + " but we expected " + translator.acceptedType() + " for " + entity.getDefinition().entityType()); - if (GeyserImpl.getInstance().config().debugMode()) { - GeyserImpl.getInstance().getLogger().debug(metadata.toString()); - } - return; - } - - translator.translate(entity, metadata); } @Setter @Accessors(fluent = true, chain = true) - public static abstract class Builder { + public static abstract class Builder extends EntityDefinitionBase.Builder { protected final EntityFactory factory; @Setter(AccessLevel.NONE) protected GeyserEntityType type; - - protected String identifier; - protected float width; - protected float height; - protected float offset = 0.00001f; + protected String bedrockIdentifier; @Setter(AccessLevel.NONE) protected GeyserEntityProperties.Builder propertiesBuilder; - protected final List> translators; protected Builder(EntityFactory factory) { + super(); this.factory = factory; - translators = new ObjectArrayList<>(); } - protected Builder(EntityFactory factory, GeyserEntityType type, String identifier, float width, float height, float offset, List> translators) { + protected Builder(EntityFactory factory, float width, float height, float offset, List> translators) { + super(width, height, offset, translators); this.factory = factory; - this.type = type; - this.identifier = identifier; this.width = width; this.height = height; this.offset = offset; - this.translators = translators; } /** - * Sets the height and width as one value + * Resets the bedrock identifier as well */ - public Builder heightAndWidth(float value) { - height = value; - width = value; + public Builder type(GeyserEntityType type) { + this.type = type; + this.bedrockIdentifier = null; return this; } - public Builder offset(float offset) { - this.offset = offset + 0.00001f; - return this; + @Override + public Builder width(float width) { + return (Builder) super.width(width); } - public Builder property(PropertyType propertyType) { - if (this.propertiesBuilder == null) { - this.propertiesBuilder = new GeyserEntityProperties.Builder(this.identifier); - } - propertiesBuilder.add(propertyType); - return this; + @Override + public Builder height(float height) { + return (Builder) super.height(height); + } + + @Override + public Builder heightAndWidth(float value) { + return (Builder) super.heightAndWidth(value); + } + + @Override + public Builder offset(float offset) { + return (Builder) super.offset(offset); } + @Override public >> Builder addTranslator(MetadataType type, BiConsumer translateFunction) { - translators.add(new EntityMetadataTranslator<>(type, translateFunction)); - return this; + return (Builder) super.addTranslator(type, translateFunction); } + @Override public Builder addTranslator(EntityMetadataTranslator translator) { - translators.add(translator); + return (Builder) super.addTranslator(translator); + } + + public Builder property(PropertyType propertyType) { + if (this.propertiesBuilder == null) { + this.propertiesBuilder = new GeyserEntityProperties.Builder(this.bedrockIdentifier); + } + propertiesBuilder.add(propertyType); return this; } - public EntityDefinition build() { - if (identifier == null && type != null) { - identifier = type.javaIdentifier().toString(); + protected void validateTypeAndIdentifier() { + if (type == null) { + throw new IllegalStateException("Missing entity type!"); + } else if (bedrockIdentifier == null) { + bedrockIdentifier = type.javaIdentifier().toString(); } - GeyserEntityProperties registeredProperties = propertiesBuilder == null ? null : propertiesBuilder.build(); - return new EntityDefinition<>(factory, type, identifier, width, height, offset, registeredProperties, translators); } } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBase.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBase.java new file mode 100644 index 00000000000..518491e6647 --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBase.java @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.entity; + +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.Accessors; +import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.entity.type.Entity; +import org.geysermc.geyser.translator.entity.EntityMetadataTranslator; +import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; +import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataType; + +import java.util.List; +import java.util.function.BiConsumer; + +@Getter +@Accessors(fluent = true) +@EqualsAndHashCode +@ToString +public class EntityDefinitionBase { + private final float width; + private final float height; + private final float offset; + private final List> translators; + + public EntityDefinitionBase(float width, float height, float offset, List> translators) { + this.width = width; + this.height = height; + this.offset = offset; + this.translators = translators; + } + + public static Builder baseBuilder(Class clazz) { + return new Builder<>(clazz); + } + + public static Builder baseInherited(EntityDefinitionBase parent) { + return new Builder<>(parent.width(), parent.height(), parent.offset(), new ObjectArrayList<>(parent.translators())); + } + + @SuppressWarnings("unchecked") + public void translateMetadata(T entity, EntityMetadata> metadata) { + EntityMetadataTranslator>> translator = (EntityMetadataTranslator>>) this.translators.get(metadata.getId()); + if (translator == null) { + // This can safely happen; it means we don't translate this entity metadata + return; + } + + if (translator.acceptedType() != metadata.getType()) { + GeyserImpl.getInstance().getLogger().warning("Metadata ID " + metadata.getId() + " was received with type " + metadata.getType() + " but we expected " + translator.acceptedType() + " for " + entity.getDefinition().entityType()); + if (GeyserImpl.getInstance().getConfig().isDebugMode()) { + GeyserImpl.getInstance().getLogger().debug(metadata.toString()); + } + return; + } + + translator.translate(entity, metadata); + } + + @Setter + @Accessors(fluent = true, chain = true) + public static class Builder { + protected float width; + protected float height; + protected float offset = 0.00001f; + protected final List> translators; + + protected Builder() { + translators = new ObjectArrayList<>(); + } + + // Unused param so Java knows what entity we're talking about + protected Builder(@SuppressWarnings("unused") Class clazz) { + this(); + } + + protected Builder(float width, float height, float offset, List> translators) { + this.width = width; + this.height = height; + this.offset = offset; + this.translators = translators; + } + + /** + * Sets the height and width as one value + */ + public Builder heightAndWidth(float value) { + height = value; + width = value; + return this; + } + + public Builder offset(float offset) { + this.offset = offset + 0.00001f; + return this; + } + + public >> Builder addTranslator(MetadataType type, BiConsumer translateFunction) { + translators.add(new EntityMetadataTranslator<>(type, translateFunction)); + return this; + } + + public Builder addTranslator(EntityMetadataTranslator translator) { + translators.add(translator); + return this; + } + + public EntityDefinitionBase build() { + return new EntityDefinitionBase<>(width, height, offset, translators); + } + } +} diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java index 0e85bdf4d2c..7796b634630 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java @@ -364,7 +364,7 @@ public final class EntityDefinitions { END_CRYSTAL = VanillaEntityDefinition.inherited(EnderCrystalEntity::new, entityBase) .type(BuiltinEntityType.END_CRYSTAL) .heightAndWidth(2.0f) - .identifier("minecraft:ender_crystal") + .bedrockIdentifier("minecraft:ender_crystal") .addTranslator(MetadataTypes.OPTIONAL_BLOCK_POS, EnderCrystalEntity::setBlockTarget) .addTranslator(MetadataTypes.BOOLEAN, (enderCrystalEntity, entityMetadata) -> enderCrystalEntity.setFlag(EntityFlag.SHOW_BOTTOM, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) // There is a base located on the ender crystal @@ -372,17 +372,17 @@ public final class EntityDefinitions { EXPERIENCE_ORB = VanillaEntityDefinition.inherited(ExpOrbEntity::new, entityBase) .type(BuiltinEntityType.EXPERIENCE_ORB) .addTranslator(null) // int determining xb orb texture - .identifier("minecraft:xp_orb") + .bedrockIdentifier("minecraft:xp_orb") .build(); EVOKER_FANGS = VanillaEntityDefinition.inherited(EvokerFangsEntity::new, entityBase) .type(BuiltinEntityType.EVOKER_FANGS) .height(0.8f).width(0.5f) - .identifier("minecraft:evocation_fang") + .bedrockIdentifier("minecraft:evocation_fang") .build(); EYE_OF_ENDER = VanillaEntityDefinition.inherited(EnderEyeEntity::new, entityBase) .type(BuiltinEntityType.EYE_OF_ENDER) .heightAndWidth(0.25f) - .identifier("minecraft:eye_of_ender_signal") + .bedrockIdentifier("minecraft:eye_of_ender_signal") .addTranslator(null) // Item .build(); FALLING_BLOCK = VanillaEntityDefinition.inherited(null, entityBase) @@ -393,14 +393,14 @@ public final class EntityDefinitions { FIREWORK_ROCKET = VanillaEntityDefinition.inherited(FireworkEntity::new, entityBase) .type(BuiltinEntityType.FIREWORK_ROCKET) .heightAndWidth(0.25f) - .identifier("minecraft:fireworks_rocket") + .bedrockIdentifier("minecraft:fireworks_rocket") .addTranslator(MetadataTypes.ITEM_STACK, FireworkEntity::setFireworkItem) .addTranslator(MetadataTypes.OPTIONAL_UNSIGNED_INT, FireworkEntity::setPlayerGliding) .addTranslator(null) // Shot at angle .build(); FISHING_BOBBER = VanillaEntityDefinition.inherited(null, entityBase) .type(BuiltinEntityType.FISHING_BOBBER) - .identifier("minecraft:fishing_hook") + .bedrockIdentifier("minecraft:fishing_hook") .addTranslator(MetadataTypes.INT, FishingHookEntity::setHookedEntity) .addTranslator(null) // Biting TODO check .build(); @@ -451,7 +451,7 @@ public final class EntityDefinitions { .build(); TEXT_DISPLAY = VanillaEntityDefinition.inherited(TextDisplayEntity::new, displayBase) .type(BuiltinEntityType.TEXT_DISPLAY) - .identifier("minecraft:armor_stand") + .bedrockIdentifier("minecraft:armor_stand") .offset(-0.5f) .addTranslator(MetadataTypes.COMPONENT, TextDisplayEntity::setText) .addTranslator(null) // Line width @@ -463,7 +463,7 @@ public final class EntityDefinitions { INTERACTION = VanillaEntityDefinition.inherited(InteractionEntity::new, entityBase) .type(BuiltinEntityType.INTERACTION) .heightAndWidth(1.0f) // default size until server specifies otherwise - .identifier("minecraft:armor_stand") + .bedrockIdentifier("minecraft:armor_stand") .addTranslator(MetadataTypes.FLOAT, InteractionEntity::setWidth) .addTranslator(MetadataTypes.FLOAT, InteractionEntity::setHeight) .addTranslator(MetadataTypes.BOOLEAN, InteractionEntity::setResponse) @@ -496,17 +496,17 @@ public final class EntityDefinitions { EXPERIENCE_BOTTLE = VanillaEntityDefinition.inherited(ThrowableItemEntity::new, throwableItemBase) .type(BuiltinEntityType.EXPERIENCE_BOTTLE) .heightAndWidth(0.25f) - .identifier("minecraft:xp_bottle") + .bedrockIdentifier("minecraft:xp_bottle") .build(); SPLASH_POTION = VanillaEntityDefinition.inherited(ThrownPotionEntity::new, throwableItemBase) .type(BuiltinEntityType.SPLASH_POTION) .heightAndWidth(0.25f) - .identifier("minecraft:splash_potion") + .bedrockIdentifier("minecraft:splash_potion") .build(); LINGERING_POTION = VanillaEntityDefinition.inherited(ThrownPotionEntity::new, throwableItemBase) .type(BuiltinEntityType.LINGERING_POTION) .heightAndWidth(0.25f) - .identifier("minecraft:splash_potion") + .bedrockIdentifier("minecraft:splash_potion") .build(); SNOWBALL = VanillaEntityDefinition.inherited(ThrowableItemEntity::new, throwableItemBase) .type(BuiltinEntityType.SNOWBALL) @@ -516,12 +516,12 @@ public final class EntityDefinitions { EntityFactory windChargeSupplier = AbstractWindChargeEntity::new; BREEZE_WIND_CHARGE = VanillaEntityDefinition.inherited(windChargeSupplier, entityBase) .type(BuiltinEntityType.BREEZE_WIND_CHARGE) - .identifier("minecraft:breeze_wind_charge_projectile") + .bedrockIdentifier("minecraft:breeze_wind_charge_projectile") .heightAndWidth(0.3125f) .build(); WIND_CHARGE = VanillaEntityDefinition.inherited(windChargeSupplier, entityBase) .type(BuiltinEntityType.WIND_CHARGE) - .identifier("minecraft:wind_charge_projectile") + .bedrockIdentifier("minecraft:wind_charge_projectile") .heightAndWidth(0.3125f) .build(); @@ -538,11 +538,11 @@ public final class EntityDefinitions { SPECTRAL_ARROW = VanillaEntityDefinition.inherited(abstractArrowBase.factory(), abstractArrowBase) .type(BuiltinEntityType.SPECTRAL_ARROW) .heightAndWidth(0.25f) - .identifier("minecraft:arrow") + .bedrockIdentifier("minecraft:arrow") .build(); TRIDENT = VanillaEntityDefinition.inherited(TridentEntity::new, abstractArrowBase) // TODO remove class .type(BuiltinEntityType.TRIDENT) - .identifier("minecraft:thrown_trident") + .bedrockIdentifier("minecraft:thrown_trident") .addTranslator(null) // Loyalty .addTranslator(MetadataTypes.BOOLEAN, (tridentEntity, entityMetadata) -> tridentEntity.setFlag(EntityFlag.ENCHANTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .build(); @@ -588,7 +588,7 @@ public final class EntityDefinitions { .build(); FURNACE_MINECART = VanillaEntityDefinition.inherited(FurnaceMinecartEntity::new, MINECART) .type(BuiltinEntityType.FURNACE_MINECART) - .identifier("minecraft:minecart") + .bedrockIdentifier("minecraft:minecart") .addTranslator(MetadataTypes.BOOLEAN, FurnaceMinecartEntity::setHasFuel) .build(); HOPPER_MINECART = VanillaEntityDefinition.inherited(MINECART.factory(), MINECART) @@ -596,7 +596,7 @@ public final class EntityDefinitions { .build(); SPAWNER_MINECART = VanillaEntityDefinition.inherited(SpawnerMinecartEntity::new, MINECART) .type(BuiltinEntityType.SPAWNER_MINECART) - .identifier("minecraft:minecart") + .bedrockIdentifier("minecraft:minecart") .build(); TNT_MINECART = VanillaEntityDefinition.inherited(MINECART.factory(), MINECART) .type(BuiltinEntityType.TNT_MINECART) @@ -779,7 +779,7 @@ public final class EntityDefinitions { .type(BuiltinEntityType.GIANT) .height(1.8f).width(1.6f) .offset(1.62f) - .identifier("minecraft:zombie") + .bedrockIdentifier("minecraft:zombie") .build(); IRON_GOLEM = VanillaEntityDefinition.inherited(IronGolemEntity::new, mobEntityBase) .type(BuiltinEntityType.IRON_GOLEM) @@ -868,7 +868,7 @@ public final class EntityDefinitions { .type(BuiltinEntityType.ZOMBIE_VILLAGER) .height(1.8f).width(0.6f) .offset(1.62f) - .identifier("minecraft:zombie_villager_v2") + .bedrockIdentifier("minecraft:zombie_villager_v2") .addTranslator(MetadataTypes.BOOLEAN, ZombieVillagerEntity::setTransforming) .addTranslator(MetadataTypes.VILLAGER_DATA, ZombieVillagerEntity::setZombieVillagerData) .build(); @@ -876,7 +876,7 @@ public final class EntityDefinitions { .type(BuiltinEntityType.ZOMBIFIED_PIGLIN) .height(1.95f).width(0.6f) .offset(1.62f) - .identifier("minecraft:zombie_pigman") + .bedrockIdentifier("minecraft:zombie_pigman") .build(); DROWNED = VanillaEntityDefinition.inherited(ZOMBIE.factory(), ZOMBIE) @@ -931,7 +931,7 @@ public final class EntityDefinitions { TROPICAL_FISH = VanillaEntityDefinition.inherited(TropicalFishEntity::new, abstractFishEntityBase) .type(BuiltinEntityType.TROPICAL_FISH) .heightAndWidth(0.6f) - .identifier("minecraft:tropicalfish") + .bedrockIdentifier("minecraft:tropicalfish") .addTranslator(MetadataTypes.INT, TropicalFishEntity::setFishVariant) .build(); @@ -959,12 +959,12 @@ public final class EntityDefinitions { EVOKER = VanillaEntityDefinition.inherited(spellcasterEntityBase.factory(), spellcasterEntityBase) .type(BuiltinEntityType.EVOKER) .height(1.95f).width(0.6f) - .identifier("minecraft:evocation_illager") + .bedrockIdentifier("minecraft:evocation_illager") .build(); ILLUSIONER = VanillaEntityDefinition.inherited(spellcasterEntityBase.factory(), spellcasterEntityBase) .type(BuiltinEntityType.ILLUSIONER) .height(1.95f).width(0.6f) - .identifier("minecraft:evocation_illager") + .bedrockIdentifier("minecraft:evocation_illager") .build(); PILLAGER = VanillaEntityDefinition.inherited(PillagerEntity::new, raidParticipantEntityBase) .type(BuiltinEntityType.PILLAGER) @@ -1132,7 +1132,7 @@ public final class EntityDefinitions { .type(BuiltinEntityType.VILLAGER) .height(1.8f).width(0.6f) .offset(1.62f) - .identifier("minecraft:villager_v2") + .bedrockIdentifier("minecraft:villager_v2") .addTranslator(MetadataTypes.VILLAGER_DATA, VillagerEntity::setVillagerData) .build(); WANDERING_TRADER = VanillaEntityDefinition.inherited(abstractVillagerEntityBase.factory(), abstractVillagerEntityBase) @@ -1205,7 +1205,7 @@ public final class EntityDefinitions { .build(); TRADER_LLAMA = VanillaEntityDefinition.inherited(TraderLlamaEntity::new, LLAMA) .type(BuiltinEntityType.TRADER_LLAMA) - .identifier("minecraft:llama") + .bedrockIdentifier("minecraft:llama") .build(); } @@ -1240,7 +1240,7 @@ public final class EntityDefinitions { // As of 1.18 these don't track entity data at all ENDER_DRAGON_PART = VanillaEntityDefinition.builder(null) - .identifier("minecraft:armor_stand") // Emulated + .bedrockIdentifier("minecraft:armor_stand") // Emulated .build(false); // Never sent over the network Registries.JAVA_ENTITY_IDENTIFIERS.get().put("minecraft:marker", null); // We don't need an entity definition for this as it is never sent over the network @@ -1250,7 +1250,7 @@ private static VanillaEntityDefinition buildBoat(VanillaEntityDefini return VanillaEntityDefinition.inherited((session, javaId, bedrockId, uuid, definition, position, motion, yaw, pitch, headYaw) -> new BoatEntity(session, javaId, bedrockId, uuid, definition, position, motion, yaw, variant), base) .type(BuiltinEntityType) - .identifier("minecraft:boat") + .bedrockIdentifier("minecraft:boat") .build(); } @@ -1258,7 +1258,7 @@ private static VanillaEntityDefinition buildChestBoat(VanillaEn return VanillaEntityDefinition.inherited((session, javaId, bedrockId, uuid, definition, position, motion, yaw, pitch, headYaw) -> new ChestBoatEntity(session, javaId, bedrockId, uuid, definition, position, motion, yaw, variant), base) .type(BuiltinEntityType) - .identifier("minecraft:chest_boat") + .bedrockIdentifier("minecraft:chest_boat") .build(); } @@ -1339,7 +1339,7 @@ public Collection> properties(@NonNull Identifier identi }); for (var definition : Registries.ENTITY_DEFINITIONS.get().values()) { - if (!definition.registeredProperties().isEmpty()) { + if (!definition.registeredProperties().isEmpty()) { // TODO Null or empty check?? Registries.BEDROCK_ENTITY_PROPERTIES.get().add(definition.registeredProperties().toNbtMap(definition.identifier())); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java index 1871d7f3786..3a3a156cbf1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java @@ -36,6 +36,7 @@ import org.geysermc.geyser.Constants; import org.geysermc.geyser.api.entity.JavaEntityType; import org.geysermc.geyser.api.util.Identifier; +import org.geysermc.geyser.impl.IdentifierImpl; import org.geysermc.geyser.util.MinecraftKey; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; @@ -46,21 +47,29 @@ import java.util.Objects; public record GeyserEntityType(Identifier javaIdentifier, int javaId) implements JavaEntityType { + private static final Identifier UNREGISTERED = IdentifierImpl.of(Constants.GEYSER_CUSTOM_NAMESPACE, "unregistered_sadface"); + private static final Map VANILLA = new EnumMap<>(BuiltinEntityType.class); private static final Int2ObjectMap CUSTOM = new Int2ObjectOpenHashMap<>(); private static final Object2ObjectMap CUSTOM_BY_IDENTIFIER = new Object2ObjectOpenHashMap<>(); + public GeyserEntityType { + if (!VANILLA.containsValue(this) && !CUSTOM.containsKey(javaId)) { + throw new IllegalCallerException("Public constructor of GeyserEntityType should not be used; use one of the static factory methods instead"); + } + } + private GeyserEntityType(BuiltinEntityType builtin) { this(Identifier.of(builtin.name().toLowerCase(Locale.ROOT)), builtin.id()); } private GeyserEntityType(int javaId) { - this(Identifier.of(Constants.GEYSER_CUSTOM_NAMESPACE, "unregistered_sadface"), javaId); + this(UNREGISTERED, javaId); } @Override public boolean isUnregistered() { - return javaIdentifier.namespace().equals(Constants.GEYSER_CUSTOM_NAMESPACE) && javaIdentifier.path().equals("unregistered_sadface"); + return javaIdentifier.equals(UNREGISTERED); } public boolean is(EntityType type) { @@ -71,6 +80,13 @@ public static GeyserEntityType ofVanilla(BuiltinEntityType builtin) { return VANILLA.computeIfAbsent(builtin, GeyserEntityType::new); } + /** + * @throws IllegalArgumentException document this in API + */ + public static GeyserEntityType ofVanilla(Identifier javaIdentifier) { + return ofVanilla(BuiltinEntityType.valueOf(javaIdentifier.path().toUpperCase(Locale.ROOT))); + } + public static GeyserEntityType of(int javaId) { if (javaId >= 0 && javaId < BuiltinEntityType.VALUES.length) { return ofVanilla(BuiltinEntityType.VALUES[javaId]); @@ -84,7 +100,7 @@ public static GeyserEntityType of(int javaId) { public static GeyserEntityType of(Key javaKey) { if (javaKey.namespace().equals(Key.MINECRAFT_NAMESPACE)) { try { - return ofVanilla(BuiltinEntityType.valueOf(javaKey.value().toUpperCase(Locale.ROOT))); + return ofVanilla(MinecraftKey.keyToIdentifier(javaKey)); } catch (IllegalArgumentException exception) { return null; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java index 1d08631d178..6350407dca4 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java @@ -48,50 +48,37 @@ @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class VanillaEntityDefinition extends EntityDefinition { - private final BuiltinEntityType builtinType; - - /** - * @param identifier the Bedrock identifier of this entity - */ - public VanillaEntityDefinition(EntityFactory factory, GeyserEntityType entityType, String identifier, - float width, float height, float offset, GeyserEntityProperties registeredProperties, List> translators, - BuiltinEntityType builtinType) { - super(factory, entityType, identifier, width, height, offset, registeredProperties, translators); - this.builtinType = builtinType; - } - public static Builder inherited(EntityFactory factory, EntityDefinition parent) { - return new Builder<>(factory, parent.entityType(), parent.identifier(), parent.width(), parent.height(), parent.offset(), new ObjectArrayList<>(parent.translators())); + public VanillaEntityDefinition(EntityFactory factory, GeyserEntityType entityType, String bedrockIdentifier, + float width, float height, float offset, GeyserEntityProperties registeredProperties, List> translators) { + super(factory, entityType, bedrockIdentifier, width, height, offset, registeredProperties, translators); } public static Builder builder(EntityFactory factory) { return new Builder<>(factory); } + public static Builder inherited(EntityFactory factory, EntityDefinition parent) { + return new Builder<>(factory, parent.width(), parent.height(), parent.offset(), new ObjectArrayList<>(parent.translators())); + } + public static class Builder extends EntityDefinition.Builder { - private BuiltinEntityType builtinType; - private Builder(EntityFactory factory) { + protected Builder(EntityFactory factory) { super(factory); } - public Builder(EntityFactory factory, GeyserEntityType type, String identifier, float width, float height, float offset, List> entityMetadataTranslators) { - super(factory, type, identifier, width, height, offset, entityMetadataTranslators); + protected Builder(EntityFactory factory, float width, float height, float offset, List> translators) { + super(factory, width, height, offset, translators); } - /** - * Resets the identifier as well - */ public Builder type(BuiltinEntityType type) { - this.type = GeyserEntityType.ofVanilla(type); - builtinType = type; - identifier(null); - return this; + return (Builder) super.type(GeyserEntityType.ofVanilla(type)); } @Override - public Builder identifier(String identifier) { - return (Builder) super.identifier(identifier); + public Builder bedrockIdentifier(String bedrockIdentifier) { + return (Builder) super.bedrockIdentifier(bedrockIdentifier); } @Override @@ -138,13 +125,11 @@ public VanillaEntityDefinition build() { * @param register whether to register this entity in the Registries for entity types. Generally this should be * set to false if we're not expecting this entity to spawn from the network. */ - // TODO fix code duplication public VanillaEntityDefinition build(boolean register) { - if (identifier == null && type != null) { - identifier = type.javaIdentifier().toString(); - } + validateTypeAndIdentifier(); + GeyserEntityProperties registeredProperties = propertiesBuilder == null ? null : propertiesBuilder.build(); - VanillaEntityDefinition definition = new VanillaEntityDefinition<>(factory, type, identifier, width, height, offset, registeredProperties, translators, builtinType); + VanillaEntityDefinition definition = new VanillaEntityDefinition<>(factory, type, bedrockIdentifier, width, height, offset, registeredProperties, translators); if (register && definition.entityType() != null) { Registries.ENTITY_DEFINITIONS.get().putIfAbsent(definition.entityType(), definition); Registries.JAVA_ENTITY_IDENTIFIERS.get().putIfAbsent(type.javaIdentifier().toString(), definition); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index 88141066116..8313226da5d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -70,7 +70,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; import java.util.Collections; import java.util.EnumMap; @@ -199,7 +198,7 @@ protected void setClientSideSilent() { public void spawnEntity() { AddEntityPacket addEntityPacket = new AddEntityPacket(); - addEntityPacket.setIdentifier(definition.identifier()); + addEntityPacket.setIdentifier(definition.bedrockIdentifier()); addEntityPacket.setRuntimeEntityId(geyserId); addEntityPacket.setUniqueEntityId(geyserId); addEntityPacket.setPosition(position); diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java index 3d2426b5650..31ec971b450 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java @@ -112,7 +112,7 @@ public Map, ProviderSupplier> load(Map, ProviderSupplier> prov providers.put(CameraPosition.Builder.class, args -> new GeyserCameraPosition.Builder()); // entities - providers.put(JavaEntityType.class, args -> GeyserEntityType.createCustom((Identifier) args[0], (int) args[1])); + providers.put(JavaEntityType.class, args -> args.length == 1 ? GeyserEntityType.ofVanilla((Identifier) args[0]) : GeyserEntityType.createCustom((Identifier) args[0], (int) args[1])); return providers; } diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java index 25925a89b5f..dec3108eb52 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java @@ -49,7 +49,7 @@ public void translateTag(GeyserSession session, NbtMapBuilder bedrockNbt, NbtMap NbtMapBuilder spawnData = NbtMap.builder(); EntityDefinition definition = Registries.JAVA_ENTITY_IDENTIFIERS.get(entityData.getString("id")); if (definition != null) { - spawnData.putString("TypeId", definition.identifier()); + spawnData.putString("TypeId", definition.bedrockIdentifier()); } spawnData.putInt("Weight", entityData.getInt("Size", 1)); // ??? presumably since these are the only other two extra attributes bedrockNbt.putCompound("spawn_data", spawnData.build()); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEquipmentTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEquipmentTranslator.java index 2c806d7bed5..82af862b9b2 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEquipmentTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEquipmentTranslator.java @@ -50,7 +50,7 @@ public void translate(GeyserSession session, ClientboundSetEquipmentPacket packe if (!(entity instanceof LivingEntity livingEntity)) { session.getGeyser().getLogger().debug("Attempted to add armor to a non-living entity (" + - entity.getDefinition().identifier() + ")."); + entity.getDefinition().bedrockIdentifier() + ")."); return; } From 7fe8992ceb9ea4f7fbabe6f999dbcb0d80892854 Mon Sep 17 00:00:00 2001 From: Eclipse Date: Mon, 27 Oct 2025 10:18:50 +0000 Subject: [PATCH 05/62] Work on exposing custom entity definitions in the API --- .../api/entity/CustomEntityDefinition.java | 81 +++++++++ .../geyser/api/entity/JavaEntityType.java | 2 + .../geyser/entity/EntityDefinition.java | 23 +-- .../geyser/entity/EntityDefinitionBase.java | 7 +- .../geyser/entity/EntityDefinitionBases.java | 165 ++++++++++++++++++ .../geyser/entity/EntityDefinitions.java | 60 +++---- .../entity/GeyserCustomEntityDefinition.java | 152 ++++++++++++++++ .../geyser/entity/GeyserEntityType.java | 5 + .../entity/VanillaEntityDefinition.java | 22 ++- .../geysermc/geyser/registry/Registries.java | 9 +- .../loader/ProviderRegistryLoader.java | 3 + 11 files changed, 467 insertions(+), 62 deletions(-) create mode 100644 api/src/main/java/org/geysermc/geyser/api/entity/CustomEntityDefinition.java create mode 100644 core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBases.java create mode 100644 core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/CustomEntityDefinition.java b/api/src/main/java/org/geysermc/geyser/api/entity/CustomEntityDefinition.java new file mode 100644 index 00000000000..18e99b9663f --- /dev/null +++ b/api/src/main/java/org/geysermc/geyser/api/entity/CustomEntityDefinition.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.api.entity; + +import org.checkerframework.checker.index.qual.Positive; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.common.returnsreceiver.qual.This; +import org.geysermc.geyser.api.GeyserApi; +import org.geysermc.geyser.api.predicate.MinecraftPredicate; +import org.geysermc.geyser.api.predicate.PredicateStrategy; +import org.geysermc.geyser.api.predicate.context.entity.EntitySpawnContext; +import org.geysermc.geyser.api.util.GenericBuilder; + +import java.util.List; + +public interface CustomEntityDefinition { + + // TODO Identifier + String bedrockIdentifier(); + + float width(); + + float height(); + + float offset(); + + List> predicates(); + + PredicateStrategy predicateStrategy(); + + static Builder builder(@NonNull String bedrockIdentifier, @NonNull JavaEntityType vanillaType) { + return GeyserApi.api().provider(Builder.class, bedrockIdentifier, vanillaType); + } + + interface Builder extends GenericBuilder { + + @This + Builder width(@Positive float width); + + @This + Builder height(@Positive float height); + + @This + Builder heightAndWidth(@Positive float value); + + @This + Builder offset(@Positive float offset); + + @This + Builder predicate(@NonNull MinecraftPredicate predicate); + + @This + Builder predicateStrategy(@NonNull PredicateStrategy strategy); + + @Override + CustomEntityDefinition build(); + } +} diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java index 454aa27350f..853a014c605 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java @@ -38,6 +38,8 @@ public interface JavaEntityType { boolean isUnregistered(); + boolean vanilla(); + default boolean is(Identifier javaIdentifier) { return javaIdentifier().equals(javaIdentifier); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java index 4311b564e2b..28978bb8919 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java @@ -55,15 +55,13 @@ @ToString(callSuper = true) public abstract class EntityDefinition extends EntityDefinitionBase { private final EntityFactory factory; - private final GeyserEntityType entityType; private final String bedrockIdentifier; private final GeyserEntityProperties registeredProperties; - public EntityDefinition(EntityFactory factory, GeyserEntityType entityType, String bedrockIdentifier, + public EntityDefinition(EntityFactory factory, String bedrockIdentifier, float width, float height, float offset, GeyserEntityProperties registeredProperties, List> translators) { super(width, height, offset, translators); this.factory = factory; - this.entityType = entityType; this.bedrockIdentifier = bedrockIdentifier; this.registeredProperties = registeredProperties; } @@ -72,8 +70,6 @@ public EntityDefinition(EntityFactory factory, GeyserEntityType entityType, S @Accessors(fluent = true, chain = true) public static abstract class Builder extends EntityDefinitionBase.Builder { protected final EntityFactory factory; - @Setter(AccessLevel.NONE) - protected GeyserEntityType type; protected String bedrockIdentifier; @Setter(AccessLevel.NONE) protected GeyserEntityProperties.Builder propertiesBuilder; @@ -91,15 +87,6 @@ protected Builder(EntityFactory factory, float width, float height, float off this.offset = offset; } - /** - * Resets the bedrock identifier as well - */ - public Builder type(GeyserEntityType type) { - this.type = type; - this.bedrockIdentifier = null; - return this; - } - @Override public Builder width(float width) { return (Builder) super.width(width); @@ -137,13 +124,5 @@ public Builder property(PropertyType propertyType) { propertiesBuilder.add(propertyType); return this; } - - protected void validateTypeAndIdentifier() { - if (type == null) { - throw new IllegalStateException("Missing entity type!"); - } else if (bedrockIdentifier == null) { - bedrockIdentifier = type.javaIdentifier().toString(); - } - } } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBase.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBase.java index 518491e6647..cfcb3d8ca1a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBase.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBase.java @@ -61,7 +61,9 @@ public static Builder baseBuilder(Class clazz) { return new Builder<>(clazz); } - public static Builder baseInherited(EntityDefinitionBase parent) { + // Unused param so Java knows what entity we're talking about + @SuppressWarnings("unused") + public static Builder baseInherited(Class clazz, EntityDefinitionBase parent) { return new Builder<>(parent.width(), parent.height(), parent.offset(), new ObjectArrayList<>(parent.translators())); } @@ -97,7 +99,8 @@ protected Builder() { } // Unused param so Java knows what entity we're talking about - protected Builder(@SuppressWarnings("unused") Class clazz) { + @SuppressWarnings("unused") + protected Builder(Class clazz) { this(); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBases.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBases.java new file mode 100644 index 00000000000..d3a9a6a6d2c --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBases.java @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.entity; + +import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.geysermc.geyser.entity.type.BoatEntity; +import org.geysermc.geyser.entity.type.ChestBoatEntity; +import org.geysermc.geyser.entity.type.DisplayBaseEntity; +import org.geysermc.geyser.entity.type.Entity; +import org.geysermc.geyser.entity.type.FireballEntity; +import org.geysermc.geyser.entity.type.HangingEntity; +import org.geysermc.geyser.entity.type.LivingEntity; +import org.geysermc.geyser.entity.type.ThrowableItemEntity; +import org.geysermc.geyser.entity.type.living.AbstractFishEntity; +import org.geysermc.geyser.entity.type.living.AgeableEntity; +import org.geysermc.geyser.entity.type.living.MobEntity; +import org.geysermc.geyser.entity.type.living.animal.horse.AbstractHorseEntity; +import org.geysermc.geyser.entity.type.living.animal.tameable.TameableEntity; +import org.geysermc.geyser.entity.type.living.monster.BasePiglinEntity; +import org.geysermc.geyser.entity.type.living.monster.raid.RaidParticipantEntity; +import org.geysermc.geyser.entity.type.living.monster.raid.SpellcasterIllagerEntity; +import org.geysermc.geyser.entity.type.player.AvatarEntity; +import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataTypes; +import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; +import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.FloatEntityMetadata; + +public final class EntityDefinitionBases { + public static final EntityDefinitionBase ENTITY; + public static final EntityDefinitionBase DISPLAY; + public static final EntityDefinitionBase FIREBALL; + public static final EntityDefinitionBase THROWABLE; + public static final EntityDefinitionBase HANGING; + public static final EntityDefinitionBase BOAT; + public static final EntityDefinitionBase CHEST_BOAT; + public static final EntityDefinitionBase LIVING_ENTITY; + public static final EntityDefinitionBase AVATAR; + public static final EntityDefinitionBase MOB; + public static final EntityDefinitionBase FISH; + public static final EntityDefinitionBase PIGLIN; + public static final EntityDefinitionBase RAID_PARTICIPANT; + public static final EntityDefinitionBase SPELLCASTER; + public static final EntityDefinitionBase AGEABLE; + public static final EntityDefinitionBase HORSE; + public static final EntityDefinitionBase TAMABLE; + + static { + ENTITY = EntityDefinition.baseBuilder(Entity.class) + .addTranslator(MetadataTypes.BYTE, Entity::setFlags) + .addTranslator(MetadataTypes.INT, Entity::setAir) // Air/bubbles + .addTranslator(MetadataTypes.OPTIONAL_COMPONENT, Entity::setDisplayName) + .addTranslator(MetadataTypes.BOOLEAN, Entity::setDisplayNameVisible) + .addTranslator(MetadataTypes.BOOLEAN, Entity::setSilent) + .addTranslator(MetadataTypes.BOOLEAN, Entity::setGravity) + .addTranslator(MetadataTypes.POSE, (entity, entityMetadata) -> entity.setPose(entityMetadata.getValue())) + .addTranslator(MetadataTypes.INT, Entity::setFreezing) + .build(); + DISPLAY = EntityDefinitionBase.baseInherited(DisplayBaseEntity.class, ENTITY) + .addTranslator(null) // Interpolation delay + .addTranslator(null) // Transformation interpolation duration + .addTranslator(null) // Position/Rotation interpolation duration + .addTranslator(MetadataTypes.VECTOR3, DisplayBaseEntity::setTranslation) // Translation + .addTranslator(null) // Scale + .addTranslator(null) // Left rotation + .addTranslator(null) // Right rotation + .addTranslator(null) // Billboard render constraints + .addTranslator(null) // Brightness override + .addTranslator(null) // View range + .addTranslator(null) // Shadow radius + .addTranslator(null) // Shadow strength + .addTranslator(null) // Width + .addTranslator(null) // Height + .addTranslator(null) // Glow color override + .build(); + FIREBALL = EntityDefinitionBase.baseInherited(FireballEntity.class, ENTITY) + .addTranslator(null) // Item + .build(); + THROWABLE = EntityDefinitionBase.baseInherited(ThrowableItemEntity.class, ENTITY) + .addTranslator(MetadataTypes.ITEM_STACK, ThrowableItemEntity::setItem) + .build(); + HANGING = EntityDefinitionBase.baseInherited(HangingEntity.class, ENTITY) + .addTranslator(MetadataTypes.DIRECTION, HangingEntity::setDirectionMetadata) + .build(); + BOAT = EntityDefinitionBase.baseInherited(BoatEntity.class, ENTITY) + .height(0.6f).width(1.6f) + .offset(0.35f) + .addTranslator(MetadataTypes.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityDataTypes.HURT_TICKS, entityMetadata.getValue())) // Time since last hit + .addTranslator(MetadataTypes.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityDataTypes.HURT_DIRECTION, entityMetadata.getValue())) // Rocking direction + .addTranslator(MetadataTypes.FLOAT, (boatEntity, entityMetadata) -> + // 'Health' in Bedrock, damage taken in Java - it makes motion in Bedrock + boatEntity.getDirtyMetadata().put(EntityDataTypes.STRUCTURAL_INTEGRITY, 40 - ((int) ((FloatEntityMetadata) entityMetadata).getPrimitiveValue()))) + .addTranslator(MetadataTypes.BOOLEAN, BoatEntity::setPaddlingLeft) + .addTranslator(MetadataTypes.BOOLEAN, BoatEntity::setPaddlingRight) + .addTranslator(MetadataTypes.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityDataTypes.BOAT_BUBBLE_TIME, entityMetadata.getValue())) // May not actually do anything + .build(); + CHEST_BOAT = EntityDefinitionBase.baseInherited(ChestBoatEntity.class, BOAT) + .build(); + LIVING_ENTITY = EntityDefinitionBase.baseInherited(LivingEntity.class, ENTITY) + .addTranslator(MetadataTypes.BYTE, LivingEntity::setLivingEntityFlags) + .addTranslator(MetadataTypes.FLOAT, LivingEntity::setHealth) + .addTranslator(MetadataTypes.PARTICLES, LivingEntity::setParticles) + .addTranslator(MetadataTypes.BOOLEAN, + (livingEntity, entityMetadata) -> livingEntity.getDirtyMetadata().put(EntityDataTypes.EFFECT_AMBIENCE, (byte) (((BooleanEntityMetadata) entityMetadata).getPrimitiveValue() ? 1 : 0))) + .addTranslator(null) // Arrow count + .addTranslator(null) // Stinger count + .addTranslator(MetadataTypes.OPTIONAL_BLOCK_POS, LivingEntity::setBedPosition) + .build(); + AVATAR = EntityDefinitionBase.baseInherited(AvatarEntity.class, LIVING_ENTITY) + .height(1.8f).width(0.6f) + .offset(1.62f) + .addTranslator(null) // Player main hand + .addTranslator(MetadataTypes.BYTE, AvatarEntity::setSkinVisibility) + .build(); + MOB = EntityDefinitionBase.baseInherited(MobEntity.class, LIVING_ENTITY) + .addTranslator(MetadataTypes.BYTE, MobEntity::setMobFlags) + .build(); + FISH = EntityDefinitionBase.baseInherited(AbstractFishEntity.class, MOB) + .addTranslator(null) // From bucket + .build(); + PIGLIN = EntityDefinitionBase.baseInherited(BasePiglinEntity.class, MOB) + .addTranslator(MetadataTypes.BOOLEAN, BasePiglinEntity::setImmuneToZombification) + .build(); + RAID_PARTICIPANT = EntityDefinitionBase.baseInherited(RaidParticipantEntity.class, MOB) + .addTranslator(null) // Celebrating //TODO + .build(); + SPELLCASTER = EntityDefinitionBase.baseInherited(SpellcasterIllagerEntity.class, RAID_PARTICIPANT) + .addTranslator(MetadataTypes.BYTE, SpellcasterIllagerEntity::setSpellType) + .build(); + AGEABLE = EntityDefinitionBase.baseInherited(AgeableEntity.class, MOB) + .addTranslator(MetadataTypes.BOOLEAN, AgeableEntity::setBaby) + .build(); + HORSE = EntityDefinitionBase.baseInherited(AbstractHorseEntity.class, AGEABLE) + .addTranslator(MetadataTypes.BYTE, AbstractHorseEntity::setHorseFlags) + .build(); + TAMABLE = EntityDefinitionBase.baseInherited(TameableEntity.class, AGEABLE) + .addTranslator(MetadataTypes.BYTE, TameableEntity::setTameableFlags) + .addTranslator(MetadataTypes.OPTIONAL_LIVING_ENTITY_REFERENCE, TameableEntity::setOwner) + .build(); + } + + private EntityDefinitionBases() { + } +} diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java index 7796b634630..bf300893067 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java @@ -337,7 +337,7 @@ public final class EntityDefinitions { public static final VanillaEntityDefinition WITHER_SKULL_DANGEROUS; static { - EntityDefinition entityBase = VanillaEntityDefinition.builder(Entity::new) + EntityDefinitionBase entityBase = EntityDefinition.baseBuilder(Entity.class) .addTranslator(MetadataTypes.BYTE, Entity::setFlags) .addTranslator(MetadataTypes.INT, Entity::setAir) // Air/bubbles .addTranslator(MetadataTypes.OPTIONAL_COMPONENT, Entity::setDisplayName) @@ -432,7 +432,7 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.INT, TNTEntity::setFuseLength) .build(); - VanillaEntityDefinition displayBase = VanillaEntityDefinition.inherited(DisplayBaseEntity::new, entityBase) + EntityDefinitionBase displayBase = EntityDefinitionBase.baseInherited(DisplayBaseEntity.class, entityBase) .addTranslator(null) // Interpolation delay .addTranslator(null) // Transformation interpolation duration .addTranslator(null) // Position/Rotation interpolation duration @@ -469,7 +469,7 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.BOOLEAN, InteractionEntity::setResponse) .build(); - VanillaEntityDefinition fireballBase = VanillaEntityDefinition.inherited(FireballEntity::new, entityBase) + EntityDefinitionBase fireballBase = EntityDefinitionBase.baseInherited(FireballEntity.class, entityBase) .addTranslator(null) // Item .build(); FIREBALL = VanillaEntityDefinition.inherited(FireballEntity::new, fireballBase) @@ -481,7 +481,7 @@ public final class EntityDefinitions { .heightAndWidth(0.3125f) .build(); - VanillaEntityDefinition throwableItemBase = VanillaEntityDefinition.inherited(ThrowableItemEntity::new, entityBase) + EntityDefinitionBase throwableItemBase = EntityDefinitionBase.baseInherited(ThrowableItemEntity.class, entityBase) .addTranslator(MetadataTypes.ITEM_STACK, ThrowableItemEntity::setItem) .build(); EGG = VanillaEntityDefinition.inherited(ThrowableEggEntity::new, throwableItemBase) @@ -525,7 +525,7 @@ public final class EntityDefinitions { .heightAndWidth(0.3125f) .build(); - VanillaEntityDefinition abstractArrowBase = VanillaEntityDefinition.inherited(AbstractArrowEntity::new, entityBase) + EntityDefinitionBase abstractArrowBase = EntityDefinitionBase.baseInherited(AbstractArrowEntity.class, entityBase) .addTranslator(MetadataTypes.BYTE, AbstractArrowEntity::setArrowFlags) .addTranslator(null) // "Piercing level" .addTranslator(null) // If the arrow is in the ground @@ -535,7 +535,7 @@ public final class EntityDefinitions { .heightAndWidth(0.25f) .addTranslator(MetadataTypes.INT, ArrowEntity::setPotionEffectColor) .build(); - SPECTRAL_ARROW = VanillaEntityDefinition.inherited(abstractArrowBase.factory(), abstractArrowBase) + SPECTRAL_ARROW = VanillaEntityDefinition.inherited(AbstractArrowEntity::new, abstractArrowBase) .type(BuiltinEntityType.SPECTRAL_ARROW) .heightAndWidth(0.25f) .bedrockIdentifier("minecraft:arrow") @@ -547,7 +547,7 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.BOOLEAN, (tridentEntity, entityMetadata) -> tridentEntity.setFlag(EntityFlag.ENCHANTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .build(); - VanillaEntityDefinition hangingEntityBase = VanillaEntityDefinition.inherited(null, entityBase) + EntityDefinitionBase hangingEntityBase = EntityDefinitionBase.baseInherited(HangingEntity.class, entityBase) .addTranslator(MetadataTypes.DIRECTION, HangingEntity::setDirectionMetadata) .build(); @@ -613,7 +613,7 @@ public final class EntityDefinitions { // Boats { - VanillaEntityDefinition boatBase = VanillaEntityDefinition.inherited(null, entityBase) + EntityDefinitionBase boatBase = EntityDefinitionBase.baseInherited(BoatEntity.class, entityBase) .height(0.6f).width(1.6f) .offset(0.35f) .addTranslator(MetadataTypes.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityDataTypes.HURT_TICKS, entityMetadata.getValue())) // Time since last hit @@ -637,7 +637,7 @@ public final class EntityDefinitions { SPRUCE_BOAT = buildBoat(boatBase, BuiltinEntityType.SPRUCE_BOAT, BoatEntity.BoatVariant.SPRUCE); PALE_OAK_BOAT = buildBoat(boatBase, BuiltinEntityType.PALE_OAK_BOAT, BoatEntity.BoatVariant.PALE_OAK); - VanillaEntityDefinition chestBoatBase = VanillaEntityDefinition.inherited(null, boatBase) + EntityDefinitionBase chestBoatBase = EntityDefinitionBase.baseInherited(ChestBoatEntity.class, boatBase) .build(); ACACIA_CHEST_BOAT = buildChestBoat(chestBoatBase, BuiltinEntityType.ACACIA_CHEST_BOAT, BoatEntity.BoatVariant.ACACIA); @@ -652,7 +652,7 @@ public final class EntityDefinitions { PALE_OAK_CHEST_BOAT = buildChestBoat(chestBoatBase, BuiltinEntityType.PALE_OAK_CHEST_BOAT, BoatEntity.BoatVariant.PALE_OAK); } - VanillaEntityDefinition livingEntityBase = VanillaEntityDefinition.inherited(LivingEntity::new, entityBase) + EntityDefinitionBase livingEntityBase = EntityDefinitionBase.baseInherited(LivingEntity.class, entityBase) .addTranslator(MetadataTypes.BYTE, LivingEntity::setLivingEntityFlags) .addTranslator(MetadataTypes.FLOAT, LivingEntity::setHealth) .addTranslator(MetadataTypes.PARTICLES, LivingEntity::setParticles) @@ -675,7 +675,7 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.ROTATIONS, ArmorStandEntity::setRightLegRotation) .build(); - VanillaEntityDefinition avatarEntityBase = VanillaEntityDefinition.inherited(null, livingEntityBase) + EntityDefinitionBase avatarEntityBase = EntityDefinitionBase.baseInherited(AvatarEntity.class, livingEntityBase) .height(1.8f).width(0.6f) .offset(1.62f) .addTranslator(null) // Player main hand @@ -697,7 +697,7 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.OPTIONAL_UNSIGNED_INT, PlayerEntity::setRightParrot) .build(); - VanillaEntityDefinition mobEntityBase = VanillaEntityDefinition.inherited(MobEntity::new, livingEntityBase) + EntityDefinitionBase mobEntityBase = EntityDefinitionBase.baseInherited(MobEntity.class, livingEntityBase) .addTranslator(MetadataTypes.BYTE, MobEntity::setMobFlags) .build(); @@ -907,10 +907,10 @@ public final class EntityDefinitions { .type(BuiltinEntityType.MAGMA_CUBE) .build(); - VanillaEntityDefinition abstractFishEntityBase = VanillaEntityDefinition.inherited(AbstractFishEntity::new, mobEntityBase) + EntityDefinitionBase abstractFishEntityBase = EntityDefinitionBase.baseInherited(AbstractFishEntity.class, mobEntityBase) .addTranslator(null) // From bucket .build(); - COD = VanillaEntityDefinition.inherited(abstractFishEntityBase.factory(), abstractFishEntityBase) + COD = VanillaEntityDefinition.inherited(AbstractFishEntity::new, abstractFishEntityBase) .type(BuiltinEntityType.COD) .height(0.25f).width(0.5f) .build(); @@ -919,7 +919,7 @@ public final class EntityDefinitions { .heightAndWidth(0.7f) .addTranslator(MetadataTypes.INT, PufferFishEntity::setPufferfishSize) .build(); - SALMON = VanillaEntityDefinition.inherited(abstractFishEntityBase.factory(), abstractFishEntityBase) + SALMON = VanillaEntityDefinition.inherited(AbstractFishEntity::new, abstractFishEntityBase) .type(BuiltinEntityType.SALMON) .height(0.5f).width(0.7f) .addTranslator(null) // Scale/variant - TODO @@ -935,7 +935,7 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.INT, TropicalFishEntity::setFishVariant) .build(); - VanillaEntityDefinition abstractPiglinEntityBase = VanillaEntityDefinition.inherited(BasePiglinEntity::new, mobEntityBase) + EntityDefinitionBase abstractPiglinEntityBase = EntityDefinitionBase.baseInherited(BasePiglinEntity.class, mobEntityBase) .addTranslator(MetadataTypes.BOOLEAN, BasePiglinEntity::setImmuneToZombification) .build(); PIGLIN = VanillaEntityDefinition.inherited(PiglinEntity::new, abstractPiglinEntityBase) @@ -945,23 +945,23 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.BOOLEAN, PiglinEntity::setChargingCrossbow) .addTranslator(MetadataTypes.BOOLEAN, PiglinEntity::setDancing) .build(); - PIGLIN_BRUTE = VanillaEntityDefinition.inherited(abstractPiglinEntityBase.factory(), abstractPiglinEntityBase) + PIGLIN_BRUTE = VanillaEntityDefinition.inherited(BasePiglinEntity::new, abstractPiglinEntityBase) .type(BuiltinEntityType.PIGLIN_BRUTE) .height(1.95f).width(0.6f) .build(); - VanillaEntityDefinition raidParticipantEntityBase = VanillaEntityDefinition.inherited(RaidParticipantEntity::new, mobEntityBase) + EntityDefinitionBase raidParticipantEntityBase = EntityDefinitionBase.baseInherited(RaidParticipantEntity.class, mobEntityBase) .addTranslator(null) // Celebrating //TODO .build(); - VanillaEntityDefinition spellcasterEntityBase = VanillaEntityDefinition.inherited(SpellcasterIllagerEntity::new, raidParticipantEntityBase) + EntityDefinitionBase spellcasterEntityBase = EntityDefinitionBase.baseInherited(SpellcasterIllagerEntity.class, raidParticipantEntityBase) .addTranslator(MetadataTypes.BYTE, SpellcasterIllagerEntity::setSpellType) .build(); - EVOKER = VanillaEntityDefinition.inherited(spellcasterEntityBase.factory(), spellcasterEntityBase) + EVOKER = VanillaEntityDefinition.inherited(SpellcasterIllagerEntity::new, spellcasterEntityBase) .type(BuiltinEntityType.EVOKER) .height(1.95f).width(0.6f) .bedrockIdentifier("minecraft:evocation_illager") .build(); - ILLUSIONER = VanillaEntityDefinition.inherited(spellcasterEntityBase.factory(), spellcasterEntityBase) + ILLUSIONER = VanillaEntityDefinition.inherited(SpellcasterIllagerEntity::new, spellcasterEntityBase) .type(BuiltinEntityType.ILLUSIONER) .height(1.95f).width(0.6f) .bedrockIdentifier("minecraft:evocation_illager") @@ -981,7 +981,7 @@ public final class EntityDefinitions { .height(1.8f).width(0.6f) .offset(1.62f) .build(); - WITCH = VanillaEntityDefinition.inherited(raidParticipantEntityBase.factory(), raidParticipantEntityBase) + WITCH = VanillaEntityDefinition.inherited(RaidParticipantEntity::new, raidParticipantEntityBase) .type(BuiltinEntityType.WITCH) .height(1.8f).width(0.6f) .offset(1.62f) @@ -989,7 +989,7 @@ public final class EntityDefinitions { .build(); } - VanillaEntityDefinition ageableEntityBase = VanillaEntityDefinition.inherited(AgeableEntity::new, mobEntityBase) + EntityDefinitionBase ageableEntityBase = EntityDefinitionBase.baseInherited(AgeableEntity.class, mobEntityBase) .addTranslator(MetadataTypes.BOOLEAN, AgeableEntity::setBaby) .build(); @@ -1164,7 +1164,7 @@ public final class EntityDefinitions { // Horses { - VanillaEntityDefinition abstractHorseEntityBase = VanillaEntityDefinition.inherited(AbstractHorseEntity::new, ageableEntityBase) + EntityDefinitionBase abstractHorseEntityBase = EntityDefinitionBase.baseInherited(AbstractHorseEntity.class, ageableEntityBase) .addTranslator(MetadataTypes.BYTE, AbstractHorseEntity::setHorseFlags) .build(); CAMEL = VanillaEntityDefinition.inherited(CamelEntity::new, abstractHorseEntityBase) @@ -1186,14 +1186,14 @@ public final class EntityDefinitions { .type(BuiltinEntityType.ZOMBIE_HORSE) .height(1.6f).width(1.3965f) .build(); - VanillaEntityDefinition chestedHorseEntityBase = VanillaEntityDefinition.inherited(ChestedHorseEntity::new, abstractHorseEntityBase) + EntityDefinitionBase chestedHorseEntityBase = EntityDefinitionBase.baseInherited(ChestedHorseEntity.class, abstractHorseEntityBase) .addTranslator(MetadataTypes.BOOLEAN, (horseEntity, entityMetadata) -> horseEntity.setFlag(EntityFlag.CHESTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .build(); - DONKEY = VanillaEntityDefinition.inherited(chestedHorseEntityBase.factory(), chestedHorseEntityBase) + DONKEY = VanillaEntityDefinition.inherited(ChestedHorseEntity::new, chestedHorseEntityBase) .type(BuiltinEntityType.DONKEY) .height(1.6f).width(1.3965f) .build(); - MULE = VanillaEntityDefinition.inherited(chestedHorseEntityBase.factory(), chestedHorseEntityBase) + MULE = VanillaEntityDefinition.inherited(ChestedHorseEntity::new, chestedHorseEntityBase) .type(BuiltinEntityType.MULE) .height(1.6f).width(1.3965f) .build(); @@ -1209,7 +1209,7 @@ public final class EntityDefinitions { .build(); } - VanillaEntityDefinition tameableEntityBase = VanillaEntityDefinition.inherited(null, ageableEntityBase) // No factory, is abstract + EntityDefinitionBase tameableEntityBase = EntityDefinitionBase.baseInherited(TameableEntity.class, ageableEntityBase) .addTranslator(MetadataTypes.BYTE, TameableEntity::setTameableFlags) .addTranslator(MetadataTypes.OPTIONAL_LIVING_ENTITY_REFERENCE, TameableEntity::setOwner) .build(); @@ -1246,7 +1246,7 @@ public final class EntityDefinitions { Registries.JAVA_ENTITY_IDENTIFIERS.get().put("minecraft:marker", null); // We don't need an entity definition for this as it is never sent over the network } - private static VanillaEntityDefinition buildBoat(VanillaEntityDefinition base, BuiltinEntityType BuiltinEntityType, BoatEntity.BoatVariant variant) { + private static VanillaEntityDefinition buildBoat(EntityDefinitionBase base, BuiltinEntityType BuiltinEntityType, BoatEntity.BoatVariant variant) { return VanillaEntityDefinition.inherited((session, javaId, bedrockId, uuid, definition, position, motion, yaw, pitch, headYaw) -> new BoatEntity(session, javaId, bedrockId, uuid, definition, position, motion, yaw, variant), base) .type(BuiltinEntityType) @@ -1254,7 +1254,7 @@ private static VanillaEntityDefinition buildBoat(VanillaEntityDefini .build(); } - private static VanillaEntityDefinition buildChestBoat(VanillaEntityDefinition base, BuiltinEntityType BuiltinEntityType, BoatEntity.BoatVariant variant) { + private static VanillaEntityDefinition buildChestBoat(EntityDefinitionBase base, BuiltinEntityType BuiltinEntityType, BoatEntity.BoatVariant variant) { return VanillaEntityDefinition.inherited((session, javaId, bedrockId, uuid, definition, position, motion, yaw, pitch, headYaw) -> new ChestBoatEntity(session, javaId, bedrockId, uuid, definition, position, motion, yaw, variant), base) .type(BuiltinEntityType) diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java new file mode 100644 index 00000000000..899b79824ef --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.entity; + +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Accessors; +import org.checkerframework.checker.index.qual.Positive; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.geysermc.geyser.api.entity.CustomEntityDefinition; +import org.geysermc.geyser.api.entity.JavaEntityType; +import org.geysermc.geyser.api.predicate.MinecraftPredicate; +import org.geysermc.geyser.api.predicate.PredicateStrategy; +import org.geysermc.geyser.api.predicate.context.entity.EntitySpawnContext; +import org.geysermc.geyser.entity.factory.EntityFactory; +import org.geysermc.geyser.entity.properties.GeyserEntityProperties; +import org.geysermc.geyser.entity.properties.type.PropertyType; +import org.geysermc.geyser.entity.type.Entity; +import org.geysermc.geyser.registry.Registries; +import org.geysermc.geyser.translator.entity.EntityMetadataTranslator; +import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; +import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataType; + +import java.util.List; +import java.util.Objects; +import java.util.function.BiConsumer; + +@Getter +@Accessors(fluent = true) +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class GeyserCustomEntityDefinition extends EntityDefinition implements CustomEntityDefinition { + private final List> predicates; + private final PredicateStrategy predicateStrategy; + + public GeyserCustomEntityDefinition(EntityFactory factory, String bedrockIdentifier, List> predicates, PredicateStrategy predicateStrategy, + float width, float height, float offset, GeyserEntityProperties registeredProperties, List> translators) { + super(factory, bedrockIdentifier, width, height, offset, registeredProperties, translators); + this.predicates = predicates; + this.predicateStrategy = predicateStrategy; + } + + public static Builder inherited(String bedrockIdentifier, JavaEntityType vanillaType) { + if (!vanillaType.vanilla()) { + throw new IllegalArgumentException("vanillaType must be a vanilla entity type, was: " + vanillaType); + } + VanillaEntityDefinition parent = Registries.ENTITY_DEFINITIONS.get(vanillaType); + if (parent == null) { + throw new IllegalArgumentException("No vanilla entity definition registered for vanilla entity type " + vanillaType); + } + // TODO fix the rawtypes/unchecked + return new Builder<>(bedrockIdentifier, parent.factory(), parent.width(), parent.height(), parent.offset(), new ObjectArrayList(parent.translators())); + } + + public static class Builder extends EntityDefinition.Builder implements CustomEntityDefinition.Builder { + protected List> predicates; + protected PredicateStrategy predicateStrategy = PredicateStrategy.AND; + + protected Builder(EntityFactory factory, String bedrockIdentifier) { + super(factory); + this.bedrockIdentifier = Objects.requireNonNull(bedrockIdentifier, "bedrockIdentifier must not be null"); + } + + protected Builder(String bedrockIdentifier, EntityFactory factory, float width, float height, float offset, List> translators) { + super(factory, width, height, offset, translators); + this.bedrockIdentifier = Objects.requireNonNull(bedrockIdentifier, "bedrockIdentifier must not be null"); + } + + @Override + public EntityDefinition.Builder bedrockIdentifier(String bedrockIdentifier) { + throw new UnsupportedOperationException("bedrockIdentifier should be immutable"); + } + + @Override + public Builder width(@Positive float width) { + return (Builder) super.width(width); + } + + @Override + public Builder height(@Positive float height) { + return (Builder) super.height(height); + } + + @Override + public Builder heightAndWidth(@Positive float value) { + return (Builder) super.heightAndWidth(value); + } + + @Override + public Builder offset(@Positive float offset) { + return (Builder) super.offset(offset); + } + + public Builder predicate(@NonNull MinecraftPredicate predicate) { + predicates.add(Objects.requireNonNull(predicate, "predicate must not be null")); + return this; + } + + public Builder predicateStrategy(@NonNull PredicateStrategy strategy) { + predicateStrategy = Objects.requireNonNull(strategy, "strategy must not be null"); + return this; + } + + @Override + public Builder property(PropertyType propertyType) { + return (Builder) super.property(propertyType); + } + + @Override + public >> Builder addTranslator(MetadataType type, BiConsumer translateFunction) { + return (Builder) super.addTranslator(type, translateFunction); + } + + @Override + public Builder addTranslator(EntityMetadataTranslator translator) { + return (Builder) super.addTranslator(translator); + } + + @Override + public GeyserCustomEntityDefinition build() { + if (predicates.isEmpty()) { + throw new IllegalStateException("predicates must not be empty!"); + } + return new GeyserCustomEntityDefinition<>(factory, bedrockIdentifier, predicates, predicateStrategy, width, height, offset, propertiesBuilder.build(), translators); + } + } +} diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java index 3a3a156cbf1..db961c9160e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java @@ -72,6 +72,11 @@ public boolean isUnregistered() { return javaIdentifier.equals(UNREGISTERED); } + @Override + public boolean vanilla() { + return VANILLA.containsValue(this); + } + public boolean is(EntityType type) { return javaId == type.id(); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java index 6350407dca4..8bb3423a7cc 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java @@ -48,21 +48,24 @@ @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class VanillaEntityDefinition extends EntityDefinition { + private final GeyserEntityType entityType; public VanillaEntityDefinition(EntityFactory factory, GeyserEntityType entityType, String bedrockIdentifier, float width, float height, float offset, GeyserEntityProperties registeredProperties, List> translators) { - super(factory, entityType, bedrockIdentifier, width, height, offset, registeredProperties, translators); + super(factory, bedrockIdentifier, width, height, offset, registeredProperties, translators); + this.entityType = entityType; } public static Builder builder(EntityFactory factory) { return new Builder<>(factory); } - public static Builder inherited(EntityFactory factory, EntityDefinition parent) { + public static Builder inherited(EntityFactory factory, EntityDefinitionBase parent) { return new Builder<>(factory, parent.width(), parent.height(), parent.offset(), new ObjectArrayList<>(parent.translators())); } public static class Builder extends EntityDefinition.Builder { + protected GeyserEntityType type; protected Builder(EntityFactory factory) { super(factory); @@ -72,8 +75,13 @@ protected Builder(EntityFactory factory, float width, float height, float off super(factory, width, height, offset, translators); } + /** + * Resets the bedrock identifier as well + */ public Builder type(BuiltinEntityType type) { - return (Builder) super.type(GeyserEntityType.ofVanilla(type)); + this.type = GeyserEntityType.ofVanilla(type); + this.bedrockIdentifier = null; + return this; } @Override @@ -121,6 +129,14 @@ public VanillaEntityDefinition build() { return build(true); } + private void validateTypeAndIdentifier() { + if (type == null) { + throw new IllegalStateException("Missing entity type!"); + } else if (bedrockIdentifier == null) { + bedrockIdentifier = type.javaIdentifier().toString(); + } + } + /** * @param register whether to register this entity in the Registries for entity types. Generally this should be * set to false if we're not expecting this entity to spawn from the network. diff --git a/core/src/main/java/org/geysermc/geyser/registry/Registries.java b/core/src/main/java/org/geysermc/geyser/registry/Registries.java index e20efc1926e..9c70d892d19 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/Registries.java +++ b/core/src/main/java/org/geysermc/geyser/registry/Registries.java @@ -38,7 +38,7 @@ import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.entity.JavaEntityType; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.VanillaEntityDefinition; import org.geysermc.geyser.inventory.recipe.GeyserRecipe; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.pack.ResourcePackHolder; @@ -65,14 +65,12 @@ import org.geysermc.geyser.translator.sound.SoundInteractionTranslator; import org.geysermc.geyser.translator.sound.SoundTranslator; import org.geysermc.mcprotocollib.network.packet.Packet; -import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents; import org.geysermc.mcprotocollib.protocol.data.game.level.block.BlockEntityType; import org.geysermc.mcprotocollib.protocol.data.game.level.event.LevelEvent; import org.geysermc.mcprotocollib.protocol.data.game.level.particle.ParticleType; import java.util.ArrayList; -import java.util.EnumMap; import java.util.HashSet; import java.util.IdentityHashMap; import java.util.Map; @@ -126,7 +124,8 @@ public final class Registries { * A map containing all entity types and their respective Geyser definitions */ // Is a Reference2ObjectMap since GeyserEntityType, the implementation of JavaEntityType, only ever keeps one instance per registered entity type - public static final SimpleMappedRegistry> ENTITY_DEFINITIONS = SimpleMappedRegistry.create(RegistryLoaders.empty(Reference2ObjectOpenHashMap::new)); + // TODO rename to VANILLA_ENTITY_DEFINITIONS + public static final SimpleMappedRegistry> ENTITY_DEFINITIONS = SimpleMappedRegistry.create(RegistryLoaders.empty(Reference2ObjectOpenHashMap::new)); /** * A registry holding a list of all the known entity properties to be sent to the client after start game. @@ -136,7 +135,7 @@ public final class Registries { /** * A map containing all Java entity identifiers and their respective Geyser definitions */ - public static final SimpleMappedRegistry> JAVA_ENTITY_IDENTIFIERS = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new)); + public static final SimpleMappedRegistry> JAVA_ENTITY_IDENTIFIERS = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new)); /** * A registry containing all the Java packet translators. diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java index 31ec971b450..5a2960c5ff8 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java @@ -34,6 +34,7 @@ import org.geysermc.geyser.api.block.custom.component.MaterialInstance; import org.geysermc.geyser.api.block.custom.nonvanilla.JavaBlockState; import org.geysermc.geyser.api.command.Command; +import org.geysermc.geyser.api.entity.CustomEntityDefinition; import org.geysermc.geyser.api.entity.JavaEntityType; import org.geysermc.geyser.api.event.EventRegistrar; import org.geysermc.geyser.api.extension.Extension; @@ -46,6 +47,7 @@ import org.geysermc.geyser.api.pack.option.SubpackOption; import org.geysermc.geyser.api.pack.option.UrlFallbackOption; import org.geysermc.geyser.api.util.Identifier; +import org.geysermc.geyser.entity.GeyserCustomEntityDefinition; import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.event.GeyserEventRegistrar; import org.geysermc.geyser.extension.command.GeyserExtensionCommand; @@ -113,6 +115,7 @@ public Map, ProviderSupplier> load(Map, ProviderSupplier> prov // entities providers.put(JavaEntityType.class, args -> args.length == 1 ? GeyserEntityType.ofVanilla((Identifier) args[0]) : GeyserEntityType.createCustom((Identifier) args[0], (int) args[1])); + providers.put(CustomEntityDefinition.class, args -> GeyserCustomEntityDefinition.inherited((String) args[0], (JavaEntityType) args[1])); return providers; } From e398c545f949ffeb9e5195a4f47f92fc92206b43 Mon Sep 17 00:00:00 2001 From: Eclipse Date: Mon, 27 Oct 2025 10:27:22 +0000 Subject: [PATCH 06/62] Add EntityDefinition#is --- .../geyser/entity/EntityDefinition.java | 3 + .../geyser/entity/EntityDefinitionBase.java | 2 +- .../entity/GeyserCustomEntityDefinition.java | 6 ++ .../entity/VanillaEntityDefinition.java | 5 + .../geyser/entity/type/ThrowableEntity.java | 23 ++--- .../entity/JavaSetPassengersTranslator.java | 5 +- .../org/geysermc/geyser/util/EntityUtils.java | 91 ++++++++++--------- 7 files changed, 73 insertions(+), 62 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java index 28978bb8919..efb8f7fcfe3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java @@ -38,6 +38,7 @@ import org.geysermc.geyser.translator.entity.EntityMetadataTranslator; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataType; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import java.util.List; import java.util.function.BiConsumer; @@ -66,6 +67,8 @@ public EntityDefinition(EntityFactory factory, String bedrockIdentifier, this.registeredProperties = registeredProperties; } + public abstract boolean is(BuiltinEntityType type); + @Setter @Accessors(fluent = true, chain = true) public static abstract class Builder extends EntityDefinitionBase.Builder { diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBase.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBase.java index cfcb3d8ca1a..f4e7fd70b8b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBase.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBase.java @@ -76,7 +76,7 @@ public void translateMetadata(T entity, EntityMetadata factory, String bedrockIden this.predicateStrategy = predicateStrategy; } + @Override + public boolean is(BuiltinEntityType type) { + return false; + } + public static Builder inherited(String bedrockIdentifier, JavaEntityType vanillaType) { if (!vanillaType.vanilla()) { throw new IllegalArgumentException("vanillaType must be a vanilla entity type, was: " + vanillaType); diff --git a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java index 8bb3423a7cc..76933b1ecbd 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java @@ -56,6 +56,11 @@ public VanillaEntityDefinition(EntityFactory factory, GeyserEntityType entity this.entityType = entityType; } + @Override + public boolean is(BuiltinEntityType builtin) { + return entityType.is(builtin); + } + public static Builder builder(EntityFactory factory) { return new Builder<>(factory); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java index ec1581ec7fa..4e6cb64c7cb 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java @@ -31,7 +31,6 @@ import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; import org.cloudburstmc.protocol.bedrock.packet.MoveEntityDeltaPacket; import org.geysermc.geyser.entity.EntityDefinition; -import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.level.block.BlockStateValues; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; @@ -120,16 +119,15 @@ protected void moveAbsoluteImmediate(Vector3f position, float yaw, float pitch, */ protected float getGravity() { if (getFlag(EntityFlag.HAS_GRAVITY)) { - GeyserEntityType type = definition.entityType(); - if (type.is(BuiltinEntityType.LINGERING_POTION) || type.is(BuiltinEntityType.SPLASH_POTION)) { + if (definition.is(BuiltinEntityType.LINGERING_POTION) || definition.is(BuiltinEntityType.SPLASH_POTION)) { return 0.05f; - } else if (type.is(BuiltinEntityType.EXPERIENCE_BOTTLE)) { + } else if (definition.is(BuiltinEntityType.EXPERIENCE_BOTTLE)) { return 0.07f; - } else if (type.is(BuiltinEntityType.FIREBALL) || type.is(BuiltinEntityType.SHULKER_BULLET)) { + } else if (definition.is(BuiltinEntityType.FIREBALL) || definition.is(BuiltinEntityType.SHULKER_BULLET)) { return 0; - } else if (type.is(BuiltinEntityType.SNOWBALL) || type.is(BuiltinEntityType.EGG) || type.is(BuiltinEntityType.ENDER_PEARL)) { + } else if (definition.is(BuiltinEntityType.SNOWBALL) || definition.is(BuiltinEntityType.EGG) || definition.is(BuiltinEntityType.ENDER_PEARL)) { return 0.03f; - } else if (type.is(BuiltinEntityType.LLAMA_SPIT)) { + } else if (definition.is(BuiltinEntityType.LLAMA_SPIT)) { return 0.06f; } } @@ -143,13 +141,12 @@ protected float getDrag() { if (isInWater()) { return 0.8f; } else { - GeyserEntityType type = definition.entityType(); - if (type.is(BuiltinEntityType.LINGERING_POTION) || type.is(BuiltinEntityType.SPLASH_POTION) || type.is(BuiltinEntityType.EXPERIENCE_BOTTLE) - || type.is(BuiltinEntityType.SNOWBALL) || type.is(BuiltinEntityType.EGG) || type.is(BuiltinEntityType.ENDER_PEARL) || type.is(BuiltinEntityType.LLAMA_SPIT)) { + if (definition.is(BuiltinEntityType.LINGERING_POTION) || definition.is(BuiltinEntityType.SPLASH_POTION) || definition.is(BuiltinEntityType.EXPERIENCE_BOTTLE) + || definition.is(BuiltinEntityType.SNOWBALL) || definition.is(BuiltinEntityType.EGG) || definition.is(BuiltinEntityType.ENDER_PEARL) || definition.is(BuiltinEntityType.LLAMA_SPIT)) { return 0.99f; - } else if (type.is(BuiltinEntityType.FIREBALL) || type.is(BuiltinEntityType.SMALL_FIREBALL) || type.is(BuiltinEntityType.DRAGON_FIREBALL)) { + } else if (definition.is(BuiltinEntityType.FIREBALL) || definition.is(BuiltinEntityType.SMALL_FIREBALL) || definition.is(BuiltinEntityType.DRAGON_FIREBALL)) { return 0.95f; - } else if (type.is(BuiltinEntityType.SHULKER_BULLET)) { + } else if (definition.is(BuiltinEntityType.SHULKER_BULLET)) { return 1; } } @@ -166,7 +163,7 @@ protected boolean isInWater() { @Override public void despawnEntity() { - if (definition.entityType().is(BuiltinEntityType.ENDER_PEARL)) { + if (definition.is(BuiltinEntityType.ENDER_PEARL)) { LevelEventPacket particlePacket = new LevelEventPacket(); particlePacket.setType(LevelEvent.PARTICLE_TELEPORT); particlePacket.setPosition(position); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java index 67c36620d38..8618edd19c1 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java @@ -30,7 +30,6 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityLinkData; import org.cloudburstmc.protocol.bedrock.packet.SetEntityLinkPacket; import org.geysermc.geyser.entity.EntityDefinitions; -import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.vehicle.ClientVehicle; import org.geysermc.geyser.session.GeyserSession; @@ -126,8 +125,8 @@ public void translate(GeyserSession session, ClientboundSetPassengersPacket pack entity.setPassengers(newPassengers); - GeyserEntityType type = entity.getDefinition().entityType(); - if (type.is(BuiltinEntityType.HORSE) || type.is(BuiltinEntityType.SKELETON_HORSE) || type.is(BuiltinEntityType.DONKEY) || type.is(BuiltinEntityType.MULE) || type.is(BuiltinEntityType.RAVAGER)) { + if (entity.getDefinition().is(BuiltinEntityType.HORSE) || entity.getDefinition().is(BuiltinEntityType.SKELETON_HORSE) || entity.getDefinition().is(BuiltinEntityType.DONKEY) + || entity.getDefinition().is(BuiltinEntityType.MULE) || entity.getDefinition().is(BuiltinEntityType.RAVAGER)) { entity.getDirtyMetadata().put(EntityDataTypes.SEAT_ROTATION_OFFSET_DEGREES, 181.0f); entity.updateBedrockMetadata(); } diff --git a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java index 0b58b14cdf6..5c11d6453bf 100644 --- a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java @@ -33,6 +33,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.api.util.Identifier; +import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.EntityDefinitions; import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.entity.type.BoatEntity; @@ -108,36 +109,36 @@ private static float getMountedHeightOffset(Entity mount) { float height = mount.getBoundingBoxHeight(); float mountedHeightOffset = height * 0.75f; - GeyserEntityType type = mount.getDefinition().entityType(); - if (type.is(BuiltinEntityType.CAMEL)) { + EntityDefinition definition = mount.getDefinition(); + if (definition.is(BuiltinEntityType.CAMEL)) { boolean isBaby = mount.getFlag(EntityFlag.BABY); mountedHeightOffset = height - (isBaby ? 0.35f : 0.6f); - } else if (type.is(BuiltinEntityType.CAVE_SPIDER) || type.is(BuiltinEntityType.CHICKEN) || type.is(BuiltinEntityType.SPIDER)) { + } else if (definition.is(BuiltinEntityType.CAVE_SPIDER) || definition.is(BuiltinEntityType.CHICKEN) || definition.is(BuiltinEntityType.SPIDER)) { mountedHeightOffset = height * 0.5f; - } else if (type.is(BuiltinEntityType.DONKEY) || type.is(BuiltinEntityType.MULE)) { + } else if (definition.is(BuiltinEntityType.DONKEY) || definition.is(BuiltinEntityType.MULE)) { mountedHeightOffset -= 0.25f; - } else if (type.is(BuiltinEntityType.TRADER_LLAMA) || type.is(BuiltinEntityType.LLAMA)) { + } else if (definition.is(BuiltinEntityType.TRADER_LLAMA) || definition.is(BuiltinEntityType.LLAMA)) { mountedHeightOffset = height * 0.6f; - } else if (type.is(BuiltinEntityType.MINECART) || type.is(BuiltinEntityType.HOPPER_MINECART) || type.is(BuiltinEntityType.TNT_MINECART) - || type.is(BuiltinEntityType.CHEST_MINECART) || type.is(BuiltinEntityType.FURNACE_MINECART) - || type.is(BuiltinEntityType.SPAWNER_MINECART) || type.is(BuiltinEntityType.COMMAND_BLOCK_MINECART)) { + } else if (definition.is(BuiltinEntityType.MINECART) || definition.is(BuiltinEntityType.HOPPER_MINECART) || definition.is(BuiltinEntityType.TNT_MINECART) + || definition.is(BuiltinEntityType.CHEST_MINECART) || definition.is(BuiltinEntityType.FURNACE_MINECART) + || definition.is(BuiltinEntityType.SPAWNER_MINECART) || definition.is(BuiltinEntityType.COMMAND_BLOCK_MINECART)) { mountedHeightOffset = 0; - } else if (type.is(BuiltinEntityType.BAMBOO_RAFT) || type.is(BuiltinEntityType.BAMBOO_CHEST_RAFT)) { + } else if (definition.is(BuiltinEntityType.BAMBOO_RAFT) || definition.is(BuiltinEntityType.BAMBOO_CHEST_RAFT)) { mountedHeightOffset = 0.25f; - } else if (type.is(BuiltinEntityType.HOGLIN) || type.is(BuiltinEntityType.ZOGLIN)) { + } else if (definition.is(BuiltinEntityType.HOGLIN) || definition.is(BuiltinEntityType.ZOGLIN)) { boolean isBaby = mount.getFlag(EntityFlag.BABY); mountedHeightOffset = height - (isBaby ? 0.2f : 0.15f); - } else if (type.is(BuiltinEntityType.PIGLIN)) { + } else if (definition.is(BuiltinEntityType.PIGLIN)) { mountedHeightOffset = height * 0.92f; - } else if (type.is(BuiltinEntityType.PHANTOM)) { + } else if (definition.is(BuiltinEntityType.PHANTOM)) { mountedHeightOffset = height * 0.35f; - } else if (type.is(BuiltinEntityType.RAVAGER)) { + } else if (definition.is(BuiltinEntityType.RAVAGER)) { mountedHeightOffset = 2.1f; - } else if (type.is(BuiltinEntityType.SKELETON_HORSE)) { + } else if (definition.is(BuiltinEntityType.SKELETON_HORSE)) { mountedHeightOffset -= 0.1875f; - } else if (type.is(BuiltinEntityType.SNIFFER)) { + } else if (definition.is(BuiltinEntityType.SNIFFER)) { mountedHeightOffset = 1.8f; - } else if (type.is(BuiltinEntityType.STRIDER)) { + } else if (definition.is(BuiltinEntityType.STRIDER)) { mountedHeightOffset = height - 0.19f; } return mountedHeightOffset; @@ -145,32 +146,32 @@ private static float getMountedHeightOffset(Entity mount) { private static float getHeightOffset(Entity passenger) { boolean isBaby; - GeyserEntityType type = passenger.getDefinition().entityType(); - if (type.is(BuiltinEntityType.ALLAY) || type.is(BuiltinEntityType.VEX)) { + EntityDefinition definition = passenger.getDefinition(); + if (definition.is(BuiltinEntityType.ALLAY) || definition.is(BuiltinEntityType.VEX)) { return 0.4f; - } else if (type.is(BuiltinEntityType.SKELETON) || type.is(BuiltinEntityType.STRAY) || type.is(BuiltinEntityType.WITHER_SKELETON)) { + } else if (definition.is(BuiltinEntityType.SKELETON) || definition.is(BuiltinEntityType.STRAY) || definition.is(BuiltinEntityType.WITHER_SKELETON)) { return -0.6f; - } else if (type.is(BuiltinEntityType.ARMOR_STAND)) { + } else if (definition.is(BuiltinEntityType.ARMOR_STAND)) { if (((ArmorStandEntity) passenger).isMarker()) { return 0.0f; } else { return 0.1f; } - } else if (type.is(BuiltinEntityType.ENDERMITE) || type.is(BuiltinEntityType.SILVERFISH)) { + } else if (definition.is(BuiltinEntityType.ENDERMITE) || definition.is(BuiltinEntityType.SILVERFISH)) { return 0.1f; - } else if (type.is(BuiltinEntityType.PIGLIN) || type.is(BuiltinEntityType.PIGLIN_BRUTE) || type.is(BuiltinEntityType.ZOMBIFIED_PIGLIN)) { + } else if (definition.is(BuiltinEntityType.PIGLIN) || definition.is(BuiltinEntityType.PIGLIN_BRUTE) || definition.is(BuiltinEntityType.ZOMBIFIED_PIGLIN)) { isBaby = passenger.getFlag(EntityFlag.BABY); return isBaby ? -0.05f : -0.45f; - } else if (type.is(BuiltinEntityType.DROWNED) || type.is(BuiltinEntityType.HUSK) || type.is(BuiltinEntityType.ZOMBIE_VILLAGER) - || type.is(BuiltinEntityType.ZOMBIE)) { + } else if (definition.is(BuiltinEntityType.DROWNED) || definition.is(BuiltinEntityType.HUSK) || definition.is(BuiltinEntityType.ZOMBIE_VILLAGER) + || definition.is(BuiltinEntityType.ZOMBIE)) { isBaby = passenger.getFlag(EntityFlag.BABY); return isBaby ? 0.0f : -0.45f; - } else if (type.is(BuiltinEntityType.EVOKER) || type.is(BuiltinEntityType.ILLUSIONER) || type.is(BuiltinEntityType.PILLAGER) - || type.is(BuiltinEntityType.RAVAGER) || type.is(BuiltinEntityType.VINDICATOR) || type.is(BuiltinEntityType.WITCH)) { + } else if (definition.is(BuiltinEntityType.EVOKER) || definition.is(BuiltinEntityType.ILLUSIONER) || definition.is(BuiltinEntityType.PILLAGER) + || definition.is(BuiltinEntityType.RAVAGER) || definition.is(BuiltinEntityType.VINDICATOR) || definition.is(BuiltinEntityType.WITCH)) { return -0.45f; - } else if (type.is(BuiltinEntityType.PLAYER)) { + } else if (definition.is(BuiltinEntityType.PLAYER)) { return -0.35f; - } else if (type.is(BuiltinEntityType.SHULKER)) { + } else if (definition.is(BuiltinEntityType.SHULKER)) { Entity vehicle = passenger.getVehicle(); if (vehicle instanceof BoatEntity || vehicle.getDefinition() == EntityDefinitions.MINECART) { return 0.1875f - getMountedHeightOffset(vehicle); @@ -195,8 +196,8 @@ public static void updateMountOffset(Entity passenger, Entity mount, boolean rid float xOffset = 0; float yOffset = mountedHeightOffset + heightOffset; float zOffset = 0; - GeyserEntityType mountType = mount.getDefinition().entityType(); - if (mountType.is(BuiltinEntityType.CAMEL)) { + EntityDefinition mountDefinition = mount.getDefinition(); + if (mountDefinition.is(BuiltinEntityType.CAMEL)) { zOffset = 0.5f; if (passengers > 1) { if (!rider) { @@ -213,11 +214,11 @@ public static void updateMountOffset(Entity passenger, Entity mount, boolean rid yOffset += CamelEntity.SITTING_HEIGHT_DIFFERENCE; } } - } else if (mountType.is(BuiltinEntityType.CHICKEN)) { + } else if (mountDefinition.is(BuiltinEntityType.CHICKEN)) { zOffset = -0.1f; - } else if (mountType.is(BuiltinEntityType.TRADER_LLAMA) || mountType.is(BuiltinEntityType.LLAMA)) { + } else if (mountDefinition.is(BuiltinEntityType.TRADER_LLAMA) || mountDefinition.is(BuiltinEntityType.LLAMA)) { zOffset = -0.3f; - } else if (mountType.is(BuiltinEntityType.TEXT_DISPLAY)) { + } else if (mountDefinition.is(BuiltinEntityType.TEXT_DISPLAY)) { if (passenger instanceof TextDisplayEntity textDisplay) { Vector3f displayTranslation = textDisplay.getTranslation(); if (displayTranslation == null) { @@ -228,7 +229,7 @@ public static void updateMountOffset(Entity passenger, Entity mount, boolean rid yOffset = displayTranslation.getY() + 0.2f; zOffset = displayTranslation.getZ(); } - } else if (mountType.is(BuiltinEntityType.PLAYER)) { + } else if (mountDefinition.is(BuiltinEntityType.PLAYER)) { if (passenger instanceof TextDisplayEntity textDisplay) { Vector3f displayTranslation = textDisplay.getTranslation(); int lines = textDisplay.getLineCount(); @@ -239,7 +240,7 @@ public static void updateMountOffset(Entity passenger, Entity mount, boolean rid zOffset = displayTranslation.getZ(); } } - } else if (mountType.is(BuiltinEntityType.HAPPY_GHAST)) { + } else if (mountDefinition.is(BuiltinEntityType.HAPPY_GHAST)) { int seatingIndex = Math.min(index, 4); xOffset = HappyGhastEntity.X_OFFSETS[seatingIndex]; yOffset = 3.4f; @@ -263,23 +264,23 @@ public static void updateMountOffset(Entity passenger, Entity mount, boolean rid * Horses are tinier * Players, Minecarts, and Boats have different origins */ - GeyserEntityType passengerType = passenger.getDefinition().entityType(); - if (mountType.is(BuiltinEntityType.PLAYER)) { + EntityDefinition passengerDefinition = passenger.getDefinition(); + if (mountDefinition.is(BuiltinEntityType.PLAYER)) { yOffset -= EntityDefinitions.PLAYER.offset(); } - if (passengerType.is(BuiltinEntityType.PLAYER)) { + if (passengerDefinition.is(BuiltinEntityType.PLAYER)) { yOffset += EntityDefinitions.PLAYER.offset(); } - if (mountType.is(BuiltinEntityType.MINECART) || mountType.is(BuiltinEntityType.HOPPER_MINECART) || mountType.is(BuiltinEntityType.TNT_MINECART) - || mountType.is(BuiltinEntityType.CHEST_MINECART) || mountType.is(BuiltinEntityType.FURNACE_MINECART) - || mountType.is(BuiltinEntityType.SPAWNER_MINECART) || mountType.is(BuiltinEntityType.COMMAND_BLOCK_MINECART)) { + if (mountDefinition.is(BuiltinEntityType.MINECART) || mountDefinition.is(BuiltinEntityType.HOPPER_MINECART) || mountDefinition.is(BuiltinEntityType.TNT_MINECART) + || mountDefinition.is(BuiltinEntityType.CHEST_MINECART) || mountDefinition.is(BuiltinEntityType.FURNACE_MINECART) + || mountDefinition.is(BuiltinEntityType.SPAWNER_MINECART) || mountDefinition.is(BuiltinEntityType.COMMAND_BLOCK_MINECART)) { yOffset -= mount.getDefinition().height() * 0.5f; } - if (passengerType.is(BuiltinEntityType.MINECART) || passengerType.is(BuiltinEntityType.HOPPER_MINECART) || passengerType.is(BuiltinEntityType.TNT_MINECART) - || passengerType.is(BuiltinEntityType.CHEST_MINECART) || passengerType.is(BuiltinEntityType.FURNACE_MINECART) || passengerType.is(BuiltinEntityType.SPAWNER_MINECART) - || passengerType.is(BuiltinEntityType.COMMAND_BLOCK_MINECART) || passengerType.is(BuiltinEntityType.SHULKER)) { + if (passengerDefinition.is(BuiltinEntityType.MINECART) || passengerDefinition.is(BuiltinEntityType.HOPPER_MINECART) || passengerDefinition.is(BuiltinEntityType.TNT_MINECART) + || passengerDefinition.is(BuiltinEntityType.CHEST_MINECART) || passengerDefinition.is(BuiltinEntityType.FURNACE_MINECART) || passengerDefinition.is(BuiltinEntityType.SPAWNER_MINECART) + || passengerDefinition.is(BuiltinEntityType.COMMAND_BLOCK_MINECART) || passengerDefinition.is(BuiltinEntityType.SHULKER)) { yOffset += passenger.getDefinition().height() * 0.5f; - } else if (passengerType.is(BuiltinEntityType.FALLING_BLOCK)) { + } else if (passengerDefinition.is(BuiltinEntityType.FALLING_BLOCK)) { yOffset += 0.995f; } if (mount instanceof BoatEntity) { From a3869cf5f8a613d3a17fc1af79b66880bc951a72 Mon Sep 17 00:00:00 2001 From: Eclipse Date: Mon, 27 Oct 2025 13:39:16 +0100 Subject: [PATCH 07/62] Implement CustomEntityDefinition, part one --- .../api/entity/CustomEntityDefinition.java | 18 +------- .../geyser/api/entity/JavaEntityType.java | 2 +- .../GeyserDefineCustomEntitiesEvent.java | 42 +++++++++++++++++++ .../geyser/entity/EntityDefinitions.java | 25 ++++++++--- .../entity/GeyserCustomEntityDefinition.java | 10 ++--- .../geyser/entity/GeyserEntityType.java | 2 +- .../geysermc/geyser/entity/type/Entity.java | 4 +- .../geyser/registry/ListRegistry.java | 9 +++- .../geysermc/geyser/registry/Registries.java | 4 ++ .../loader/ProviderRegistryLoader.java | 2 +- .../java/entity/JavaAddEntityTranslator.java | 23 ++++++++-- 11 files changed, 104 insertions(+), 37 deletions(-) create mode 100644 api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomEntitiesEvent.java diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/CustomEntityDefinition.java b/api/src/main/java/org/geysermc/geyser/api/entity/CustomEntityDefinition.java index 18e99b9663f..0b409bd16e0 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/CustomEntityDefinition.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/CustomEntityDefinition.java @@ -29,12 +29,6 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.common.returnsreceiver.qual.This; import org.geysermc.geyser.api.GeyserApi; -import org.geysermc.geyser.api.predicate.MinecraftPredicate; -import org.geysermc.geyser.api.predicate.PredicateStrategy; -import org.geysermc.geyser.api.predicate.context.entity.EntitySpawnContext; -import org.geysermc.geyser.api.util.GenericBuilder; - -import java.util.List; public interface CustomEntityDefinition { @@ -47,15 +41,11 @@ public interface CustomEntityDefinition { float offset(); - List> predicates(); - - PredicateStrategy predicateStrategy(); - static Builder builder(@NonNull String bedrockIdentifier, @NonNull JavaEntityType vanillaType) { return GeyserApi.api().provider(Builder.class, bedrockIdentifier, vanillaType); } - interface Builder extends GenericBuilder { + interface Builder { @This Builder width(@Positive float width); @@ -69,12 +59,6 @@ interface Builder extends GenericBuilder { @This Builder offset(@Positive float offset); - @This - Builder predicate(@NonNull MinecraftPredicate predicate); - - @This - Builder predicateStrategy(@NonNull PredicateStrategy strategy); - @Override CustomEntityDefinition build(); } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java index 853a014c605..07374b18429 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java @@ -48,7 +48,7 @@ static JavaEntityType ofVanilla(@NonNull Identifier javaIdentifier) { return GeyserApi.api().provider(JavaEntityType.class, javaIdentifier); } - static JavaEntityType create(@NonNull Identifier javaIdentifier, @NonNegative int javaId) { + static JavaEntityType createAndRegister(@NonNull Identifier javaIdentifier, @NonNegative int javaId) { return GeyserApi.api().provider(JavaEntityType.class, javaIdentifier, javaId); } } diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomEntitiesEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomEntitiesEvent.java new file mode 100644 index 00000000000..65fd52552e9 --- /dev/null +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomEntitiesEvent.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.api.event.lifecycle; + +import org.geysermc.event.Event; +import org.geysermc.geyser.api.entity.CustomEntityDefinition; + +import java.util.List; + +public interface GeyserDefineCustomEntitiesEvent extends Event { + + List existingCustomEntityDefinitions(); + + default void register(CustomEntityDefinition.Builder builder) { + register(builder.build()); + } + + void register(CustomEntityDefinition customEntityDefinition); +} diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java index bf300893067..4e9030ed2f2 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java @@ -30,9 +30,11 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.api.entity.CustomEntityDefinition; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.entity.property.type.GeyserFloatEntityProperty; import org.geysermc.geyser.api.entity.property.type.GeyserStringEnumProperty; +import org.geysermc.geyser.api.event.lifecycle.GeyserDefineCustomEntitiesEvent; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntityPropertiesEvent; import org.geysermc.geyser.api.util.Identifier; import org.geysermc.geyser.entity.factory.EntityFactory; @@ -173,6 +175,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -1263,7 +1266,19 @@ private static VanillaEntityDefinition buildChestBoat(EntityDef } public static void init() { - // entities would be initialized before this event is called + // entities would be initialized before these events are called + GeyserImpl.getInstance().getEventBus().fire(new GeyserDefineCustomEntitiesEvent() { + @Override + public List existingCustomEntityDefinitions() { + return Collections.unmodifiableList(Registries.CUSTOM_ENTITY_DEFINITIONS.get()); + } + + @Override + public void register(CustomEntityDefinition customEntityDefinition) { + Registries.CUSTOM_ENTITY_DEFINITIONS.register(Registries.CUSTOM_ENTITY_DEFINITIONS.get().size(), customEntityDefinition); + } + }); + GeyserImpl.getInstance().getEventBus().fire(new GeyserDefineEntityPropertiesEvent() { @Override public GeyserFloatEntityProperty registerFloatProperty(@NonNull Identifier identifier, @NonNull Identifier propertyId, float min, float max, @Nullable Float defaultValue) { @@ -1345,13 +1360,13 @@ public Collection> properties(@NonNull Identifier identi } } - private static void registerProperty(Identifier BuiltinEntityType, PropertyType property) { - var definition = Registries.JAVA_ENTITY_IDENTIFIERS.get(BuiltinEntityType.toString()); + private static void registerProperty(Identifier entityType, PropertyType property) { + var definition = Registries.JAVA_ENTITY_IDENTIFIERS.get(entityType.toString()); if (definition == null) { - throw new IllegalArgumentException("Unknown entity type: " + BuiltinEntityType); + throw new IllegalArgumentException("Unknown entity type: " + entityType); } - definition.registeredProperties().add(BuiltinEntityType.toString(), property); + definition.registeredProperties().add(entityType.toString(), property); } private EntityDefinitions() { diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java index 734d6811902..84af91ce982 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java @@ -36,7 +36,7 @@ import org.geysermc.geyser.api.entity.JavaEntityType; import org.geysermc.geyser.api.predicate.MinecraftPredicate; import org.geysermc.geyser.api.predicate.PredicateStrategy; -import org.geysermc.geyser.api.predicate.context.entity.EntitySpawnContext; +import org.geysermc.geyser.api.predicate.context.entity.EntitySpawnPredicateContext; import org.geysermc.geyser.entity.factory.EntityFactory; import org.geysermc.geyser.entity.properties.GeyserEntityProperties; import org.geysermc.geyser.entity.properties.type.PropertyType; @@ -56,10 +56,10 @@ @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class GeyserCustomEntityDefinition extends EntityDefinition implements CustomEntityDefinition { - private final List> predicates; + private final List> predicates; private final PredicateStrategy predicateStrategy; - public GeyserCustomEntityDefinition(EntityFactory factory, String bedrockIdentifier, List> predicates, PredicateStrategy predicateStrategy, + public GeyserCustomEntityDefinition(EntityFactory factory, String bedrockIdentifier, List> predicates, PredicateStrategy predicateStrategy, float width, float height, float offset, GeyserEntityProperties registeredProperties, List> translators) { super(factory, bedrockIdentifier, width, height, offset, registeredProperties, translators); this.predicates = predicates; @@ -84,7 +84,7 @@ public static Builder inherited(String bedrockIdentifier, JavaEntityType vani } public static class Builder extends EntityDefinition.Builder implements CustomEntityDefinition.Builder { - protected List> predicates; + protected List> predicates; protected PredicateStrategy predicateStrategy = PredicateStrategy.AND; protected Builder(EntityFactory factory, String bedrockIdentifier) { @@ -122,7 +122,7 @@ public Builder offset(@Positive float offset) { return (Builder) super.offset(offset); } - public Builder predicate(@NonNull MinecraftPredicate predicate) { + public Builder predicate(@NonNull MinecraftPredicate predicate) { predicates.add(Objects.requireNonNull(predicate, "predicate must not be null")); return this; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java index db961c9160e..7eb60e308b7 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java @@ -117,7 +117,7 @@ public static GeyserEntityType of(EntityType type) { return type instanceof BuiltinEntityType builtin ? ofVanilla(builtin) : of(type.id()); } - public static GeyserEntityType createCustom(@NonNull Identifier javaIdentifier, @NonNegative int javaId) { + public static GeyserEntityType createCustomAndRegister(@NonNull Identifier javaIdentifier, @NonNegative int javaId) { Objects.requireNonNull(javaIdentifier, "javaIdentifier may not be null"); if (javaIdentifier.vanilla()) { throw new IllegalArgumentException("Cannot register custom entity type in vanilla namespace!" + javaIdentifier); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index 8313226da5d..90ff6fa426e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -221,9 +221,7 @@ public void spawnEntity() { flagsDirty = false; if (session.getGeyser().config().debugMode() && PRINT_ENTITY_SPAWN_DEBUG) { - JavaEntityType type = definition.entityType(); - String name = type != null ? type.javaIdentifier().toString() : getClass().getSimpleName(); - session.getGeyser().getLogger().debug("Spawned entity " + name + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")"); + session.getGeyser().getLogger().debug("Spawned entity " + definition.bedrockIdentifier() + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")"); } } diff --git a/core/src/main/java/org/geysermc/geyser/registry/ListRegistry.java b/core/src/main/java/org/geysermc/geyser/registry/ListRegistry.java index 084835c2e79..85dc5644b8e 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/ListRegistry.java +++ b/core/src/main/java/org/geysermc/geyser/registry/ListRegistry.java @@ -27,13 +27,15 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.registry.loader.RegistryLoader; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.List; import java.util.function.Supplier; -public class ListRegistry extends Registry> { +public class ListRegistry extends Registry> implements Iterable { private boolean frozen = false; /** @@ -114,6 +116,11 @@ public M registerWithAnyIndex(int index, M value, M defaultValue) { return this.mappings.set(index, value); } + @Override + public @NotNull Iterator iterator() { + return get().iterator(); + } + /** * Mark this registry as unsuitable for new additions. The backing list will then be optimized for storage. */ diff --git a/core/src/main/java/org/geysermc/geyser/registry/Registries.java b/core/src/main/java/org/geysermc/geyser/registry/Registries.java index 9c70d892d19..a3ad2a0ace7 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/Registries.java +++ b/core/src/main/java/org/geysermc/geyser/registry/Registries.java @@ -37,7 +37,9 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.PotionMixData; import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket; import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.api.entity.CustomEntityDefinition; import org.geysermc.geyser.api.entity.JavaEntityType; +import org.geysermc.geyser.entity.GeyserCustomEntityDefinition; import org.geysermc.geyser.entity.VanillaEntityDefinition; import org.geysermc.geyser.inventory.recipe.GeyserRecipe; import org.geysermc.geyser.item.type.Item; @@ -127,6 +129,8 @@ public final class Registries { // TODO rename to VANILLA_ENTITY_DEFINITIONS public static final SimpleMappedRegistry> ENTITY_DEFINITIONS = SimpleMappedRegistry.create(RegistryLoaders.empty(Reference2ObjectOpenHashMap::new)); + public static final ListRegistry> CUSTOM_ENTITY_DEFINITIONS = ListRegistry.create(RegistryLoaders.empty(ArrayList::new)); + /** * A registry holding a list of all the known entity properties to be sent to the client after start game. */ diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java index 5a2960c5ff8..6f387aeee70 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java @@ -114,7 +114,7 @@ public Map, ProviderSupplier> load(Map, ProviderSupplier> prov providers.put(CameraPosition.Builder.class, args -> new GeyserCameraPosition.Builder()); // entities - providers.put(JavaEntityType.class, args -> args.length == 1 ? GeyserEntityType.ofVanilla((Identifier) args[0]) : GeyserEntityType.createCustom((Identifier) args[0], (int) args[1])); + providers.put(JavaEntityType.class, args -> args.length == 1 ? GeyserEntityType.ofVanilla((Identifier) args[0]) : GeyserEntityType.createCustomAndRegister((Identifier) args[0], (int) args[1])); providers.put(CustomEntityDefinition.class, args -> GeyserCustomEntityDefinition.inherited((String) args[0], (JavaEntityType) args[1])); return providers; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java index b39785c20e1..77cec1f9cd7 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java @@ -27,13 +27,16 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.api.predicate.context.entity.EntitySpawnPredicateContext; import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.GeyserCustomEntityDefinition; import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.FallingBlockEntity; import org.geysermc.geyser.entity.type.FishingHookEntity; import org.geysermc.geyser.entity.type.HangingEntity; import org.geysermc.geyser.entity.type.player.PlayerEntity; +import org.geysermc.geyser.impl.predicate.GeyserEntitySpawnPredicateContext; import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.skin.SkinManager; @@ -47,7 +50,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.object.ProjectileData; import org.geysermc.mcprotocollib.protocol.data.game.entity.object.WardenData; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; -import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundAddEntityPacket; @Translator(packet = ClientboundAddEntityPacket.class) @@ -58,9 +60,14 @@ public class JavaAddEntityTranslator extends PacketTranslator definition = Registries.ENTITY_DEFINITIONS.get(type); + if (type.isUnregistered()) { + session.getGeyser().getLogger().warning("Received unregistered entity type " + type + " in add entity packet"); + return; + } + + EntityDefinition definition = getEntityDefinition(session, type, packet); if (definition == null) { - session.getGeyser().getLogger().warning("Could not find an entity definition with type " + type); + session.getGeyser().getLogger().warning("Could not find an entity definition for add entity packet " + packet); return; } @@ -138,4 +145,14 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) session.getEntityCache().spawnEntity(entity); } + + private static EntityDefinition getEntityDefinition(GeyserSession session, GeyserEntityType entityType, ClientboundAddEntityPacket packet) { + EntitySpawnPredicateContext context = new GeyserEntitySpawnPredicateContext(session, entityType, packet); + for (GeyserCustomEntityDefinition customEntityDefinition : Registries.CUSTOM_ENTITY_DEFINITIONS) { + if (customEntityDefinition.test(context)) { + return customEntityDefinition; + } + } + return Registries.ENTITY_DEFINITIONS.get(context.entityType()); + } } From 11e6b50d5384fc580d79223c534c5d64548d5fcc Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Mon, 10 Nov 2025 16:09:32 +0100 Subject: [PATCH 08/62] Move CustomEntityDefinition into custom package --- .../geyser/api/entity/JavaEntityType.java | 15 +++++++++++---- .../{ => custom}/CustomEntityDefinition.java | 6 +++--- .../GeyserDefineCustomEntitiesEvent.java | 2 +- .../geysermc/geyser/entity/EntityDefinitions.java | 2 +- .../entity/GeyserCustomEntityDefinition.java | 2 +- .../geysermc/geyser/entity/GeyserEntityType.java | 5 ++--- .../geyser/entity/VanillaEntityDefinition.java | 4 ++-- .../org/geysermc/geyser/entity/type/Entity.java | 2 ++ .../geyser/item/hashing/RegistryHasher.java | 2 +- .../org/geysermc/geyser/registry/Registries.java | 1 - .../registry/loader/ProviderRegistryLoader.java | 2 +- .../session/cache/registry/JavaRegistries.java | 2 +- .../org/geysermc/geyser/util/EntityUtils.java | 2 +- 13 files changed, 27 insertions(+), 20 deletions(-) rename api/src/main/java/org/geysermc/geyser/api/entity/{ => custom}/CustomEntityDefinition.java (94%) diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java index 07374b18429..28181137a83 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java @@ -30,18 +30,25 @@ import org.geysermc.geyser.api.GeyserApi; import org.geysermc.geyser.api.util.Identifier; +/** + * Represents a Java edition entity type + */ public interface JavaEntityType { - Identifier javaIdentifier(); + /** + * @return the identifier of the type + */ + Identifier identifier(); + /** + * @return the + */ int javaId(); - boolean isUnregistered(); - boolean vanilla(); default boolean is(Identifier javaIdentifier) { - return javaIdentifier().equals(javaIdentifier); + return identifier().equals(javaIdentifier); } static JavaEntityType ofVanilla(@NonNull Identifier javaIdentifier) { diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/CustomEntityDefinition.java b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java similarity index 94% rename from api/src/main/java/org/geysermc/geyser/api/entity/CustomEntityDefinition.java rename to api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java index 0b409bd16e0..3885f132333 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/CustomEntityDefinition.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java @@ -23,17 +23,17 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.geyser.api.entity; +package org.geysermc.geyser.api.entity.custom; import org.checkerframework.checker.index.qual.Positive; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.common.returnsreceiver.qual.This; import org.geysermc.geyser.api.GeyserApi; +import org.geysermc.geyser.api.util.Identifier; public interface CustomEntityDefinition { - // TODO Identifier - String bedrockIdentifier(); + Identifier bedrockIdentifier(); float width(); diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomEntitiesEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomEntitiesEvent.java index 65fd52552e9..48386b35f73 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomEntitiesEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomEntitiesEvent.java @@ -26,7 +26,7 @@ package org.geysermc.geyser.api.event.lifecycle; import org.geysermc.event.Event; -import org.geysermc.geyser.api.entity.CustomEntityDefinition; +import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; import java.util.List; diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java index 4e9030ed2f2..ee8fe928b99 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java @@ -30,7 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.GeyserImpl; -import org.geysermc.geyser.api.entity.CustomEntityDefinition; +import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.entity.property.type.GeyserFloatEntityProperty; import org.geysermc.geyser.api.entity.property.type.GeyserStringEnumProperty; diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java index 84af91ce982..76191ff6077 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java @@ -32,7 +32,7 @@ import lombok.experimental.Accessors; import org.checkerframework.checker.index.qual.Positive; import org.checkerframework.checker.nullness.qual.NonNull; -import org.geysermc.geyser.api.entity.CustomEntityDefinition; +import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; import org.geysermc.geyser.api.entity.JavaEntityType; import org.geysermc.geyser.api.predicate.MinecraftPredicate; import org.geysermc.geyser.api.predicate.PredicateStrategy; diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java index 7eb60e308b7..775783afc96 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java @@ -46,7 +46,7 @@ import java.util.Map; import java.util.Objects; -public record GeyserEntityType(Identifier javaIdentifier, int javaId) implements JavaEntityType { +public record GeyserEntityType(Identifier identifier, int javaId) implements JavaEntityType { private static final Identifier UNREGISTERED = IdentifierImpl.of(Constants.GEYSER_CUSTOM_NAMESPACE, "unregistered_sadface"); private static final Map VANILLA = new EnumMap<>(BuiltinEntityType.class); @@ -67,9 +67,8 @@ private GeyserEntityType(int javaId) { this(UNREGISTERED, javaId); } - @Override public boolean isUnregistered() { - return javaIdentifier.equals(UNREGISTERED); + return identifier.equals(UNREGISTERED); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java index 76933b1ecbd..8453a36c759 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java @@ -138,7 +138,7 @@ private void validateTypeAndIdentifier() { if (type == null) { throw new IllegalStateException("Missing entity type!"); } else if (bedrockIdentifier == null) { - bedrockIdentifier = type.javaIdentifier().toString(); + bedrockIdentifier = type.identifier().toString(); } } @@ -153,7 +153,7 @@ public VanillaEntityDefinition build(boolean register) { VanillaEntityDefinition definition = new VanillaEntityDefinition<>(factory, type, bedrockIdentifier, width, height, offset, registeredProperties, translators); if (register && definition.entityType() != null) { Registries.ENTITY_DEFINITIONS.get().putIfAbsent(definition.entityType(), definition); - Registries.JAVA_ENTITY_IDENTIFIERS.get().putIfAbsent(type.javaIdentifier().toString(), definition); + Registries.JAVA_ENTITY_IDENTIFIERS.get().putIfAbsent(type.identifier().toString(), definition); } return definition; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index 90ff6fa426e..ddc5fc16e7e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -669,6 +669,8 @@ public boolean isAlive() { return this.valid; } + + /** * Update the suggestion that the client currently has on their screen for this entity (for example, "Feed" or "Ride") */ diff --git a/core/src/main/java/org/geysermc/geyser/item/hashing/RegistryHasher.java b/core/src/main/java/org/geysermc/geyser/item/hashing/RegistryHasher.java index fd6b3b17928..83551bc590a 100644 --- a/core/src/main/java/org/geysermc/geyser/item/hashing/RegistryHasher.java +++ b/core/src/main/java/org/geysermc/geyser/item/hashing/RegistryHasher.java @@ -111,7 +111,7 @@ public interface RegistryHasher extends MinecraftHasher { RegistryHasher ENTITY_TYPE = registry(JavaRegistries.ENTITY_TYPE); - MinecraftHasher ENTITY_TYPE_KEY = IDENTIFIER.cast(type -> GeyserEntityType.of(type).javaIdentifier()); + MinecraftHasher ENTITY_TYPE_KEY = IDENTIFIER.cast(type -> GeyserEntityType.of(type).identifier()); MinecraftHasher BLOCK_ENTITY_TYPE_KEY = enumRegistry(); diff --git a/core/src/main/java/org/geysermc/geyser/registry/Registries.java b/core/src/main/java/org/geysermc/geyser/registry/Registries.java index a3ad2a0ace7..7c7fd6748ac 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/Registries.java +++ b/core/src/main/java/org/geysermc/geyser/registry/Registries.java @@ -37,7 +37,6 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.PotionMixData; import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket; import org.geysermc.geyser.GeyserImpl; -import org.geysermc.geyser.api.entity.CustomEntityDefinition; import org.geysermc.geyser.api.entity.JavaEntityType; import org.geysermc.geyser.entity.GeyserCustomEntityDefinition; import org.geysermc.geyser.entity.VanillaEntityDefinition; diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java index 6f387aeee70..6c7a6cf6d91 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java @@ -34,7 +34,7 @@ import org.geysermc.geyser.api.block.custom.component.MaterialInstance; import org.geysermc.geyser.api.block.custom.nonvanilla.JavaBlockState; import org.geysermc.geyser.api.command.Command; -import org.geysermc.geyser.api.entity.CustomEntityDefinition; +import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; import org.geysermc.geyser.api.entity.JavaEntityType; import org.geysermc.geyser.api.event.EventRegistrar; import org.geysermc.geyser.api.extension.Extension; diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/registry/JavaRegistries.java b/core/src/main/java/org/geysermc/geyser/session/cache/registry/JavaRegistries.java index d52c7408e2c..c428affe945 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/registry/JavaRegistries.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/registry/JavaRegistries.java @@ -189,7 +189,7 @@ private static Optional> lookup(Function } private static RegistryEntryData wrap(GeyserEntityType type) { - return new RegistryEntryData<>(type.javaId(), MinecraftKey.identifierToKey(type.javaIdentifier()), type); + return new RegistryEntryData<>(type.javaId(), MinecraftKey.identifierToKey(type.identifier()), type); } } diff --git a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java index 5c11d6453bf..a60518e69d9 100644 --- a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java @@ -366,7 +366,7 @@ public static String translatedEntityName(@Nullable GeyserEntityType type, @NonN return "Player"; // the player's name is always shown instead } // this works at least with all 1.20.5 entities, except the killer bunny since that's not an entity type. - Identifier typeName = type.javaIdentifier(); + Identifier typeName = type.identifier(); return translatedEntityName(typeName.namespace(), typeName.path(), session); } From 6fab5872274925e1074bf214af6715462b443d85 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Mon, 17 Nov 2025 15:13:35 +0100 Subject: [PATCH 09/62] CustomEntityDefinition should extend GeyserEntityDefinition --- .../geyser/api/entity/EntityData.java | 9 +++ .../api/entity/GeyserEntityDefinition.java | 58 +++++++++++++++++++ .../geyser/api/entity/JavaEntityType.java | 14 ++++- .../entity/custom/CustomEntityDefinition.java | 17 +++--- .../geyser/api/entity/type/GeyserEntity.java | 13 +++++ .../type/player/GeyserPlayerEntity.java | 8 +-- .../GeyserDefineCustomEntitiesEvent.java | 31 +++++++++- .../geyser/entity/EntityDefinition.java | 10 +++- .../geyser/entity/EntityDefinitions.java | 16 ++++- .../geyser/entity/GeyserEntityType.java | 1 + .../geysermc/geyser/entity/type/Entity.java | 19 +++++- .../geyser/entity/type/LivingEntity.java | 2 +- .../org/geysermc/geyser/util/EntityUtils.java | 2 +- gradle/libs.versions.toml | 2 +- 14 files changed, 168 insertions(+), 34 deletions(-) create mode 100644 api/src/main/java/org/geysermc/geyser/api/entity/GeyserEntityDefinition.java diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java b/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java index 48c71708914..a4c2717d319 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java @@ -49,6 +49,11 @@ public interface EntityData { */ @NonNull CompletableFuture<@Nullable GeyserEntity> entityByJavaId(@NonNegative int javaId); + /** + * Returns a {@link GeyserEntity} to e.g. update entity properties. + */ + @NonNull CompletableFuture<@Nullable GeyserEntity> entityByJavaUuid(@NonNegative UUID javaUuid); + /** * Displays a player entity as emoting to this client. * @@ -62,6 +67,7 @@ public interface EntityData { * * @return the {@link GeyserPlayerEntity} of this connection */ + // TODO move to GeyserConnection @NonNull GeyserPlayerEntity playerEntity(); /** @@ -73,6 +79,7 @@ public interface EntityData { * @param owner the owner of the lock * @return if the movement is locked after this method call */ + // TODO move to GeyserConnection boolean lockMovement(boolean lock, @NonNull UUID owner); /** @@ -80,11 +87,13 @@ public interface EntityData { * * @return whether the movement is locked */ + // TODO move to GeyserConnection boolean isMovementLocked(); /** * Sends a request to the Java server to switch the items in the main and offhand. * There is no guarantee of the server accepting the request. */ + // TODO move to GeyserConnection void switchHands(); } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/GeyserEntityDefinition.java b/api/src/main/java/org/geysermc/geyser/api/entity/GeyserEntityDefinition.java new file mode 100644 index 00000000000..7b8cb8965ee --- /dev/null +++ b/api/src/main/java/org/geysermc/geyser/api/entity/GeyserEntityDefinition.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.api.entity; + +import org.geysermc.geyser.api.util.Identifier; + +/** + * Represents a Bedrock entity definition. + */ +public interface GeyserEntityDefinition { + + /** + * @return the Bedrock entity identifier + */ + Identifier identifier(); + + /** + * @return the width of the entity + */ + float width(); + + /** + * @return the height of the entity + */ + float height(); + + /** + * The vertical offset applied by Geyser + * to entities to ensure they don't clip + * in the ground due to Java vs Bedrock differences. + * + * @return the offset of the entity + */ + float offset(); +} diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java index 28181137a83..3f228b85848 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java @@ -36,17 +36,26 @@ public interface JavaEntityType { /** - * @return the identifier of the type + * @return the Java identifier of the type */ Identifier identifier(); /** - * @return the + * @return the numeric Java entity type id */ int javaId(); + /** + * @return whether this entity exists in the vanilla base game + */ boolean vanilla(); + /** + * Compares two entity identifiers. + * + * @param javaIdentifier the other entity identifier + * @return true if the entity identifier is the same + */ default boolean is(Identifier javaIdentifier) { return identifier().equals(javaIdentifier); } @@ -55,6 +64,7 @@ static JavaEntityType ofVanilla(@NonNull Identifier javaIdentifier) { return GeyserApi.api().provider(JavaEntityType.class, javaIdentifier); } + // TODO move to event??? static JavaEntityType createAndRegister(@NonNull Identifier javaIdentifier, @NonNegative int javaId) { return GeyserApi.api().provider(JavaEntityType.class, javaIdentifier, javaId); } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java index 3885f132333..2e299cf32a1 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java @@ -29,19 +29,16 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.common.returnsreceiver.qual.This; import org.geysermc.geyser.api.GeyserApi; +import org.geysermc.geyser.api.entity.GeyserEntityDefinition; +import org.geysermc.geyser.api.entity.JavaEntityType; import org.geysermc.geyser.api.util.Identifier; -public interface CustomEntityDefinition { - - Identifier bedrockIdentifier(); - - float width(); - - float height(); - - float offset(); +/** + * Represents a custom entity definition + */ +public interface CustomEntityDefinition extends GeyserEntityDefinition, PredicateHolder { - static Builder builder(@NonNull String bedrockIdentifier, @NonNull JavaEntityType vanillaType) { + static Builder builder(@NonNull Identifier bedrockIdentifier, @NonNull JavaEntityType vanillaType) { return GeyserApi.api().provider(Builder.class, bedrockIdentifier, vanillaType); } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java b/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java index 6dd3c4fe2a5..6e312229d17 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java @@ -28,11 +28,13 @@ import org.checkerframework.checker.index.qual.NonNegative; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.api.connection.GeyserConnection; import org.geysermc.geyser.api.entity.property.BatchPropertyUpdater; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntityPropertiesEvent; +import java.util.UUID; import java.util.function.Consumer; /** @@ -46,6 +48,17 @@ public interface GeyserEntity { @NonNegative int javaId(); + /** + * @return the entity uuid that the server has assigned to this entity + */ + @NonNull + UUID uuid(); + + /** + * @return the position of the entity, as it is known to the Java server. + */ + Vector3f position(); + /** * Updates an entity property with a new value. * If the new value is null, the property is reset to the default value. diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/type/player/GeyserPlayerEntity.java b/api/src/main/java/org/geysermc/geyser/api/entity/type/player/GeyserPlayerEntity.java index d31def99670..0c92843cf37 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/type/player/GeyserPlayerEntity.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/type/player/GeyserPlayerEntity.java @@ -25,15 +25,9 @@ package org.geysermc.geyser.api.entity.type.player; -import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.api.entity.type.GeyserEntity; public interface GeyserPlayerEntity extends GeyserEntity { - /** - * Gets the position of the player, as it is known to the Java server. - * - * @return the player's position - */ - Vector3f position(); + // TODO expose skin data here?? } diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomEntitiesEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomEntitiesEvent.java index 48386b35f73..d49d8d028ae 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomEntitiesEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomEntitiesEvent.java @@ -25,18 +25,43 @@ package org.geysermc.geyser.api.event.lifecycle; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.event.Event; +import org.geysermc.geyser.api.entity.GeyserEntityDefinition; +import org.geysermc.geyser.api.entity.JavaEntityType; import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; -import java.util.List; +import java.util.Collection; +/** + * Called when entities are defined within Geyser. + *

+ * This event can be used to add custom entities to Geyser. + * Entity definitions can be created using the builder provided + * inside of {@link GeyserEntityDefinition}. + */ public interface GeyserDefineCustomEntitiesEvent extends Event { - List existingCustomEntityDefinitions(); + /** + * Gets an immutable list of registered custom entity definitions. + * + * @return an immutable collection of registered custom entity definitions + */ + Collection customEntities(); + /** + * Registers a custom entity definition from its builder + * @param builder the custom entity definition builder + */ default void register(CustomEntityDefinition.Builder builder) { register(builder.build()); } - void register(CustomEntityDefinition customEntityDefinition); + void register(@NonNull CustomEntityDefinition customEntityDefinition); + + /** + * Registers a non-vanilla entity type + * @param javaEntityType + */ + void register(@NonNull JavaEntityType javaEntityType); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java index efb8f7fcfe3..c7ecb594764 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java @@ -31,6 +31,8 @@ import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; +import org.geysermc.geyser.api.entity.GeyserEntityDefinition; +import org.geysermc.geyser.api.util.Identifier; import org.geysermc.geyser.entity.factory.EntityFactory; import org.geysermc.geyser.entity.properties.GeyserEntityProperties; import org.geysermc.geyser.entity.properties.type.PropertyType; @@ -38,7 +40,6 @@ import org.geysermc.geyser.translator.entity.EntityMetadataTranslator; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataType; -import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import java.util.List; import java.util.function.BiConsumer; @@ -54,7 +55,7 @@ @Accessors(fluent = true) @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public abstract class EntityDefinition extends EntityDefinitionBase { +public abstract class EntityDefinition extends EntityDefinitionBase implements GeyserEntityDefinition { private final EntityFactory factory; private final String bedrockIdentifier; private final GeyserEntityProperties registeredProperties; @@ -67,7 +68,10 @@ public EntityDefinition(EntityFactory factory, String bedrockIdentifier, this.registeredProperties = registeredProperties; } - public abstract boolean is(BuiltinEntityType type); + @Override + public Identifier identifier() { + return Identifier.of(bedrockIdentifier); + } @Setter @Accessors(fluent = true, chain = true) diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java index ee8fe928b99..3827a5cdf59 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java @@ -30,6 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.api.entity.JavaEntityType; import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.entity.property.type.GeyserFloatEntityProperty; @@ -1269,13 +1270,22 @@ public static void init() { // entities would be initialized before these events are called GeyserImpl.getInstance().getEventBus().fire(new GeyserDefineCustomEntitiesEvent() { @Override - public List existingCustomEntityDefinitions() { + public List customEntities() { return Collections.unmodifiableList(Registries.CUSTOM_ENTITY_DEFINITIONS.get()); } @Override - public void register(CustomEntityDefinition customEntityDefinition) { - Registries.CUSTOM_ENTITY_DEFINITIONS.register(Registries.CUSTOM_ENTITY_DEFINITIONS.get().size(), customEntityDefinition); + public void register(@NonNull CustomEntityDefinition customEntityDefinition) { + Objects.requireNonNull(customEntityDefinition); + if (!(customEntityDefinition instanceof GeyserCustomEntityDefinition geyserCustomEntityDefinition)) { + throw new IllegalStateException("Unknown custom entity definition: " + customEntityDefinition); + } + Registries.CUSTOM_ENTITY_DEFINITIONS.register(Registries.CUSTOM_ENTITY_DEFINITIONS.get().size(), geyserCustomEntityDefinition); + } + + @Override + public void register(@NonNull JavaEntityType javaEntityType) { + // TODO??? } }); diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java index 775783afc96..0ffa330051f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java @@ -116,6 +116,7 @@ public static GeyserEntityType of(EntityType type) { return type instanceof BuiltinEntityType builtin ? ofVanilla(builtin) : of(type.id()); } + @SuppressWarnings("ConstantValue") public static GeyserEntityType createCustomAndRegister(@NonNull Identifier javaIdentifier, @NonNegative int javaId) { Objects.requireNonNull(javaIdentifier, "javaIdentifier may not be null"); if (javaIdentifier.vanilla()) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index ddc5fc16e7e..0901e3672b8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -43,12 +43,12 @@ import org.cloudburstmc.protocol.bedrock.packet.MoveEntityDeltaPacket; import org.cloudburstmc.protocol.bedrock.packet.RemoveEntityPacket; import org.cloudburstmc.protocol.bedrock.packet.SetEntityDataPacket; -import org.geysermc.geyser.api.entity.JavaEntityType; import org.geysermc.geyser.api.entity.property.BatchPropertyUpdater; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.entity.type.GeyserEntity; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.GeyserDirtyMetadata; +import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.entity.properties.GeyserEntityProperties; import org.geysermc.geyser.entity.properties.GeyserEntityPropertyManager; import org.geysermc.geyser.entity.properties.type.PropertyType; @@ -114,6 +114,8 @@ public class Entity implements GeyserEntity { protected EntityDefinition definition; + protected GeyserEntityType type; + /** * Indicates if the entity has been initialized and spawned */ @@ -152,8 +154,9 @@ public class Entity implements GeyserEntity { protected final GeyserEntityPropertyManager propertyManager; - public Entity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public Entity(GeyserSession session, GeyserEntityType type, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { this.session = session; + this.type = type; this.definition = definition; this.displayName = standardDisplayName(); @@ -491,7 +494,7 @@ public void setDisplayName(EntityMetadata, ?> entityMetadata } protected String standardDisplayName() { - return EntityUtils.translatedEntityName(definition.entityType(), session); + return EntityUtils.translatedEntityName(type, session); } protected void setNametag(@Nullable String nametag, boolean fromDisplayName) { @@ -818,4 +821,14 @@ public void update(@NonNull GeyserEntityProperty property, @Nullable T va } } } + + @Override + public @NonNull UUID uuid() { + return uuid; + } + + @Override + public Vector3f position() { + return this.position.down(definition.offset()); + } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java index d59cd0842d2..bc0e68fd97d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java @@ -553,7 +553,7 @@ private boolean hasValidEquippableItemForSlot(EquipmentSlot slot) { if (equippable != null) { return slot == equippable.slot() && canUseSlot(slot) && - EntityUtils.equipmentUsableByEntity(session, equippable, this.definition.entityType()); + EntityUtils.equipmentUsableByEntity(session, equippable, type); } else { return slot == EquipmentSlot.MAIN_HAND && canUseSlot(EquipmentSlot.MAIN_HAND); } diff --git a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java index a60518e69d9..2666d04b8db 100644 --- a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java @@ -360,7 +360,7 @@ public static String translatedEntityName(@NonNull Key type, @NonNull GeyserSess public static String translatedEntityName(@Nullable GeyserEntityType type, @NonNull GeyserSession session) { // default fallback value as used in Minecraft Java - if (type == null) { + if (type == null || type.isUnregistered()) { return "entity.unregistered_sadface"; } else if (type.is(BuiltinEntityType.PLAYER)) { return "Player"; // the player's name is always shown instead diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 74484cfe0ab..9db8682ef28 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -18,7 +18,7 @@ protocol-common = "3.0.0.Beta11-20251105.180808-2" protocol-codec = "3.0.0.Beta11-20251105.180808-3" raknet = "1.0.0.CR3-20251031.125212-22" minecraftauth = "5.0.0" -mcprotocollib = "1.21.9-custom-entities-SNAPSHOT" +mcprotocollib = "1.21.9-feature-custom-entities" adventure = "4.25.0" adventure-platform = "4.4.1" junit = "5.9.2" From 33925103260637b8453bee9ea11325350703553f Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Mon, 17 Nov 2025 21:27:25 +0100 Subject: [PATCH 10/62] Separate BedrockEntityDefinition from Entity classes --- .../entity/BedrockEntityDefinition.java | 99 ++++++++++ .../geyser/entity/EntityDefinition.java | 28 +-- .../geyser/entity/EntityDefinitionBase.java | 15 +- .../geyser/entity/EntityDefinitionBases.java | 8 +- .../geyser/entity/EntityDefinitions.java | 22 +-- .../entity/GeyserCustomEntityDefinition.java | 173 ++++++++---------- .../geyser/entity/GeyserEntityData.java | 7 + .../geyser/entity/GeyserEntityType.java | 2 +- .../entity/VanillaEntityDefinition.java | 41 +++-- .../geyser/entity/factory/EntityFactory.java | 3 +- .../entity/type/AbstractArrowEntity.java | 11 +- .../entity/type/AbstractWindChargeEntity.java | 5 +- .../entity/type/AreaEffectCloudEntity.java | 5 +- .../geyser/entity/type/ArrowEntity.java | 5 +- .../geyser/entity/type/BoatEntity.java | 9 +- .../geyser/entity/type/ChestBoatEntity.java | 5 +- .../type/CommandBlockMinecartEntity.java | 7 +- .../type/DefaultBlockMinecartEntity.java | 5 +- .../geyser/entity/type/DisplayBaseEntity.java | 5 +- .../entity/type/EnderCrystalEntity.java | 7 +- .../geyser/entity/type/EnderEyeEntity.java | 6 +- .../geysermc/geyser/entity/type/Entity.java | 31 ++-- .../geyser/entity/type/EvokerFangsEntity.java | 5 +- .../geyser/entity/type/ExpOrbEntity.java | 5 +- .../entity/type/FallingBlockEntity.java | 6 +- .../geyser/entity/type/FireballEntity.java | 5 +- .../geyser/entity/type/FireworkEntity.java | 5 +- .../geyser/entity/type/FishingHookEntity.java | 5 +- .../entity/type/FurnaceMinecartEntity.java | 5 +- .../geyser/entity/type/HangingEntity.java | 7 +- .../geyser/entity/type/InteractionEntity.java | 8 +- .../geyser/entity/type/ItemEntity.java | 11 +- .../geyser/entity/type/ItemFrameEntity.java | 10 +- .../geyser/entity/type/LeashKnotEntity.java | 5 +- .../geyser/entity/type/LightningEntity.java | 5 +- .../geyser/entity/type/LivingEntity.java | 7 +- .../geyser/entity/type/MinecartEntity.java | 9 +- .../geyser/entity/type/PaintingEntity.java | 5 +- .../entity/type/SpawnerMinecartEntity.java | 5 +- .../geyser/entity/type/TNTEntity.java | 9 +- .../geyser/entity/type/TextDisplayEntity.java | 7 +- .../entity/type/ThrowableEggEntity.java | 6 +- .../geyser/entity/type/ThrowableEntity.java | 5 +- .../entity/type/ThrowableItemEntity.java | 9 +- .../entity/type/ThrownPotionEntity.java | 7 +- .../geyser/entity/type/TridentEntity.java | 5 +- .../geyser/entity/type/WitherSkullEntity.java | 7 +- .../type/living/AbstractFishEntity.java | 5 +- .../entity/type/living/AgeableEntity.java | 9 +- .../type/living/AgeableWaterEntity.java | 5 +- .../entity/type/living/AllayEntity.java | 5 +- .../entity/type/living/AmbientEntity.java | 5 +- .../entity/type/living/ArmorStandEntity.java | 13 +- .../geyser/entity/type/living/BatEntity.java | 5 +- .../entity/type/living/CopperGolemEntity.java | 5 +- .../entity/type/living/CreatureEntity.java | 5 +- .../entity/type/living/DolphinEntity.java | 5 +- .../entity/type/living/FlyingEntity.java | 5 +- .../entity/type/living/GlowSquidEntity.java | 5 +- .../entity/type/living/GolemEntity.java | 5 +- .../entity/type/living/IronGolemEntity.java | 5 +- .../entity/type/living/MagmaCubeEntity.java | 5 +- .../geyser/entity/type/living/MobEntity.java | 5 +- .../entity/type/living/SlimeEntity.java | 5 +- .../entity/type/living/SnowGolemEntity.java | 5 +- .../entity/type/living/SquidEntity.java | 5 +- .../entity/type/living/TadpoleEntity.java | 5 +- .../entity/type/living/WaterEntity.java | 5 +- .../type/living/animal/AnimalEntity.java | 5 +- .../type/living/animal/ArmadilloEntity.java | 5 +- .../type/living/animal/AxolotlEntity.java | 5 +- .../entity/type/living/animal/BeeEntity.java | 5 +- .../entity/type/living/animal/FoxEntity.java | 5 +- .../entity/type/living/animal/FrogEntity.java | 5 +- .../entity/type/living/animal/GoatEntity.java | 5 +- .../type/living/animal/HappyGhastEntity.java | 5 +- .../type/living/animal/HoglinEntity.java | 5 +- .../type/living/animal/MooshroomEntity.java | 5 +- .../type/living/animal/OcelotEntity.java | 5 +- .../type/living/animal/PandaEntity.java | 5 +- .../type/living/animal/PolarBearEntity.java | 5 +- .../type/living/animal/PufferFishEntity.java | 5 +- .../type/living/animal/RabbitEntity.java | 5 +- .../type/living/animal/SheepEntity.java | 5 +- .../type/living/animal/SnifferEntity.java | 11 +- .../type/living/animal/StriderEntity.java | 7 +- .../living/animal/TropicalFishEntity.java | 5 +- .../type/living/animal/TurtleEntity.java | 5 +- .../living/animal/farm/ChickenEntity.java | 5 +- .../type/living/animal/farm/CowEntity.java | 5 +- .../type/living/animal/farm/PigEntity.java | 7 +- .../animal/farm/TemperatureVariantAnimal.java | 5 +- .../animal/horse/AbstractHorseEntity.java | 5 +- .../type/living/animal/horse/CamelEntity.java | 13 +- .../animal/horse/ChestedHorseEntity.java | 5 +- .../type/living/animal/horse/HorseEntity.java | 5 +- .../type/living/animal/horse/LlamaEntity.java | 5 +- .../animal/horse/SkeletonHorseEntity.java | 5 +- .../animal/horse/TraderLlamaEntity.java | 5 +- .../animal/horse/ZombieHorseEntity.java | 5 +- .../living/animal/tameable/CatEntity.java | 5 +- .../living/animal/tameable/ParrotEntity.java | 5 +- .../animal/tameable/TameableEntity.java | 5 +- .../living/animal/tameable/WolfEntity.java | 5 +- .../merchant/AbstractMerchantEntity.java | 5 +- .../type/living/merchant/VillagerEntity.java | 5 +- .../monster/AbstractSkeletonEntity.java | 5 +- .../type/living/monster/BasePiglinEntity.java | 6 +- .../type/living/monster/BlazeEntity.java | 5 +- .../type/living/monster/BoggedEntity.java | 5 +- .../type/living/monster/BreezeEntity.java | 5 +- .../type/living/monster/CreakingEntity.java | 5 +- .../type/living/monster/CreeperEntity.java | 5 +- .../living/monster/ElderGuardianEntity.java | 5 +- .../living/monster/EnderDragonEntity.java | 5 +- .../living/monster/EnderDragonPartEntity.java | 2 +- .../type/living/monster/EndermanEntity.java | 5 +- .../type/living/monster/GhastEntity.java | 5 +- .../type/living/monster/GiantEntity.java | 5 +- .../type/living/monster/GuardianEntity.java | 5 +- .../type/living/monster/MonsterEntity.java | 5 +- .../type/living/monster/PhantomEntity.java | 11 +- .../type/living/monster/PiglinEntity.java | 5 +- .../type/living/monster/ShulkerEntity.java | 5 +- .../type/living/monster/SkeletonEntity.java | 5 +- .../type/living/monster/SpiderEntity.java | 5 +- .../entity/type/living/monster/VexEntity.java | 5 +- .../type/living/monster/WardenEntity.java | 5 +- .../type/living/monster/WitherEntity.java | 5 +- .../type/living/monster/ZoglinEntity.java | 7 +- .../type/living/monster/ZombieEntity.java | 5 +- .../living/monster/ZombieVillagerEntity.java | 5 +- .../living/monster/ZombifiedPiglinEntity.java | 5 +- .../monster/raid/AbstractIllagerEntity.java | 5 +- .../living/monster/raid/PillagerEntity.java | 5 +- .../monster/raid/RaidParticipantEntity.java | 5 +- .../living/monster/raid/RavagerEntity.java | 5 +- .../raid/SpellcasterIllagerEntity.java | 5 +- .../living/monster/raid/VindicatorEntity.java | 5 +- .../entity/type/player/AvatarEntity.java | 15 +- .../entity/type/player/MannequinEntity.java | 5 +- .../entity/type/player/PlayerEntity.java | 8 +- .../type/player/SessionPlayerEntity.java | 14 +- .../entity/type/player/SkullPlayerEntity.java | 2 +- .../entity/vehicle/VehicleComponent.java | 2 +- .../level/physics/CollisionManager.java | 2 +- .../geysermc/geyser/registry/Registries.java | 12 +- .../loader/ProviderRegistryLoader.java | 8 +- .../geyser/session/GeyserSession.java | 2 +- .../session/cache/BlockBreakHandler.java | 2 +- .../geyser/session/cache/WorldBorder.java | 4 +- .../MerchantInventoryTranslator.java | 2 +- .../entity/SpawnerBlockEntityTranslator.java | 4 +- .../TrialSpawnerBlockEntityTranslator.java | 2 +- ...BedrockInventoryTransactionTranslator.java | 2 +- .../player/input/BedrockMovePlayer.java | 6 +- .../BedrockPlayerAuthInputTranslator.java | 2 +- .../java/entity/JavaAddEntityTranslator.java | 27 +-- .../entity/JavaEntityEventTranslator.java | 2 +- .../entity/JavaSetEntityDataTranslator.java | 2 +- .../entity/JavaSetEquipmentTranslator.java | 2 +- .../entity/JavaSetPassengersTranslator.java | 2 +- .../player/JavaPlayerPositionTranslator.java | 8 +- .../org/geysermc/geyser/util/EntityUtils.java | 12 +- 164 files changed, 758 insertions(+), 549 deletions(-) create mode 100644 core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java new file mode 100644 index 00000000000..a1ac8a50018 --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.entity; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; +import org.geysermc.geyser.api.entity.GeyserEntityDefinition; +import org.geysermc.geyser.api.util.Identifier; +import org.geysermc.geyser.entity.properties.GeyserEntityProperties; + +@Getter +@Accessors(fluent = true) +public class BedrockEntityDefinition implements GeyserEntityDefinition { + + private final Identifier identifier; + private final GeyserEntityProperties registeredProperties; + private final float width; + private final float height; + private final float offset; + + public BedrockEntityDefinition(Identifier identifier, GeyserEntityProperties registeredProperties, float width, float height, float offset) { + this.identifier = identifier; + this.registeredProperties = registeredProperties; + this.width = width; + this.height = height; + this.offset = offset; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private Identifier identifier; + private float width; + private float height; + private float offset = 0.00001f; + @Setter(AccessLevel.NONE) + protected GeyserEntityProperties.Builder propertiesBuilder; + + public Builder() { + } + + public Builder height(float height) { + this.height = height; + return this; + } + + public Builder width(float width) { + this.width = width; + return this; + } + + public Builder offset(float offset) { + this.offset = offset + 0.00001f; + return this; + } + + public Builder identifier(Identifier identifier) { + this.identifier = identifier; + return this; + } + + public Builder properties(GeyserEntityProperties.Builder propertiesBuilder) { + this.propertiesBuilder = propertiesBuilder; + return this; + } + + BedrockEntityDefinition build() { + return new BedrockEntityDefinition(identifier, propertiesBuilder != null ? propertiesBuilder.build() : null, width, height, offset); + } + } + +} diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java index c7ecb594764..2529271afb4 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java @@ -31,8 +31,6 @@ import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; -import org.geysermc.geyser.api.entity.GeyserEntityDefinition; -import org.geysermc.geyser.api.util.Identifier; import org.geysermc.geyser.entity.factory.EntityFactory; import org.geysermc.geyser.entity.properties.GeyserEntityProperties; import org.geysermc.geyser.entity.properties.type.PropertyType; @@ -40,12 +38,13 @@ import org.geysermc.geyser.translator.entity.EntityMetadataTranslator; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataType; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import java.util.List; import java.util.function.BiConsumer; /** - * Represents data for an entity. This includes properties such as height and width, as well as the list of entity + * Represents data for an entity. This includes the default bedrock entity definition, as well as the list of Java entity * metadata translators needed to translate the properties sent from the server. The translators are structured in such * a way that inserting a new one (for example in version updates) is convenient. * @@ -55,23 +54,19 @@ @Accessors(fluent = true) @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public abstract class EntityDefinition extends EntityDefinitionBase implements GeyserEntityDefinition { +public abstract class EntityDefinition extends EntityDefinitionBase { private final EntityFactory factory; - private final String bedrockIdentifier; - private final GeyserEntityProperties registeredProperties; + private final GeyserEntityType type; + private BedrockEntityDefinition bedrockDefinition; - public EntityDefinition(EntityFactory factory, String bedrockIdentifier, - float width, float height, float offset, GeyserEntityProperties registeredProperties, List> translators) { - super(width, height, offset, translators); + public EntityDefinition(EntityFactory factory, GeyserEntityType type, BedrockEntityDefinition bedrockDefinition, List> translators) { + super(bedrockDefinition.width(), bedrockDefinition.height(), bedrockDefinition.offset(), translators); + this.type = type; this.factory = factory; - this.bedrockIdentifier = bedrockIdentifier; - this.registeredProperties = registeredProperties; + this.bedrockDefinition = bedrockDefinition; } - @Override - public Identifier identifier() { - return Identifier.of(bedrockIdentifier); - } + public abstract boolean is(BuiltinEntityType builtinEntityType); @Setter @Accessors(fluent = true, chain = true) @@ -89,9 +84,6 @@ protected Builder(EntityFactory factory) { protected Builder(EntityFactory factory, float width, float height, float offset, List> translators) { super(width, height, offset, translators); this.factory = factory; - this.width = width; - this.height = height; - this.offset = offset; } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBase.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBase.java index f4e7fd70b8b..17edeaf11bd 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBase.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBase.java @@ -40,15 +40,14 @@ import java.util.List; import java.util.function.BiConsumer; -@Getter -@Accessors(fluent = true) @EqualsAndHashCode @ToString public class EntityDefinitionBase { - private final float width; - private final float height; - private final float offset; - private final List> translators; + final float width; + final float height; + final float offset; + @Getter @Accessors(fluent = true) + protected final List> translators; public EntityDefinitionBase(float width, float height, float offset, List> translators) { this.width = width; @@ -64,7 +63,7 @@ public static Builder baseBuilder(Class clazz) { // Unused param so Java knows what entity we're talking about @SuppressWarnings("unused") public static Builder baseInherited(Class clazz, EntityDefinitionBase parent) { - return new Builder<>(parent.width(), parent.height(), parent.offset(), new ObjectArrayList<>(parent.translators())); + return new Builder(parent.width, parent.height, parent.offset, new ObjectArrayList<>(parent.translators)); } @SuppressWarnings("unchecked") @@ -76,7 +75,7 @@ public void translateMetadata(T entity, EntityMetadata boatEntity.getDirtyMetadata().put(EntityDataTypes.HURT_TICKS, entityMetadata.getValue())) // Time since last hit .addTranslator(MetadataTypes.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityDataTypes.HURT_DIRECTION, entityMetadata.getValue())) // Rocking direction .addTranslator(MetadataTypes.FLOAT, (boatEntity, entityMetadata) -> @@ -128,8 +128,8 @@ public final class EntityDefinitionBases { .addTranslator(MetadataTypes.OPTIONAL_BLOCK_POS, LivingEntity::setBedPosition) .build(); AVATAR = EntityDefinitionBase.baseInherited(AvatarEntity.class, LIVING_ENTITY) - .height(1.8f).width(0.6f) - .offset(1.62f) +// .height(1.8f).width(0.6f) TODO CE +// .offset(1.62f) .addTranslator(null) // Player main hand .addTranslator(MetadataTypes.BYTE, AvatarEntity::setSkinVisibility) .build(); diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java index 3827a5cdf59..d85caa022ab 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java @@ -176,7 +176,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Objects; @@ -1251,16 +1250,16 @@ public final class EntityDefinitions { } private static VanillaEntityDefinition buildBoat(EntityDefinitionBase base, BuiltinEntityType BuiltinEntityType, BoatEntity.BoatVariant variant) { - return VanillaEntityDefinition.inherited((session, javaId, bedrockId, uuid, definition, position, motion, yaw, pitch, headYaw) -> - new BoatEntity(session, javaId, bedrockId, uuid, definition, position, motion, yaw, variant), base) + return VanillaEntityDefinition.inherited((session, javaId, bedrockId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw) -> + new BoatEntity(session, javaId, bedrockId, uuid, definition, bedrockDefinition, position, motion, yaw, variant), base) .type(BuiltinEntityType) .bedrockIdentifier("minecraft:boat") .build(); } private static VanillaEntityDefinition buildChestBoat(EntityDefinitionBase base, BuiltinEntityType BuiltinEntityType, BoatEntity.BoatVariant variant) { - return VanillaEntityDefinition.inherited((session, javaId, bedrockId, uuid, definition, position, motion, yaw, pitch, headYaw) -> - new ChestBoatEntity(session, javaId, bedrockId, uuid, definition, position, motion, yaw, variant), base) + return VanillaEntityDefinition.inherited((session, javaId, bedrockId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw) -> + new ChestBoatEntity(session, javaId, bedrockId, uuid, definition, bedrockDefinition, position, motion, yaw, variant), base) .type(BuiltinEntityType) .bedrockIdentifier("minecraft:chest_boat") .build(); @@ -1271,7 +1270,7 @@ public static void init() { GeyserImpl.getInstance().getEventBus().fire(new GeyserDefineCustomEntitiesEvent() { @Override public List customEntities() { - return Collections.unmodifiableList(Registries.CUSTOM_ENTITY_DEFINITIONS.get()); + return null; // TODO Collections.unmodifiableList(Registries.CUSTOM_ENTITY_DEFINITIONS.get()); } @Override @@ -1353,9 +1352,10 @@ public GeyserStringEnumProperty registerEnumProperty(@NonNull Identifier identif } @Override + // TODO breaking change!!! public Collection> properties(@NonNull Identifier identifier) { Objects.requireNonNull(identifier); - var definition = Registries.JAVA_ENTITY_IDENTIFIERS.get(identifier.toString()); + var definition = Registries.BEDROCK_ENTITY_DEFINITIONS.get(identifier); if (definition == null) { throw new IllegalArgumentException("Unknown entity type: " + identifier); } @@ -1363,15 +1363,15 @@ public Collection> properties(@NonNull Identifier identi } }); - for (var definition : Registries.ENTITY_DEFINITIONS.get().values()) { - if (!definition.registeredProperties().isEmpty()) { // TODO Null or empty check?? - Registries.BEDROCK_ENTITY_PROPERTIES.get().add(definition.registeredProperties().toNbtMap(definition.identifier())); + for (var definition : Registries.BEDROCK_ENTITY_DEFINITIONS.get().values()) { + if (definition.registeredProperties() != null) { + Registries.BEDROCK_ENTITY_PROPERTIES.get().add(definition.registeredProperties().toNbtMap(definition.identifier().toString())); } } } private static void registerProperty(Identifier entityType, PropertyType property) { - var definition = Registries.JAVA_ENTITY_IDENTIFIERS.get(entityType.toString()); + var definition = Registries.BEDROCK_ENTITY_DEFINITIONS.get(entityType); if (definition == null) { throw new IllegalArgumentException("Unknown entity type: " + entityType); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java index 76191ff6077..8fb656b8174 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java @@ -25,134 +25,105 @@ package org.geysermc.geyser.entity; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; import lombok.experimental.Accessors; -import org.checkerframework.checker.index.qual.Positive; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; -import org.geysermc.geyser.api.entity.JavaEntityType; import org.geysermc.geyser.api.predicate.MinecraftPredicate; import org.geysermc.geyser.api.predicate.PredicateStrategy; import org.geysermc.geyser.api.predicate.context.entity.EntitySpawnPredicateContext; import org.geysermc.geyser.entity.factory.EntityFactory; -import org.geysermc.geyser.entity.properties.GeyserEntityProperties; -import org.geysermc.geyser.entity.properties.type.PropertyType; import org.geysermc.geyser.entity.type.Entity; -import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.translator.entity.EntityMetadataTranslator; -import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; -import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataType; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import java.util.List; -import java.util.Objects; -import java.util.function.BiConsumer; @Getter @Accessors(fluent = true) @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class GeyserCustomEntityDefinition extends EntityDefinition implements CustomEntityDefinition { +// TODO CHANGE TO ONLY APPLY THIS TO NON-VANILLA TYPES! +public class GeyserCustomEntityDefinition extends EntityDefinition { private final List> predicates; private final PredicateStrategy predicateStrategy; - public GeyserCustomEntityDefinition(EntityFactory factory, String bedrockIdentifier, List> predicates, PredicateStrategy predicateStrategy, - float width, float height, float offset, GeyserEntityProperties registeredProperties, List> translators) { - super(factory, bedrockIdentifier, width, height, offset, registeredProperties, translators); + public GeyserCustomEntityDefinition(EntityFactory factory, GeyserEntityType type, List> predicates, PredicateStrategy predicateStrategy, + BedrockEntityDefinition definition, List> translators) { + super(factory, type, definition, translators); this.predicates = predicates; this.predicateStrategy = predicateStrategy; } @Override - public boolean is(BuiltinEntityType type) { + public boolean is(BuiltinEntityType builtinEntityType) { return false; } - public static Builder inherited(String bedrockIdentifier, JavaEntityType vanillaType) { - if (!vanillaType.vanilla()) { - throw new IllegalArgumentException("vanillaType must be a vanilla entity type, was: " + vanillaType); - } - VanillaEntityDefinition parent = Registries.ENTITY_DEFINITIONS.get(vanillaType); - if (parent == null) { - throw new IllegalArgumentException("No vanilla entity definition registered for vanilla entity type " + vanillaType); - } - // TODO fix the rawtypes/unchecked - return new Builder<>(bedrockIdentifier, parent.factory(), parent.width(), parent.height(), parent.offset(), new ObjectArrayList(parent.translators())); - } - - public static class Builder extends EntityDefinition.Builder implements CustomEntityDefinition.Builder { - protected List> predicates; - protected PredicateStrategy predicateStrategy = PredicateStrategy.AND; - - protected Builder(EntityFactory factory, String bedrockIdentifier) { - super(factory); - this.bedrockIdentifier = Objects.requireNonNull(bedrockIdentifier, "bedrockIdentifier must not be null"); - } - - protected Builder(String bedrockIdentifier, EntityFactory factory, float width, float height, float offset, List> translators) { - super(factory, width, height, offset, translators); - this.bedrockIdentifier = Objects.requireNonNull(bedrockIdentifier, "bedrockIdentifier must not be null"); - } - - @Override - public EntityDefinition.Builder bedrockIdentifier(String bedrockIdentifier) { - throw new UnsupportedOperationException("bedrockIdentifier should be immutable"); - } - - @Override - public Builder width(@Positive float width) { - return (Builder) super.width(width); - } - - @Override - public Builder height(@Positive float height) { - return (Builder) super.height(height); - } - - @Override - public Builder heightAndWidth(@Positive float value) { - return (Builder) super.heightAndWidth(value); - } - - @Override - public Builder offset(@Positive float offset) { - return (Builder) super.offset(offset); - } - - public Builder predicate(@NonNull MinecraftPredicate predicate) { - predicates.add(Objects.requireNonNull(predicate, "predicate must not be null")); - return this; - } - - public Builder predicateStrategy(@NonNull PredicateStrategy strategy) { - predicateStrategy = Objects.requireNonNull(strategy, "strategy must not be null"); - return this; - } - - @Override - public Builder property(PropertyType propertyType) { - return (Builder) super.property(propertyType); - } - - @Override - public >> Builder addTranslator(MetadataType type, BiConsumer translateFunction) { - return (Builder) super.addTranslator(type, translateFunction); - } - - @Override - public Builder addTranslator(EntityMetadataTranslator translator) { - return (Builder) super.addTranslator(translator); - } - - @Override - public GeyserCustomEntityDefinition build() { - if (predicates.isEmpty()) { - throw new IllegalStateException("predicates must not be empty!"); - } - return new GeyserCustomEntityDefinition<>(factory, bedrockIdentifier, predicates, predicateStrategy, width, height, offset, propertiesBuilder.build(), translators); - } - } + // TODO this is relevant for nonvanilla; entity definitions are now split up +// public static Builder inherited(String bedrockIdentifier, JavaEntityType vanillaType) { +// if (!vanillaType.vanilla()) { +// throw new IllegalArgumentException("vanillaType must be a vanilla entity type, was: " + vanillaType); +// } +// VanillaEntityDefinition parent = Registries.ENTITY_DEFINITIONS.get(vanillaType); +// if (parent == null) { +// throw new IllegalArgumentException("No vanilla entity definition registered for vanilla entity type " + vanillaType); +// } +// // TODO fix the rawtypes/unchecked +// return new Builder<>(bedrockIdentifier, parent.factory(), parent.width(), parent.height(), parent.offset(), new ObjectArrayList(parent.translators())); +// } + + // TODO +// public static class Builder extends EntityDefinition.Builder implements CustomEntityDefinition.Builder { +// protected List> predicates; +// protected PredicateStrategy predicateStrategy = PredicateStrategy.AND; +// +// protected Builder(EntityFactory factory, String bedrockIdentifier) { +// super(factory); +// this.bedrockIdentifier = Objects.requireNonNull(bedrockIdentifier, "bedrockIdentifier must not be null"); +// } +// +// protected Builder(String bedrockIdentifier, EntityFactory factory, float width, float height, float offset, List> translators) { +// super(factory, width, height, offset, translators); +// this.bedrockIdentifier = Objects.requireNonNull(bedrockIdentifier, "bedrockIdentifier must not be null"); +// } +// +// @Override +// public EntityDefinition.Builder bedrockIdentifier(String bedrockIdentifier) { +// throw new UnsupportedOperationException("bedrockIdentifier should be immutable"); +// } +// +// public Builder predicate(@NonNull MinecraftPredicate predicate) { +// predicates.add(Objects.requireNonNull(predicate, "predicate must not be null")); +// return this; +// } +// +// public Builder predicateStrategy(@NonNull PredicateStrategy strategy) { +// predicateStrategy = Objects.requireNonNull(strategy, "strategy must not be null"); +// return this; +// } +// +// @Override +// public Builder property(PropertyType propertyType) { +// return (Builder) super.property(propertyType); +// } +// +// @Override +// public >> Builder addTranslator(MetadataType type, BiConsumer translateFunction) { +// return (Builder) super.addTranslator(type, translateFunction); +// } +// +// @Override +// public Builder addTranslator(EntityMetadataTranslator translator) { +// return (Builder) super.addTranslator(translator); +// } +// +// @Override +// public GeyserCustomEntityDefinition build() { +// if (predicates.isEmpty()) { +// throw new IllegalStateException("predicates must not be empty!"); +// } +// return new GeyserCustomEntityDefinition<>(factory, type, predicates, predicateStrategy, bedrockDefinition, translators); +// } +// } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java index 0549dd393ed..593bcbc7d0c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java @@ -58,6 +58,13 @@ public GeyserEntityData(GeyserSession session) { return future; } + @Override + public @NonNull CompletableFuture<@Nullable GeyserEntity> entityByJavaUuid(@NonNegative UUID javaUuid) { + CompletableFuture future = new CompletableFuture<>(); + session.ensureInEventLoop(() -> future.complete(null)); // TODO CE + return future; + } + @Override public void showEmote(@NonNull GeyserPlayerEntity emoter, @NonNull String emoteId) { Objects.requireNonNull(emoter, "emoter must not be null!"); diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java index 0ffa330051f..caae00c105f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java @@ -60,7 +60,7 @@ public record GeyserEntityType(Identifier identifier, int javaId) implements Jav } private GeyserEntityType(BuiltinEntityType builtin) { - this(Identifier.of(builtin.name().toLowerCase(Locale.ROOT)), builtin.id()); + this(IdentifierImpl.of(builtin.name().toLowerCase(Locale.ROOT)), builtin.id()); } private GeyserEntityType(int javaId) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java index 8453a36c759..c9fd77d8319 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java @@ -30,8 +30,8 @@ import lombok.Getter; import lombok.ToString; import lombok.experimental.Accessors; +import org.geysermc.geyser.api.util.Identifier; import org.geysermc.geyser.entity.factory.EntityFactory; -import org.geysermc.geyser.entity.properties.GeyserEntityProperties; import org.geysermc.geyser.entity.properties.type.PropertyType; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.registry.Registries; @@ -50,9 +50,8 @@ public class VanillaEntityDefinition extends EntityDefinition { private final GeyserEntityType entityType; - public VanillaEntityDefinition(EntityFactory factory, GeyserEntityType entityType, String bedrockIdentifier, - float width, float height, float offset, GeyserEntityProperties registeredProperties, List> translators) { - super(factory, bedrockIdentifier, width, height, offset, registeredProperties, translators); + public VanillaEntityDefinition(EntityFactory factory, GeyserEntityType entityType, BedrockEntityDefinition bedrockDefinition, List> translators) { + super(factory, entityType, bedrockDefinition, translators); this.entityType = entityType; } @@ -66,7 +65,7 @@ public static Builder builder(EntityFactory factory) { } public static Builder inherited(EntityFactory factory, EntityDefinitionBase parent) { - return new Builder<>(factory, parent.width(), parent.height(), parent.offset(), new ObjectArrayList<>(parent.translators())); + return new Builder<>(factory, parent.width, parent.height, parent.offset, new ObjectArrayList<>(parent.translators)); } public static class Builder extends EntityDefinition.Builder { @@ -134,23 +133,33 @@ public VanillaEntityDefinition build() { return build(true); } - private void validateTypeAndIdentifier() { - if (type == null) { - throw new IllegalStateException("Missing entity type!"); - } else if (bedrockIdentifier == null) { - bedrockIdentifier = type.identifier().toString(); - } - } + // TODO CE +// private void validateTypeAndIdentifier() { +// if (type == null) { +// throw new IllegalStateException("Missing entity type!"); +// } else if (bedrockIdentifier == null) { +// bedrockIdentifier = type.identifier().toString(); +// } +// } /** * @param register whether to register this entity in the Registries for entity types. Generally this should be * set to false if we're not expecting this entity to spawn from the network. */ public VanillaEntityDefinition build(boolean register) { - validateTypeAndIdentifier(); - - GeyserEntityProperties registeredProperties = propertiesBuilder == null ? null : propertiesBuilder.build(); - VanillaEntityDefinition definition = new VanillaEntityDefinition<>(factory, type, bedrockIdentifier, width, height, offset, registeredProperties, translators); + //validateTypeAndIdentifier(); + + BedrockEntityDefinition bedrockDefinition = BedrockEntityDefinition.builder() + .height(height) + .width(width) + .properties(propertiesBuilder) + .offset(offset) + .identifier(Identifier.of(bedrockIdentifier)) + .build(); + // TODO TEST!!! + Registries.BEDROCK_ENTITY_DEFINITIONS.get().put(Identifier.of(bedrockIdentifier), bedrockDefinition); + + VanillaEntityDefinition definition = new VanillaEntityDefinition<>(factory, type, bedrockDefinition, translators); if (register && definition.entityType() != null) { Registries.ENTITY_DEFINITIONS.get().putIfAbsent(definition.entityType(), definition); Registries.JAVA_ENTITY_IDENTIFIERS.get().putIfAbsent(type.identifier().toString(), definition); diff --git a/core/src/main/java/org/geysermc/geyser/entity/factory/EntityFactory.java b/core/src/main/java/org/geysermc/geyser/entity/factory/EntityFactory.java index 7675ea8fd3b..dd18c0d2da0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/factory/EntityFactory.java +++ b/core/src/main/java/org/geysermc/geyser/entity/factory/EntityFactory.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.factory; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.session.GeyserSession; @@ -37,5 +38,5 @@ */ public interface EntityFactory { - T create(GeyserSession session, int javaId, long bedrockId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw); + T create(GeyserSession session, int javaId, long bedrockId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/AbstractArrowEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/AbstractArrowEntity.java index fe62b3407f4..28393eed3c0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/AbstractArrowEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/AbstractArrowEntity.java @@ -25,22 +25,23 @@ package org.geysermc.geyser.entity.type; -import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; -import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import java.util.UUID; public class AbstractArrowEntity extends Entity { - public AbstractArrowEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public AbstractArrowEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); // Set the correct texture if using the resource pack - setFlag(EntityFlag.BRIBED, definition.entityType().is(BuiltinEntityType.SPECTRAL_ARROW)); + setFlag(EntityFlag.BRIBED, definition.type().is(BuiltinEntityType.SPECTRAL_ARROW)); setMotion(motion); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/AbstractWindChargeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/AbstractWindChargeEntity.java index 5678c3af484..3eabf06e615 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/AbstractWindChargeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/AbstractWindChargeEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; @@ -36,8 +37,8 @@ * the "hide until far away" aspect. */ public class AbstractWindChargeEntity extends ThrowableItemEntity { - public AbstractWindChargeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public AbstractWindChargeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/AreaEffectCloudEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/AreaEffectCloudEntity.java index e84b2aae26f..f2bb8fe949a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/AreaEffectCloudEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/AreaEffectCloudEntity.java @@ -29,6 +29,7 @@ import org.cloudburstmc.protocol.bedrock.data.ParticleType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.session.GeyserSession; @@ -42,8 +43,8 @@ public class AreaEffectCloudEntity extends Entity { - public AreaEffectCloudEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public AreaEffectCloudEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ArrowEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ArrowEntity.java index ba1241434b1..845d4df5443 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ArrowEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ArrowEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.item.Potion; import org.geysermc.geyser.session.GeyserSession; @@ -36,8 +37,8 @@ public class ArrowEntity extends AbstractArrowEntity { - public ArrowEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public ArrowEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setPotionEffectColor(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java index 3b77b1eec56..8c5526dc85d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java @@ -31,6 +31,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.AnimatePacket; import org.cloudburstmc.protocol.bedrock.packet.MoveEntityAbsolutePacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.EntityDefinitions; import org.geysermc.geyser.session.GeyserSession; @@ -71,9 +72,9 @@ public class BoatEntity extends Entity implements Leashable, Tickable { // Looks too fast and too choppy with 0.1f, which is how I believe the Microsoftian client handles it private final float ROWING_SPEED = 0.1f; - public BoatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, BoatVariant variant) { + public BoatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, BoatVariant variant) { // Initial rotation is incorrect - super(session, entityId, geyserId, uuid, definition, position.add(0d, definition.offset(), 0d), motion, yaw + 90, 0, yaw + 90); + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position.add(0d, bedrockDefinition.offset(), 0d), motion, yaw + 90, 0, yaw + 90); this.variant = variant; dirtyMetadata.put(EntityDataTypes.VARIANT, variant.ordinal()); @@ -93,7 +94,7 @@ protected void initializeMetadata() { @Override public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { // We don't include the rotation (y) as it causes the boat to appear sideways - setPosition(position.add(0d, this.definition.offset(), 0d)); + setPosition(position.add(0d, this.bedrockDefinition.offset(), 0d)); setYaw(yaw + 90); setHeadYaw(yaw + 90); setOnGround(isOnGround); @@ -102,7 +103,7 @@ public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYa moveEntityPacket.setRuntimeEntityId(geyserId); if (session.getPlayerEntity().getVehicle() == this && session.getPlayerEntity().isRidingInFront()) { // Minimal glitching when ClientboundMoveVehiclePacket is sent - moveEntityPacket.setPosition(position.up(EntityDefinitions.PLAYER.offset() - this.definition.offset())); + moveEntityPacket.setPosition(position.up(EntityDefinitions.PLAYER.bedrockDefinition().offset() - this.bedrockDefinition.offset())); } else { moveEntityPacket.setPosition(this.position); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ChestBoatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ChestBoatEntity.java index 5475ca772dd..8b04054d51b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ChestBoatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ChestBoatEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; @@ -35,8 +36,8 @@ import java.util.UUID; public class ChestBoatEntity extends BoatEntity { - public ChestBoatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, BoatVariant variant) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, variant); + public ChestBoatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, BoatVariant variant) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, variant); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/CommandBlockMinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/CommandBlockMinecartEntity.java index 2d0835286da..4e11a22c5ff 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/CommandBlockMinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/CommandBlockMinecartEntity.java @@ -25,23 +25,24 @@ package org.geysermc.geyser.entity.type; -import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerType; import org.cloudburstmc.protocol.bedrock.packet.ContainerOpenPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; +import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; import java.util.UUID; public class CommandBlockMinecartEntity extends DefaultBlockMinecartEntity { - public CommandBlockMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public CommandBlockMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/DefaultBlockMinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/DefaultBlockMinecartEntity.java index 65b71adcd12..865c7a35580 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/DefaultBlockMinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/DefaultBlockMinecartEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; @@ -42,8 +43,8 @@ public class DefaultBlockMinecartEntity extends MinecartEntity { public int customBlockOffset = 0; public boolean showCustomBlock = false; - public DefaultBlockMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public DefaultBlockMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); dirtyMetadata.put(EntityDataTypes.CUSTOM_DISPLAY, (byte) 1); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/DisplayBaseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/DisplayBaseEntity.java index 414ed054166..3a752987070 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/DisplayBaseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/DisplayBaseEntity.java @@ -28,6 +28,7 @@ import net.kyori.adventure.text.Component; import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.EntityUtils; @@ -41,8 +42,8 @@ public class DisplayBaseEntity extends Entity { private @Nullable Vector3f baseTranslation; - public DisplayBaseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public DisplayBaseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/EnderCrystalEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/EnderCrystalEntity.java index 932864bf73d..6b40bc4de3a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/EnderCrystalEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/EnderCrystalEntity.java @@ -25,21 +25,22 @@ package org.geysermc.geyser.entity.type; -import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import java.util.Optional; import java.util.UUID; public class EnderCrystalEntity extends Entity { - public EnderCrystalEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public EnderCrystalEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/EnderEyeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/EnderEyeEntity.java index cc5a58f2125..015e3f0993e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/EnderEyeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/EnderEyeEntity.java @@ -28,15 +28,15 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; -import org.geysermc.geyser.entity.EntityDefinitions; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public class EnderEyeEntity extends Entity { - public EnderEyeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public EnderEyeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index 0901e3672b8..c10c41a15e8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -46,9 +46,9 @@ import org.geysermc.geyser.api.entity.property.BatchPropertyUpdater; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.entity.type.GeyserEntity; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.GeyserDirtyMetadata; -import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.entity.properties.GeyserEntityProperties; import org.geysermc.geyser.entity.properties.GeyserEntityPropertyManager; import org.geysermc.geyser.entity.properties.type.PropertyType; @@ -85,6 +85,8 @@ public class Entity implements GeyserEntity { private static final boolean PRINT_ENTITY_SPAWN_DEBUG = Boolean.parseBoolean(System.getProperty("Geyser.PrintEntitySpawnDebug", "false")); protected final GeyserSession session; + protected final BedrockEntityDefinition bedrockDefinition; + protected EntityDefinition definition; protected int entityId; protected final long geyserId; @@ -112,10 +114,6 @@ public class Entity implements GeyserEntity { */ protected boolean onGround; - protected EntityDefinition definition; - - protected GeyserEntityType type; - /** * Indicates if the entity has been initialized and spawned */ @@ -154,10 +152,11 @@ public class Entity implements GeyserEntity { protected final GeyserEntityPropertyManager propertyManager; - public Entity(GeyserSession session, GeyserEntityType type, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public Entity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, + Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { this.session = session; - this.type = type; this.definition = definition; + this.bedrockDefinition = bedrockDefinition; this.displayName = standardDisplayName(); this.entityId = entityId; @@ -169,8 +168,8 @@ public Entity(GeyserSession session, GeyserEntityType type, int entityId, long g this.headYaw = headYaw; this.valid = false; - - this.propertyManager = definition.registeredProperties().isEmpty() ? null : new GeyserEntityPropertyManager(definition.registeredProperties()); + // TODO null or empty check + this.propertyManager = bedrockDefinition.registeredProperties() == null ? null : new GeyserEntityPropertyManager(bedrockDefinition.registeredProperties()); setPosition(position); setAirSupply(getMaxAir()); @@ -201,7 +200,7 @@ protected void setClientSideSilent() { public void spawnEntity() { AddEntityPacket addEntityPacket = new AddEntityPacket(); - addEntityPacket.setIdentifier(definition.bedrockIdentifier()); + addEntityPacket.setIdentifier(bedrockDefinition.identifier().toString()); addEntityPacket.setRuntimeEntityId(geyserId); addEntityPacket.setUniqueEntityId(geyserId); addEntityPacket.setPosition(position); @@ -224,7 +223,7 @@ public void spawnEntity() { flagsDirty = false; if (session.getGeyser().config().debugMode() && PRINT_ENTITY_SPAWN_DEBUG) { - session.getGeyser().getLogger().debug("Spawned entity " + definition.bedrockIdentifier() + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")"); + session.getGeyser().getLogger().debug("Spawned entity " + definition.type() + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")"); } } @@ -494,7 +493,7 @@ public void setDisplayName(EntityMetadata, ?> entityMetadata } protected String standardDisplayName() { - return EntityUtils.translatedEntityName(type, session); + return EntityUtils.translatedEntityName(definition.type(), session); } protected void setNametag(@Nullable String nametag, boolean fromDisplayName) { @@ -574,8 +573,8 @@ public void setPose(Pose pose) { */ protected void setDimensionsFromPose(Pose pose) { // No flexibility options for basic entities - setBoundingBoxHeight(definition.height()); - setBoundingBoxWidth(definition.width()); + setBoundingBoxHeight(bedrockDefinition.height()); + setBoundingBoxWidth(bedrockDefinition.width()); } public boolean setBoundingBoxHeight(float height) { @@ -787,7 +786,7 @@ public void updatePropertiesBatched(Consumer consumer, boo } Objects.requireNonNull(consumer); - GeyserEntityProperties propertyDefinitions = definition.registeredProperties(); + GeyserEntityProperties propertyDefinitions = bedrockDefinition.registeredProperties(); consumer.accept(new BatchPropertyUpdater() { @Override public void update(@NonNull GeyserEntityProperty property, @Nullable T value) { @@ -829,6 +828,6 @@ public void update(@NonNull GeyserEntityProperty property, @Nullable T va @Override public Vector3f position() { - return this.position.down(definition.offset()); + return this.position.down(bedrockDefinition.offset()); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java index 56d761afd97..93a911e9980 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java @@ -28,6 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.packet.PlaySoundPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; @@ -38,8 +39,8 @@ public class EvokerFangsEntity extends Entity implements Tickable { private int limitedLife = 22; private boolean attackStarted = false; - public EvokerFangsEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public EvokerFangsEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); // As of 1.18.2 Bedrock, this line is required for the entity to be visible // 22 is the starting number on Java Edition dirtyMetadata.put(EntityDataTypes.DATA_LIFETIME_TICKS, this.limitedLife); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ExpOrbEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ExpOrbEntity.java index 8cca969b161..19c7749dc49 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ExpOrbEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ExpOrbEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; @@ -34,8 +35,8 @@ public class ExpOrbEntity extends Entity { - public ExpOrbEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition entityDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, entityDefinition, position, motion, yaw, pitch, headYaw); + public ExpOrbEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); this.dirtyMetadata.put(EntityDataTypes.TRADE_EXPERIENCE, 1); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FallingBlockEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FallingBlockEntity.java index 4fcec7a6391..81aeb2fabeb 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FallingBlockEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FallingBlockEntity.java @@ -28,6 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinitions; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; @@ -36,8 +37,9 @@ public class FallingBlockEntity extends Entity { - public FallingBlockEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw, int javaId) { - super(session, entityId, geyserId, uuid, EntityDefinitions.FALLING_BLOCK, position, motion, yaw, pitch, headYaw); + // TODO + public FallingBlockEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, BedrockEntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw, int javaId) { + super(session, entityId, geyserId, uuid, EntityDefinitions.FALLING_BLOCK, definition, position, motion, yaw, pitch, headYaw); this.dirtyMetadata.put(EntityDataTypes.BLOCK, session.getBlockMappings().getBedrockBlock(javaId)); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java index 904596b3af9..e3e82a4508e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; @@ -39,8 +40,8 @@ public class FireballEntity extends ThrowableEntity { */ protected int futureTicks = 3; - public FireballEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, Vector3f.ZERO, yaw, pitch, headYaw); + public FireballEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, Vector3f.ZERO, yaw, pitch, headYaw); float magnitude = motion.length(); if (magnitude != 0) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FireworkEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FireworkEntity.java index 8db92a11837..b4a22534a46 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FireworkEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FireworkEntity.java @@ -29,6 +29,7 @@ import org.cloudburstmc.protocol.bedrock.data.MovementEffectType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.packet.MovementEffectPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.TooltipOptions; @@ -45,8 +46,8 @@ public class FireworkEntity extends Entity { private boolean attachedToSession; - public FireworkEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public FireworkEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setFireworkItem(EntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java index 26a64bcae3e..77c4127ce6c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java @@ -30,6 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.packet.PlaySoundPacket; import org.geysermc.erosion.util.BlockPositionIterator; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinitions; import org.geysermc.geyser.entity.type.player.PlayerEntity; import org.geysermc.geyser.level.block.BlockStateValues; @@ -55,8 +56,8 @@ public class FishingHookEntity extends ThrowableEntity { private final BoundingBox boundingBox; - public FishingHookEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw, PlayerEntity owner) { - super(session, entityId, geyserId, uuid, EntityDefinitions.FISHING_BOBBER, position, motion, yaw, pitch, 0f); + public FishingHookEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, BedrockEntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw, PlayerEntity owner) { + super(session, entityId, geyserId, uuid, EntityDefinitions.FISHING_BOBBER, definition, position, motion, yaw, pitch, 0f); this.boundingBox = new BoundingBox(0.125, 0.125, 0.125, 0.25, 0.25, 0.25); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FurnaceMinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FurnaceMinecartEntity.java index e33e6d7b6c4..749179231fb 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FurnaceMinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FurnaceMinecartEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.level.block.Blocks; import org.geysermc.geyser.level.block.property.Properties; @@ -41,8 +42,8 @@ public class FurnaceMinecartEntity extends DefaultBlockMinecartEntity { private boolean hasFuel = false; - public FurnaceMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public FurnaceMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setHasFuel(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/HangingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/HangingEntity.java index 7c0e8a77337..7d5f53dbf02 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/HangingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/HangingEntity.java @@ -26,17 +26,18 @@ package org.geysermc.geyser.entity.type; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; -import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; +import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction; import java.util.UUID; public abstract class HangingEntity extends Entity { - public HangingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public HangingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setDirectionMetadata(EntityMetadata direction) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java index 967269069ff..6bf34cd6eaa 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java @@ -31,6 +31,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.AnimatePacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.EntityDefinitions; import org.geysermc.geyser.entity.type.living.ArmorStandEntity; @@ -53,8 +54,8 @@ public class InteractionEntity extends Entity { */ private boolean response = false; - public InteractionEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public InteractionEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } /** @@ -161,8 +162,9 @@ public void updateNameTag() { } if (this.secondEntity == null) { + // TODO CE make this controllable??? secondEntity = new ArmorStandEntity(session, 0, session.getEntityCache().getNextEntityId().incrementAndGet(), null, - EntityDefinitions.ARMOR_STAND, position.up(getBoundingBoxHeight()), motion, getYaw(), getPitch(), getHeadYaw()); + EntityDefinitions.ARMOR_STAND, bedrockDefinition, position.up(getBoundingBoxHeight()), motion, getYaw(), getPitch(), getHeadYaw()); } secondEntity.getDirtyMetadata().put(EntityDataTypes.NAME, nametag); secondEntity.getDirtyMetadata().put(EntityDataTypes.NAMETAG_ALWAYS_SHOW, isNameTagVisible ? (byte) 1 : (byte) 0); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java index 49eb9ddc494..042c01a20e6 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java @@ -32,6 +32,7 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; import org.cloudburstmc.protocol.bedrock.packet.AddItemEntityPacket; import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.level.block.BlockStateValues; import org.geysermc.geyser.level.block.type.BlockState; @@ -48,8 +49,8 @@ public class ItemEntity extends ThrowableEntity { private CompletableFuture waterLevel = CompletableFuture.completedFuture(-1); - public ItemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public ItemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override @@ -61,7 +62,7 @@ public void spawnEntity() { AddItemEntityPacket itemPacket = new AddItemEntityPacket(); itemPacket.setRuntimeEntityId(geyserId); itemPacket.setUniqueEntityId(geyserId); - itemPacket.setPosition(position.add(0d, this.definition.offset(), 0d)); + itemPacket.setPosition(position.add(0d, this.bedrockDefinition.offset(), 0d)); itemPacket.setMotion(motion); itemPacket.setFromFishing(false); itemPacket.setItemInHand(item); @@ -112,10 +113,10 @@ public void setItem(EntityMetadata entityMetadata) { @Override protected void moveAbsoluteImmediate(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - float offset = definition.offset(); + float offset = bedrockDefinition.offset(); if (waterLevel.join() == 0) { // Item is in a full block of water // Move the item entity down so it doesn't float above the water - offset = -definition.offset(); + offset = -bedrockDefinition.offset(); } super.moveAbsoluteImmediate(position.add(0, offset, 0), 0, 0, 0, isOnGround, teleported); this.position = position; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java index e836a58db0d..7f8132f441c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java @@ -34,6 +34,7 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; import org.cloudburstmc.protocol.bedrock.packet.BlockEntityDataPacket; import org.cloudburstmc.protocol.bedrock.packet.UpdateBlockPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.item.ItemTranslator; @@ -44,7 +45,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; -import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; import java.util.UUID; @@ -80,8 +80,8 @@ public class ItemFrameEntity extends HangingEntity { */ private boolean changed = true; - public ItemFrameEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public ItemFrameEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); blockDefinition = buildBlockDefinition(Direction.SOUTH); // Default to SOUTH direction, like on Java - entity metadata should correct this when necessary bedrockPosition = Vector3i.from(position.getFloorX(), position.getFloorY(), position.getFloorZ()); @@ -177,7 +177,7 @@ private NbtMap getDefaultTag() { builder.putInt("y", bedrockPosition.getY()); builder.putInt("z", bedrockPosition.getZ()); builder.putByte("isMovable", (byte) 1); - builder.putString("id", this.definition.entityType().is(BuiltinEntityType.GLOW_ITEM_FRAME) ? "GlowItemFrame" : "ItemFrame"); + builder.putString("id", this.definition.type().is(BuiltinEntityType.GLOW_ITEM_FRAME) ? "GlowItemFrame" : "ItemFrame"); return builder.build(); } @@ -223,7 +223,7 @@ public InteractionResult interact(Hand hand) { private BlockDefinition buildBlockDefinition(Direction direction) { NbtMapBuilder blockBuilder = NbtMap.builder() - .putString("name", this.definition.entityType().is(BuiltinEntityType.GLOW_ITEM_FRAME) ? "minecraft:glow_frame" : "minecraft:frame"); + .putString("name", this.definition.type().is(BuiltinEntityType.GLOW_ITEM_FRAME) ? "minecraft:glow_frame" : "minecraft:frame"); NbtMapBuilder statesBuilder = NbtMap.builder() .putInt("facing_direction", direction.ordinal()) .putByte("item_frame_map_bit", (byte) 0) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java index af739297c99..40a9de0eb15 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; @@ -35,9 +36,9 @@ public class LeashKnotEntity extends Entity { - public LeashKnotEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public LeashKnotEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { // Position is incorrect by default - super(session, entityId, geyserId, uuid, definition, position.add(0.5f, 0.25f, 0.5f), motion, yaw, pitch, headYaw); + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position.add(0.5f, 0.25f, 0.5f), motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LightningEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LightningEntity.java index 6db486f0340..a134cf07327 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LightningEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LightningEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.packet.PlaySoundPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; @@ -35,8 +36,8 @@ public class LightningEntity extends Entity { - public LightningEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public LightningEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java index bc0e68fd97d..469a08a8710 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java @@ -38,6 +38,7 @@ import org.cloudburstmc.protocol.bedrock.packet.MobArmorEquipmentPacket; import org.cloudburstmc.protocol.bedrock.packet.MobEquipmentPacket; import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.attribute.GeyserAttributeType; import org.geysermc.geyser.entity.type.living.animal.HappyGhastEntity; @@ -105,8 +106,8 @@ public class LivingEntity extends Entity { @Setter(AccessLevel.NONE) private float attributeScale; - public LivingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public LivingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public GeyserItemStack getItemInSlot(EquipmentSlot slot) { @@ -553,7 +554,7 @@ private boolean hasValidEquippableItemForSlot(EquipmentSlot slot) { if (equippable != null) { return slot == equippable.slot() && canUseSlot(slot) && - EntityUtils.equipmentUsableByEntity(session, equippable, type); + EntityUtils.equipmentUsableByEntity(session, equippable, definition.type()); } else { return slot == EquipmentSlot.MAIN_HAND && canUseSlot(EquipmentSlot.MAIN_HAND); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java index 90621967817..4d81aefb69b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java @@ -30,6 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.packet.MoveEntityDeltaPacket; import org.cloudburstmc.protocol.bedrock.packet.SetEntityMotionPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.EntityDefinitions; import org.geysermc.geyser.session.GeyserSession; @@ -59,8 +60,8 @@ public class MinecartEntity extends Entity implements Tickable { private int cachedStepDelay; private float cachedDelta; - public MinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position.add(0d, definition.offset(), 0d), motion, yaw, pitch, headYaw); + public MinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position.add(0d, bedrockDefinition.offset(), 0d), motion, yaw, pitch, headYaw); } public void setCustomBlock(IntEntityMetadata entityMetadata) { @@ -113,7 +114,7 @@ public void tick() { moveEntityPacket.setRuntimeEntityId(geyserId); moveEntityPacket.setX(position.getX()); - moveEntityPacket.setY(position.getY() + definition.offset()); + moveEntityPacket.setY(position.getY() + bedrockDefinition.offset()); moveEntityPacket.setZ(position.getZ()); moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_X); moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Y); @@ -201,7 +202,7 @@ private void updateCompletedStep() { @Override public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - super.moveAbsolute(position.add(0d, this.definition.offset(), 0d), yaw, pitch, headYaw, isOnGround, teleported); + super.moveAbsolute(position.add(0d, this.bedrockDefinition.offset(), 0d), yaw, pitch, headYaw, isOnGround, teleported); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java index ea3600768dd..4733f1e07e1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.packet.AddPaintingPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.level.PaintingType; import org.geysermc.geyser.session.GeyserSession; @@ -43,8 +44,8 @@ public class PaintingEntity extends HangingEntity { private int paintingId = -1; // Ideally this would be the default painting Java uses in their metadata, but seems to depend on the current paintings loaded in the registry private Direction direction = Direction.SOUTH; // Default to SOUTH direction, like on Java - entity metadata should correct this when necessary - public PaintingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public PaintingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/SpawnerMinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/SpawnerMinecartEntity.java index 4d69c8a1ea8..84e1e0ef99c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/SpawnerMinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/SpawnerMinecartEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.level.block.Blocks; import org.geysermc.geyser.session.GeyserSession; @@ -35,8 +36,8 @@ public class SpawnerMinecartEntity extends DefaultBlockMinecartEntity { - public SpawnerMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public SpawnerMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java index 47d97b8f7ed..fe0777ea7e3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java @@ -29,6 +29,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.SetEntityDataPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; @@ -38,18 +39,18 @@ public class TNTEntity extends Entity implements Tickable { private int currentTick; - public TNTEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position.add(0, definition.offset(), 0), motion, yaw, pitch, headYaw); + public TNTEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position.add(0, bedrockDefinition.offset(), 0), motion, yaw, pitch, headYaw); } @Override public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, boolean isOnGround) { - super.moveRelative(relX, relY + definition.offset(), relZ, yaw, pitch, isOnGround); + super.moveRelative(relX, relY + bedrockDefinition.offset(), relZ, yaw, pitch, isOnGround); } @Override public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - super.moveAbsolute(position.add(Vector3f.from(0, definition.offset(), 0)), yaw, pitch, headYaw, isOnGround, teleported); + super.moveAbsolute(position.add(Vector3f.from(0, bedrockDefinition.offset(), 0)), yaw, pitch, headYaw, isOnGround, teleported); } public void setFuseLength(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java index 69a24cf0c9d..2ce33a1ce8a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java @@ -31,6 +31,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.text.MessageTranslator; @@ -55,13 +56,13 @@ public class TextDisplayEntity extends DisplayBaseEntity { private int lineCount; - public TextDisplayEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position.add(0, definition.offset(), 0), motion, yaw, pitch, headYaw); + public TextDisplayEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position.add(0, bedrockDefinition.offset(), 0), motion, yaw, pitch, headYaw); } @Override public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, boolean isOnGround) { - super.moveRelative(relX, relY + definition.offset(), relZ, yaw, pitch, isOnGround); + super.moveRelative(relX, relY + bedrockDefinition.offset(), relZ, yaw, pitch, isOnGround); } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEggEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEggEntity.java index a32762abe2f..87682ba9d8d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEggEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEggEntity.java @@ -28,12 +28,14 @@ import lombok.Getter; import net.kyori.adventure.key.Key; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.living.animal.farm.TemperatureVariantAnimal; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.registry.JavaRegistries; +import org.geysermc.geyser.translator.protocol.bedrock.entity.player.BedrockSetDefaultGameTypeTranslator; import org.geysermc.mcprotocollib.protocol.data.game.Holder; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; @@ -47,8 +49,8 @@ public class ThrowableEggEntity extends ThrowableItemEntity { // Used for egg break particles private GeyserItemStack itemStack = GeyserItemStack.of(Items.EGG.javaId(), 1); - public ThrowableEggEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public ThrowableEggEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java index 4e6cb64c7cb..8d68b9e205d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java @@ -30,6 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; import org.cloudburstmc.protocol.bedrock.packet.MoveEntityDeltaPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.level.block.BlockStateValues; import org.geysermc.geyser.session.GeyserSession; @@ -44,8 +45,8 @@ public class ThrowableEntity extends Entity implements Tickable { protected Vector3f lastJavaPosition; - public ThrowableEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public ThrowableEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); this.lastJavaPosition = position; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java index fbbe2de5037..49907a36c7f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java @@ -28,6 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.EntityDefinitions; import org.geysermc.geyser.session.GeyserSession; @@ -46,8 +47,8 @@ public class ThrowableItemEntity extends ThrowableEntity { private int age; private boolean invisible; - public ThrowableItemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public ThrowableItemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); setFlag(EntityFlag.INVISIBLE, true); invisible = false; age = 0; @@ -66,8 +67,8 @@ private void checkVisibility() { // Prevent projectiles from blocking the player's screen if (session.isTickingFrozen()) { // This may seem odd, but it matches java edition - Vector3f playerPos = session.getPlayerEntity().getPosition().down(EntityDefinitions.PLAYER.offset()); - setInvisible(playerPos.distanceSquared(position.add(0, definition.offset(), 0)) < 12.25); + Vector3f playerPos = session.getPlayerEntity().getPosition().down(EntityDefinitions.PLAYER.bedrockDefinition().offset()); + setInvisible(playerPos.distanceSquared(position.add(0, bedrockDefinition.offset(), 0)) < 12.25); } else { setInvisible(age < 2); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java index 2d9d2af0d7e..b7dbdefdef1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java @@ -29,6 +29,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.item.Potion; import org.geysermc.geyser.session.GeyserSession; @@ -45,8 +46,8 @@ public class ThrownPotionEntity extends ThrowableItemEntity { private static final EnumSet NON_ENCHANTED_POTIONS = EnumSet.of(Potion.WATER, Potion.MUNDANE, Potion.THICK, Potion.AWKWARD); - public ThrownPotionEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public ThrownPotionEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override @@ -72,7 +73,7 @@ public void setItem(EntityMetadata entityMetadata) { } } - boolean isLingering = definition.entityType().is(BuiltinEntityType.LINGERING_POTION); + boolean isLingering = definition.type().is(BuiltinEntityType.LINGERING_POTION); setFlag(EntityFlag.LINGERING, isLingering); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/TridentEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/TridentEntity.java index 2167f2c4d79..bb26929e60d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/TridentEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/TridentEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; @@ -33,7 +34,7 @@ public class TridentEntity extends AbstractArrowEntity { - public TridentEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public TridentEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java index 8427a8e100c..69cd7121cd3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java @@ -25,19 +25,20 @@ package org.geysermc.geyser.entity.type; -import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.EntityDefinitions; import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import java.util.UUID; public class WitherSkullEntity extends FireballEntity { private boolean isCharged; - public WitherSkullEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public WitherSkullEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); this.futureTicks = 1; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AbstractFishEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AbstractFishEntity.java index 6ecfa4978a4..fc61550f170 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AbstractFishEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AbstractFishEntity.java @@ -28,6 +28,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.session.GeyserSession; @@ -39,8 +40,8 @@ public class AbstractFishEntity extends WaterEntity { - public AbstractFishEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public AbstractFishEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); setFlag(EntityFlag.CAN_SWIM, true); setFlag(EntityFlag.BREATHING, true); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java index 8f84e051b80..ace43f2c571 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; @@ -35,8 +36,8 @@ public class AgeableEntity extends CreatureEntity { - public AgeableEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public AgeableEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override @@ -51,8 +52,8 @@ public void setBaby(BooleanEntityMetadata entityMetadata) { setScale(isBaby ? getBabySize() : getAdultSize()); setFlag(EntityFlag.BABY, isBaby); - setBoundingBoxHeight(definition.height() * (isBaby ? getBabySize() : getAdultSize())); - setBoundingBoxWidth(definition.width() * (isBaby ? getBabySize() : getAdultSize())); + setBoundingBoxHeight(bedrockDefinition.height() * (isBaby ? getBabySize() : getAdultSize())); + setBoundingBoxWidth(bedrockDefinition.width() * (isBaby ? getBabySize() : getAdultSize())); } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableWaterEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableWaterEntity.java index 84321567480..e082701dec0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableWaterEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableWaterEntity.java @@ -26,14 +26,15 @@ package org.geysermc.geyser.entity.type.living; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public abstract class AgeableWaterEntity extends AgeableEntity { - public AgeableWaterEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public AgeableWaterEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java index e87e20236d1..cc5577bb707 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java @@ -28,6 +28,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.session.GeyserSession; @@ -42,8 +43,8 @@ public class AllayEntity extends MobEntity { private boolean canDuplicate; - public AllayEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public AllayEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setDancing(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AmbientEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AmbientEntity.java index f4b80edf180..4ecdb6f3e29 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AmbientEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AmbientEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; @@ -33,8 +34,8 @@ public class AmbientEntity extends MobEntity { - public AmbientEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public AmbientEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java index a1834648874..595436794e9 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java @@ -32,6 +32,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.EntityDefinitions; import org.geysermc.geyser.entity.type.LivingEntity; @@ -88,8 +89,8 @@ public class ArmorStandEntity extends LivingEntity { */ private boolean positionUpdateRequired = false; - public ArmorStandEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public ArmorStandEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override @@ -157,8 +158,8 @@ public void setArmorStandFlags(ByteEntityMetadata entityMetadata) { setBoundingBoxWidth(0.0f); setBoundingBoxHeight(0.0f); } else { - setBoundingBoxWidth(definition.width()); - setBoundingBoxHeight(definition.height()); + setBoundingBoxWidth(bedrockDefinition.width()); + setBoundingBoxHeight(bedrockDefinition.height()); } updateMountOffset(); @@ -344,7 +345,7 @@ private void updateSecondEntityStatus(boolean sendMetadata) { // Create the second entity. It doesn't need to worry about the items, but it does need to worry about // the metadata as it will hold the name tag. secondEntity = new ArmorStandEntity(session, 0, session.getEntityCache().getNextEntityId().incrementAndGet(), null, - EntityDefinitions.ARMOR_STAND, position, motion, getYaw(), getPitch(), getHeadYaw()); + EntityDefinitions.ARMOR_STAND, EntityDefinitions.ARMADILLO.bedrockDefinition(), position, motion, getYaw(), getPitch(), getHeadYaw()); secondEntity.primaryEntity = false; } // Copy metadata @@ -421,7 +422,7 @@ public float getYOffset() { if (!positionRequiresOffset || isMarker || secondEntity != null) { return 0; } - return definition.height() * getScale(); + return bedrockDefinition.height() * getScale(); } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/BatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/BatEntity.java index bdfc20c8894..cb03d3cfcc3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/BatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/BatEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; @@ -35,8 +36,8 @@ public class BatEntity extends AmbientEntity { - public BatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public BatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setBatFlags(ByteEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/CopperGolemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/CopperGolemEntity.java index 946d961694c..7f25638300b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/CopperGolemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/CopperGolemEntity.java @@ -27,6 +27,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.properties.type.BooleanProperty; import org.geysermc.geyser.entity.properties.type.EnumProperty; @@ -79,8 +80,8 @@ public enum OxidationLevelState { OXIDIZED } - public CopperGolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public CopperGolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/CreatureEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/CreatureEntity.java index fd38bf6668a..149612f4048 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/CreatureEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/CreatureEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; @@ -33,7 +34,7 @@ public class CreatureEntity extends MobEntity { - public CreatureEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public CreatureEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/DolphinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/DolphinEntity.java index cb300a7c9de..6bd837c3bcb 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/DolphinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/DolphinEntity.java @@ -27,6 +27,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.session.GeyserSession; @@ -38,8 +39,8 @@ import java.util.UUID; public class DolphinEntity extends AgeableWaterEntity { - public DolphinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public DolphinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/FlyingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/FlyingEntity.java index 472a9b3dcb1..9e00ba24cb5 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/FlyingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/FlyingEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; @@ -33,7 +34,7 @@ public class FlyingEntity extends MobEntity { - public FlyingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public FlyingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/GlowSquidEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/GlowSquidEntity.java index 58c2f608249..e4ef0500fad 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/GlowSquidEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/GlowSquidEntity.java @@ -26,13 +26,14 @@ package org.geysermc.geyser.entity.type.living; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public class GlowSquidEntity extends SquidEntity { - public GlowSquidEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public GlowSquidEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/GolemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/GolemEntity.java index 12b2ca91d2a..468a52009d0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/GolemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/GolemEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; @@ -33,7 +34,7 @@ public class GolemEntity extends CreatureEntity { - public GolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public GolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/IronGolemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/IronGolemEntity.java index 8cbed6373aa..eed7df38808 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/IronGolemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/IronGolemEntity.java @@ -29,6 +29,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; @@ -40,8 +41,8 @@ public class IronGolemEntity extends GolemEntity { - public IronGolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public IronGolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); // Indicate that we should show cracks through a resource pack setFlag(EntityFlag.BRIBED, true); // Required, or else the overlay is black diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java index 5a66ef36e47..0cf8f9a6596 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; @@ -34,8 +35,8 @@ public class MagmaCubeEntity extends SlimeEntity { - public MagmaCubeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public MagmaCubeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java index d6c00f6944c..69d3e66dc5a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java @@ -29,6 +29,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.Leashable; import org.geysermc.geyser.entity.type.LivingEntity; @@ -55,8 +56,8 @@ public class MobEntity extends LivingEntity implements Leashable { */ private long leashHolderBedrockId; - public MobEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public MobEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/SlimeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/SlimeEntity.java index 3be2db1db69..af90c50fc77 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/SlimeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/SlimeEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; @@ -34,8 +35,8 @@ public class SlimeEntity extends MobEntity { - public SlimeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public SlimeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setSlimeScale(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/SnowGolemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/SnowGolemEntity.java index f766cd40211..4c428723d5d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/SnowGolemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/SnowGolemEntity.java @@ -28,6 +28,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; @@ -41,8 +42,8 @@ public class SnowGolemEntity extends GolemEntity { - public SnowGolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public SnowGolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setSnowGolemFlags(ByteEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java index fe3e26a6c7a..5408756c262 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java @@ -28,6 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.MoveEntityDeltaPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.level.block.BlockStateValues; @@ -42,8 +43,8 @@ public class SquidEntity extends AgeableWaterEntity implements Tickable { private CompletableFuture inWater = CompletableFuture.completedFuture(Boolean.FALSE); - public SquidEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public SquidEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/TadpoleEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/TadpoleEntity.java index 42ef51f674d..71d25527a21 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/TadpoleEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/TadpoleEntity.java @@ -27,6 +27,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.session.GeyserSession; @@ -38,8 +39,8 @@ import java.util.UUID; public class TadpoleEntity extends AbstractFishEntity { - public TadpoleEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public TadpoleEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @NonNull diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/WaterEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/WaterEntity.java index ae9d0d6599e..d32aef79c5f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/WaterEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/WaterEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; @@ -33,8 +34,8 @@ public class WaterEntity extends CreatureEntity { - public WaterEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public WaterEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AnimalEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AnimalEntity.java index d0c097ec812..41144663b12 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AnimalEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AnimalEntity.java @@ -30,6 +30,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.living.AgeableEntity; import org.geysermc.geyser.inventory.GeyserItemStack; @@ -44,8 +45,8 @@ public abstract class AnimalEntity extends AgeableEntity { - public AnimalEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public AnimalEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } protected final boolean canEat(GeyserItemStack itemStack) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/ArmadilloEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/ArmadilloEntity.java index 0ebd92021e6..b36c9e991b8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/ArmadilloEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/ArmadilloEntity.java @@ -27,6 +27,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.properties.type.EnumProperty; import org.geysermc.geyser.impl.IdentifierImpl; @@ -51,8 +52,8 @@ public class ArmadilloEntity extends AnimalEntity { private ArmadilloState armadilloState = ArmadilloState.IDLE; public ArmadilloEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, - EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setArmadilloState(ObjectEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AxolotlEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AxolotlEntity.java index 0a87f59bcec..ad9e79e2928 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AxolotlEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AxolotlEntity.java @@ -30,6 +30,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.type.Item; @@ -45,8 +46,8 @@ import java.util.UUID; public class AxolotlEntity extends AnimalEntity { - public AxolotlEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public AxolotlEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setVariant(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/BeeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/BeeEntity.java index 919af7c2298..41bfc94974d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/BeeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/BeeEntity.java @@ -31,6 +31,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.properties.type.BooleanProperty; import org.geysermc.geyser.impl.IdentifierImpl; @@ -50,8 +51,8 @@ public class BeeEntity extends AnimalEntity { false ); - public BeeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public BeeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setBeeFlags(ByteEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FoxEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FoxEntity.java index b140b79565c..caa8051b25c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FoxEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FoxEntity.java @@ -29,6 +29,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; @@ -41,8 +42,8 @@ public class FoxEntity extends AnimalEntity { - public FoxEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public FoxEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setFoxVariant(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FrogEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FrogEntity.java index 8638267c899..9debe57e130 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FrogEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FrogEntity.java @@ -29,6 +29,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.item.type.Item; @@ -44,8 +45,8 @@ import java.util.UUID; public class FrogEntity extends AnimalEntity implements VariantIntHolder { - public FrogEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public FrogEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java index 02d7c62de71..08ff9d73e26 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java @@ -31,6 +31,7 @@ import org.cloudburstmc.protocol.bedrock.data.SoundEvent; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; @@ -53,8 +54,8 @@ public class GoatEntity extends AnimalEntity { private boolean hasLeftHorn; private boolean hasRightHorn; - public GoatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public GoatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setScreamer(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HappyGhastEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HappyGhastEntity.java index 51f61c6bf9b..da49a8647d1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HappyGhastEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HappyGhastEntity.java @@ -32,6 +32,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.AttributeData; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.properties.type.BooleanProperty; import org.geysermc.geyser.entity.type.Entity; @@ -71,8 +72,8 @@ public class HappyGhastEntity extends AnimalEntity implements ClientVehicle { private final HappyGhastVehicleComponent vehicleComponent = new HappyGhastVehicleComponent(this, 0.0f); private boolean staysStill; - public HappyGhastEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public HappyGhastEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HoglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HoglinEntity.java index 9ea70fa7859..31861a6093f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HoglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HoglinEntity.java @@ -29,6 +29,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; @@ -41,8 +42,8 @@ public class HoglinEntity extends AnimalEntity { private boolean isImmuneToZombification; - public HoglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public HoglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); dirtyMetadata.put(EntityDataTypes.TARGET_EID, session.getPlayerEntity().getGeyserId()); setFlag(EntityFlag.SHAKING, isShaking()); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/MooshroomEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/MooshroomEntity.java index 78f2ea025b9..15530059525 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/MooshroomEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/MooshroomEntity.java @@ -29,6 +29,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.packet.AddEntityPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.living.animal.farm.CowEntity; import org.geysermc.geyser.inventory.GeyserItemStack; @@ -45,8 +46,8 @@ public class MooshroomEntity extends CowEntity { private boolean isBrown = false; - public MooshroomEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public MooshroomEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setMooshroomVariant(IntEntityMetadata metadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java index c45092b026f..4d1f6677a94 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java @@ -29,6 +29,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.type.Item; @@ -43,8 +44,8 @@ public class OcelotEntity extends AnimalEntity { - public OcelotEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public OcelotEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PandaEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PandaEntity.java index 358643b0efe..477ad8d3c16 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PandaEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PandaEntity.java @@ -32,6 +32,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.type.Item; @@ -50,8 +51,8 @@ public class PandaEntity extends AnimalEntity { private Gene mainGene = Gene.NORMAL; private Gene hiddenGene = Gene.NORMAL; - public PandaEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public PandaEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setEatingCounter(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PolarBearEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PolarBearEntity.java index 900878dbd81..6a6af6b8c1e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PolarBearEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PolarBearEntity.java @@ -27,6 +27,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; @@ -36,8 +37,8 @@ public class PolarBearEntity extends AnimalEntity { - public PolarBearEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public PolarBearEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PufferFishEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PufferFishEntity.java index 6f00634744b..b4bf53017fc 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PufferFishEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PufferFishEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.living.AbstractFishEntity; import org.geysermc.geyser.session.GeyserSession; @@ -36,8 +37,8 @@ public class PufferFishEntity extends AbstractFishEntity { - public PufferFishEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public PufferFishEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setPufferfishSize(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/RabbitEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/RabbitEntity.java index dca6fe5ff88..d389786d88b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/RabbitEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/RabbitEntity.java @@ -30,6 +30,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; @@ -43,8 +44,8 @@ public class RabbitEntity extends AnimalEntity { private boolean isKillerBunny; - public RabbitEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public RabbitEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setRabbitVariant(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SheepEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SheepEntity.java index 35863071c87..3821b65eb71 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SheepEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SheepEntity.java @@ -30,6 +30,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; @@ -48,8 +49,8 @@ public class SheepEntity extends AnimalEntity { private int color; - public SheepEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public SheepEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setSheepFlags(ByteEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java index 2def028698c..cb7ede4cf67 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java @@ -32,8 +32,8 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; -import org.geysermc.geyser.entity.EntityDefinitions; import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; @@ -46,15 +46,14 @@ import java.util.UUID; public class SnifferEntity extends AnimalEntity implements Tickable { - private static final float DIGGING_HEIGHT = EntityDefinitions.SNIFFER.height() - 0.4f; private static final int DIG_END = 120; private static final int DIG_START = DIG_END - 34; - + private final float DIGGING_HEIGHT = bedrockDefinition.height() - 0.4f; private Pose pose = Pose.STANDING; // Needed to call setDimensions for DIGGING state private int digTicks; - public SnifferEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public SnifferEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override @@ -67,7 +66,7 @@ public void setPose(Pose pose) { protected void setDimensionsFromPose(Pose pose) { if (getFlag(EntityFlag.DIGGING)) { setBoundingBoxHeight(DIGGING_HEIGHT); - setBoundingBoxWidth(definition.width()); + setBoundingBoxWidth(bedrockDefinition.width()); } else { super.setDimensionsFromPose(pose); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java index 186ecd2dd5a..161c90bc4ea 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java @@ -30,6 +30,7 @@ import org.cloudburstmc.math.vector.Vector2f; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.Tickable; @@ -38,8 +39,8 @@ import org.geysermc.geyser.entity.vehicle.ClientVehicle; import org.geysermc.geyser.entity.vehicle.VehicleComponent; import org.geysermc.geyser.inventory.GeyserItemStack; -import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.item.Items; +import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; @@ -58,8 +59,8 @@ public class StriderEntity extends AnimalEntity implements Tickable, ClientVehic private final BoostableVehicleComponent vehicleComponent = new BoostableVehicleComponent<>(this, 1.0f); private boolean isCold = false; - public StriderEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public StriderEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); setFlag(EntityFlag.FIRE_IMMUNE, true); setFlag(EntityFlag.BREATHING, true); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TropicalFishEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TropicalFishEntity.java index 182bb176ff4..b9c9e5ec79a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TropicalFishEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TropicalFishEntity.java @@ -29,6 +29,7 @@ import it.unimi.dsi.fastutil.ints.IntList; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.living.AbstractFishEntity; import org.geysermc.geyser.session.GeyserSession; @@ -48,8 +49,8 @@ public class TropicalFishEntity extends AbstractFishEntity { private static final List VARIANT_NAMES = ImmutableList.of("kob", "sunstreak", "snooper", "dasher", "brinely", "spotty", "flopper", "stripey", "glitter", "blockfish", "betty", "clayfish"); private static final List COLOR_NAMES = ImmutableList.of("white", "orange", "magenta", "light_blue", "yellow", "lime", "pink", "gray", "light_gray", "cyan", "purple", "blue", "brown", "green", "red", "black"); - public TropicalFishEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public TropicalFishEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setFishVariant(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TurtleEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TurtleEntity.java index 1f700f12b64..a423517167c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TurtleEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TurtleEntity.java @@ -28,6 +28,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; @@ -39,8 +40,8 @@ public class TurtleEntity extends AnimalEntity { - public TurtleEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public TurtleEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setPregnant(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/ChickenEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/ChickenEntity.java index 4ee7175dea2..eb08d31a1ac 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/ChickenEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/ChickenEntity.java @@ -27,6 +27,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; @@ -39,8 +40,8 @@ public class ChickenEntity extends TemperatureVariantAnimal { - public ChickenEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public ChickenEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/CowEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/CowEntity.java index 8c1a27b95b5..9a5113a4260 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/CowEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/CowEntity.java @@ -30,6 +30,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.SoundEvent; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; @@ -47,8 +48,8 @@ public class CowEntity extends TemperatureVariantAnimal { - public CowEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public CowEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @NonNull diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/PigEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/PigEntity.java index bb629c3d74e..13070610493 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/PigEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/PigEntity.java @@ -30,6 +30,7 @@ import org.cloudburstmc.math.vector.Vector2f; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.entity.type.player.PlayerEntity; @@ -37,8 +38,8 @@ import org.geysermc.geyser.entity.vehicle.ClientVehicle; import org.geysermc.geyser.entity.vehicle.VehicleComponent; import org.geysermc.geyser.inventory.GeyserItemStack; -import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.item.Items; +import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.registry.JavaRegistries; import org.geysermc.geyser.session.cache.registry.JavaRegistryKey; @@ -56,8 +57,8 @@ public class PigEntity extends TemperatureVariantAnimal implements Tickable, ClientVehicle { private final BoostableVehicleComponent vehicleComponent = new BoostableVehicleComponent<>(this, 1.0f); - public PigEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public PigEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/TemperatureVariantAnimal.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/TemperatureVariantAnimal.java index 9d772c8a260..d5f64edfae3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/TemperatureVariantAnimal.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/TemperatureVariantAnimal.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living.animal.farm; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.properties.type.EnumProperty; import org.geysermc.geyser.entity.type.living.animal.AnimalEntity; @@ -46,9 +47,9 @@ public abstract class TemperatureVariantAnimal extends AnimalEntity implements V public static final RegistryCache.RegistryReader VARIANT_READER = VariantHolder.reader(BuiltInVariant.class, BuiltInVariant.TEMPERATE); - public TemperatureVariantAnimal(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, + public TemperatureVariantAnimal(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java index 35e3d17ae66..c8d8b59d2de 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java @@ -34,6 +34,7 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerType; import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket; import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.attribute.GeyserAttributeType; import org.geysermc.geyser.entity.type.living.animal.AnimalEntity; @@ -54,8 +55,8 @@ public class AbstractHorseEntity extends AnimalEntity { - public AbstractHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public AbstractHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); // Specifies the size of the entity's inventory. Required to place slots in the entity. dirtyMetadata.put(EntityDataTypes.CONTAINER_SIZE, getContainerBaseSize()); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java index 138b60e3578..fa962b31a0a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java @@ -25,8 +25,8 @@ package org.geysermc.geyser.entity.type.living.animal.horse; -import org.cloudburstmc.math.vector.Vector2f; import org.checkerframework.checker.nullness.qual.Nullable; +import org.cloudburstmc.math.vector.Vector2f; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.AttributeData; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; @@ -34,12 +34,13 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerType; import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; -import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.entity.attribute.GeyserAttributeType; import org.geysermc.geyser.entity.vehicle.CamelVehicleComponent; import org.geysermc.geyser.entity.vehicle.ClientVehicle; import org.geysermc.geyser.entity.vehicle.VehicleComponent; +import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; @@ -57,8 +58,8 @@ public class CamelEntity extends AbstractHorseEntity implements ClientVehicle { private final CamelVehicleComponent vehicleComponent = new CamelVehicleComponent(this); - public CamelEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public CamelEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); dirtyMetadata.put(EntityDataTypes.CONTAINER_TYPE, (byte) ContainerType.HORSE.getId()); @@ -113,8 +114,8 @@ public void setPose(Pose pose) { @Override protected void setDimensionsFromPose(Pose pose) { if (pose == Pose.SITTING) { - setBoundingBoxHeight(definition.height() - SITTING_HEIGHT_DIFFERENCE); - setBoundingBoxWidth(definition.width()); + setBoundingBoxHeight(bedrockDefinition.height() - SITTING_HEIGHT_DIFFERENCE); + setBoundingBoxWidth(bedrockDefinition.width()); } else { super.setDimensionsFromPose(pose); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ChestedHorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ChestedHorseEntity.java index 491ca02df71..f39256cb2b9 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ChestedHorseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ChestedHorseEntity.java @@ -28,6 +28,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; @@ -37,8 +38,8 @@ public class ChestedHorseEntity extends AbstractHorseEntity { - public ChestedHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public ChestedHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/HorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/HorseEntity.java index 478f89aeb97..d20a52e2a90 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/HorseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/HorseEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.EquipmentSlot; @@ -36,8 +37,8 @@ public class HorseEntity extends AbstractHorseEntity { - public HorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public HorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setHorseVariant(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/LlamaEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/LlamaEntity.java index 6ef1cd57a72..a4c6803f070 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/LlamaEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/LlamaEntity.java @@ -29,6 +29,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; @@ -47,8 +48,8 @@ public class LlamaEntity extends ChestedHorseEntity { @Getter private int strength = 1; - public LlamaEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public LlamaEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); dirtyMetadata.put(EntityDataTypes.CONTAINER_STRENGTH_MODIFIER, 3); // Presumably 3 slots for every 1 strength } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/SkeletonHorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/SkeletonHorseEntity.java index d74913c3177..c559d61a345 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/SkeletonHorseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/SkeletonHorseEntity.java @@ -27,6 +27,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.session.GeyserSession; @@ -37,8 +38,8 @@ import java.util.UUID; public class SkeletonHorseEntity extends AbstractHorseEntity { - public SkeletonHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public SkeletonHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @NonNull diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/TraderLlamaEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/TraderLlamaEntity.java index 4be0ef5e297..0c2029d3663 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/TraderLlamaEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/TraderLlamaEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; @@ -34,8 +35,8 @@ public class TraderLlamaEntity extends LlamaEntity { - public TraderLlamaEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public TraderLlamaEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ZombieHorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ZombieHorseEntity.java index 9e77daebc8f..f5c7ebc296e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ZombieHorseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ZombieHorseEntity.java @@ -27,6 +27,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.session.GeyserSession; @@ -37,8 +38,8 @@ import java.util.UUID; public class ZombieHorseEntity extends AbstractHorseEntity { - public ZombieHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public ZombieHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @NonNull diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java index e90cb3f1c61..dbf14f73e61 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java @@ -30,6 +30,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.living.animal.VariantIntHolder; import org.geysermc.geyser.inventory.GeyserItemStack; @@ -52,8 +53,8 @@ public class CatEntity extends TameableEntity implements VariantIntHolder { private byte collarColor = 14; // Red - default - public CatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public CatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java index ef6121456d6..e349e8271ea 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java @@ -29,6 +29,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.type.Item; @@ -42,8 +43,8 @@ import java.util.UUID; public class ParrotEntity extends TameableEntity { - public ParrotEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public ParrotEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/TameableEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/TameableEntity.java index a24eb17550a..43ac740fe67 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/TameableEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/TameableEntity.java @@ -29,6 +29,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.living.animal.AnimalEntity; @@ -46,8 +47,8 @@ public abstract class TameableEntity extends AnimalEntity { @Getter protected long ownerBedrockId; - public TameableEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public TameableEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setTameableFlags(ByteEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java index eee7a0052a5..18901e3b6bd 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java @@ -31,6 +31,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.properties.type.StringEnumProperty; import org.geysermc.geyser.entity.type.living.animal.VariantIntHolder; @@ -80,8 +81,8 @@ public class WolfEntity extends TameableEntity implements VariantIntHolder { private HolderSet repairableItems = null; private boolean isCurseOfBinding = false; - public WolfEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public WolfEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/AbstractMerchantEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/AbstractMerchantEntity.java index ecc517489b0..9a148e4cc91 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/AbstractMerchantEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/AbstractMerchantEntity.java @@ -28,6 +28,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.EntityDefinitions; import org.geysermc.geyser.entity.type.living.AgeableEntity; @@ -42,8 +43,8 @@ public class AbstractMerchantEntity extends AgeableEntity { - public AbstractMerchantEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public AbstractMerchantEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java index d7efa9f1de8..976a5b6b827 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java @@ -32,6 +32,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.MoveEntityAbsolutePacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.level.block.property.Properties; import org.geysermc.geyser.level.block.type.BedBlock; @@ -88,8 +89,8 @@ public class VillagerEntity extends AbstractMerchantEntity { @Getter private boolean canTradeWith; - public VillagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public VillagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setVillagerData(EntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/AbstractSkeletonEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/AbstractSkeletonEntity.java index 16b5cc01c47..42d82e7ee26 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/AbstractSkeletonEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/AbstractSkeletonEntity.java @@ -28,6 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.session.GeyserSession; @@ -37,8 +38,8 @@ public class AbstractSkeletonEntity extends MonsterEntity { - public AbstractSkeletonEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public AbstractSkeletonEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BasePiglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BasePiglinEntity.java index 9258cd3b8dc..f812217ce12 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BasePiglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BasePiglinEntity.java @@ -28,19 +28,19 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; -import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; import java.util.UUID; public class BasePiglinEntity extends MonsterEntity { private boolean isImmuneToZombification; - public BasePiglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public BasePiglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); // Both TARGET_EID and BLOCK are needed for melee attack animation dirtyMetadata.put(EntityDataTypes.BLOCK, session.getBlockMappings().getDefinition(1)); setFlag(EntityFlag.SHAKING, isShaking()); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BlazeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BlazeEntity.java index 5b26d7bd115..4175472d252 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BlazeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BlazeEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; @@ -35,8 +36,8 @@ public class BlazeEntity extends MonsterEntity { - public BlazeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public BlazeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setBlazeFlags(ByteEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BoggedEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BoggedEntity.java index c4d8eeff39d..be1fd36bba8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BoggedEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BoggedEntity.java @@ -28,6 +28,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; @@ -42,8 +43,8 @@ public class BoggedEntity extends AbstractSkeletonEntity { private boolean sheared = false; - public BoggedEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public BoggedEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setSheared(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BreezeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BreezeEntity.java index 251a77fb949..4850a467d56 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BreezeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BreezeEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.Pose; @@ -34,8 +35,8 @@ import java.util.UUID; public class BreezeEntity extends MonsterEntity { - public BreezeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public BreezeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java index dc9755a2bbd..da309a3db80 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java @@ -31,6 +31,7 @@ import org.cloudburstmc.protocol.bedrock.data.LevelEvent; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.LevelEventGenericPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.properties.type.EnumProperty; import org.geysermc.geyser.entity.properties.type.IntProperty; @@ -63,8 +64,8 @@ public class CreakingEntity extends MonsterEntity { private Vector3i homePosition; - public CreakingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public CreakingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java index cc58aa7aa54..a59e036db2c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java @@ -29,6 +29,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.SoundEvent; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.session.GeyserSession; @@ -48,8 +49,8 @@ public class CreeperEntity extends MonsterEntity { */ private boolean ignitedByFlintAndSteel = false; - public CreeperEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public CreeperEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setSwelling(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ElderGuardianEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ElderGuardianEntity.java index 8890e72a974..17da37bf897 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ElderGuardianEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ElderGuardianEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; @@ -34,8 +35,8 @@ public class ElderGuardianEntity extends GuardianEntity { - public ElderGuardianEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public ElderGuardianEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java index 04044fcb4d5..a6314ae9480 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java @@ -35,6 +35,7 @@ import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; import org.cloudburstmc.protocol.bedrock.packet.PlaySoundPacket; import org.cloudburstmc.protocol.bedrock.packet.SpawnParticleEffectPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.entity.type.living.MobEntity; @@ -84,8 +85,8 @@ public class EnderDragonEntity extends MobEntity implements Tickable { private float wingPosition; private float lastWingPosition; - public EnderDragonEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public EnderDragonEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java index 590337556f4..3de7d9c8db9 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java @@ -35,7 +35,7 @@ public class EnderDragonPartEntity extends Entity { public EnderDragonPartEntity(GeyserSession session, int entityId, long geyserId, float width, float height) { - super(session, entityId, geyserId, null, EntityDefinitions.ENDER_DRAGON_PART, Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0); + super(session, entityId, geyserId, null, EntityDefinitions.ENDER_DRAGON_PART, EntityDefinitions.ENDER_DRAGON.bedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0); dirtyMetadata.put(EntityDataTypes.WIDTH, width); dirtyMetadata.put(EntityDataTypes.HEIGHT, height); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EndermanEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EndermanEntity.java index 94ff657d2b5..f66f4846d47 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EndermanEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EndermanEntity.java @@ -31,6 +31,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; @@ -40,8 +41,8 @@ public class EndermanEntity extends MonsterEntity { - public EndermanEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public EndermanEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setCarriedBlock(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GhastEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GhastEntity.java index 984aab64282..984610c9741 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GhastEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GhastEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.living.FlyingEntity; import org.geysermc.geyser.session.GeyserSession; @@ -36,8 +37,8 @@ public class GhastEntity extends FlyingEntity { - public GhastEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public GhastEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setGhastAttacking(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GiantEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GiantEntity.java index 6bef3ae3ec1..a245560ddda 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GiantEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GiantEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living.monster; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; @@ -33,8 +34,8 @@ public class GiantEntity extends MonsterEntity { - public GiantEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public GiantEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GuardianEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GuardianEntity.java index 40793522ea1..a5552af673d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GuardianEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GuardianEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.session.GeyserSession; @@ -36,8 +37,8 @@ public class GuardianEntity extends MonsterEntity { - public GuardianEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public GuardianEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setGuardianTarget(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/MonsterEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/MonsterEntity.java index c0edc448cd7..77111e290b2 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/MonsterEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/MonsterEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living.monster; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.living.CreatureEntity; import org.geysermc.geyser.session.GeyserSession; @@ -34,8 +35,8 @@ public class MonsterEntity extends CreatureEntity { - public MonsterEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public MonsterEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java index 18b7f6ae15d..288aa2e1aa8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living.monster; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.living.FlyingEntity; import org.geysermc.geyser.session.GeyserSession; @@ -34,17 +35,17 @@ import java.util.UUID; public class PhantomEntity extends FlyingEntity { - public PhantomEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public PhantomEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setPhantomScale(IntEntityMetadata entityMetadata) { int size = entityMetadata.getPrimitiveValue(); float modelScale = 1f + 0.15f * size; - float boundsScale = (1f + (0.2f * size) / definition.width()) / modelScale; + float boundsScale = (1f + (0.2f * size) / bedrockDefinition.width()) / modelScale; - setBoundingBoxWidth(boundsScale * definition.width()); - setBoundingBoxHeight(boundsScale * definition.height()); + setBoundingBoxWidth(boundsScale * bedrockDefinition.width()); + setBoundingBoxHeight(boundsScale * bedrockDefinition.height()); setScale(modelScale); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PiglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PiglinEntity.java index b35e6a17f99..7272038052d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PiglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PiglinEntity.java @@ -32,6 +32,7 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerId; import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; import org.cloudburstmc.protocol.bedrock.packet.MobEquipmentPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; @@ -47,8 +48,8 @@ public class PiglinEntity extends BasePiglinEntity { - public PiglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public PiglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setBaby(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ShulkerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ShulkerEntity.java index d8266f29d40..3f4ce19aed2 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ShulkerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ShulkerEntity.java @@ -28,6 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.living.GolemEntity; import org.geysermc.geyser.session.GeyserSession; @@ -39,8 +40,8 @@ public class ShulkerEntity extends GolemEntity { - public ShulkerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public ShulkerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); // Indicate that invisibility should be fixed through the resource pack setFlag(EntityFlag.BRIBED, true); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SkeletonEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SkeletonEntity.java index a6343e256b0..fc40a6b8af0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SkeletonEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SkeletonEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; @@ -36,8 +37,8 @@ public class SkeletonEntity extends AbstractSkeletonEntity { private boolean convertingToStray = false; - public SkeletonEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public SkeletonEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setConvertingToStray(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SpiderEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SpiderEntity.java index 4a4527cef36..dcc07b47b7d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SpiderEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SpiderEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; @@ -35,8 +36,8 @@ public class SpiderEntity extends MonsterEntity { - public SpiderEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public SpiderEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setSpiderFlags(ByteEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/VexEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/VexEntity.java index 840f5b3b4af..f0a655ffaca 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/VexEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/VexEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; @@ -35,8 +36,8 @@ public class VexEntity extends MonsterEntity { - public VexEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public VexEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setVexFlags(ByteEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WardenEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WardenEntity.java index 2341b8c321c..148b06d2278 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WardenEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WardenEntity.java @@ -30,6 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.PlaySoundPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.session.GeyserSession; @@ -46,8 +47,8 @@ public class WardenEntity extends MonsterEntity implements Tickable { private int sonicBoomTickDuration; - public WardenEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public WardenEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WitherEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WitherEntity.java index 19c1a457b9a..effca7601f3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WitherEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WitherEntity.java @@ -28,6 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.session.GeyserSession; @@ -37,8 +38,8 @@ public class WitherEntity extends MonsterEntity { - public WitherEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public WitherEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java index e382777ff1f..d718cfdb207 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java @@ -28,6 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; @@ -36,8 +37,8 @@ public class ZoglinEntity extends MonsterEntity { - public ZoglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public ZoglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); dirtyMetadata.put(EntityDataTypes.TARGET_EID, session.getPlayerEntity().getGeyserId()); } @@ -54,7 +55,7 @@ public void setBaby(BooleanEntityMetadata entityMetadata) { @Override public float getBoundingBoxHeight() { float scale = getFlag(EntityFlag.BABY) ? 0.55f : 1f; - return scale * definition.height(); + return scale * bedrockDefinition.height(); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieEntity.java index b07afd7424c..8b65af6a745 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; @@ -36,8 +37,8 @@ public class ZombieEntity extends MonsterEntity { private boolean convertingToDrowned = false; - public ZombieEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public ZombieEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setZombieBaby(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieVillagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieVillagerEntity.java index e09568102dd..c626fe04d36 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieVillagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieVillagerEntity.java @@ -29,6 +29,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.living.merchant.VillagerEntity; import org.geysermc.geyser.inventory.GeyserItemStack; @@ -45,8 +46,8 @@ public class ZombieVillagerEntity extends ZombieEntity { - public ZombieVillagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public ZombieVillagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setTransforming(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombifiedPiglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombifiedPiglinEntity.java index 0a0fe630692..d712913ad0c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombifiedPiglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombifiedPiglinEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; @@ -34,8 +35,8 @@ public class ZombifiedPiglinEntity extends ZombieEntity { - public ZombifiedPiglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public ZombifiedPiglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); setFlag(EntityFlag.FIRE_IMMUNE, true); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/AbstractIllagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/AbstractIllagerEntity.java index 90138742f89..9d0ad6e1c67 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/AbstractIllagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/AbstractIllagerEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living.monster.raid; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; @@ -33,7 +34,7 @@ public class AbstractIllagerEntity extends RaidParticipantEntity { - public AbstractIllagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public AbstractIllagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/PillagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/PillagerEntity.java index e73052286c1..190a85c3380 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/PillagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/PillagerEntity.java @@ -28,6 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; @@ -39,8 +40,8 @@ public class PillagerEntity extends AbstractIllagerEntity { - public PillagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public PillagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setChargingCrossbow(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RaidParticipantEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RaidParticipantEntity.java index 05becf490f9..af58e202c89 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RaidParticipantEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RaidParticipantEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living.monster.raid; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.type.living.monster.MonsterEntity; import org.geysermc.geyser.session.GeyserSession; @@ -34,7 +35,7 @@ public class RaidParticipantEntity extends MonsterEntity { - public RaidParticipantEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public RaidParticipantEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RavagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RavagerEntity.java index 6190bae10a0..7b1dd8dc2dd 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RavagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RavagerEntity.java @@ -27,6 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; @@ -35,8 +36,8 @@ public class RavagerEntity extends RaidParticipantEntity { - public RavagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public RavagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/SpellcasterIllagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/SpellcasterIllagerEntity.java index 8d4b3c44ee7..f43ba95671c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/SpellcasterIllagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/SpellcasterIllagerEntity.java @@ -28,6 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.EntityDefinitions; import org.geysermc.geyser.session.GeyserSession; @@ -40,8 +41,8 @@ public class SpellcasterIllagerEntity extends AbstractIllagerEntity { private static final int ATTACK_PARTICLE_COLOR = (102 << 16) | (77 << 8) | 89; private static final int WOLOLO_PARTICLE_COLOR = (179 << 16) | (128 << 8) | 51; - public SpellcasterIllagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public SpellcasterIllagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); // OptionalPack usage setFlag(EntityFlag.BRIBED, this.definition == EntityDefinitions.ILLUSIONER); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/VindicatorEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/VindicatorEntity.java index a2557e75a27..d48ddd91f39 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/VindicatorEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/VindicatorEntity.java @@ -28,6 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; @@ -36,8 +37,8 @@ public class VindicatorEntity extends AbstractIllagerEntity { - public VindicatorEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + public VindicatorEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); dirtyMetadata.put(EntityDataTypes.TARGET_EID, session.getPlayerEntity().getGeyserId()); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java index 355c2dd9730..7339161d5ad 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java @@ -40,6 +40,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.AddPlayerPacket; import org.cloudburstmc.protocol.bedrock.packet.MovePlayerPacket; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.EntityDefinitions; import org.geysermc.geyser.entity.type.LivingEntity; @@ -93,9 +94,9 @@ public class AvatarEntity extends LivingEntity { BASE_ABILITY_LAYER = Collections.singletonList(abilityLayer); } - public AvatarEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, + public AvatarEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw, String username) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); this.username = username; this.nametag = username; } @@ -114,7 +115,7 @@ public void spawnEntity() { addPlayerPacket.setUsername(username); addPlayerPacket.setRuntimeEntityId(geyserId); addPlayerPacket.setUniqueEntityId(geyserId); - addPlayerPacket.setPosition(position.sub(0, definition.offset(), 0)); + addPlayerPacket.setPosition(position.sub(0, bedrockDefinition.offset(), 0)); addPlayerPacket.setRotation(getBedrockRotation()); addPlayerPacket.setMotion(motion); addPlayerPacket.setHand(ItemTranslator.translateToBedrock(session, getMainHandItem())); @@ -180,7 +181,7 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float if (getFlag(EntityFlag.SLEEPING)) { if (bedPosition != null && (bedPosition.getY() == 0 || bedPosition.distanceSquared(position.toInt()) > 4)) { // Force the player movement by using a teleport - movePlayerPacket.setPosition(Vector3f.from(position.getX(), position.getY() - definition.offset() + 0.2f, position.getZ())); + movePlayerPacket.setPosition(Vector3f.from(position.getX(), position.getY() - bedrockDefinition.offset() + 0.2f, position.getZ())); movePlayerPacket.setMode(MovePlayerPacket.Mode.TELEPORT); } } @@ -199,7 +200,7 @@ public void setPosition(Vector3f position) { // Messes with Bedrock if we send this to the client itself, though. super.setPosition(position.up(0.2f)); } else { - super.setPosition(position.add(0, definition.offset(), 0)); + super.setPosition(position.add(0, bedrockDefinition.offset(), 0)); } } @@ -344,11 +345,11 @@ public void setDimensionsFromPose(Pose pose) { switch (pose) { case SNEAKING -> { height = SNEAKING_POSE_HEIGHT; - width = definition.width(); + width = bedrockDefinition.width(); } case FALL_FLYING, SPIN_ATTACK, SWIMMING -> { height = 0.6f; - width = definition.width(); + width = bedrockDefinition.width(); } case DYING -> { height = 0.2f; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/MannequinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/MannequinEntity.java index c45221a1a45..de080eaa62d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/MannequinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/MannequinEntity.java @@ -27,6 +27,7 @@ import net.kyori.adventure.text.Component; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; @@ -37,8 +38,8 @@ public class MannequinEntity extends AvatarEntity { - public MannequinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw, ""); + public MannequinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw, ""); } public void setProfile(EntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java index 71f294ccb52..e64edabf4c3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java @@ -68,7 +68,8 @@ public class PlayerEntity extends AvatarEntity implements GeyserPlayerEntity { public PlayerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw, String username, @Nullable String texturesProperty) { - super(session, entityId, geyserId, uuid, EntityDefinitions.PLAYER, position, motion, yaw, pitch, headYaw, username); + // TODO allow changing bedrock player definition??? + super(session, entityId, geyserId, uuid, EntityDefinitions.PLAYER, EntityDefinitions.PLAYER.bedrockDefinition(), position, motion, yaw, pitch, headYaw, username); this.texturesProperty = texturesProperty; } @@ -161,8 +162,9 @@ protected void setParrot(OptionalInt variant, boolean isLeft) { return; } // The parrot is a separate entity in Bedrock, but part of the player entity in Java + // TODO CE allow customizing? ParrotEntity parrot = new ParrotEntity(session, 0, session.getEntityCache().getNextEntityId().incrementAndGet(), - null, EntityDefinitions.PARROT, position, motion, getYaw(), getPitch(), getHeadYaw()); + null, EntityDefinitions.PARROT, EntityDefinitions.PARROT.bedrockDefinition(), position, motion, getYaw(), getPitch(), getHeadYaw()); parrot.spawnEntity(); parrot.getDirtyMetadata().put(EntityDataTypes.VARIANT, variant.getAsInt()); // Different position whether the parrot is left or right @@ -224,7 +226,7 @@ public UUID getTabListUuid() { @Override public Vector3f position() { - return this.position.down(definition.offset()); + return this.position.down(bedrockDefinition.offset()); } // From 1.21.8 code, should be correct since some pose should be prioritized. diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java index 51230dd58ce..dafc32fbff1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java @@ -163,7 +163,7 @@ public void setYaw(float yaw) { @Override public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, float headYaw, boolean isOnGround) { super.moveRelative(relX, relY, relZ, yaw, pitch, headYaw, isOnGround); - session.getCollisionManager().updatePlayerBoundingBox(this.position.down(definition.offset())); + session.getCollisionManager().updatePlayerBoundingBox(this.position.down(bedrockDefinition.offset())); } @Override @@ -175,7 +175,7 @@ public void setPosition(Vector3f position) { session.setNoClip(false); } } - this.position = position.add(0, definition.offset(), 0); + this.position = position.add(0, bedrockDefinition.offset(), 0); } /** @@ -218,7 +218,7 @@ public void setPositionManual(Vector3f position) { this.position = position; // Player is "above" the void so they're not supposed to no clip. - if (session.isNoClip() && position.getY() - EntityDefinitions.PLAYER.offset() >= session.getBedrockDimension().minY() - 5) { + if (session.isNoClip() && position.getY() - EntityDefinitions.PLAYER.bedrockDefinition().offset() >= session.getBedrockDimension().minY() - 5) { session.setNoClip(false); } } @@ -471,8 +471,8 @@ public void setVehicle(Entity entity) { entity.setBoundingBoxHeight(0.5625F); entity.updateBedrockMetadata(); } else if (entity == null && this.vehicle instanceof BoatEntity) { - this.vehicle.setBoundingBoxWidth(this.vehicle.getDefinition().width()); - this.vehicle.setBoundingBoxHeight(this.vehicle.getDefinition().height()); + this.vehicle.setBoundingBoxWidth(this.vehicle.getDefinition().bedrockDefinition().width()); + this.vehicle.setBoundingBoxHeight(this.vehicle.getDefinition().bedrockDefinition().height()); this.vehicle.updateBedrockMetadata(); } @@ -489,7 +489,7 @@ public void setVehicle(Entity entity) { public float getJumpVelocity() { float velocity = 0.42F; - if (session.getGeyser().getWorldManager().blockAt(session, this.getPosition().sub(0, EntityDefinitions.PLAYER.offset() + 0.1F, 0).toInt()).is(Blocks.HONEY_BLOCK)) { + if (session.getGeyser().getWorldManager().blockAt(session, this.getPosition().sub(0, EntityDefinitions.PLAYER.bedrockDefinition().offset() + 0.1F, 0).toInt()).is(Blocks.HONEY_BLOCK)) { velocity *= 0.6F; } @@ -500,7 +500,7 @@ public boolean isOnClimbableBlock() { if (session.getGameMode() == GameMode.SPECTATOR) { return false; } - Vector3i pos = getPosition().down(EntityDefinitions.PLAYER.offset()).toInt(); + Vector3i pos = getPosition().down(EntityDefinitions.PLAYER.bedrockDefinition().offset()).toInt(); BlockState state = session.getGeyser().getWorldManager().blockAt(session, pos); if (state.block().is(session, BlockTag.CLIMBABLE)) { return true; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/SkullPlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/SkullPlayerEntity.java index 2819d9486a4..20559637c6b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/SkullPlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/SkullPlayerEntity.java @@ -61,7 +61,7 @@ public class SkullPlayerEntity extends AvatarEntity { private Vector3i skullPosition; public SkullPlayerEntity(GeyserSession session, long geyserId) { - super(session, 0, geyserId, UUID.randomUUID(), EntityDefinitions.PLAYER, Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, ""); + super(session, 0, geyserId, UUID.randomUUID(), EntityDefinitions.PLAYER, EntityDefinitions.PLAYER.bedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, ""); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java index c85547dee56..7472bd35491 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java +++ b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java @@ -218,7 +218,7 @@ protected ObjectDoublePair updateFluidMovement(VehicleContext ctx) { double lavaHeight = getFluidHeightAndApplyMovement(ctx, iter, Fluid.LAVA, vehicle.getSession().getDimensionType().ultrawarm() ? 0.007 : 0.007 / 3, min.getY()); // Apply upward motion if the vehicle is a Strider, and it is submerged in lava - if (lavaHeight > 0 && vehicle.getDefinition().entityType().is(BuiltinEntityType.STRIDER)) { + if (lavaHeight > 0 && vehicle.getDefinition().type().is(BuiltinEntityType.STRIDER)) { Vector3i blockPos = ctx.centerPos().toInt(); if (!CollisionManager.FLUID_COLLISION.isBelow(blockPos.getY(), boundingBox) || ctx.getBlock(blockPos.up()).is(Blocks.LAVA)) { vehicle.setMotion(vehicle.getMotion().mul(0.5f).add(0, 0.05f, 0)); diff --git a/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java b/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java index 822ed9b3ba7..b5ca4bd1d98 100644 --- a/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java +++ b/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java @@ -166,7 +166,7 @@ public BoundingBox getActiveBoundingBox() { } // We need to parse the float as a string since casting a float to a double causes us to // lose precision and thus, causes players to get stuck when walking near walls - double javaY = Double.parseDouble(Float.toString(bedrockPosition.getY() - EntityDefinitions.PLAYER.offset())); + double javaY = Double.parseDouble(Float.toString(bedrockPosition.getY() - EntityDefinitions.PLAYER.bedrockDefinition().offset())); Vector3d position = Vector3d.from(Double.parseDouble(Float.toString(bedrockPosition.getX())), javaY, Double.parseDouble(Float.toString(bedrockPosition.getZ()))); diff --git a/core/src/main/java/org/geysermc/geyser/registry/Registries.java b/core/src/main/java/org/geysermc/geyser/registry/Registries.java index 7c7fd6748ac..6da58d56667 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/Registries.java +++ b/core/src/main/java/org/geysermc/geyser/registry/Registries.java @@ -37,9 +37,11 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.PotionMixData; import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket; import org.geysermc.geyser.GeyserImpl; -import org.geysermc.geyser.api.entity.JavaEntityType; +import org.geysermc.geyser.api.util.Identifier; +import org.geysermc.geyser.entity.BedrockEntityDefinition; +import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.GeyserCustomEntityDefinition; -import org.geysermc.geyser.entity.VanillaEntityDefinition; +import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.inventory.recipe.GeyserRecipe; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.pack.ResourcePackHolder; @@ -126,10 +128,12 @@ public final class Registries { */ // Is a Reference2ObjectMap since GeyserEntityType, the implementation of JavaEntityType, only ever keeps one instance per registered entity type // TODO rename to VANILLA_ENTITY_DEFINITIONS - public static final SimpleMappedRegistry> ENTITY_DEFINITIONS = SimpleMappedRegistry.create(RegistryLoaders.empty(Reference2ObjectOpenHashMap::new)); + public static final SimpleMappedRegistry> ENTITY_DEFINITIONS = SimpleMappedRegistry.create(RegistryLoaders.empty(Reference2ObjectOpenHashMap::new)); public static final ListRegistry> CUSTOM_ENTITY_DEFINITIONS = ListRegistry.create(RegistryLoaders.empty(ArrayList::new)); + public static final SimpleMappedRegistry BEDROCK_ENTITY_DEFINITIONS = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new)); + /** * A registry holding a list of all the known entity properties to be sent to the client after start game. */ @@ -138,7 +142,7 @@ public final class Registries { /** * A map containing all Java entity identifiers and their respective Geyser definitions */ - public static final SimpleMappedRegistry> JAVA_ENTITY_IDENTIFIERS = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new)); + public static final SimpleMappedRegistry> JAVA_ENTITY_IDENTIFIERS = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new)); /** * A registry containing all the Java packet translators. diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java index 6c7a6cf6d91..812665f1431 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java @@ -47,8 +47,6 @@ import org.geysermc.geyser.api.pack.option.SubpackOption; import org.geysermc.geyser.api.pack.option.UrlFallbackOption; import org.geysermc.geyser.api.util.Identifier; -import org.geysermc.geyser.entity.GeyserCustomEntityDefinition; -import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.event.GeyserEventRegistrar; import org.geysermc.geyser.extension.command.GeyserExtensionCommand; import org.geysermc.geyser.impl.IdentifierImpl; @@ -113,9 +111,9 @@ public Map, ProviderSupplier> load(Map, ProviderSupplier> prov providers.put(CameraFade.Builder.class, args -> new GeyserCameraFade.Builder()); providers.put(CameraPosition.Builder.class, args -> new GeyserCameraPosition.Builder()); - // entities - providers.put(JavaEntityType.class, args -> args.length == 1 ? GeyserEntityType.ofVanilla((Identifier) args[0]) : GeyserEntityType.createCustomAndRegister((Identifier) args[0], (int) args[1])); - providers.put(CustomEntityDefinition.class, args -> GeyserCustomEntityDefinition.inherited((String) args[0], (JavaEntityType) args[1])); + // entities TODO CE + //providers.put(JavaEntityType.class, args -> args.length == 1 ? GeyserEntityType.ofVanilla((Identifier) args[0]) : GeyserEntityType.createCustomAndRegister((Identifier) args[0], (int) args[1])); + //providers.put(CustomEntityDefinition.class, args -> GeyserCustomEntityDefinition.inherited((String) args[0], (JavaEntityType) args[1])); return providers; } diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index 55a2ffcb26c..9fdf43a2425 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -2179,7 +2179,7 @@ public float getEyeHeight() { FALL_FLYING, // Elytra SPIN_ATTACK -> 0.4f; // Trident spin attack case SLEEPING -> 0.2f; - default -> EntityDefinitions.PLAYER.offset(); // 1.62F + default -> EntityDefinitions.PLAYER.bedrockDefinition().offset(); // 1.62F }; } diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/BlockBreakHandler.java b/core/src/main/java/org/geysermc/geyser/session/cache/BlockBreakHandler.java index 7bd1d751837..f33d8ed5917 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/BlockBreakHandler.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/BlockBreakHandler.java @@ -491,7 +491,7 @@ protected boolean canBreak(Vector3i vector, BlockState state, PlayerActionType a } Vector3f playerPosition = session.getPlayerEntity().getPosition(); - playerPosition = playerPosition.down(EntityDefinitions.PLAYER.offset() - session.getEyeHeight()); + playerPosition = playerPosition.down(EntityDefinitions.PLAYER.bedrockDefinition().offset() - session.getEyeHeight()); return BedrockInventoryTransactionTranslator.canInteractWithBlock(session, playerPosition, vector); } diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java b/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java index 35579db1309..cd6bb6bca10 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java @@ -168,7 +168,7 @@ public boolean isPassingIntoBorderBoundaries(Vector3f newPosition, boolean adjus PlayerEntity playerEntity = session.getPlayerEntity(); // Move the player back, but allow gravity to take place // Teleported = true makes going back better, but disconnects the player from their mounted entity - playerEntity.moveAbsolute(Vector3f.from(playerEntity.getPosition().getX(), (newPosition.getY() - EntityDefinitions.PLAYER.offset()), playerEntity.getPosition().getZ()), + playerEntity.moveAbsolute(Vector3f.from(playerEntity.getPosition().getX(), (newPosition.getY() - EntityDefinitions.PLAYER.bedrockDefinition().offset()), playerEntity.getPosition().getZ()), playerEntity.getYaw(), playerEntity.getPitch(), playerEntity.getHeadYaw(), playerEntity.isOnGround(), playerEntity.getVehicle() == null); } return isInWorldBorder; @@ -325,7 +325,7 @@ public void drawWall() { } private void drawWall(Vector3f position, boolean drawWallX) { - int initialY = (int) (position.getY() - EntityDefinitions.PLAYER.offset() - 1); + int initialY = (int) (position.getY() - EntityDefinitions.PLAYER.bedrockDefinition().offset() - 1); for (int y = initialY; y < (initialY + 5); y++) { if (drawWallX) { float x = position.getX(); diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java index 70ac90e8320..abd349d82fb 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java @@ -99,7 +99,7 @@ public boolean prepareInventory(GeyserSession session, MerchantContainer contain long geyserId = session.getEntityCache().getNextEntityId().incrementAndGet(); Vector3f pos = session.getPlayerEntity().getPosition().sub(0, 3, 0); - Entity villager = new Entity(session, 0, geyserId, null, EntityDefinitions.VILLAGER, pos, Vector3f.ZERO, 0f, 0f, 0f) { + Entity villager = new Entity(session, 0, geyserId, null, EntityDefinitions.VILLAGER, EntityDefinitions.VILLAGER.bedrockDefinition(), pos, Vector3f.ZERO, 0f, 0f, 0f) { @Override protected void initializeMetadata() { dirtyMetadata.put(EntityDataTypes.SCALE, 0f); diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SpawnerBlockEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SpawnerBlockEntityTranslator.java index 14f706f2789..7fbc7dda01f 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SpawnerBlockEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SpawnerBlockEntityTranslator.java @@ -120,8 +120,8 @@ private static void translateSpawnData(@NonNull NbtMapBuilder builder, @Nullable EntityDefinition definition = Registries.JAVA_ENTITY_IDENTIFIERS.get(entityId); if (definition != null) { - builder.putFloat("DisplayEntityWidth", definition.width()); - builder.putFloat("DisplayEntityHeight", definition.height()); + builder.putFloat("DisplayEntityWidth", definition.bedrockDefinition().width()); + builder.putFloat("DisplayEntityHeight", definition.bedrockDefinition().height()); builder.putFloat("DisplayEntityScale", 1.0f); } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java index dec3108eb52..b5ad06f7c7f 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java @@ -49,7 +49,7 @@ public void translateTag(GeyserSession session, NbtMapBuilder bedrockNbt, NbtMap NbtMapBuilder spawnData = NbtMap.builder(); EntityDefinition definition = Registries.JAVA_ENTITY_IDENTIFIERS.get(entityData.getString("id")); if (definition != null) { - spawnData.putString("TypeId", definition.bedrockIdentifier()); + spawnData.putString("TypeId", definition.bedrockDefinition().identifier().toString()); } spawnData.putInt("Weight", entityData.getInt("Size", 1)); // ??? presumably since these are the only other two extra attributes bedrockNbt.putCompound("spawn_data", spawnData.build()); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java index 3e8e889bf8e..897eccda17c 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java @@ -249,7 +249,7 @@ public void translate(GeyserSession session, InventoryTransactionPacket packet) // As of 1.21, Paper does not have any additional range checks that would inconvenience normal players. Vector3f playerPosition = session.getPlayerEntity().getPosition(); - playerPosition = playerPosition.down(EntityDefinitions.PLAYER.offset() - session.getEyeHeight()); + playerPosition = playerPosition.down(EntityDefinitions.PLAYER.bedrockDefinition().offset() - session.getEyeHeight()); if (!canInteractWithBlock(session, playerPosition, packetBlockPosition)) { BlockUtils.restoreCorrectBlock(session, blockPos); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java index 195f5dcea4c..9dce0d5467b 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java @@ -60,7 +60,7 @@ static void translate(GeyserSession session, PlayerAuthInputPacket packet) { // Ignore movement packets until Bedrock's position matches the teleported position if (session.getUnconfirmedTeleport() != null) { - session.confirmTeleport(packet.getPosition().sub(0, EntityDefinitions.PLAYER.offset(), 0)); + session.confirmTeleport(packet.getPosition().sub(0, EntityDefinitions.PLAYER.bedrockDefinition().offset(), 0)); return; } @@ -125,7 +125,7 @@ static void translate(GeyserSession session, PlayerAuthInputPacket packet) { // Therefore, we're fixing this by allowing player to no clip to clip through the floor, not only this fixed the issue but // player y velocity should match java perfectly, much better than teleport player right down :) // Shouldn't mess with anything because beyond this point there is nothing to collide and not even entities since they're prob dead. - if (packet.getPosition().getY() - EntityDefinitions.PLAYER.offset() < session.getBedrockDimension().minY() - 5) { + if (packet.getPosition().getY() - EntityDefinitions.PLAYER.bedrockDefinition().offset() < session.getBedrockDimension().minY() - 5) { // Ensuring that we still can collide with collidable entity that are also in the void (eg: boat, shulker) boolean possibleOnGround = false; @@ -146,7 +146,7 @@ static void translate(GeyserSession session, PlayerAuthInputPacket packet) { final BoundingBox entityBoundingBox = new BoundingBox(0, 0, 0, other.getBoundingBoxWidth(), other.getBoundingBoxHeight(), other.getBoundingBoxWidth()); // Also offset the position down for boat as their position is offset. - entityBoundingBox.translate(other.getPosition().down(other instanceof BoatEntity ? other.getDefinition().offset() : 0).toDouble()); + entityBoundingBox.translate(other.getPosition().down(other instanceof BoatEntity ? other.getDefinition().bedrockDefinition().offset() : 0).toDouble()); if (entityBoundingBox.checkIntersection(boundingBox)) { possibleOnGround = true; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java index b2ccd4bf85b..3006096c6fc 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java @@ -327,7 +327,7 @@ private static void processVehicleInput(GeyserSession session, PlayerAuthInputPa if (vehicle instanceof BoatEntity) { // Remove some Y position to prevents boats flying up - vehiclePosition = vehiclePosition.down(vehicle.getDefinition().offset()); + vehiclePosition = vehiclePosition.down(vehicle.getBedrockDefinition().offset()); } vehicle.setPosition(vehiclePosition); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java index 77cec1f9cd7..517674a6e2d 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java @@ -27,16 +27,14 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.GeyserImpl; -import org.geysermc.geyser.api.predicate.context.entity.EntitySpawnPredicateContext; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityDefinition; -import org.geysermc.geyser.entity.GeyserCustomEntityDefinition; import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.FallingBlockEntity; import org.geysermc.geyser.entity.type.FishingHookEntity; import org.geysermc.geyser.entity.type.HangingEntity; import org.geysermc.geyser.entity.type.player.PlayerEntity; -import org.geysermc.geyser.impl.predicate.GeyserEntitySpawnPredicateContext; import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.skin.SkinManager; @@ -111,10 +109,12 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) return; } + BedrockEntityDefinition bedrockDefinition = definition.bedrockDefinition(); + Entity entity; if (type.is(BuiltinEntityType.FALLING_BLOCK)) { entity = new FallingBlockEntity(session, packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), packet.getUuid(), - position, motion, yaw, pitch, headYaw, ((FallingBlockData) packet.getData()).getId()); + bedrockDefinition, position, motion, yaw, pitch, headYaw, ((FallingBlockData) packet.getData()).getId()); } else if (type.is(BuiltinEntityType.FISHING_BOBBER)) { // Fishing bobbers need the owner for the line int ownerEntityId = ((ProjectileData) packet.getData()).getOwnerId(); @@ -122,13 +122,13 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) // Java clients only spawn fishing hooks with a player as its owner if (owner instanceof PlayerEntity) { entity = new FishingHookEntity(session, packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), packet.getUuid(), - position, motion, yaw, pitch, headYaw, (PlayerEntity) owner); + bedrockDefinition, position, motion, yaw, pitch, headYaw, (PlayerEntity) owner); } else { return; } } else { entity = definition.factory().create(session, packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), - packet.getUuid(), definition, position, motion, yaw, pitch, headYaw); + packet.getUuid(), definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); // This is done over entity metadata in modern versions, but is still sent over network in the spawn packet if (entity instanceof HangingEntity hanging) { @@ -147,12 +147,13 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) } private static EntityDefinition getEntityDefinition(GeyserSession session, GeyserEntityType entityType, ClientboundAddEntityPacket packet) { - EntitySpawnPredicateContext context = new GeyserEntitySpawnPredicateContext(session, entityType, packet); - for (GeyserCustomEntityDefinition customEntityDefinition : Registries.CUSTOM_ENTITY_DEFINITIONS) { - if (customEntityDefinition.test(context)) { - return customEntityDefinition; - } - } - return Registries.ENTITY_DEFINITIONS.get(context.entityType()); +// EntitySpawnPredicateContext context = new GeyserEntitySpawnPredicateContext(session, entityType, packet); +// for (GeyserCustomEntityDefinition customEntityDefinition : Registries.CUSTOM_ENTITY_DEFINITIONS) { +// if (customEntityDefinition.test(context)) { +// return customEntityDefinition; +// } +// } + // TODO custom entities mf + return Registries.ENTITY_DEFINITIONS.get(entityType); } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java index f11d7d9a260..af365a40144 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java @@ -216,7 +216,7 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet case VILLAGER_SWEAT: LevelEventPacket levelEventPacket = new LevelEventPacket(); levelEventPacket.setType(ParticleType.WATER_SPLASH); - levelEventPacket.setPosition(entity.getPosition().up(entity.getDefinition().height())); + levelEventPacket.setPosition(entity.getPosition().up(entity.getBedrockDefinition().height())); session.sendUpstreamPacket(levelEventPacket); return; case IRON_GOLEM_EMPTY_HAND: diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityDataTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityDataTranslator.java index 44ab214aab4..3ba9369efa2 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityDataTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityDataTranslator.java @@ -47,7 +47,7 @@ public void translate(GeyserSession session, ClientboundSetEntityDataPacket pack if (metadata.getId() >= definition.translators().size()) { if (session.getGeyser().config().debugMode()) { // Minecraft client just ignores these - session.getGeyser().getLogger().warning("Metadata ID " + metadata.getId() + " is out of bounds of known entity metadata size " + definition.translators().size() + " for entity type " + entity.getDefinition().entityType()); + session.getGeyser().getLogger().warning("Metadata ID " + metadata.getId() + " is out of bounds of known entity metadata size " + definition.translators().size() + " for entity type " + entity.getDefinition().type()); session.getGeyser().getLogger().debug(metadata.toString()); } continue; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEquipmentTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEquipmentTranslator.java index 82af862b9b2..af41d49ccb1 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEquipmentTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEquipmentTranslator.java @@ -50,7 +50,7 @@ public void translate(GeyserSession session, ClientboundSetEquipmentPacket packe if (!(entity instanceof LivingEntity livingEntity)) { session.getGeyser().getLogger().debug("Attempted to add armor to a non-living entity (" + - entity.getDefinition().bedrockIdentifier() + ")."); + entity.getBedrockDefinition().identifier() + ")."); return; } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java index 8618edd19c1..b5809d673c2 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java @@ -59,7 +59,7 @@ public void translate(GeyserSession session, ClientboundSetPassengersPacket pack if (passenger == session.getPlayerEntity()) { session.getPlayerEntity().setVehicle(entity); // We need to confirm teleports before entering a vehicle, or else we will likely exit right out - session.confirmTeleport(passenger.getPosition().down(EntityDefinitions.PLAYER.offset())); + session.confirmTeleport(passenger.getPosition().down(EntityDefinitions.PLAYER.bedrockDefinition().offset())); if (entity instanceof ClientVehicle clientVehicle) { clientVehicle.getVehicleComponent().onMount(); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java index 12f02990800..e9c790deef1 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java @@ -58,7 +58,7 @@ public void translate(GeyserSession session, ClientboundPlayerPositionPacket pac position = position.add( packet.getRelatives().contains(PositionElement.X) ? entity.getPosition().getX() : 0, - packet.getRelatives().contains(PositionElement.Y) ? entity.getPosition().getY() - EntityDefinitions.PLAYER.offset() : 0, + packet.getRelatives().contains(PositionElement.Y) ? entity.getPosition().getY() - EntityDefinitions.PLAYER.bedrockDefinition().offset() : 0, packet.getRelatives().contains(PositionElement.Z) ? entity.getPosition().getZ() : 0); float newPitch = MathUtils.clamp(packet.getXRot() + (packet.getRelatives().contains(PositionElement.X_ROT) ? entity.getPitch() : 0), -90, 90); @@ -116,9 +116,9 @@ public void translate(GeyserSession session, ClientboundPlayerPositionPacket pac return; } - session.getGeyser().getLogger().debug("Teleport (" + teleportId + ") from " + entity.getPosition().getX() + " " + (entity.getPosition().getY() - EntityDefinitions.PLAYER.offset()) + " " + entity.getPosition().getZ()); + session.getGeyser().getLogger().debug("Teleport (" + teleportId + ") from " + entity.getPosition().getX() + " " + (entity.getPosition().getY() - EntityDefinitions.PLAYER.bedrockDefinition().offset()) + " " + entity.getPosition().getZ()); - Vector3f lastPlayerPosition = entity.getPosition().down(EntityDefinitions.PLAYER.offset()); + Vector3f lastPlayerPosition = entity.getPosition().down(EntityDefinitions.PLAYER.bedrockDefinition().offset()); float lastPlayerPitch = entity.getPitch(); float lastPlayerYaw = entity.getYaw(); Vector3f teleportDestination = position.toFloat(); @@ -155,7 +155,7 @@ public void translate(GeyserSession session, ClientboundPlayerPositionPacket pac session.setUnconfirmedTeleport(new TeleportCache(teleportDestination, deltaMovement, newPitch, newYaw, teleportId, type)); } - session.getGeyser().getLogger().debug("to " + entity.getPosition().getX() + " " + (entity.getPosition().getY() - EntityDefinitions.PLAYER.offset()) + " " + entity.getPosition().getZ()); + session.getGeyser().getLogger().debug("to " + entity.getPosition().getX() + " " + (entity.getPosition().getY() - EntityDefinitions.PLAYER.bedrockDefinition().offset()) + " " + entity.getPosition().getZ()); } private void acceptTeleport(GeyserSession session, Vector3d position, float yaw, float pitch, int id) { diff --git a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java index 2666d04b8db..6da60d885ff 100644 --- a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java @@ -266,28 +266,28 @@ public static void updateMountOffset(Entity passenger, Entity mount, boolean rid */ EntityDefinition passengerDefinition = passenger.getDefinition(); if (mountDefinition.is(BuiltinEntityType.PLAYER)) { - yOffset -= EntityDefinitions.PLAYER.offset(); + yOffset -= EntityDefinitions.PLAYER.bedrockDefinition().offset(); } if (passengerDefinition.is(BuiltinEntityType.PLAYER)) { - yOffset += EntityDefinitions.PLAYER.offset(); + yOffset += EntityDefinitions.PLAYER.bedrockDefinition().offset(); } if (mountDefinition.is(BuiltinEntityType.MINECART) || mountDefinition.is(BuiltinEntityType.HOPPER_MINECART) || mountDefinition.is(BuiltinEntityType.TNT_MINECART) || mountDefinition.is(BuiltinEntityType.CHEST_MINECART) || mountDefinition.is(BuiltinEntityType.FURNACE_MINECART) || mountDefinition.is(BuiltinEntityType.SPAWNER_MINECART) || mountDefinition.is(BuiltinEntityType.COMMAND_BLOCK_MINECART)) { - yOffset -= mount.getDefinition().height() * 0.5f; + yOffset -= mount.getDefinition().bedrockDefinition().height() * 0.5f; } if (passengerDefinition.is(BuiltinEntityType.MINECART) || passengerDefinition.is(BuiltinEntityType.HOPPER_MINECART) || passengerDefinition.is(BuiltinEntityType.TNT_MINECART) || passengerDefinition.is(BuiltinEntityType.CHEST_MINECART) || passengerDefinition.is(BuiltinEntityType.FURNACE_MINECART) || passengerDefinition.is(BuiltinEntityType.SPAWNER_MINECART) || passengerDefinition.is(BuiltinEntityType.COMMAND_BLOCK_MINECART) || passengerDefinition.is(BuiltinEntityType.SHULKER)) { - yOffset += passenger.getDefinition().height() * 0.5f; + yOffset += passenger.getDefinition().bedrockDefinition().height() * 0.5f; } else if (passengerDefinition.is(BuiltinEntityType.FALLING_BLOCK)) { yOffset += 0.995f; } if (mount instanceof BoatEntity) { - yOffset -= mount.getDefinition().height() * 0.5f; + yOffset -= mount.getDefinition().bedrockDefinition().height() * 0.5f; } if (passenger instanceof BoatEntity) { - yOffset += passenger.getDefinition().height() * 0.5f; + yOffset += passenger.getDefinition().bedrockDefinition().height() * 0.5f; } if (mount instanceof ArmorStandEntity armorStand) { yOffset -= armorStand.getYOffset(); From c57f2508cca8d5f0a4c5c19671ea89953ceb1d04 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sat, 22 Nov 2025 19:53:29 +0100 Subject: [PATCH 11/62] EntityDefinition -> EntityTypeDefinition --- .../api/entity/GeyserEntityDefinition.java | 13 + .../geyser/api/entity/JavaEntityType.java | 12 - .../entity/custom/CustomEntityDefinition.java | 50 +- .../geyser/api/entity/type/GeyserEntity.java | 9 + .../event/java/ServerSpawnEntityEvent.java | 84 +++ ...nt.java => GeyserDefineEntitiesEvent.java} | 22 +- .../java/org/geysermc/geyser/GeyserImpl.java | 4 +- .../entity/BedrockEntityDefinition.java | 26 +- ...inition.java => EntityTypeDefinition.java} | 12 +- .../entity/GeyserCustomEntityDefinition.java | 129 ---- .../GeyserCustomEntityTypeDefinition.java | 47 +- ...yDefinitions.java => VanillaEntities.java} | 642 +++++++++--------- ...nitionBase.java => VanillaEntityBase.java} | 14 +- ...tionBases.java => VanillaEntityBases.java} | 80 +-- ...Definition.java => VanillaEntityType.java} | 31 +- .../geyser/entity/factory/EntityFactory.java | 4 +- .../entity/type/AbstractArrowEntity.java | 4 +- .../entity/type/AbstractWindChargeEntity.java | 4 +- .../entity/type/AreaEffectCloudEntity.java | 4 +- .../geyser/entity/type/ArrowEntity.java | 4 +- .../geyser/entity/type/BoatEntity.java | 10 +- .../geyser/entity/type/ChestBoatEntity.java | 4 +- .../type/CommandBlockMinecartEntity.java | 4 +- .../type/DefaultBlockMinecartEntity.java | 4 +- .../geyser/entity/type/DisplayBaseEntity.java | 4 +- .../entity/type/EnderCrystalEntity.java | 4 +- .../geyser/entity/type/EnderEyeEntity.java | 4 +- .../geysermc/geyser/entity/type/Entity.java | 28 +- .../geyser/entity/type/EvokerFangsEntity.java | 4 +- .../geyser/entity/type/ExpOrbEntity.java | 4 +- .../entity/type/FallingBlockEntity.java | 4 +- .../geyser/entity/type/FireballEntity.java | 4 +- .../geyser/entity/type/FireworkEntity.java | 4 +- .../geyser/entity/type/FishingHookEntity.java | 4 +- .../entity/type/FurnaceMinecartEntity.java | 4 +- .../geyser/entity/type/HangingEntity.java | 4 +- .../geyser/entity/type/InteractionEntity.java | 8 +- .../geyser/entity/type/ItemEntity.java | 10 +- .../geyser/entity/type/ItemFrameEntity.java | 8 +- .../geyser/entity/type/LeashKnotEntity.java | 4 +- .../geyser/entity/type/LightningEntity.java | 4 +- .../geyser/entity/type/LivingEntity.java | 6 +- .../geyser/entity/type/MinecartEntity.java | 14 +- .../geyser/entity/type/PaintingEntity.java | 4 +- .../entity/type/SpawnerMinecartEntity.java | 4 +- .../geyser/entity/type/TNTEntity.java | 8 +- .../geyser/entity/type/TextDisplayEntity.java | 6 +- .../entity/type/ThrowableEggEntity.java | 5 +- .../geyser/entity/type/ThrowableEntity.java | 24 +- .../entity/type/ThrowableItemEntity.java | 10 +- .../entity/type/ThrownPotionEntity.java | 6 +- .../geyser/entity/type/TridentEntity.java | 4 +- .../geyser/entity/type/WitherSkullEntity.java | 8 +- .../type/living/AbstractFishEntity.java | 4 +- .../entity/type/living/AgeableEntity.java | 8 +- .../type/living/AgeableWaterEntity.java | 4 +- .../entity/type/living/AllayEntity.java | 4 +- .../entity/type/living/AmbientEntity.java | 4 +- .../entity/type/living/ArmorStandEntity.java | 14 +- .../geyser/entity/type/living/BatEntity.java | 4 +- .../entity/type/living/CopperGolemEntity.java | 4 +- .../entity/type/living/CreatureEntity.java | 4 +- .../entity/type/living/DolphinEntity.java | 4 +- .../entity/type/living/FlyingEntity.java | 4 +- .../entity/type/living/GlowSquidEntity.java | 4 +- .../entity/type/living/GolemEntity.java | 4 +- .../entity/type/living/IronGolemEntity.java | 4 +- .../entity/type/living/MagmaCubeEntity.java | 4 +- .../geyser/entity/type/living/MobEntity.java | 4 +- .../entity/type/living/SlimeEntity.java | 4 +- .../entity/type/living/SnowGolemEntity.java | 4 +- .../entity/type/living/SquidEntity.java | 4 +- .../entity/type/living/TadpoleEntity.java | 4 +- .../entity/type/living/WaterEntity.java | 4 +- .../type/living/animal/AnimalEntity.java | 4 +- .../type/living/animal/ArmadilloEntity.java | 4 +- .../type/living/animal/AxolotlEntity.java | 4 +- .../entity/type/living/animal/BeeEntity.java | 4 +- .../entity/type/living/animal/FoxEntity.java | 4 +- .../entity/type/living/animal/FrogEntity.java | 4 +- .../entity/type/living/animal/GoatEntity.java | 4 +- .../type/living/animal/HappyGhastEntity.java | 4 +- .../type/living/animal/HoglinEntity.java | 4 +- .../type/living/animal/MooshroomEntity.java | 4 +- .../type/living/animal/OcelotEntity.java | 4 +- .../type/living/animal/PandaEntity.java | 4 +- .../type/living/animal/PolarBearEntity.java | 4 +- .../type/living/animal/PufferFishEntity.java | 4 +- .../type/living/animal/RabbitEntity.java | 4 +- .../type/living/animal/SheepEntity.java | 4 +- .../type/living/animal/SnifferEntity.java | 8 +- .../type/living/animal/StriderEntity.java | 4 +- .../living/animal/TropicalFishEntity.java | 4 +- .../type/living/animal/TurtleEntity.java | 4 +- .../living/animal/farm/ChickenEntity.java | 4 +- .../type/living/animal/farm/CowEntity.java | 4 +- .../type/living/animal/farm/PigEntity.java | 4 +- .../animal/farm/TemperatureVariantAnimal.java | 4 +- .../animal/horse/AbstractHorseEntity.java | 4 +- .../type/living/animal/horse/CamelEntity.java | 8 +- .../animal/horse/ChestedHorseEntity.java | 4 +- .../type/living/animal/horse/HorseEntity.java | 4 +- .../type/living/animal/horse/LlamaEntity.java | 4 +- .../animal/horse/SkeletonHorseEntity.java | 4 +- .../animal/horse/TraderLlamaEntity.java | 4 +- .../animal/horse/ZombieHorseEntity.java | 4 +- .../living/animal/tameable/CatEntity.java | 4 +- .../living/animal/tameable/ParrotEntity.java | 4 +- .../animal/tameable/TameableEntity.java | 4 +- .../living/animal/tameable/WolfEntity.java | 4 +- .../merchant/AbstractMerchantEntity.java | 12 +- .../type/living/merchant/VillagerEntity.java | 4 +- .../monster/AbstractSkeletonEntity.java | 4 +- .../type/living/monster/BasePiglinEntity.java | 4 +- .../type/living/monster/BlazeEntity.java | 4 +- .../type/living/monster/BoggedEntity.java | 4 +- .../type/living/monster/BreezeEntity.java | 4 +- .../type/living/monster/CreakingEntity.java | 4 +- .../type/living/monster/CreeperEntity.java | 4 +- .../living/monster/ElderGuardianEntity.java | 4 +- .../living/monster/EnderDragonEntity.java | 4 +- .../living/monster/EnderDragonPartEntity.java | 4 +- .../type/living/monster/EndermanEntity.java | 4 +- .../type/living/monster/GhastEntity.java | 4 +- .../type/living/monster/GiantEntity.java | 4 +- .../type/living/monster/GuardianEntity.java | 4 +- .../type/living/monster/MonsterEntity.java | 4 +- .../type/living/monster/PhantomEntity.java | 10 +- .../type/living/monster/PiglinEntity.java | 4 +- .../type/living/monster/ShulkerEntity.java | 4 +- .../type/living/monster/SkeletonEntity.java | 4 +- .../type/living/monster/SpiderEntity.java | 4 +- .../entity/type/living/monster/VexEntity.java | 4 +- .../type/living/monster/WardenEntity.java | 4 +- .../type/living/monster/WitherEntity.java | 4 +- .../type/living/monster/ZoglinEntity.java | 6 +- .../type/living/monster/ZombieEntity.java | 4 +- .../living/monster/ZombieVillagerEntity.java | 4 +- .../living/monster/ZombifiedPiglinEntity.java | 4 +- .../monster/raid/AbstractIllagerEntity.java | 4 +- .../living/monster/raid/PillagerEntity.java | 4 +- .../monster/raid/RaidParticipantEntity.java | 4 +- .../living/monster/raid/RavagerEntity.java | 4 +- .../raid/SpellcasterIllagerEntity.java | 8 +- .../living/monster/raid/VindicatorEntity.java | 4 +- .../entity/type/player/AvatarEntity.java | 18 +- .../entity/type/player/MannequinEntity.java | 4 +- .../entity/type/player/PlayerEntity.java | 12 +- .../type/player/SessionPlayerEntity.java | 16 +- .../entity/type/player/SkullPlayerEntity.java | 10 +- .../entity/vehicle/VehicleComponent.java | 2 +- .../level/physics/CollisionManager.java | 4 +- .../geysermc/geyser/registry/Registries.java | 11 +- .../geyser/session/GeyserSession.java | 4 +- .../session/cache/BlockBreakHandler.java | 4 +- .../geyser/session/cache/WorldBorder.java | 6 +- .../MerchantInventoryTranslator.java | 4 +- .../entity/SpawnerBlockEntityTranslator.java | 8 +- .../TrialSpawnerBlockEntityTranslator.java | 6 +- ...BedrockInventoryTransactionTranslator.java | 6 +- .../player/input/BedrockMovePlayer.java | 8 +- .../BedrockPlayerAuthInputTranslator.java | 4 +- .../java/entity/JavaAddEntityTranslator.java | 57 +- .../entity/JavaEntityEventTranslator.java | 22 +- .../entity/JavaSetEntityDataTranslator.java | 8 +- .../entity/JavaSetEquipmentTranslator.java | 2 +- .../entity/JavaSetPassengersTranslator.java | 8 +- .../player/JavaPlayerPositionTranslator.java | 10 +- .../org/geysermc/geyser/util/EntityUtils.java | 29 +- core/src/main/resources/languages | 2 +- 170 files changed, 1080 insertions(+), 1017 deletions(-) create mode 100644 api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java rename api/src/main/java/org/geysermc/geyser/api/event/lifecycle/{GeyserDefineCustomEntitiesEvent.java => GeyserDefineEntitiesEvent.java} (77%) rename core/src/main/java/org/geysermc/geyser/entity/{EntityDefinition.java => EntityTypeDefinition.java} (89%) delete mode 100644 core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java rename api/src/main/java/org/geysermc/geyser/api/predicate/context/entity/EntitySpawnContext.java => core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityTypeDefinition.java (53%) rename core/src/main/java/org/geysermc/geyser/entity/{EntityDefinitions.java => VanillaEntities.java} (69%) rename core/src/main/java/org/geysermc/geyser/entity/{EntityDefinitionBase.java => VanillaEntityBase.java} (91%) rename core/src/main/java/org/geysermc/geyser/entity/{EntityDefinitionBases.java => VanillaEntityBases.java} (72%) rename core/src/main/java/org/geysermc/geyser/entity/{VanillaEntityDefinition.java => VanillaEntityType.java} (85%) diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/GeyserEntityDefinition.java b/api/src/main/java/org/geysermc/geyser/api/entity/GeyserEntityDefinition.java index 7b8cb8965ee..3d6514e1701 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/GeyserEntityDefinition.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/GeyserEntityDefinition.java @@ -25,8 +25,11 @@ package org.geysermc.geyser.api.entity; +import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.util.Identifier; +import java.util.List; + /** * Represents a Bedrock entity definition. */ @@ -37,6 +40,11 @@ public interface GeyserEntityDefinition { */ Identifier identifier(); + /** + * @return the properties registered for this entity type + */ + List> properties(); + /** * @return the width of the entity */ @@ -55,4 +63,9 @@ public interface GeyserEntityDefinition { * @return the offset of the entity */ float offset(); + + /** + * @return whether this entity is a vanilla entity + */ + boolean vanilla(); } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java index 3f228b85848..2f84372f2f7 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java @@ -25,9 +25,6 @@ package org.geysermc.geyser.api.entity; -import org.checkerframework.checker.index.qual.NonNegative; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.geysermc.geyser.api.GeyserApi; import org.geysermc.geyser.api.util.Identifier; /** @@ -59,13 +56,4 @@ public interface JavaEntityType { default boolean is(Identifier javaIdentifier) { return identifier().equals(javaIdentifier); } - - static JavaEntityType ofVanilla(@NonNull Identifier javaIdentifier) { - return GeyserApi.api().provider(JavaEntityType.class, javaIdentifier); - } - - // TODO move to event??? - static JavaEntityType createAndRegister(@NonNull Identifier javaIdentifier, @NonNegative int javaId) { - return GeyserApi.api().provider(JavaEntityType.class, javaIdentifier, javaId); - } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java index 2e299cf32a1..0b7a50bccb8 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java @@ -30,33 +30,71 @@ import org.checkerframework.common.returnsreceiver.qual.This; import org.geysermc.geyser.api.GeyserApi; import org.geysermc.geyser.api.entity.GeyserEntityDefinition; -import org.geysermc.geyser.api.entity.JavaEntityType; import org.geysermc.geyser.api.util.Identifier; /** - * Represents a custom entity definition + * Represents a custom entity definition. */ -public interface CustomEntityDefinition extends GeyserEntityDefinition, PredicateHolder { +public interface CustomEntityDefinition extends GeyserEntityDefinition { - static Builder builder(@NonNull Identifier bedrockIdentifier, @NonNull JavaEntityType vanillaType) { - return GeyserApi.api().provider(Builder.class, bedrockIdentifier, vanillaType); + @Override + default boolean vanilla() { + return false; + } + + /** + * Creates a builder for a custom entity definition. + * + * @param bedrockIdentifier the Bedrock entity identifier + * @return a new builder + */ + static Builder builder(@NonNull Identifier bedrockIdentifier) { + return GeyserApi.api().provider(Builder.class, bedrockIdentifier); } interface Builder { + /** + * Sets the width of this entity. + * + * @param width the width of this entity + * @return the builder + */ @This Builder width(@Positive float width); + /** + * Sets the height of this entity. + * + * @param height the height of this entity + * @return the builder + */ @This Builder height(@Positive float height); + /** + * Sets the height and with of this entity. + * + * @param value the width and height + * @return the builder + */ @This Builder heightAndWidth(@Positive float value); + /** + * Sets the offset of this entity. + * + * @param offset the offset of this entity + * @return the builder + */ @This Builder offset(@Positive float offset); - @Override + /** + * Builds the entity definition. + * + * @return the entity definition + */ CustomEntityDefinition build(); } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java b/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java index 6e312229d17..86fa9d8faa0 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java @@ -30,6 +30,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.api.connection.GeyserConnection; +import org.geysermc.geyser.api.entity.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.property.BatchPropertyUpdater; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntityPropertiesEvent; @@ -55,6 +56,14 @@ public interface GeyserEntity { UUID uuid(); /** + * @return the Bedrock entity definition + */ + GeyserEntityDefinition definition(); + + /** + * The position of this entity, without the Bedrock edition offset + * defined in the Bedrock entity definition. + * * @return the position of the entity, as it is known to the Java server. */ Vector3f position(); diff --git a/api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java new file mode 100644 index 00000000000..e165feeaebf --- /dev/null +++ b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.api.event.java; + +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.geysermc.geyser.api.connection.GeyserConnection; +import org.geysermc.geyser.api.entity.GeyserEntityDefinition; +import org.geysermc.geyser.api.entity.JavaEntityType; +import org.geysermc.geyser.api.event.connection.ConnectionEvent; +import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; + +import java.util.UUID; + +/** + * Called when the downstream server spawns an entity. + */ +public abstract class ServerSpawnEntityEvent extends ConnectionEvent { + + public ServerSpawnEntityEvent(@NonNull GeyserConnection connection) { + super(connection); + } + + /** + * Gets the entity id of the entity being spawned. + * + * @return the entity id of the entity being spawned + */ + public abstract int entityId(); + + /** + * Gets the uuid of the entity being spawned. + * + * @return the uuid of the entity being spawned + */ + public abstract @NonNull UUID uuid(); + + /** + * Gets the Java entity type sent by the server + * + * @return the Java edition entity type of the entity being spawned + */ + public abstract @NonNull JavaEntityType entityType(); + + /** + * Gets the entity definition sent to the connection when the entity is spawned. + * + * @return the entity definition sent to the connection when the entity is spawned + */ + public abstract @Nullable GeyserEntityDefinition entityDefinition(); + + /** + * Sets the entity definition sent to the connection when the entity is spawned. + * This entity definition MUST have been registered in the {@link GeyserDefineEntitiesEvent} before + * using it here! + * + * @param entityDefinition the entity definition sent to the connection when the entity is spawned + */ + public abstract void entityDefinition(@Nullable GeyserEntityDefinition entityDefinition); + +} diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomEntitiesEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java similarity index 77% rename from api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomEntitiesEvent.java rename to api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java index d49d8d028ae..8e6e1e9dd70 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomEntitiesEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java @@ -28,8 +28,8 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.event.Event; import org.geysermc.geyser.api.entity.GeyserEntityDefinition; -import org.geysermc.geyser.api.entity.JavaEntityType; import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; +import org.geysermc.geyser.api.util.Identifier; import java.util.Collection; @@ -40,14 +40,12 @@ * Entity definitions can be created using the builder provided * inside of {@link GeyserEntityDefinition}. */ -public interface GeyserDefineCustomEntitiesEvent extends Event { +public interface GeyserDefineEntitiesEvent extends Event { /** - * Gets an immutable list of registered custom entity definitions. - * - * @return an immutable collection of registered custom entity definitions + * @return an immutable collection of all registered entity definitions */ - Collection customEntities(); + Collection entities(); /** * Registers a custom entity definition from its builder @@ -57,11 +55,17 @@ default void register(CustomEntityDefinition.Builder builder) { register(builder.build()); } + /** + * Registers a custom entity definition + * @param customEntityDefinition the custom entity definition to register + */ void register(@NonNull CustomEntityDefinition customEntityDefinition); /** - * Registers a non-vanilla entity type - * @param javaEntityType + * Registers a non-vanilla Java entity type. + * + * @param javaEntityType the identifier of the Java entity type + * @param javaId the network id of this entity type */ - void register(@NonNull JavaEntityType javaEntityType); + void registerEntityType(@NonNull Identifier javaEntityType, int javaId); } diff --git a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java index ed9d6c90cbb..d40a11626d7 100644 --- a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java +++ b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java @@ -73,7 +73,7 @@ import org.geysermc.geyser.command.CommandRegistry; import org.geysermc.geyser.configuration.GeyserConfig; import org.geysermc.geyser.configuration.GeyserPluginConfig; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.erosion.UnixSocketClientListener; import org.geysermc.geyser.event.GeyserEventBus; import org.geysermc.geyser.event.type.SessionDisconnectEventImpl; @@ -252,7 +252,7 @@ public void initialize() { RegistryCache.init(); /* Initialize translators */ - EntityDefinitions.init(); + VanillaEntities.init(); MessageTranslator.init(); // Download the latest asset list and cache it diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java index a1ac8a50018..5b79994312c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java @@ -29,21 +29,24 @@ import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.api.entity.GeyserEntityDefinition; +import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.util.Identifier; import org.geysermc.geyser.entity.properties.GeyserEntityProperties; +import java.util.List; + @Getter @Accessors(fluent = true) public class BedrockEntityDefinition implements GeyserEntityDefinition { - - private final Identifier identifier; - private final GeyserEntityProperties registeredProperties; + private final @NonNull Identifier identifier; + private final @NonNull GeyserEntityProperties registeredProperties; private final float width; private final float height; private final float offset; - public BedrockEntityDefinition(Identifier identifier, GeyserEntityProperties registeredProperties, float width, float height, float offset) { + public BedrockEntityDefinition(@NonNull Identifier identifier, @NonNull GeyserEntityProperties registeredProperties, float width, float height, float offset) { this.identifier = identifier; this.registeredProperties = registeredProperties; this.width = width; @@ -55,6 +58,19 @@ public static Builder builder() { return new Builder(); } + @Override + public List> properties() { + if (registeredProperties.isEmpty()) { + return List.of(); + } + return List.copyOf(registeredProperties.getProperties()); + } + + @Override + public boolean vanilla() { + return identifier.vanilla(); + } + public static class Builder { private Identifier identifier; private float width; @@ -92,7 +108,7 @@ public Builder properties(GeyserEntityProperties.Builder propertiesBuilder) { } BedrockEntityDefinition build() { - return new BedrockEntityDefinition(identifier, propertiesBuilder != null ? propertiesBuilder.build() : null, width, height, offset); + return new BedrockEntityDefinition(identifier, propertiesBuilder != null ? propertiesBuilder.build() : new GeyserEntityProperties(), width, height, offset); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/EntityTypeDefinition.java similarity index 89% rename from core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java rename to core/src/main/java/org/geysermc/geyser/entity/EntityTypeDefinition.java index 2529271afb4..e990d4ba73e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityTypeDefinition.java @@ -54,23 +54,23 @@ @Accessors(fluent = true) @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public abstract class EntityDefinition extends EntityDefinitionBase { +public abstract class EntityTypeDefinition extends VanillaEntityBase { private final EntityFactory factory; private final GeyserEntityType type; - private BedrockEntityDefinition bedrockDefinition; + private final BedrockEntityDefinition defaultBedrockDefinition; - public EntityDefinition(EntityFactory factory, GeyserEntityType type, BedrockEntityDefinition bedrockDefinition, List> translators) { - super(bedrockDefinition.width(), bedrockDefinition.height(), bedrockDefinition.offset(), translators); + public EntityTypeDefinition(EntityFactory factory, GeyserEntityType type, BedrockEntityDefinition defaultBedrockDefinition, List> translators) { + super(defaultBedrockDefinition.width(), defaultBedrockDefinition.height(), defaultBedrockDefinition.offset(), translators); this.type = type; this.factory = factory; - this.bedrockDefinition = bedrockDefinition; + this.defaultBedrockDefinition = defaultBedrockDefinition; } public abstract boolean is(BuiltinEntityType builtinEntityType); @Setter @Accessors(fluent = true, chain = true) - public static abstract class Builder extends EntityDefinitionBase.Builder { + public static abstract class Builder extends VanillaEntityBase.Builder { protected final EntityFactory factory; protected String bedrockIdentifier; @Setter(AccessLevel.NONE) diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java deleted file mode 100644 index 8fb656b8174..00000000000 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityDefinition.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2025 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.geyser.entity; - -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; -import lombok.experimental.Accessors; -import org.geysermc.geyser.api.predicate.MinecraftPredicate; -import org.geysermc.geyser.api.predicate.PredicateStrategy; -import org.geysermc.geyser.api.predicate.context.entity.EntitySpawnPredicateContext; -import org.geysermc.geyser.entity.factory.EntityFactory; -import org.geysermc.geyser.entity.type.Entity; -import org.geysermc.geyser.translator.entity.EntityMetadataTranslator; -import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; - -import java.util.List; - -@Getter -@Accessors(fluent = true) -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -// TODO CHANGE TO ONLY APPLY THIS TO NON-VANILLA TYPES! -public class GeyserCustomEntityDefinition extends EntityDefinition { - private final List> predicates; - private final PredicateStrategy predicateStrategy; - - public GeyserCustomEntityDefinition(EntityFactory factory, GeyserEntityType type, List> predicates, PredicateStrategy predicateStrategy, - BedrockEntityDefinition definition, List> translators) { - super(factory, type, definition, translators); - this.predicates = predicates; - this.predicateStrategy = predicateStrategy; - } - - @Override - public boolean is(BuiltinEntityType builtinEntityType) { - return false; - } - - // TODO this is relevant for nonvanilla; entity definitions are now split up -// public static Builder inherited(String bedrockIdentifier, JavaEntityType vanillaType) { -// if (!vanillaType.vanilla()) { -// throw new IllegalArgumentException("vanillaType must be a vanilla entity type, was: " + vanillaType); -// } -// VanillaEntityDefinition parent = Registries.ENTITY_DEFINITIONS.get(vanillaType); -// if (parent == null) { -// throw new IllegalArgumentException("No vanilla entity definition registered for vanilla entity type " + vanillaType); -// } -// // TODO fix the rawtypes/unchecked -// return new Builder<>(bedrockIdentifier, parent.factory(), parent.width(), parent.height(), parent.offset(), new ObjectArrayList(parent.translators())); -// } - - // TODO -// public static class Builder extends EntityDefinition.Builder implements CustomEntityDefinition.Builder { -// protected List> predicates; -// protected PredicateStrategy predicateStrategy = PredicateStrategy.AND; -// -// protected Builder(EntityFactory factory, String bedrockIdentifier) { -// super(factory); -// this.bedrockIdentifier = Objects.requireNonNull(bedrockIdentifier, "bedrockIdentifier must not be null"); -// } -// -// protected Builder(String bedrockIdentifier, EntityFactory factory, float width, float height, float offset, List> translators) { -// super(factory, width, height, offset, translators); -// this.bedrockIdentifier = Objects.requireNonNull(bedrockIdentifier, "bedrockIdentifier must not be null"); -// } -// -// @Override -// public EntityDefinition.Builder bedrockIdentifier(String bedrockIdentifier) { -// throw new UnsupportedOperationException("bedrockIdentifier should be immutable"); -// } -// -// public Builder predicate(@NonNull MinecraftPredicate predicate) { -// predicates.add(Objects.requireNonNull(predicate, "predicate must not be null")); -// return this; -// } -// -// public Builder predicateStrategy(@NonNull PredicateStrategy strategy) { -// predicateStrategy = Objects.requireNonNull(strategy, "strategy must not be null"); -// return this; -// } -// -// @Override -// public Builder property(PropertyType propertyType) { -// return (Builder) super.property(propertyType); -// } -// -// @Override -// public >> Builder addTranslator(MetadataType type, BiConsumer translateFunction) { -// return (Builder) super.addTranslator(type, translateFunction); -// } -// -// @Override -// public Builder addTranslator(EntityMetadataTranslator translator) { -// return (Builder) super.addTranslator(translator); -// } -// -// @Override -// public GeyserCustomEntityDefinition build() { -// if (predicates.isEmpty()) { -// throw new IllegalStateException("predicates must not be empty!"); -// } -// return new GeyserCustomEntityDefinition<>(factory, type, predicates, predicateStrategy, bedrockDefinition, translators); -// } -// } -} diff --git a/api/src/main/java/org/geysermc/geyser/api/predicate/context/entity/EntitySpawnContext.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityTypeDefinition.java similarity index 53% rename from api/src/main/java/org/geysermc/geyser/api/predicate/context/entity/EntitySpawnContext.java rename to core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityTypeDefinition.java index 8072e25fcf8..3314a46ec84 100644 --- a/api/src/main/java/org/geysermc/geyser/api/predicate/context/entity/EntitySpawnContext.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityTypeDefinition.java @@ -23,20 +23,35 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.geyser.api.predicate.context.entity; - -import org.geysermc.geyser.api.entity.JavaEntityType; -import org.geysermc.geyser.api.predicate.context.MinecraftPredicateContext; - -import java.util.UUID; - -public interface EntitySpawnContext extends MinecraftPredicateContext { - - JavaEntityType entityType(); - - int entityId(); - - UUID entityUuid(); - - int data(); +package org.geysermc.geyser.entity; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +import lombok.experimental.Accessors; +import org.geysermc.geyser.entity.factory.EntityFactory; +import org.geysermc.geyser.entity.type.Entity; +import org.geysermc.geyser.translator.entity.EntityMetadataTranslator; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; + +import java.util.List; + +@Getter +@Accessors(fluent = true) +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +// TODO CHANGE TO ONLY APPLY THIS TO NON-VANILLA TYPES! +public class GeyserCustomEntityTypeDefinition extends EntityTypeDefinition { + + public GeyserCustomEntityTypeDefinition(EntityFactory factory, GeyserEntityType type, BedrockEntityDefinition definition, List> translators) { + super(factory, type, definition, translators); + } + + @Override + public boolean is(BuiltinEntityType builtinEntityType) { + return false; + } + + // TODO: + // - handle } diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntities.java similarity index 69% rename from core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java rename to core/src/main/java/org/geysermc/geyser/entity/VanillaEntities.java index d85caa022ab..6140b971d36 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntities.java @@ -30,12 +30,12 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.GeyserImpl; -import org.geysermc.geyser.api.entity.JavaEntityType; +import org.geysermc.geyser.api.entity.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.entity.property.type.GeyserFloatEntityProperty; import org.geysermc.geyser.api.entity.property.type.GeyserStringEnumProperty; -import org.geysermc.geyser.api.event.lifecycle.GeyserDefineCustomEntitiesEvent; +import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntityPropertiesEvent; import org.geysermc.geyser.api.util.Identifier; import org.geysermc.geyser.entity.factory.EntityFactory; @@ -176,171 +176,174 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Objects; -public final class EntityDefinitions { - public static final VanillaEntityDefinition ACACIA_BOAT; - public static final VanillaEntityDefinition ACACIA_CHEST_BOAT; - public static final VanillaEntityDefinition ALLAY; - public static final VanillaEntityDefinition AREA_EFFECT_CLOUD; - public static final VanillaEntityDefinition ARMADILLO; - public static final VanillaEntityDefinition ARMOR_STAND; - public static final VanillaEntityDefinition ARROW; - public static final VanillaEntityDefinition AXOLOTL; - public static final VanillaEntityDefinition BAMBOO_RAFT; - public static final VanillaEntityDefinition BAMBOO_CHEST_RAFT; - public static final VanillaEntityDefinition BAT; - public static final VanillaEntityDefinition BEE; - public static final VanillaEntityDefinition BIRCH_BOAT; - public static final VanillaEntityDefinition BIRCH_CHEST_BOAT; - public static final VanillaEntityDefinition BLAZE; - public static final VanillaEntityDefinition BOGGED; - public static final VanillaEntityDefinition BREEZE; - public static final VanillaEntityDefinition BREEZE_WIND_CHARGE; - public static final VanillaEntityDefinition CAMEL; - public static final VanillaEntityDefinition CAT; - public static final VanillaEntityDefinition CAVE_SPIDER; - public static final VanillaEntityDefinition CHERRY_BOAT; - public static final VanillaEntityDefinition CHERRY_CHEST_BOAT; - public static final VanillaEntityDefinition CHEST_MINECART; - public static final VanillaEntityDefinition CHICKEN; - public static final VanillaEntityDefinition COD; - public static final VanillaEntityDefinition COPPER_GOLEM; - public static final VanillaEntityDefinition COMMAND_BLOCK_MINECART; - public static final VanillaEntityDefinition COW; - public static final VanillaEntityDefinition CREAKING; - public static final VanillaEntityDefinition CREEPER; - public static final VanillaEntityDefinition DARK_OAK_BOAT; - public static final VanillaEntityDefinition DARK_OAK_CHEST_BOAT; - public static final VanillaEntityDefinition DOLPHIN; - public static final VanillaEntityDefinition DONKEY; - public static final VanillaEntityDefinition DRAGON_FIREBALL; - public static final VanillaEntityDefinition DROWNED; - public static final VanillaEntityDefinition EGG; - public static final VanillaEntityDefinition ELDER_GUARDIAN; - public static final VanillaEntityDefinition ENDERMAN; - public static final VanillaEntityDefinition ENDERMITE; - public static final VanillaEntityDefinition ENDER_DRAGON; - public static final VanillaEntityDefinition ENDER_PEARL; - public static final VanillaEntityDefinition END_CRYSTAL; - public static final VanillaEntityDefinition EVOKER; - public static final VanillaEntityDefinition EVOKER_FANGS; - public static final VanillaEntityDefinition EXPERIENCE_BOTTLE; - public static final VanillaEntityDefinition EXPERIENCE_ORB; - public static final VanillaEntityDefinition EYE_OF_ENDER; - public static final VanillaEntityDefinition FALLING_BLOCK; - public static final VanillaEntityDefinition FIREBALL; - public static final VanillaEntityDefinition FIREWORK_ROCKET; - public static final VanillaEntityDefinition FISHING_BOBBER; - public static final VanillaEntityDefinition FOX; - public static final VanillaEntityDefinition FROG; - public static final VanillaEntityDefinition FURNACE_MINECART; // Not present on Bedrock - public static final VanillaEntityDefinition GHAST; - public static final VanillaEntityDefinition GIANT; - public static final VanillaEntityDefinition GLOW_ITEM_FRAME; - public static final VanillaEntityDefinition GLOW_SQUID; - public static final VanillaEntityDefinition GOAT; - public static final VanillaEntityDefinition GUARDIAN; - public static final VanillaEntityDefinition HAPPY_GHAST; - public static final VanillaEntityDefinition HOGLIN; - public static final VanillaEntityDefinition HOPPER_MINECART; - public static final VanillaEntityDefinition HORSE; - public static final VanillaEntityDefinition HUSK; - public static final VanillaEntityDefinition ILLUSIONER; // Not present on Bedrock - public static final VanillaEntityDefinition INTERACTION; - public static final VanillaEntityDefinition IRON_GOLEM; - public static final VanillaEntityDefinition ITEM; - public static final VanillaEntityDefinition ITEM_FRAME; - public static final VanillaEntityDefinition JUNGLE_BOAT; - public static final VanillaEntityDefinition JUNGLE_CHEST_BOAT; - public static final VanillaEntityDefinition LEASH_KNOT; - public static final VanillaEntityDefinition LIGHTNING_BOLT; - public static final VanillaEntityDefinition LLAMA; - public static final VanillaEntityDefinition LLAMA_SPIT; - public static final VanillaEntityDefinition MAGMA_CUBE; - public static final VanillaEntityDefinition MANGROVE_BOAT; - public static final VanillaEntityDefinition MANGROVE_CHEST_BOAT; - public static final VanillaEntityDefinition MANNEQUIN; - public static final VanillaEntityDefinition MINECART; - public static final VanillaEntityDefinition MOOSHROOM; - public static final VanillaEntityDefinition MULE; - public static final VanillaEntityDefinition OAK_BOAT; - public static final VanillaEntityDefinition OAK_CHEST_BOAT; - public static final VanillaEntityDefinition OCELOT; - public static final VanillaEntityDefinition PAINTING; - public static final VanillaEntityDefinition PALE_OAK_BOAT; - public static final VanillaEntityDefinition PALE_OAK_CHEST_BOAT; - public static final VanillaEntityDefinition PANDA; - public static final VanillaEntityDefinition PARROT; - public static final VanillaEntityDefinition PHANTOM; - public static final VanillaEntityDefinition PIG; - public static final VanillaEntityDefinition PIGLIN; - public static final VanillaEntityDefinition PIGLIN_BRUTE; - public static final VanillaEntityDefinition PILLAGER; - public static final VanillaEntityDefinition PLAYER; - public static final VanillaEntityDefinition POLAR_BEAR; - public static final VanillaEntityDefinition SPLASH_POTION; - public static final VanillaEntityDefinition LINGERING_POTION; - public static final VanillaEntityDefinition PUFFERFISH; - public static final VanillaEntityDefinition RABBIT; - public static final VanillaEntityDefinition RAVAGER; - public static final VanillaEntityDefinition SALMON; - public static final VanillaEntityDefinition SHEEP; - public static final VanillaEntityDefinition SHULKER; - public static final VanillaEntityDefinition SNIFFER; - public static final VanillaEntityDefinition SHULKER_BULLET; - public static final VanillaEntityDefinition SILVERFISH; - public static final VanillaEntityDefinition SKELETON; - public static final VanillaEntityDefinition SKELETON_HORSE; - public static final VanillaEntityDefinition SLIME; - public static final VanillaEntityDefinition SMALL_FIREBALL; - public static final VanillaEntityDefinition SNOWBALL; - public static final VanillaEntityDefinition SNOW_GOLEM; - public static final VanillaEntityDefinition SPAWNER_MINECART; // Not present on Bedrock - public static final VanillaEntityDefinition SPECTRAL_ARROW; - public static final VanillaEntityDefinition SPIDER; - public static final VanillaEntityDefinition SPRUCE_BOAT; - public static final VanillaEntityDefinition SPRUCE_CHEST_BOAT; - public static final VanillaEntityDefinition SQUID; - public static final VanillaEntityDefinition STRAY; - public static final VanillaEntityDefinition STRIDER; - public static final VanillaEntityDefinition TADPOLE; - public static final VanillaEntityDefinition TEXT_DISPLAY; - public static final VanillaEntityDefinition TNT; - public static final VanillaEntityDefinition TNT_MINECART; - public static final VanillaEntityDefinition TRADER_LLAMA; - public static final VanillaEntityDefinition TRIDENT; - public static final VanillaEntityDefinition TROPICAL_FISH; - public static final VanillaEntityDefinition TURTLE; - public static final VanillaEntityDefinition VEX; - public static final VanillaEntityDefinition VILLAGER; - public static final VanillaEntityDefinition VINDICATOR; - public static final VanillaEntityDefinition WANDERING_TRADER; - public static final VanillaEntityDefinition WARDEN; - public static final VanillaEntityDefinition WIND_CHARGE; - public static final VanillaEntityDefinition WITCH; - public static final VanillaEntityDefinition WITHER; - public static final VanillaEntityDefinition WITHER_SKELETON; - public static final VanillaEntityDefinition WITHER_SKULL; - public static final VanillaEntityDefinition WOLF; - public static final VanillaEntityDefinition ZOGLIN; - public static final VanillaEntityDefinition ZOMBIE; - public static final VanillaEntityDefinition ZOMBIE_HORSE; - public static final VanillaEntityDefinition ZOMBIE_VILLAGER; - public static final VanillaEntityDefinition ZOMBIFIED_PIGLIN; +public final class VanillaEntities { + public static final VanillaEntityType ACACIA_BOAT; + public static final VanillaEntityType ACACIA_CHEST_BOAT; + public static final VanillaEntityType ALLAY; + public static final VanillaEntityType AREA_EFFECT_CLOUD; + public static final VanillaEntityType ARMADILLO; + public static final VanillaEntityType ARMOR_STAND; + public static final VanillaEntityType ARROW; + public static final VanillaEntityType AXOLOTL; + public static final VanillaEntityType BAMBOO_RAFT; + public static final VanillaEntityType BAMBOO_CHEST_RAFT; + public static final VanillaEntityType BAT; + public static final VanillaEntityType BEE; + public static final VanillaEntityType BIRCH_BOAT; + public static final VanillaEntityType BIRCH_CHEST_BOAT; + public static final VanillaEntityType BLAZE; + public static final VanillaEntityType BOGGED; + public static final VanillaEntityType BREEZE; + public static final VanillaEntityType BREEZE_WIND_CHARGE; + public static final VanillaEntityType CAMEL; + public static final VanillaEntityType CAT; + public static final VanillaEntityType CAVE_SPIDER; + public static final VanillaEntityType CHERRY_BOAT; + public static final VanillaEntityType CHERRY_CHEST_BOAT; + public static final VanillaEntityType CHEST_MINECART; + public static final VanillaEntityType CHICKEN; + public static final VanillaEntityType COD; + public static final VanillaEntityType COPPER_GOLEM; + public static final VanillaEntityType COMMAND_BLOCK_MINECART; + public static final VanillaEntityType COW; + public static final VanillaEntityType CREAKING; + public static final VanillaEntityType CREEPER; + public static final VanillaEntityType DARK_OAK_BOAT; + public static final VanillaEntityType DARK_OAK_CHEST_BOAT; + public static final VanillaEntityType DOLPHIN; + public static final VanillaEntityType DONKEY; + public static final VanillaEntityType DRAGON_FIREBALL; + public static final VanillaEntityType DROWNED; + public static final VanillaEntityType EGG; + public static final VanillaEntityType ELDER_GUARDIAN; + public static final VanillaEntityType ENDERMAN; + public static final VanillaEntityType ENDERMITE; + public static final VanillaEntityType ENDER_DRAGON; + public static final VanillaEntityType ENDER_PEARL; + public static final VanillaEntityType END_CRYSTAL; + public static final VanillaEntityType EVOKER; + public static final VanillaEntityType EVOKER_FANGS; + public static final VanillaEntityType EXPERIENCE_BOTTLE; + public static final VanillaEntityType EXPERIENCE_ORB; + public static final VanillaEntityType EYE_OF_ENDER; + public static final VanillaEntityType FALLING_BLOCK; + public static final VanillaEntityType FIREBALL; + public static final VanillaEntityType FIREWORK_ROCKET; + public static final VanillaEntityType FISHING_BOBBER; + public static final VanillaEntityType FOX; + public static final VanillaEntityType FROG; + public static final VanillaEntityType FURNACE_MINECART; // Not present on Bedrock + public static final VanillaEntityType GHAST; + public static final VanillaEntityType GIANT; + public static final VanillaEntityType GLOW_ITEM_FRAME; + public static final VanillaEntityType GLOW_SQUID; + public static final VanillaEntityType GOAT; + public static final VanillaEntityType GUARDIAN; + public static final VanillaEntityType HAPPY_GHAST; + public static final VanillaEntityType HOGLIN; + public static final VanillaEntityType HOPPER_MINECART; + public static final VanillaEntityType HORSE; + public static final VanillaEntityType HUSK; + public static final VanillaEntityType ILLUSIONER; // Not present on Bedrock + public static final VanillaEntityType INTERACTION; + public static final VanillaEntityType IRON_GOLEM; + public static final VanillaEntityType ITEM; + public static final VanillaEntityType ITEM_FRAME; + public static final VanillaEntityType JUNGLE_BOAT; + public static final VanillaEntityType JUNGLE_CHEST_BOAT; + public static final VanillaEntityType LEASH_KNOT; + public static final VanillaEntityType LIGHTNING_BOLT; + public static final VanillaEntityType LLAMA; + public static final VanillaEntityType LLAMA_SPIT; + public static final VanillaEntityType MAGMA_CUBE; + public static final VanillaEntityType MANGROVE_BOAT; + public static final VanillaEntityType MANGROVE_CHEST_BOAT; + public static final VanillaEntityType MANNEQUIN; + public static final VanillaEntityType MINECART; + public static final VanillaEntityType MOOSHROOM; + public static final VanillaEntityType MULE; + public static final VanillaEntityType OAK_BOAT; + public static final VanillaEntityType OAK_CHEST_BOAT; + public static final VanillaEntityType OCELOT; + public static final VanillaEntityType PAINTING; + public static final VanillaEntityType PALE_OAK_BOAT; + public static final VanillaEntityType PALE_OAK_CHEST_BOAT; + public static final VanillaEntityType PANDA; + public static final VanillaEntityType PARROT; + public static final VanillaEntityType PHANTOM; + public static final VanillaEntityType PIG; + public static final VanillaEntityType PIGLIN; + public static final VanillaEntityType PIGLIN_BRUTE; + public static final VanillaEntityType PILLAGER; + public static final VanillaEntityType PLAYER; + public static final VanillaEntityType POLAR_BEAR; + public static final VanillaEntityType SPLASH_POTION; + public static final VanillaEntityType LINGERING_POTION; + public static final VanillaEntityType PUFFERFISH; + public static final VanillaEntityType RABBIT; + public static final VanillaEntityType RAVAGER; + public static final VanillaEntityType SALMON; + public static final VanillaEntityType SHEEP; + public static final VanillaEntityType SHULKER; + public static final VanillaEntityType SNIFFER; + public static final VanillaEntityType SHULKER_BULLET; + public static final VanillaEntityType SILVERFISH; + public static final VanillaEntityType SKELETON; + public static final VanillaEntityType SKELETON_HORSE; + public static final VanillaEntityType SLIME; + public static final VanillaEntityType SMALL_FIREBALL; + public static final VanillaEntityType SNOWBALL; + public static final VanillaEntityType SNOW_GOLEM; + public static final VanillaEntityType SPAWNER_MINECART; // Not present on Bedrock + public static final VanillaEntityType SPECTRAL_ARROW; + public static final VanillaEntityType SPIDER; + public static final VanillaEntityType SPRUCE_BOAT; + public static final VanillaEntityType SPRUCE_CHEST_BOAT; + public static final VanillaEntityType SQUID; + public static final VanillaEntityType STRAY; + public static final VanillaEntityType STRIDER; + public static final VanillaEntityType TADPOLE; + public static final VanillaEntityType TEXT_DISPLAY; + public static final VanillaEntityType TNT; + public static final VanillaEntityType TNT_MINECART; + public static final VanillaEntityType TRADER_LLAMA; + public static final VanillaEntityType TRIDENT; + public static final VanillaEntityType TROPICAL_FISH; + public static final VanillaEntityType TURTLE; + public static final VanillaEntityType VEX; + public static final VanillaEntityType VILLAGER; + public static final VanillaEntityType VINDICATOR; + public static final VanillaEntityType WANDERING_TRADER; + public static final VanillaEntityType WARDEN; + public static final VanillaEntityType WIND_CHARGE; + public static final VanillaEntityType WITCH; + public static final VanillaEntityType WITHER; + public static final VanillaEntityType WITHER_SKELETON; + public static final VanillaEntityType WITHER_SKULL; + public static final VanillaEntityType WOLF; + public static final VanillaEntityType ZOGLIN; + public static final VanillaEntityType ZOMBIE; + public static final VanillaEntityType ZOMBIE_HORSE; + public static final VanillaEntityType ZOMBIE_VILLAGER; + public static final VanillaEntityType ZOMBIFIED_PIGLIN; /** * Is not sent over the network */ - public static final VanillaEntityDefinition ENDER_DRAGON_PART; + public static final VanillaEntityType ENDER_DRAGON_PART; /** * Special Bedrock type */ - public static final VanillaEntityDefinition WITHER_SKULL_DANGEROUS; + public static final VanillaEntityType WITHER_SKULL_DANGEROUS; + + public static final float PLAYER_ENTITY_OFFSET; static { - EntityDefinitionBase entityBase = EntityDefinition.baseBuilder(Entity.class) + VanillaEntityBase entityBase = EntityTypeDefinition.baseBuilder(Entity.class) .addTranslator(MetadataTypes.BYTE, Entity::setFlags) .addTranslator(MetadataTypes.INT, Entity::setAir) // Air/bubbles .addTranslator(MetadataTypes.OPTIONAL_COMPONENT, Entity::setDisplayName) @@ -353,18 +356,18 @@ public final class EntityDefinitions { // Extends entity { - AREA_EFFECT_CLOUD = VanillaEntityDefinition.inherited(AreaEffectCloudEntity::new, entityBase) + AREA_EFFECT_CLOUD = VanillaEntityType.inherited(AreaEffectCloudEntity::new, entityBase) .type(BuiltinEntityType.AREA_EFFECT_CLOUD) .height(0.5f).width(1.0f) .addTranslator(MetadataTypes.FLOAT, AreaEffectCloudEntity::setRadius) .addTranslator(null) // Waiting .addTranslator(MetadataTypes.PARTICLE, AreaEffectCloudEntity::setParticle) .build(); - DRAGON_FIREBALL = VanillaEntityDefinition.inherited(FireballEntity::new, entityBase) + DRAGON_FIREBALL = VanillaEntityType.inherited(FireballEntity::new, entityBase) .type(BuiltinEntityType.DRAGON_FIREBALL) .heightAndWidth(1.0f) .build(); - END_CRYSTAL = VanillaEntityDefinition.inherited(EnderCrystalEntity::new, entityBase) + END_CRYSTAL = VanillaEntityType.inherited(EnderCrystalEntity::new, entityBase) .type(BuiltinEntityType.END_CRYSTAL) .heightAndWidth(2.0f) .bedrockIdentifier("minecraft:ender_crystal") @@ -372,28 +375,28 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.BOOLEAN, (enderCrystalEntity, entityMetadata) -> enderCrystalEntity.setFlag(EntityFlag.SHOW_BOTTOM, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) // There is a base located on the ender crystal .build(); - EXPERIENCE_ORB = VanillaEntityDefinition.inherited(ExpOrbEntity::new, entityBase) + EXPERIENCE_ORB = VanillaEntityType.inherited(ExpOrbEntity::new, entityBase) .type(BuiltinEntityType.EXPERIENCE_ORB) .addTranslator(null) // int determining xb orb texture .bedrockIdentifier("minecraft:xp_orb") .build(); - EVOKER_FANGS = VanillaEntityDefinition.inherited(EvokerFangsEntity::new, entityBase) + EVOKER_FANGS = VanillaEntityType.inherited(EvokerFangsEntity::new, entityBase) .type(BuiltinEntityType.EVOKER_FANGS) .height(0.8f).width(0.5f) .bedrockIdentifier("minecraft:evocation_fang") .build(); - EYE_OF_ENDER = VanillaEntityDefinition.inherited(EnderEyeEntity::new, entityBase) + EYE_OF_ENDER = VanillaEntityType.inherited(EnderEyeEntity::new, entityBase) .type(BuiltinEntityType.EYE_OF_ENDER) .heightAndWidth(0.25f) .bedrockIdentifier("minecraft:eye_of_ender_signal") .addTranslator(null) // Item .build(); - FALLING_BLOCK = VanillaEntityDefinition.inherited(null, entityBase) + FALLING_BLOCK = VanillaEntityType.inherited(null, entityBase) .type(BuiltinEntityType.FALLING_BLOCK) .heightAndWidth(0.98f) .addTranslator(null) // "start block position" .build(); - FIREWORK_ROCKET = VanillaEntityDefinition.inherited(FireworkEntity::new, entityBase) + FIREWORK_ROCKET = VanillaEntityType.inherited(FireworkEntity::new, entityBase) .type(BuiltinEntityType.FIREWORK_ROCKET) .heightAndWidth(0.25f) .bedrockIdentifier("minecraft:fireworks_rocket") @@ -401,41 +404,41 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.OPTIONAL_UNSIGNED_INT, FireworkEntity::setPlayerGliding) .addTranslator(null) // Shot at angle .build(); - FISHING_BOBBER = VanillaEntityDefinition.inherited(null, entityBase) + FISHING_BOBBER = VanillaEntityType.inherited(null, entityBase) .type(BuiltinEntityType.FISHING_BOBBER) .bedrockIdentifier("minecraft:fishing_hook") .addTranslator(MetadataTypes.INT, FishingHookEntity::setHookedEntity) .addTranslator(null) // Biting TODO check .build(); - ITEM = VanillaEntityDefinition.inherited(ItemEntity::new, entityBase) + ITEM = VanillaEntityType.inherited(ItemEntity::new, entityBase) .type(BuiltinEntityType.ITEM) .heightAndWidth(0.25f) .offset(0.125f) .addTranslator(MetadataTypes.ITEM_STACK, ItemEntity::setItem) .build(); - LEASH_KNOT = VanillaEntityDefinition.inherited(LeashKnotEntity::new, entityBase) + LEASH_KNOT = VanillaEntityType.inherited(LeashKnotEntity::new, entityBase) .type(BuiltinEntityType.LEASH_KNOT) .height(0.5f).width(0.375f) .build(); - LIGHTNING_BOLT = VanillaEntityDefinition.inherited(LightningEntity::new, entityBase) + LIGHTNING_BOLT = VanillaEntityType.inherited(LightningEntity::new, entityBase) .type(BuiltinEntityType.LIGHTNING_BOLT) .build(); - LLAMA_SPIT = VanillaEntityDefinition.inherited(ThrowableEntity::new, entityBase) + LLAMA_SPIT = VanillaEntityType.inherited(ThrowableEntity::new, entityBase) .type(BuiltinEntityType.LLAMA_SPIT) .heightAndWidth(0.25f) .build(); - SHULKER_BULLET = VanillaEntityDefinition.inherited(ThrowableEntity::new, entityBase) + SHULKER_BULLET = VanillaEntityType.inherited(ThrowableEntity::new, entityBase) .type(BuiltinEntityType.SHULKER_BULLET) .heightAndWidth(0.3125f) .build(); - TNT = VanillaEntityDefinition.inherited(TNTEntity::new, entityBase) + TNT = VanillaEntityType.inherited(TNTEntity::new, entityBase) .type(BuiltinEntityType.TNT) .heightAndWidth(0.98f) .offset(0.49f) .addTranslator(MetadataTypes.INT, TNTEntity::setFuseLength) .build(); - EntityDefinitionBase displayBase = EntityDefinitionBase.baseInherited(DisplayBaseEntity.class, entityBase) + VanillaEntityBase displayBase = VanillaEntityBase.baseInherited(DisplayBaseEntity.class, entityBase) .addTranslator(null) // Interpolation delay .addTranslator(null) // Transformation interpolation duration .addTranslator(null) // Position/Rotation interpolation duration @@ -452,7 +455,7 @@ public final class EntityDefinitions { .addTranslator(null) // Height .addTranslator(null) // Glow color override .build(); - TEXT_DISPLAY = VanillaEntityDefinition.inherited(TextDisplayEntity::new, displayBase) + TEXT_DISPLAY = VanillaEntityType.inherited(TextDisplayEntity::new, displayBase) .type(BuiltinEntityType.TEXT_DISPLAY) .bedrockIdentifier("minecraft:armor_stand") .offset(-0.5f) @@ -463,7 +466,7 @@ public final class EntityDefinitions { .addTranslator(null) // Bit mask .build(); - INTERACTION = VanillaEntityDefinition.inherited(InteractionEntity::new, entityBase) + INTERACTION = VanillaEntityType.inherited(InteractionEntity::new, entityBase) .type(BuiltinEntityType.INTERACTION) .heightAndWidth(1.0f) // default size until server specifies otherwise .bedrockIdentifier("minecraft:armor_stand") @@ -472,104 +475,104 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.BOOLEAN, InteractionEntity::setResponse) .build(); - EntityDefinitionBase fireballBase = EntityDefinitionBase.baseInherited(FireballEntity.class, entityBase) + VanillaEntityBase fireballBase = VanillaEntityBase.baseInherited(FireballEntity.class, entityBase) .addTranslator(null) // Item .build(); - FIREBALL = VanillaEntityDefinition.inherited(FireballEntity::new, fireballBase) + FIREBALL = VanillaEntityType.inherited(FireballEntity::new, fireballBase) .type(BuiltinEntityType.FIREBALL) .heightAndWidth(1.0f) .build(); - SMALL_FIREBALL = VanillaEntityDefinition.inherited(FireballEntity::new, fireballBase) + SMALL_FIREBALL = VanillaEntityType.inherited(FireballEntity::new, fireballBase) .type(BuiltinEntityType.SMALL_FIREBALL) .heightAndWidth(0.3125f) .build(); - EntityDefinitionBase throwableItemBase = EntityDefinitionBase.baseInherited(ThrowableItemEntity.class, entityBase) + VanillaEntityBase throwableItemBase = VanillaEntityBase.baseInherited(ThrowableItemEntity.class, entityBase) .addTranslator(MetadataTypes.ITEM_STACK, ThrowableItemEntity::setItem) .build(); - EGG = VanillaEntityDefinition.inherited(ThrowableEggEntity::new, throwableItemBase) + EGG = VanillaEntityType.inherited(ThrowableEggEntity::new, throwableItemBase) .type(BuiltinEntityType.EGG) .heightAndWidth(0.25f) .property(TemperatureVariantAnimal.TEMPERATE_VARIANT_PROPERTY) .build(); - ENDER_PEARL = VanillaEntityDefinition.inherited(ThrowableItemEntity::new, throwableItemBase) + ENDER_PEARL = VanillaEntityType.inherited(ThrowableItemEntity::new, throwableItemBase) .type(BuiltinEntityType.ENDER_PEARL) .heightAndWidth(0.25f) .build(); - EXPERIENCE_BOTTLE = VanillaEntityDefinition.inherited(ThrowableItemEntity::new, throwableItemBase) + EXPERIENCE_BOTTLE = VanillaEntityType.inherited(ThrowableItemEntity::new, throwableItemBase) .type(BuiltinEntityType.EXPERIENCE_BOTTLE) .heightAndWidth(0.25f) .bedrockIdentifier("minecraft:xp_bottle") .build(); - SPLASH_POTION = VanillaEntityDefinition.inherited(ThrownPotionEntity::new, throwableItemBase) + SPLASH_POTION = VanillaEntityType.inherited(ThrownPotionEntity::new, throwableItemBase) .type(BuiltinEntityType.SPLASH_POTION) .heightAndWidth(0.25f) .bedrockIdentifier("minecraft:splash_potion") .build(); - LINGERING_POTION = VanillaEntityDefinition.inherited(ThrownPotionEntity::new, throwableItemBase) + LINGERING_POTION = VanillaEntityType.inherited(ThrownPotionEntity::new, throwableItemBase) .type(BuiltinEntityType.LINGERING_POTION) .heightAndWidth(0.25f) .bedrockIdentifier("minecraft:splash_potion") .build(); - SNOWBALL = VanillaEntityDefinition.inherited(ThrowableItemEntity::new, throwableItemBase) + SNOWBALL = VanillaEntityType.inherited(ThrowableItemEntity::new, throwableItemBase) .type(BuiltinEntityType.SNOWBALL) .heightAndWidth(0.25f) .build(); EntityFactory windChargeSupplier = AbstractWindChargeEntity::new; - BREEZE_WIND_CHARGE = VanillaEntityDefinition.inherited(windChargeSupplier, entityBase) + BREEZE_WIND_CHARGE = VanillaEntityType.inherited(windChargeSupplier, entityBase) .type(BuiltinEntityType.BREEZE_WIND_CHARGE) .bedrockIdentifier("minecraft:breeze_wind_charge_projectile") .heightAndWidth(0.3125f) .build(); - WIND_CHARGE = VanillaEntityDefinition.inherited(windChargeSupplier, entityBase) + WIND_CHARGE = VanillaEntityType.inherited(windChargeSupplier, entityBase) .type(BuiltinEntityType.WIND_CHARGE) .bedrockIdentifier("minecraft:wind_charge_projectile") .heightAndWidth(0.3125f) .build(); - EntityDefinitionBase abstractArrowBase = EntityDefinitionBase.baseInherited(AbstractArrowEntity.class, entityBase) + VanillaEntityBase abstractArrowBase = VanillaEntityBase.baseInherited(AbstractArrowEntity.class, entityBase) .addTranslator(MetadataTypes.BYTE, AbstractArrowEntity::setArrowFlags) .addTranslator(null) // "Piercing level" .addTranslator(null) // If the arrow is in the ground .build(); - ARROW = VanillaEntityDefinition.inherited(ArrowEntity::new, abstractArrowBase) + ARROW = VanillaEntityType.inherited(ArrowEntity::new, abstractArrowBase) .type(BuiltinEntityType.ARROW) .heightAndWidth(0.25f) .addTranslator(MetadataTypes.INT, ArrowEntity::setPotionEffectColor) .build(); - SPECTRAL_ARROW = VanillaEntityDefinition.inherited(AbstractArrowEntity::new, abstractArrowBase) + SPECTRAL_ARROW = VanillaEntityType.inherited(AbstractArrowEntity::new, abstractArrowBase) .type(BuiltinEntityType.SPECTRAL_ARROW) .heightAndWidth(0.25f) .bedrockIdentifier("minecraft:arrow") .build(); - TRIDENT = VanillaEntityDefinition.inherited(TridentEntity::new, abstractArrowBase) // TODO remove class + TRIDENT = VanillaEntityType.inherited(TridentEntity::new, abstractArrowBase) // TODO remove class .type(BuiltinEntityType.TRIDENT) .bedrockIdentifier("minecraft:thrown_trident") .addTranslator(null) // Loyalty .addTranslator(MetadataTypes.BOOLEAN, (tridentEntity, entityMetadata) -> tridentEntity.setFlag(EntityFlag.ENCHANTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .build(); - EntityDefinitionBase hangingEntityBase = EntityDefinitionBase.baseInherited(HangingEntity.class, entityBase) + VanillaEntityBase hangingEntityBase = VanillaEntityBase.baseInherited(HangingEntity.class, entityBase) .addTranslator(MetadataTypes.DIRECTION, HangingEntity::setDirectionMetadata) .build(); - PAINTING = VanillaEntityDefinition.inherited(PaintingEntity::new, hangingEntityBase) + PAINTING = VanillaEntityType.inherited(PaintingEntity::new, hangingEntityBase) .type(BuiltinEntityType.PAINTING) .addTranslator(MetadataTypes.PAINTING_VARIANT, PaintingEntity::setPaintingType) .build(); // Item frames are handled differently as they are blocks, not items, in Bedrock - ITEM_FRAME = VanillaEntityDefinition.inherited(ItemFrameEntity::new, hangingEntityBase) + ITEM_FRAME = VanillaEntityType.inherited(ItemFrameEntity::new, hangingEntityBase) .type(BuiltinEntityType.ITEM_FRAME) .addTranslator(MetadataTypes.ITEM_STACK, ItemFrameEntity::setItemInFrame) .addTranslator(MetadataTypes.INT, ItemFrameEntity::setItemRotation) .build(); - GLOW_ITEM_FRAME = VanillaEntityDefinition.inherited(ITEM_FRAME.factory(), ITEM_FRAME) + GLOW_ITEM_FRAME = VanillaEntityType.inherited(ITEM_FRAME.factory(), ITEM_FRAME) .type(BuiltinEntityType.GLOW_ITEM_FRAME) .build(); - MINECART = VanillaEntityDefinition.inherited(MinecartEntity::new, entityBase) + MINECART = VanillaEntityType.inherited(MinecartEntity::new, entityBase) .type(BuiltinEntityType.MINECART) .height(0.7f).width(0.98f) .offset(0.35f) @@ -581,42 +584,42 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.OPTIONAL_BLOCK_STATE, MinecartEntity::setCustomBlock) .addTranslator(MetadataTypes.INT, MinecartEntity::setCustomBlockOffset) .build(); - CHEST_MINECART = VanillaEntityDefinition.inherited(MINECART.factory(), MINECART) + CHEST_MINECART = VanillaEntityType.inherited(MINECART.factory(), MINECART) .type(BuiltinEntityType.CHEST_MINECART) .build(); - COMMAND_BLOCK_MINECART = VanillaEntityDefinition.inherited(CommandBlockMinecartEntity::new, MINECART) + COMMAND_BLOCK_MINECART = VanillaEntityType.inherited(CommandBlockMinecartEntity::new, MINECART) .type(BuiltinEntityType.COMMAND_BLOCK_MINECART) .addTranslator(MetadataTypes.STRING, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityDataTypes.COMMAND_BLOCK_NAME, entityMetadata.getValue())) .addTranslator(MetadataTypes.COMPONENT, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityDataTypes.COMMAND_BLOCK_LAST_OUTPUT, MessageTranslator.convertMessage(entityMetadata.getValue()))) .build(); - FURNACE_MINECART = VanillaEntityDefinition.inherited(FurnaceMinecartEntity::new, MINECART) + FURNACE_MINECART = VanillaEntityType.inherited(FurnaceMinecartEntity::new, MINECART) .type(BuiltinEntityType.FURNACE_MINECART) .bedrockIdentifier("minecraft:minecart") .addTranslator(MetadataTypes.BOOLEAN, FurnaceMinecartEntity::setHasFuel) .build(); - HOPPER_MINECART = VanillaEntityDefinition.inherited(MINECART.factory(), MINECART) + HOPPER_MINECART = VanillaEntityType.inherited(MINECART.factory(), MINECART) .type(BuiltinEntityType.HOPPER_MINECART) .build(); - SPAWNER_MINECART = VanillaEntityDefinition.inherited(SpawnerMinecartEntity::new, MINECART) + SPAWNER_MINECART = VanillaEntityType.inherited(SpawnerMinecartEntity::new, MINECART) .type(BuiltinEntityType.SPAWNER_MINECART) .bedrockIdentifier("minecraft:minecart") .build(); - TNT_MINECART = VanillaEntityDefinition.inherited(MINECART.factory(), MINECART) + TNT_MINECART = VanillaEntityType.inherited(MINECART.factory(), MINECART) .type(BuiltinEntityType.TNT_MINECART) .build(); - WITHER_SKULL = VanillaEntityDefinition.inherited(WitherSkullEntity::new, entityBase) + WITHER_SKULL = VanillaEntityType.inherited(WitherSkullEntity::new, entityBase) .type(BuiltinEntityType.WITHER_SKULL) .heightAndWidth(0.3125f) .addTranslator(MetadataTypes.BOOLEAN, WitherSkullEntity::setDangerous) .build(); - WITHER_SKULL_DANGEROUS = VanillaEntityDefinition.inherited(WITHER_SKULL.factory(), WITHER_SKULL) + WITHER_SKULL_DANGEROUS = VanillaEntityType.inherited(WITHER_SKULL.factory(), WITHER_SKULL) .build(false); } // Boats { - EntityDefinitionBase boatBase = EntityDefinitionBase.baseInherited(BoatEntity.class, entityBase) + VanillaEntityBase boatBase = VanillaEntityBase.baseInherited(BoatEntity.class, entityBase) .height(0.6f).width(1.6f) .offset(0.35f) .addTranslator(MetadataTypes.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityDataTypes.HURT_TICKS, entityMetadata.getValue())) // Time since last hit @@ -640,7 +643,7 @@ public final class EntityDefinitions { SPRUCE_BOAT = buildBoat(boatBase, BuiltinEntityType.SPRUCE_BOAT, BoatEntity.BoatVariant.SPRUCE); PALE_OAK_BOAT = buildBoat(boatBase, BuiltinEntityType.PALE_OAK_BOAT, BoatEntity.BoatVariant.PALE_OAK); - EntityDefinitionBase chestBoatBase = EntityDefinitionBase.baseInherited(ChestBoatEntity.class, boatBase) + VanillaEntityBase chestBoatBase = VanillaEntityBase.baseInherited(ChestBoatEntity.class, boatBase) .build(); ACACIA_CHEST_BOAT = buildChestBoat(chestBoatBase, BuiltinEntityType.ACACIA_CHEST_BOAT, BoatEntity.BoatVariant.ACACIA); @@ -655,7 +658,7 @@ public final class EntityDefinitions { PALE_OAK_CHEST_BOAT = buildChestBoat(chestBoatBase, BuiltinEntityType.PALE_OAK_CHEST_BOAT, BoatEntity.BoatVariant.PALE_OAK); } - EntityDefinitionBase livingEntityBase = EntityDefinitionBase.baseInherited(LivingEntity.class, entityBase) + VanillaEntityBase livingEntityBase = VanillaEntityBase.baseInherited(LivingEntity.class, entityBase) .addTranslator(MetadataTypes.BYTE, LivingEntity::setLivingEntityFlags) .addTranslator(MetadataTypes.FLOAT, LivingEntity::setHealth) .addTranslator(MetadataTypes.PARTICLES, LivingEntity::setParticles) @@ -666,7 +669,7 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.OPTIONAL_BLOCK_POS, LivingEntity::setBedPosition) .build(); - ARMOR_STAND = VanillaEntityDefinition.inherited(ArmorStandEntity::new, livingEntityBase) + ARMOR_STAND = VanillaEntityType.inherited(ArmorStandEntity::new, livingEntityBase) .type(BuiltinEntityType.ARMOR_STAND) .height(1.975f).width(0.5f) .addTranslator(MetadataTypes.BYTE, ArmorStandEntity::setArmorStandFlags) @@ -678,21 +681,21 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.ROTATIONS, ArmorStandEntity::setRightLegRotation) .build(); - EntityDefinitionBase avatarEntityBase = EntityDefinitionBase.baseInherited(AvatarEntity.class, livingEntityBase) + VanillaEntityBase avatarEntityBase = VanillaEntityBase.baseInherited(AvatarEntity.class, livingEntityBase) .height(1.8f).width(0.6f) .offset(1.62f) .addTranslator(null) // Player main hand .addTranslator(MetadataTypes.BYTE, AvatarEntity::setSkinVisibility) .build(); - MANNEQUIN = VanillaEntityDefinition.inherited(MannequinEntity::new, avatarEntityBase) + MANNEQUIN = VanillaEntityType.inherited(MannequinEntity::new, avatarEntityBase) .type(BuiltinEntityType.MANNEQUIN) .addTranslator(MetadataTypes.RESOLVABLE_PROFILE, MannequinEntity::setProfile) .addTranslator(null) // Immovable .addTranslator(MetadataTypes.OPTIONAL_COMPONENT, MannequinEntity::setDescription) .build(); - PLAYER = VanillaEntityDefinition.inherited(null, avatarEntityBase) + PLAYER = VanillaEntityType.inherited(null, avatarEntityBase) .type(BuiltinEntityType.PLAYER) .addTranslator(MetadataTypes.FLOAT, PlayerEntity::setAbsorptionHearts) .addTranslator(null) // Player score @@ -700,38 +703,38 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.OPTIONAL_UNSIGNED_INT, PlayerEntity::setRightParrot) .build(); - EntityDefinitionBase mobEntityBase = EntityDefinitionBase.baseInherited(MobEntity.class, livingEntityBase) + VanillaEntityBase mobEntityBase = VanillaEntityBase.baseInherited(MobEntity.class, livingEntityBase) .addTranslator(MetadataTypes.BYTE, MobEntity::setMobFlags) .build(); // Extends mob { - ALLAY = VanillaEntityDefinition.inherited(AllayEntity::new, mobEntityBase) + ALLAY = VanillaEntityType.inherited(AllayEntity::new, mobEntityBase) .type(BuiltinEntityType.ALLAY) .height(0.6f).width(0.35f) .addTranslator(MetadataTypes.BOOLEAN, AllayEntity::setDancing) .addTranslator(MetadataTypes.BOOLEAN, AllayEntity::setCanDuplicate) .build(); - BAT = VanillaEntityDefinition.inherited(BatEntity::new, mobEntityBase) + BAT = VanillaEntityType.inherited(BatEntity::new, mobEntityBase) .type(BuiltinEntityType.BAT) .height(0.9f).width(0.5f) .addTranslator(MetadataTypes.BYTE, BatEntity::setBatFlags) .build(); - BOGGED = VanillaEntityDefinition.inherited(BoggedEntity::new, mobEntityBase) + BOGGED = VanillaEntityType.inherited(BoggedEntity::new, mobEntityBase) .type(BuiltinEntityType.BOGGED) .height(1.99f).width(0.6f) .addTranslator(MetadataTypes.BOOLEAN, BoggedEntity::setSheared) .build(); - BLAZE = VanillaEntityDefinition.inherited(BlazeEntity::new, mobEntityBase) + BLAZE = VanillaEntityType.inherited(BlazeEntity::new, mobEntityBase) .type(BuiltinEntityType.BLAZE) .height(1.8f).width(0.6f) .addTranslator(MetadataTypes.BYTE, BlazeEntity::setBlazeFlags) .build(); - BREEZE = VanillaEntityDefinition.inherited(BreezeEntity::new, mobEntityBase) + BREEZE = VanillaEntityType.inherited(BreezeEntity::new, mobEntityBase) .type(BuiltinEntityType.BREEZE) .height(1.77f).width(0.6f) .build(); - COPPER_GOLEM = VanillaEntityDefinition.inherited(CopperGolemEntity::new, mobEntityBase) + COPPER_GOLEM = VanillaEntityType.inherited(CopperGolemEntity::new, mobEntityBase) .type(BuiltinEntityType.COPPER_GOLEM) .height(0.49f).width(0.98f) .addTranslator(MetadataTypes.WEATHERING_COPPER_STATE, CopperGolemEntity::setWeatheringState) @@ -740,7 +743,7 @@ public final class EntityDefinitions { .property(CopperGolemEntity.HAS_FLOWER_PROPERTY) .property(CopperGolemEntity.OXIDATION_LEVEL_STATE_ENUM_PROPERTY) .build(); - CREAKING = VanillaEntityDefinition.inherited(CreakingEntity::new, mobEntityBase) + CREAKING = VanillaEntityType.inherited(CreakingEntity::new, mobEntityBase) .type(BuiltinEntityType.CREAKING) .height(2.7f).width(0.9f) .addTranslator(MetadataTypes.BOOLEAN, CreakingEntity::setCanMove) @@ -750,7 +753,7 @@ public final class EntityDefinitions { .property(CreakingEntity.STATE_PROPERTY) .property(CreakingEntity.SWAYING_TICKS_PROPERTY) .build(); - CREEPER = VanillaEntityDefinition.inherited(CreeperEntity::new, mobEntityBase) + CREEPER = VanillaEntityType.inherited(CreeperEntity::new, mobEntityBase) .type(BuiltinEntityType.CREEPER) .height(1.7f).width(0.6f) .offset(1.62f) @@ -758,91 +761,91 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.POWERED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .addTranslator(MetadataTypes.BOOLEAN, CreeperEntity::setIgnited) .build(); - ENDERMAN = VanillaEntityDefinition.inherited(EndermanEntity::new, mobEntityBase) + ENDERMAN = VanillaEntityType.inherited(EndermanEntity::new, mobEntityBase) .type(BuiltinEntityType.ENDERMAN) .height(2.9f).width(0.6f) .addTranslator(MetadataTypes.OPTIONAL_BLOCK_STATE, EndermanEntity::setCarriedBlock) .addTranslator(MetadataTypes.BOOLEAN, EndermanEntity::setScreaming) .addTranslator(MetadataTypes.BOOLEAN, EndermanEntity::setAngry) .build(); - ENDERMITE = VanillaEntityDefinition.inherited(MonsterEntity::new, mobEntityBase) + ENDERMITE = VanillaEntityType.inherited(MonsterEntity::new, mobEntityBase) .type(BuiltinEntityType.ENDERMITE) .height(0.3f).width(0.4f) .build(); - ENDER_DRAGON = VanillaEntityDefinition.inherited(EnderDragonEntity::new, mobEntityBase) + ENDER_DRAGON = VanillaEntityType.inherited(EnderDragonEntity::new, mobEntityBase) .type(BuiltinEntityType.ENDER_DRAGON) .addTranslator(MetadataTypes.INT, EnderDragonEntity::setPhase) .build(); - GHAST = VanillaEntityDefinition.inherited(GhastEntity::new, mobEntityBase) + GHAST = VanillaEntityType.inherited(GhastEntity::new, mobEntityBase) .type(BuiltinEntityType.GHAST) .heightAndWidth(4.0f) .addTranslator(MetadataTypes.BOOLEAN, GhastEntity::setGhastAttacking) .build(); - GIANT = VanillaEntityDefinition.inherited(GiantEntity::new, mobEntityBase) + GIANT = VanillaEntityType.inherited(GiantEntity::new, mobEntityBase) .type(BuiltinEntityType.GIANT) .height(1.8f).width(1.6f) .offset(1.62f) .bedrockIdentifier("minecraft:zombie") .build(); - IRON_GOLEM = VanillaEntityDefinition.inherited(IronGolemEntity::new, mobEntityBase) + IRON_GOLEM = VanillaEntityType.inherited(IronGolemEntity::new, mobEntityBase) .type(BuiltinEntityType.IRON_GOLEM) .height(2.7f).width(1.4f) .addTranslator(null) // "is player created", which doesn't seem to do anything clientside .build(); - PHANTOM = VanillaEntityDefinition.inherited(PhantomEntity::new, mobEntityBase) + PHANTOM = VanillaEntityType.inherited(PhantomEntity::new, mobEntityBase) .type(BuiltinEntityType.PHANTOM) .height(0.5f).width(0.9f) .offset(0.6f) .addTranslator(MetadataTypes.INT, PhantomEntity::setPhantomScale) .build(); - SILVERFISH = VanillaEntityDefinition.inherited(MonsterEntity::new, mobEntityBase) + SILVERFISH = VanillaEntityType.inherited(MonsterEntity::new, mobEntityBase) .type(BuiltinEntityType.SILVERFISH) .height(0.3f).width(0.4f) .build(); - SHULKER = VanillaEntityDefinition.inherited(ShulkerEntity::new, mobEntityBase) + SHULKER = VanillaEntityType.inherited(ShulkerEntity::new, mobEntityBase) .type(BuiltinEntityType.SHULKER) .heightAndWidth(1f) .addTranslator(MetadataTypes.DIRECTION, ShulkerEntity::setAttachedFace) .addTranslator(MetadataTypes.BYTE, ShulkerEntity::setShulkerHeight) .addTranslator(MetadataTypes.BYTE, ShulkerEntity::setShulkerColor) .build(); - SKELETON = VanillaEntityDefinition.inherited(SkeletonEntity::new, mobEntityBase) + SKELETON = VanillaEntityType.inherited(SkeletonEntity::new, mobEntityBase) .type(BuiltinEntityType.SKELETON) .height(1.8f).width(0.6f) .offset(1.62f) .addTranslator(MetadataTypes.BOOLEAN, SkeletonEntity::setConvertingToStray) .build(); - SNOW_GOLEM = VanillaEntityDefinition.inherited(SnowGolemEntity::new, mobEntityBase) + SNOW_GOLEM = VanillaEntityType.inherited(SnowGolemEntity::new, mobEntityBase) .type(BuiltinEntityType.SNOW_GOLEM) .height(1.9f).width(0.7f) .addTranslator(MetadataTypes.BYTE, SnowGolemEntity::setSnowGolemFlags) .build(); - SPIDER = VanillaEntityDefinition.inherited(SpiderEntity::new, mobEntityBase) + SPIDER = VanillaEntityType.inherited(SpiderEntity::new, mobEntityBase) .type(BuiltinEntityType.SPIDER) .height(0.9f).width(1.4f) .offset(1f) .addTranslator(MetadataTypes.BYTE, SpiderEntity::setSpiderFlags) .build(); - CAVE_SPIDER = VanillaEntityDefinition.inherited(SpiderEntity::new, SPIDER) + CAVE_SPIDER = VanillaEntityType.inherited(SpiderEntity::new, SPIDER) .type(BuiltinEntityType.CAVE_SPIDER) .height(0.5f).width(0.7f) .build(); - STRAY = VanillaEntityDefinition.inherited(AbstractSkeletonEntity::new, mobEntityBase) + STRAY = VanillaEntityType.inherited(AbstractSkeletonEntity::new, mobEntityBase) .type(BuiltinEntityType.STRAY) .height(1.8f).width(0.6f) .offset(1.62f) .build(); - VEX = VanillaEntityDefinition.inherited(VexEntity::new, mobEntityBase) + VEX = VanillaEntityType.inherited(VexEntity::new, mobEntityBase) .type(BuiltinEntityType.VEX) .height(0.8f).width(0.4f) .addTranslator(MetadataTypes.BYTE, VexEntity::setVexFlags) .build(); - WARDEN = VanillaEntityDefinition.inherited(WardenEntity::new, mobEntityBase) + WARDEN = VanillaEntityType.inherited(WardenEntity::new, mobEntityBase) .type(BuiltinEntityType.WARDEN) .height(2.9f).width(0.9f) .addTranslator(MetadataTypes.INT, WardenEntity::setAngerLevel) .build(); - WITHER = VanillaEntityDefinition.inherited(WitherEntity::new, mobEntityBase) + WITHER = VanillaEntityType.inherited(WitherEntity::new, mobEntityBase) .type(BuiltinEntityType.WITHER) .height(3.5f).width(0.9f) .addTranslator(MetadataTypes.INT, WitherEntity::setTarget1) @@ -850,16 +853,16 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.INT, WitherEntity::setTarget3) .addTranslator(MetadataTypes.INT, WitherEntity::setInvulnerableTicks) .build(); - WITHER_SKELETON = VanillaEntityDefinition.inherited(AbstractSkeletonEntity::new, mobEntityBase) + WITHER_SKELETON = VanillaEntityType.inherited(AbstractSkeletonEntity::new, mobEntityBase) .type(BuiltinEntityType.WITHER_SKELETON) .height(2.4f).width(0.7f) .build(); - ZOGLIN = VanillaEntityDefinition.inherited(ZoglinEntity::new, mobEntityBase) + ZOGLIN = VanillaEntityType.inherited(ZoglinEntity::new, mobEntityBase) .type(BuiltinEntityType.ZOGLIN) .height(1.4f).width(1.3965f) .addTranslator(MetadataTypes.BOOLEAN, ZoglinEntity::setBaby) .build(); - ZOMBIE = VanillaEntityDefinition.inherited(ZombieEntity::new, mobEntityBase) + ZOMBIE = VanillaEntityType.inherited(ZombieEntity::new, mobEntityBase) .type(BuiltinEntityType.ZOMBIE) .height(1.8f).width(0.6f) .offset(1.62f) @@ -867,7 +870,7 @@ public final class EntityDefinitions { .addTranslator(null) // "set special type", doesn't do anything .addTranslator(MetadataTypes.BOOLEAN, ZombieEntity::setConvertingToDrowned) .build(); - ZOMBIE_VILLAGER = VanillaEntityDefinition.inherited(ZombieVillagerEntity::new, ZOMBIE) + ZOMBIE_VILLAGER = VanillaEntityType.inherited(ZombieVillagerEntity::new, ZOMBIE) .type(BuiltinEntityType.ZOMBIE_VILLAGER) .height(1.8f).width(0.6f) .offset(1.62f) @@ -875,116 +878,116 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.BOOLEAN, ZombieVillagerEntity::setTransforming) .addTranslator(MetadataTypes.VILLAGER_DATA, ZombieVillagerEntity::setZombieVillagerData) .build(); - ZOMBIFIED_PIGLIN = VanillaEntityDefinition.inherited(ZombifiedPiglinEntity::new, ZOMBIE) //TODO test how zombie entity metadata is handled? + ZOMBIFIED_PIGLIN = VanillaEntityType.inherited(ZombifiedPiglinEntity::new, ZOMBIE) //TODO test how zombie entity metadata is handled? .type(BuiltinEntityType.ZOMBIFIED_PIGLIN) .height(1.95f).width(0.6f) .offset(1.62f) .bedrockIdentifier("minecraft:zombie_pigman") .build(); - DROWNED = VanillaEntityDefinition.inherited(ZOMBIE.factory(), ZOMBIE) + DROWNED = VanillaEntityType.inherited(ZOMBIE.factory(), ZOMBIE) .type(BuiltinEntityType.DROWNED) .height(1.95f).width(0.6f) .build(); - HUSK = VanillaEntityDefinition.inherited(ZOMBIE.factory(), ZOMBIE) + HUSK = VanillaEntityType.inherited(ZOMBIE.factory(), ZOMBIE) .type(BuiltinEntityType.HUSK) .build(); - GUARDIAN = VanillaEntityDefinition.inherited(GuardianEntity::new, mobEntityBase) + GUARDIAN = VanillaEntityType.inherited(GuardianEntity::new, mobEntityBase) .type(BuiltinEntityType.GUARDIAN) .heightAndWidth(0.85f) .addTranslator(null) // Moving //TODO .addTranslator(MetadataTypes.INT, GuardianEntity::setGuardianTarget) .build(); - ELDER_GUARDIAN = VanillaEntityDefinition.inherited(ElderGuardianEntity::new, GUARDIAN) + ELDER_GUARDIAN = VanillaEntityType.inherited(ElderGuardianEntity::new, GUARDIAN) .type(BuiltinEntityType.ELDER_GUARDIAN) .heightAndWidth(1.9975f) .build(); - SLIME = VanillaEntityDefinition.inherited(SlimeEntity::new, mobEntityBase) + SLIME = VanillaEntityType.inherited(SlimeEntity::new, mobEntityBase) .type(BuiltinEntityType.SLIME) .heightAndWidth(0.51f) .addTranslator(MetadataTypes.INT, SlimeEntity::setSlimeScale) .build(); - MAGMA_CUBE = VanillaEntityDefinition.inherited(MagmaCubeEntity::new, SLIME) + MAGMA_CUBE = VanillaEntityType.inherited(MagmaCubeEntity::new, SLIME) .type(BuiltinEntityType.MAGMA_CUBE) .build(); - EntityDefinitionBase abstractFishEntityBase = EntityDefinitionBase.baseInherited(AbstractFishEntity.class, mobEntityBase) + VanillaEntityBase abstractFishEntityBase = VanillaEntityBase.baseInherited(AbstractFishEntity.class, mobEntityBase) .addTranslator(null) // From bucket .build(); - COD = VanillaEntityDefinition.inherited(AbstractFishEntity::new, abstractFishEntityBase) + COD = VanillaEntityType.inherited(AbstractFishEntity::new, abstractFishEntityBase) .type(BuiltinEntityType.COD) .height(0.25f).width(0.5f) .build(); - PUFFERFISH = VanillaEntityDefinition.inherited(PufferFishEntity::new, abstractFishEntityBase) + PUFFERFISH = VanillaEntityType.inherited(PufferFishEntity::new, abstractFishEntityBase) .type(BuiltinEntityType.PUFFERFISH) .heightAndWidth(0.7f) .addTranslator(MetadataTypes.INT, PufferFishEntity::setPufferfishSize) .build(); - SALMON = VanillaEntityDefinition.inherited(AbstractFishEntity::new, abstractFishEntityBase) + SALMON = VanillaEntityType.inherited(AbstractFishEntity::new, abstractFishEntityBase) .type(BuiltinEntityType.SALMON) .height(0.5f).width(0.7f) .addTranslator(null) // Scale/variant - TODO .build(); - TADPOLE = VanillaEntityDefinition.inherited(TadpoleEntity::new, abstractFishEntityBase) + TADPOLE = VanillaEntityType.inherited(TadpoleEntity::new, abstractFishEntityBase) .type(BuiltinEntityType.TADPOLE) .height(0.3f).width(0.4f) .build(); - TROPICAL_FISH = VanillaEntityDefinition.inherited(TropicalFishEntity::new, abstractFishEntityBase) + TROPICAL_FISH = VanillaEntityType.inherited(TropicalFishEntity::new, abstractFishEntityBase) .type(BuiltinEntityType.TROPICAL_FISH) .heightAndWidth(0.6f) .bedrockIdentifier("minecraft:tropicalfish") .addTranslator(MetadataTypes.INT, TropicalFishEntity::setFishVariant) .build(); - EntityDefinitionBase abstractPiglinEntityBase = EntityDefinitionBase.baseInherited(BasePiglinEntity.class, mobEntityBase) + VanillaEntityBase abstractPiglinEntityBase = VanillaEntityBase.baseInherited(BasePiglinEntity.class, mobEntityBase) .addTranslator(MetadataTypes.BOOLEAN, BasePiglinEntity::setImmuneToZombification) .build(); - PIGLIN = VanillaEntityDefinition.inherited(PiglinEntity::new, abstractPiglinEntityBase) + PIGLIN = VanillaEntityType.inherited(PiglinEntity::new, abstractPiglinEntityBase) .type(BuiltinEntityType.PIGLIN) .height(1.95f).width(0.6f) .addTranslator(MetadataTypes.BOOLEAN, PiglinEntity::setBaby) .addTranslator(MetadataTypes.BOOLEAN, PiglinEntity::setChargingCrossbow) .addTranslator(MetadataTypes.BOOLEAN, PiglinEntity::setDancing) .build(); - PIGLIN_BRUTE = VanillaEntityDefinition.inherited(BasePiglinEntity::new, abstractPiglinEntityBase) + PIGLIN_BRUTE = VanillaEntityType.inherited(BasePiglinEntity::new, abstractPiglinEntityBase) .type(BuiltinEntityType.PIGLIN_BRUTE) .height(1.95f).width(0.6f) .build(); - EntityDefinitionBase raidParticipantEntityBase = EntityDefinitionBase.baseInherited(RaidParticipantEntity.class, mobEntityBase) + VanillaEntityBase raidParticipantEntityBase = VanillaEntityBase.baseInherited(RaidParticipantEntity.class, mobEntityBase) .addTranslator(null) // Celebrating //TODO .build(); - EntityDefinitionBase spellcasterEntityBase = EntityDefinitionBase.baseInherited(SpellcasterIllagerEntity.class, raidParticipantEntityBase) + VanillaEntityBase spellcasterEntityBase = VanillaEntityBase.baseInherited(SpellcasterIllagerEntity.class, raidParticipantEntityBase) .addTranslator(MetadataTypes.BYTE, SpellcasterIllagerEntity::setSpellType) .build(); - EVOKER = VanillaEntityDefinition.inherited(SpellcasterIllagerEntity::new, spellcasterEntityBase) + EVOKER = VanillaEntityType.inherited(SpellcasterIllagerEntity::new, spellcasterEntityBase) .type(BuiltinEntityType.EVOKER) .height(1.95f).width(0.6f) .bedrockIdentifier("minecraft:evocation_illager") .build(); - ILLUSIONER = VanillaEntityDefinition.inherited(SpellcasterIllagerEntity::new, spellcasterEntityBase) + ILLUSIONER = VanillaEntityType.inherited(SpellcasterIllagerEntity::new, spellcasterEntityBase) .type(BuiltinEntityType.ILLUSIONER) .height(1.95f).width(0.6f) .bedrockIdentifier("minecraft:evocation_illager") .build(); - PILLAGER = VanillaEntityDefinition.inherited(PillagerEntity::new, raidParticipantEntityBase) + PILLAGER = VanillaEntityType.inherited(PillagerEntity::new, raidParticipantEntityBase) .type(BuiltinEntityType.PILLAGER) .height(1.8f).width(0.6f) .offset(1.62f) .addTranslator(MetadataTypes.BOOLEAN, PillagerEntity::setChargingCrossbow) .build(); - RAVAGER = VanillaEntityDefinition.inherited(RavagerEntity::new, raidParticipantEntityBase) + RAVAGER = VanillaEntityType.inherited(RavagerEntity::new, raidParticipantEntityBase) .type(BuiltinEntityType.RAVAGER) .height(1.9f).width(1.2f) .build(); - VINDICATOR = VanillaEntityDefinition.inherited(VindicatorEntity::new, raidParticipantEntityBase) + VINDICATOR = VanillaEntityType.inherited(VindicatorEntity::new, raidParticipantEntityBase) .type(BuiltinEntityType.VINDICATOR) .height(1.8f).width(0.6f) .offset(1.62f) .build(); - WITCH = VanillaEntityDefinition.inherited(RaidParticipantEntity::new, raidParticipantEntityBase) + WITCH = VanillaEntityType.inherited(RaidParticipantEntity::new, raidParticipantEntityBase) .type(BuiltinEntityType.WITCH) .height(1.8f).width(0.6f) .offset(1.62f) @@ -992,45 +995,45 @@ public final class EntityDefinitions { .build(); } - EntityDefinitionBase ageableEntityBase = EntityDefinitionBase.baseInherited(AgeableEntity.class, mobEntityBase) + VanillaEntityBase ageableEntityBase = VanillaEntityBase.baseInherited(AgeableEntity.class, mobEntityBase) .addTranslator(MetadataTypes.BOOLEAN, AgeableEntity::setBaby) .build(); // Extends ageable { - ARMADILLO = VanillaEntityDefinition.inherited(ArmadilloEntity::new, ageableEntityBase) + ARMADILLO = VanillaEntityType.inherited(ArmadilloEntity::new, ageableEntityBase) .type(BuiltinEntityType.ARMADILLO) .height(0.65f).width(0.7f) .property(ArmadilloEntity.STATE_PROPERTY) .addTranslator(MetadataTypes.ARMADILLO_STATE, ArmadilloEntity::setArmadilloState) .build(); - AXOLOTL = VanillaEntityDefinition.inherited(AxolotlEntity::new, ageableEntityBase) + AXOLOTL = VanillaEntityType.inherited(AxolotlEntity::new, ageableEntityBase) .type(BuiltinEntityType.AXOLOTL) .height(0.42f).width(0.7f) .addTranslator(MetadataTypes.INT, AxolotlEntity::setVariant) .addTranslator(MetadataTypes.BOOLEAN, AxolotlEntity::setPlayingDead) .addTranslator(null) // From bucket .build(); - BEE = VanillaEntityDefinition.inherited(BeeEntity::new, ageableEntityBase) + BEE = VanillaEntityType.inherited(BeeEntity::new, ageableEntityBase) .type(BuiltinEntityType.BEE) .heightAndWidth(0.6f) .property(BeeEntity.NECTAR_PROPERTY) .addTranslator(MetadataTypes.BYTE, BeeEntity::setBeeFlags) .addTranslator(MetadataTypes.INT, BeeEntity::setAngerTime) .build(); - CHICKEN = VanillaEntityDefinition.inherited(ChickenEntity::new, ageableEntityBase) + CHICKEN = VanillaEntityType.inherited(ChickenEntity::new, ageableEntityBase) .type(BuiltinEntityType.CHICKEN) .height(0.7f).width(0.4f) .property(TemperatureVariantAnimal.TEMPERATE_VARIANT_PROPERTY) .addTranslator(MetadataTypes.CHICKEN_VARIANT, ChickenEntity::setVariant) .build(); - COW = VanillaEntityDefinition.inherited(CowEntity::new, ageableEntityBase) + COW = VanillaEntityType.inherited(CowEntity::new, ageableEntityBase) .type(BuiltinEntityType.COW) .height(1.4f).width(0.9f) .property(TemperatureVariantAnimal.TEMPERATE_VARIANT_PROPERTY) .addTranslator(MetadataTypes.COW_VARIANT, CowEntity::setVariant) .build(); - FOX = VanillaEntityDefinition.inherited(FoxEntity::new, ageableEntityBase) + FOX = VanillaEntityType.inherited(FoxEntity::new, ageableEntityBase) .type(BuiltinEntityType.FOX) .height(0.7f).width(0.6f) .addTranslator(MetadataTypes.INT, FoxEntity::setFoxVariant) @@ -1038,42 +1041,42 @@ public final class EntityDefinitions { .addTranslator(null) // Trusted player 1 .addTranslator(null) // Trusted player 2 .build(); - FROG = VanillaEntityDefinition.inherited(FrogEntity::new, ageableEntityBase) + FROG = VanillaEntityType.inherited(FrogEntity::new, ageableEntityBase) .type(BuiltinEntityType.FROG) .heightAndWidth(0.5f) .addTranslator(MetadataTypes.FROG_VARIANT, FrogEntity::setVariant) .addTranslator(MetadataTypes.OPTIONAL_UNSIGNED_INT, FrogEntity::setTongueTarget) .build(); - HAPPY_GHAST = VanillaEntityDefinition.inherited(HappyGhastEntity::new, ageableEntityBase) + HAPPY_GHAST = VanillaEntityType.inherited(HappyGhastEntity::new, ageableEntityBase) .type(BuiltinEntityType.HAPPY_GHAST) .heightAndWidth(4f) .property(HappyGhastEntity.CAN_MOVE_PROPERTY) .addTranslator(null) // Is leash holder .addTranslator(MetadataTypes.BOOLEAN, HappyGhastEntity::setStaysStill) .build(); - HOGLIN = VanillaEntityDefinition.inherited(HoglinEntity::new, ageableEntityBase) + HOGLIN = VanillaEntityType.inherited(HoglinEntity::new, ageableEntityBase) .type(BuiltinEntityType.HOGLIN) .height(1.4f).width(1.3965f) .addTranslator(MetadataTypes.BOOLEAN, HoglinEntity::setImmuneToZombification) .build(); - GOAT = VanillaEntityDefinition.inherited(GoatEntity::new, ageableEntityBase) + GOAT = VanillaEntityType.inherited(GoatEntity::new, ageableEntityBase) .type(BuiltinEntityType.GOAT) .height(1.3f).width(0.9f) .addTranslator(MetadataTypes.BOOLEAN, GoatEntity::setScreamer) .addTranslator(MetadataTypes.BOOLEAN, GoatEntity::setHasLeftHorn) .addTranslator(MetadataTypes.BOOLEAN, GoatEntity::setHasRightHorn) .build(); - MOOSHROOM = VanillaEntityDefinition.inherited(MooshroomEntity::new, ageableEntityBase) + MOOSHROOM = VanillaEntityType.inherited(MooshroomEntity::new, ageableEntityBase) .type(BuiltinEntityType.MOOSHROOM) .height(1.4f).width(0.9f) .addTranslator(MetadataTypes.INT, MooshroomEntity::setMooshroomVariant) .build(); - OCELOT = VanillaEntityDefinition.inherited(OcelotEntity::new, ageableEntityBase) + OCELOT = VanillaEntityType.inherited(OcelotEntity::new, ageableEntityBase) .type(BuiltinEntityType.OCELOT) .height(0.7f).width(0.6f) .addTranslator(MetadataTypes.BOOLEAN, (ocelotEntity, entityMetadata) -> ocelotEntity.setFlag(EntityFlag.TRUSTING, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .build(); - PANDA = VanillaEntityDefinition.inherited(PandaEntity::new, ageableEntityBase) + PANDA = VanillaEntityType.inherited(PandaEntity::new, ageableEntityBase) .type(BuiltinEntityType.PANDA) .height(1.25f).width(1.125f) .addTranslator(null) // Unhappy counter @@ -1083,41 +1086,41 @@ public final class EntityDefinitions { .addTranslator(MetadataTypes.BYTE, PandaEntity::setHiddenGene) .addTranslator(MetadataTypes.BYTE, PandaEntity::setPandaFlags) .build(); - PIG = VanillaEntityDefinition.inherited(PigEntity::new, ageableEntityBase) + PIG = VanillaEntityType.inherited(PigEntity::new, ageableEntityBase) .type(BuiltinEntityType.PIG) .heightAndWidth(0.9f) .property(TemperatureVariantAnimal.TEMPERATE_VARIANT_PROPERTY) .addTranslator(MetadataTypes.INT, PigEntity::setBoost) .addTranslator(MetadataTypes.PIG_VARIANT, PigEntity::setVariant) .build(); - POLAR_BEAR = VanillaEntityDefinition.inherited(PolarBearEntity::new, ageableEntityBase) + POLAR_BEAR = VanillaEntityType.inherited(PolarBearEntity::new, ageableEntityBase) .type(BuiltinEntityType.POLAR_BEAR) .height(1.4f).width(1.3f) .addTranslator(MetadataTypes.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.STANDING, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .build(); - RABBIT = VanillaEntityDefinition.inherited(RabbitEntity::new, ageableEntityBase) + RABBIT = VanillaEntityType.inherited(RabbitEntity::new, ageableEntityBase) .type(BuiltinEntityType.RABBIT) .height(0.5f).width(0.4f) .addTranslator(MetadataTypes.INT, RabbitEntity::setRabbitVariant) .build(); - SHEEP = VanillaEntityDefinition.inherited(SheepEntity::new, ageableEntityBase) + SHEEP = VanillaEntityType.inherited(SheepEntity::new, ageableEntityBase) .type(BuiltinEntityType.SHEEP) .height(1.3f).width(0.9f) .addTranslator(MetadataTypes.BYTE, SheepEntity::setSheepFlags) .build(); - SNIFFER = VanillaEntityDefinition.inherited(SnifferEntity::new, ageableEntityBase) + SNIFFER = VanillaEntityType.inherited(SnifferEntity::new, ageableEntityBase) .type(BuiltinEntityType.SNIFFER) .height(1.75f).width(1.9f) .addTranslator(MetadataTypes.SNIFFER_STATE, SnifferEntity::setSnifferState) .addTranslator(null) // Integer, drop seed at tick .build(); - STRIDER = VanillaEntityDefinition.inherited(StriderEntity::new, ageableEntityBase) + STRIDER = VanillaEntityType.inherited(StriderEntity::new, ageableEntityBase) .type(BuiltinEntityType.STRIDER) .height(1.7f).width(0.9f) .addTranslator(MetadataTypes.INT, StriderEntity::setBoost) .addTranslator(MetadataTypes.BOOLEAN, StriderEntity::setCold) .build(); - TURTLE = VanillaEntityDefinition.inherited(TurtleEntity::new, ageableEntityBase) + TURTLE = VanillaEntityType.inherited(TurtleEntity::new, ageableEntityBase) .type(BuiltinEntityType.TURTLE) .height(0.4f).width(1.2f) .addTranslator(null) // Home position @@ -1128,17 +1131,17 @@ public final class EntityDefinitions { .addTranslator(null) // Travelling .build(); - VanillaEntityDefinition abstractVillagerEntityBase = VanillaEntityDefinition.inherited(AbstractMerchantEntity::new, ageableEntityBase) + VanillaEntityType abstractVillagerEntityBase = VanillaEntityType.inherited(AbstractMerchantEntity::new, ageableEntityBase) .addTranslator(null) // Unhappy ticks .build(); - VILLAGER = VanillaEntityDefinition.inherited(VillagerEntity::new, abstractVillagerEntityBase) + VILLAGER = VanillaEntityType.inherited(VillagerEntity::new, abstractVillagerEntityBase) .type(BuiltinEntityType.VILLAGER) .height(1.8f).width(0.6f) .offset(1.62f) .bedrockIdentifier("minecraft:villager_v2") .addTranslator(MetadataTypes.VILLAGER_DATA, VillagerEntity::setVillagerData) .build(); - WANDERING_TRADER = VanillaEntityDefinition.inherited(abstractVillagerEntityBase.factory(), abstractVillagerEntityBase) + WANDERING_TRADER = VanillaEntityType.inherited(abstractVillagerEntityBase.factory(), abstractVillagerEntityBase) .type(BuiltinEntityType.WANDERING_TRADER) .height(1.8f).width(0.6f) .offset(1.62f) @@ -1147,7 +1150,7 @@ public final class EntityDefinitions { // Water creatures (AgeableWaterCreature) { - DOLPHIN = VanillaEntityDefinition.inherited(DolphinEntity::new, ageableEntityBase) + DOLPHIN = VanillaEntityType.inherited(DolphinEntity::new, ageableEntityBase) .type(BuiltinEntityType.DOLPHIN) .height(0.6f).width(0.9f) //TODO check @@ -1155,11 +1158,11 @@ public final class EntityDefinitions { .addTranslator(null) // "got fish" .addTranslator(null) // "moistness level" .build(); - SQUID = VanillaEntityDefinition.inherited(SquidEntity::new, ageableEntityBase) + SQUID = VanillaEntityType.inherited(SquidEntity::new, ageableEntityBase) .type(BuiltinEntityType.SQUID) .heightAndWidth(0.8f) .build(); - GLOW_SQUID = VanillaEntityDefinition.inherited(GlowSquidEntity::new, SQUID) + GLOW_SQUID = VanillaEntityType.inherited(GlowSquidEntity::new, SQUID) .type(BuiltinEntityType.GLOW_SQUID) .addTranslator(null) // Set dark ticks remaining, possible TODO .build(); @@ -1167,56 +1170,56 @@ public final class EntityDefinitions { // Horses { - EntityDefinitionBase abstractHorseEntityBase = EntityDefinitionBase.baseInherited(AbstractHorseEntity.class, ageableEntityBase) + VanillaEntityBase abstractHorseEntityBase = VanillaEntityBase.baseInherited(AbstractHorseEntity.class, ageableEntityBase) .addTranslator(MetadataTypes.BYTE, AbstractHorseEntity::setHorseFlags) .build(); - CAMEL = VanillaEntityDefinition.inherited(CamelEntity::new, abstractHorseEntityBase) + CAMEL = VanillaEntityType.inherited(CamelEntity::new, abstractHorseEntityBase) .type(BuiltinEntityType.CAMEL) .height(2.375f).width(1.7f) .addTranslator(MetadataTypes.BOOLEAN, CamelEntity::setDashing) .addTranslator(MetadataTypes.LONG, CamelEntity::setLastPoseTick) .build(); - HORSE = VanillaEntityDefinition.inherited(HorseEntity::new, abstractHorseEntityBase) + HORSE = VanillaEntityType.inherited(HorseEntity::new, abstractHorseEntityBase) .type(BuiltinEntityType.HORSE) .height(1.6f).width(1.3965f) .addTranslator(MetadataTypes.INT, HorseEntity::setHorseVariant) .build(); - SKELETON_HORSE = VanillaEntityDefinition.inherited(SkeletonHorseEntity::new, abstractHorseEntityBase) + SKELETON_HORSE = VanillaEntityType.inherited(SkeletonHorseEntity::new, abstractHorseEntityBase) .type(BuiltinEntityType.SKELETON_HORSE) .height(1.6f).width(1.3965f) .build(); - ZOMBIE_HORSE = VanillaEntityDefinition.inherited(ZombieHorseEntity::new, abstractHorseEntityBase) + ZOMBIE_HORSE = VanillaEntityType.inherited(ZombieHorseEntity::new, abstractHorseEntityBase) .type(BuiltinEntityType.ZOMBIE_HORSE) .height(1.6f).width(1.3965f) .build(); - EntityDefinitionBase chestedHorseEntityBase = EntityDefinitionBase.baseInherited(ChestedHorseEntity.class, abstractHorseEntityBase) + VanillaEntityBase chestedHorseEntityBase = VanillaEntityBase.baseInherited(ChestedHorseEntity.class, abstractHorseEntityBase) .addTranslator(MetadataTypes.BOOLEAN, (horseEntity, entityMetadata) -> horseEntity.setFlag(EntityFlag.CHESTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .build(); - DONKEY = VanillaEntityDefinition.inherited(ChestedHorseEntity::new, chestedHorseEntityBase) + DONKEY = VanillaEntityType.inherited(ChestedHorseEntity::new, chestedHorseEntityBase) .type(BuiltinEntityType.DONKEY) .height(1.6f).width(1.3965f) .build(); - MULE = VanillaEntityDefinition.inherited(ChestedHorseEntity::new, chestedHorseEntityBase) + MULE = VanillaEntityType.inherited(ChestedHorseEntity::new, chestedHorseEntityBase) .type(BuiltinEntityType.MULE) .height(1.6f).width(1.3965f) .build(); - LLAMA = VanillaEntityDefinition.inherited(LlamaEntity::new, chestedHorseEntityBase) + LLAMA = VanillaEntityType.inherited(LlamaEntity::new, chestedHorseEntityBase) .type(BuiltinEntityType.LLAMA) .height(1.87f).width(0.9f) .addTranslator(MetadataTypes.INT, LlamaEntity::setStrength) .addTranslator(MetadataTypes.INT, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityDataTypes.VARIANT, entityMetadata.getValue())) .build(); - TRADER_LLAMA = VanillaEntityDefinition.inherited(TraderLlamaEntity::new, LLAMA) + TRADER_LLAMA = VanillaEntityType.inherited(TraderLlamaEntity::new, LLAMA) .type(BuiltinEntityType.TRADER_LLAMA) .bedrockIdentifier("minecraft:llama") .build(); } - EntityDefinitionBase tameableEntityBase = EntityDefinitionBase.baseInherited(TameableEntity.class, ageableEntityBase) + VanillaEntityBase tameableEntityBase = VanillaEntityBase.baseInherited(TameableEntity.class, ageableEntityBase) .addTranslator(MetadataTypes.BYTE, TameableEntity::setTameableFlags) .addTranslator(MetadataTypes.OPTIONAL_LIVING_ENTITY_REFERENCE, TameableEntity::setOwner) .build(); - CAT = VanillaEntityDefinition.inherited(CatEntity::new, tameableEntityBase) + CAT = VanillaEntityType.inherited(CatEntity::new, tameableEntityBase) .type(BuiltinEntityType.CAT) .height(0.35f).width(0.3f) .addTranslator(MetadataTypes.CAT_VARIANT, CatEntity::setVariant) @@ -1224,12 +1227,12 @@ public final class EntityDefinitions { .addTranslator(null) // "resting state one" //TODO .addTranslator(MetadataTypes.INT, CatEntity::setCollarColor) .build(); - PARROT = VanillaEntityDefinition.inherited(ParrotEntity::new, tameableEntityBase) + PARROT = VanillaEntityType.inherited(ParrotEntity::new, tameableEntityBase) .type(BuiltinEntityType.PARROT) .height(0.9f).width(0.5f) .addTranslator(MetadataTypes.INT, (parrotEntity, entityMetadata) -> parrotEntity.getDirtyMetadata().put(EntityDataTypes.VARIANT, entityMetadata.getValue())) // Parrot color .build(); - WOLF = VanillaEntityDefinition.inherited(WolfEntity::new, tameableEntityBase) + WOLF = VanillaEntityType.inherited(WolfEntity::new, tameableEntityBase) .type(BuiltinEntityType.WOLF) .height(0.85f).width(0.6f) .property(WolfEntity.SOUND_VARIANT) @@ -1242,23 +1245,25 @@ public final class EntityDefinitions { .build(); // As of 1.18 these don't track entity data at all - ENDER_DRAGON_PART = VanillaEntityDefinition.builder(null) + ENDER_DRAGON_PART = VanillaEntityType.builder(null) .bedrockIdentifier("minecraft:armor_stand") // Emulated .build(false); // Never sent over the network + PLAYER_ENTITY_OFFSET = PLAYER.defaultBedrockDefinition().offset(); + Registries.JAVA_ENTITY_IDENTIFIERS.get().put("minecraft:marker", null); // We don't need an entity definition for this as it is never sent over the network } - private static VanillaEntityDefinition buildBoat(EntityDefinitionBase base, BuiltinEntityType BuiltinEntityType, BoatEntity.BoatVariant variant) { - return VanillaEntityDefinition.inherited((session, javaId, bedrockId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw) -> + private static VanillaEntityType buildBoat(VanillaEntityBase base, BuiltinEntityType BuiltinEntityType, BoatEntity.BoatVariant variant) { + return VanillaEntityType.inherited((session, javaId, bedrockId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw) -> new BoatEntity(session, javaId, bedrockId, uuid, definition, bedrockDefinition, position, motion, yaw, variant), base) .type(BuiltinEntityType) .bedrockIdentifier("minecraft:boat") .build(); } - private static VanillaEntityDefinition buildChestBoat(EntityDefinitionBase base, BuiltinEntityType BuiltinEntityType, BoatEntity.BoatVariant variant) { - return VanillaEntityDefinition.inherited((session, javaId, bedrockId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw) -> + private static VanillaEntityType buildChestBoat(VanillaEntityBase base, BuiltinEntityType BuiltinEntityType, BoatEntity.BoatVariant variant) { + return VanillaEntityType.inherited((session, javaId, bedrockId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw) -> new ChestBoatEntity(session, javaId, bedrockId, uuid, definition, bedrockDefinition, position, motion, yaw, variant), base) .type(BuiltinEntityType) .bedrockIdentifier("minecraft:chest_boat") @@ -1267,24 +1272,28 @@ private static VanillaEntityDefinition buildChestBoat(EntityDef public static void init() { // entities would be initialized before these events are called - GeyserImpl.getInstance().getEventBus().fire(new GeyserDefineCustomEntitiesEvent() { + GeyserImpl.getInstance().getEventBus().fire(new GeyserDefineEntitiesEvent() { + @Override - public List customEntities() { - return null; // TODO Collections.unmodifiableList(Registries.CUSTOM_ENTITY_DEFINITIONS.get()); + public Collection entities() { + return Collections.unmodifiableCollection(Registries.BEDROCK_ENTITY_DEFINITIONS.get().values()); } @Override public void register(@NonNull CustomEntityDefinition customEntityDefinition) { Objects.requireNonNull(customEntityDefinition); - if (!(customEntityDefinition instanceof GeyserCustomEntityDefinition geyserCustomEntityDefinition)) { + if (!(customEntityDefinition instanceof GeyserCustomEntityTypeDefinition geyserCustomEntityDefinition)) { throw new IllegalStateException("Unknown custom entity definition: " + customEntityDefinition); } Registries.CUSTOM_ENTITY_DEFINITIONS.register(Registries.CUSTOM_ENTITY_DEFINITIONS.get().size(), geyserCustomEntityDefinition); } @Override - public void register(@NonNull JavaEntityType javaEntityType) { - // TODO??? + public void registerEntityType(@NonNull Identifier javaEntityType, int javaId) { + GeyserEntityType.createCustomAndRegister(javaEntityType, javaId); + + // TODO allow extending vanilla entities? + } }); @@ -1352,7 +1361,6 @@ public GeyserStringEnumProperty registerEnumProperty(@NonNull Identifier identif } @Override - // TODO breaking change!!! public Collection> properties(@NonNull Identifier identifier) { Objects.requireNonNull(identifier); var definition = Registries.BEDROCK_ENTITY_DEFINITIONS.get(identifier); @@ -1379,6 +1387,6 @@ private static void registerProperty(Identifier entityType, PropertyType { +public class VanillaEntityBase { final float width; final float height; final float offset; @Getter @Accessors(fluent = true) protected final List> translators; - public EntityDefinitionBase(float width, float height, float offset, List> translators) { + public VanillaEntityBase(float width, float height, float offset, List> translators) { this.width = width; this.height = height; this.offset = offset; @@ -62,7 +62,7 @@ public static Builder baseBuilder(Class clazz) { // Unused param so Java knows what entity we're talking about @SuppressWarnings("unused") - public static Builder baseInherited(Class clazz, EntityDefinitionBase parent) { + public static Builder baseInherited(Class clazz, VanillaEntityBase parent) { return new Builder(parent.width, parent.height, parent.offset, new ObjectArrayList<>(parent.translators)); } @@ -75,8 +75,8 @@ public void translateMetadata(T entity, EntityMetadata addTranslator(EntityMetadataTranslator translator) { return this; } - public EntityDefinitionBase build() { - return new EntityDefinitionBase<>(width, height, offset, translators); + public VanillaEntityBase build() { + return new VanillaEntityBase<>(width, height, offset, translators); } } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBases.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityBases.java similarity index 72% rename from core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBases.java rename to core/src/main/java/org/geysermc/geyser/entity/VanillaEntityBases.java index 32b10b143a0..9b973614c0f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinitionBases.java +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityBases.java @@ -47,27 +47,27 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.FloatEntityMetadata; -public final class EntityDefinitionBases { - public static final EntityDefinitionBase ENTITY; - public static final EntityDefinitionBase DISPLAY; - public static final EntityDefinitionBase FIREBALL; - public static final EntityDefinitionBase THROWABLE; - public static final EntityDefinitionBase HANGING; - public static final EntityDefinitionBase BOAT; - public static final EntityDefinitionBase CHEST_BOAT; - public static final EntityDefinitionBase LIVING_ENTITY; - public static final EntityDefinitionBase AVATAR; - public static final EntityDefinitionBase MOB; - public static final EntityDefinitionBase FISH; - public static final EntityDefinitionBase PIGLIN; - public static final EntityDefinitionBase RAID_PARTICIPANT; - public static final EntityDefinitionBase SPELLCASTER; - public static final EntityDefinitionBase AGEABLE; - public static final EntityDefinitionBase HORSE; - public static final EntityDefinitionBase TAMABLE; +public final class VanillaEntityBases { + public static final VanillaEntityBase ENTITY; + public static final VanillaEntityBase DISPLAY; + public static final VanillaEntityBase FIREBALL; + public static final VanillaEntityBase THROWABLE; + public static final VanillaEntityBase HANGING; + public static final VanillaEntityBase BOAT; + public static final VanillaEntityBase CHEST_BOAT; + public static final VanillaEntityBase LIVING_ENTITY; + public static final VanillaEntityBase AVATAR; + public static final VanillaEntityBase MOB; + public static final VanillaEntityBase FISH; + public static final VanillaEntityBase PIGLIN; + public static final VanillaEntityBase RAID_PARTICIPANT; + public static final VanillaEntityBase SPELLCASTER; + public static final VanillaEntityBase AGEABLE; + public static final VanillaEntityBase HORSE; + public static final VanillaEntityBase TAMABLE; static { - ENTITY = EntityDefinition.baseBuilder(Entity.class) + ENTITY = EntityTypeDefinition.baseBuilder(Entity.class) .addTranslator(MetadataTypes.BYTE, Entity::setFlags) .addTranslator(MetadataTypes.INT, Entity::setAir) // Air/bubbles .addTranslator(MetadataTypes.OPTIONAL_COMPONENT, Entity::setDisplayName) @@ -77,7 +77,7 @@ public final class EntityDefinitionBases { .addTranslator(MetadataTypes.POSE, (entity, entityMetadata) -> entity.setPose(entityMetadata.getValue())) .addTranslator(MetadataTypes.INT, Entity::setFreezing) .build(); - DISPLAY = EntityDefinitionBase.baseInherited(DisplayBaseEntity.class, ENTITY) + DISPLAY = VanillaEntityBase.baseInherited(DisplayBaseEntity.class, ENTITY) .addTranslator(null) // Interpolation delay .addTranslator(null) // Transformation interpolation duration .addTranslator(null) // Position/Rotation interpolation duration @@ -94,18 +94,18 @@ public final class EntityDefinitionBases { .addTranslator(null) // Height .addTranslator(null) // Glow color override .build(); - FIREBALL = EntityDefinitionBase.baseInherited(FireballEntity.class, ENTITY) + FIREBALL = VanillaEntityBase.baseInherited(FireballEntity.class, ENTITY) .addTranslator(null) // Item .build(); - THROWABLE = EntityDefinitionBase.baseInherited(ThrowableItemEntity.class, ENTITY) + THROWABLE = VanillaEntityBase.baseInherited(ThrowableItemEntity.class, ENTITY) .addTranslator(MetadataTypes.ITEM_STACK, ThrowableItemEntity::setItem) .build(); - HANGING = EntityDefinitionBase.baseInherited(HangingEntity.class, ENTITY) + HANGING = VanillaEntityBase.baseInherited(HangingEntity.class, ENTITY) .addTranslator(MetadataTypes.DIRECTION, HangingEntity::setDirectionMetadata) .build(); - BOAT = EntityDefinitionBase.baseInherited(BoatEntity.class, ENTITY) -// .height(0.6f).width(1.6f) TODO CE -// .offset(0.35f) + BOAT = VanillaEntityBase.baseInherited(BoatEntity.class, ENTITY) + .height(0.6f).width(1.6f) + .offset(0.35f) .addTranslator(MetadataTypes.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityDataTypes.HURT_TICKS, entityMetadata.getValue())) // Time since last hit .addTranslator(MetadataTypes.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityDataTypes.HURT_DIRECTION, entityMetadata.getValue())) // Rocking direction .addTranslator(MetadataTypes.FLOAT, (boatEntity, entityMetadata) -> @@ -115,9 +115,9 @@ public final class EntityDefinitionBases { .addTranslator(MetadataTypes.BOOLEAN, BoatEntity::setPaddlingRight) .addTranslator(MetadataTypes.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityDataTypes.BOAT_BUBBLE_TIME, entityMetadata.getValue())) // May not actually do anything .build(); - CHEST_BOAT = EntityDefinitionBase.baseInherited(ChestBoatEntity.class, BOAT) + CHEST_BOAT = VanillaEntityBase.baseInherited(ChestBoatEntity.class, BOAT) .build(); - LIVING_ENTITY = EntityDefinitionBase.baseInherited(LivingEntity.class, ENTITY) + LIVING_ENTITY = VanillaEntityBase.baseInherited(LivingEntity.class, ENTITY) .addTranslator(MetadataTypes.BYTE, LivingEntity::setLivingEntityFlags) .addTranslator(MetadataTypes.FLOAT, LivingEntity::setHealth) .addTranslator(MetadataTypes.PARTICLES, LivingEntity::setParticles) @@ -127,39 +127,39 @@ public final class EntityDefinitionBases { .addTranslator(null) // Stinger count .addTranslator(MetadataTypes.OPTIONAL_BLOCK_POS, LivingEntity::setBedPosition) .build(); - AVATAR = EntityDefinitionBase.baseInherited(AvatarEntity.class, LIVING_ENTITY) -// .height(1.8f).width(0.6f) TODO CE -// .offset(1.62f) + AVATAR = VanillaEntityBase.baseInherited(AvatarEntity.class, LIVING_ENTITY) + .height(1.8f).width(0.6f) + .offset(1.62f) .addTranslator(null) // Player main hand .addTranslator(MetadataTypes.BYTE, AvatarEntity::setSkinVisibility) .build(); - MOB = EntityDefinitionBase.baseInherited(MobEntity.class, LIVING_ENTITY) + MOB = VanillaEntityBase.baseInherited(MobEntity.class, LIVING_ENTITY) .addTranslator(MetadataTypes.BYTE, MobEntity::setMobFlags) .build(); - FISH = EntityDefinitionBase.baseInherited(AbstractFishEntity.class, MOB) + FISH = VanillaEntityBase.baseInherited(AbstractFishEntity.class, MOB) .addTranslator(null) // From bucket .build(); - PIGLIN = EntityDefinitionBase.baseInherited(BasePiglinEntity.class, MOB) + PIGLIN = VanillaEntityBase.baseInherited(BasePiglinEntity.class, MOB) .addTranslator(MetadataTypes.BOOLEAN, BasePiglinEntity::setImmuneToZombification) .build(); - RAID_PARTICIPANT = EntityDefinitionBase.baseInherited(RaidParticipantEntity.class, MOB) + RAID_PARTICIPANT = VanillaEntityBase.baseInherited(RaidParticipantEntity.class, MOB) .addTranslator(null) // Celebrating //TODO .build(); - SPELLCASTER = EntityDefinitionBase.baseInherited(SpellcasterIllagerEntity.class, RAID_PARTICIPANT) + SPELLCASTER = VanillaEntityBase.baseInherited(SpellcasterIllagerEntity.class, RAID_PARTICIPANT) .addTranslator(MetadataTypes.BYTE, SpellcasterIllagerEntity::setSpellType) .build(); - AGEABLE = EntityDefinitionBase.baseInherited(AgeableEntity.class, MOB) + AGEABLE = VanillaEntityBase.baseInherited(AgeableEntity.class, MOB) .addTranslator(MetadataTypes.BOOLEAN, AgeableEntity::setBaby) .build(); - HORSE = EntityDefinitionBase.baseInherited(AbstractHorseEntity.class, AGEABLE) + HORSE = VanillaEntityBase.baseInherited(AbstractHorseEntity.class, AGEABLE) .addTranslator(MetadataTypes.BYTE, AbstractHorseEntity::setHorseFlags) .build(); - TAMABLE = EntityDefinitionBase.baseInherited(TameableEntity.class, AGEABLE) + TAMABLE = VanillaEntityBase.baseInherited(TameableEntity.class, AGEABLE) .addTranslator(MetadataTypes.BYTE, TameableEntity::setTameableFlags) .addTranslator(MetadataTypes.OPTIONAL_LIVING_ENTITY_REFERENCE, TameableEntity::setOwner) .build(); } - private EntityDefinitionBases() { + private VanillaEntityBases() { } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java similarity index 85% rename from core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java rename to core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java index c9fd77d8319..41b8ae45c3b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java @@ -47,10 +47,10 @@ @Accessors(fluent = true) @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class VanillaEntityDefinition extends EntityDefinition { +public class VanillaEntityType extends EntityTypeDefinition { private final GeyserEntityType entityType; - public VanillaEntityDefinition(EntityFactory factory, GeyserEntityType entityType, BedrockEntityDefinition bedrockDefinition, List> translators) { + public VanillaEntityType(EntityFactory factory, GeyserEntityType entityType, BedrockEntityDefinition bedrockDefinition, List> translators) { super(factory, entityType, bedrockDefinition, translators); this.entityType = entityType; } @@ -64,11 +64,11 @@ public static Builder builder(EntityFactory factory) { return new Builder<>(factory); } - public static Builder inherited(EntityFactory factory, EntityDefinitionBase parent) { + public static Builder inherited(EntityFactory factory, VanillaEntityBase parent) { return new Builder<>(factory, parent.width, parent.height, parent.offset, new ObjectArrayList<>(parent.translators)); } - public static class Builder extends EntityDefinition.Builder { + public static class Builder extends EntityTypeDefinition.Builder { protected GeyserEntityType type; protected Builder(EntityFactory factory) { @@ -129,25 +129,24 @@ public Builder addTranslator(EntityMetadataTranslator translator) { } @Override - public VanillaEntityDefinition build() { + public VanillaEntityType build() { return build(true); } - // TODO CE -// private void validateTypeAndIdentifier() { -// if (type == null) { -// throw new IllegalStateException("Missing entity type!"); -// } else if (bedrockIdentifier == null) { -// bedrockIdentifier = type.identifier().toString(); -// } -// } + private void validateTypeAndIdentifier() { + if (type == null) { + throw new IllegalStateException("Missing entity type!"); + } else if (bedrockIdentifier == null) { + bedrockIdentifier = type.identifier().toString(); + } + } /** * @param register whether to register this entity in the Registries for entity types. Generally this should be * set to false if we're not expecting this entity to spawn from the network. */ - public VanillaEntityDefinition build(boolean register) { - //validateTypeAndIdentifier(); + public VanillaEntityType build(boolean register) { + validateTypeAndIdentifier(); BedrockEntityDefinition bedrockDefinition = BedrockEntityDefinition.builder() .height(height) @@ -159,7 +158,7 @@ public VanillaEntityDefinition build(boolean register) { // TODO TEST!!! Registries.BEDROCK_ENTITY_DEFINITIONS.get().put(Identifier.of(bedrockIdentifier), bedrockDefinition); - VanillaEntityDefinition definition = new VanillaEntityDefinition<>(factory, type, bedrockDefinition, translators); + VanillaEntityType definition = new VanillaEntityType<>(factory, type, bedrockDefinition, translators); if (register && definition.entityType() != null) { Registries.ENTITY_DEFINITIONS.get().putIfAbsent(definition.entityType(), definition); Registries.JAVA_ENTITY_IDENTIFIERS.get().putIfAbsent(type.identifier().toString(), definition); diff --git a/core/src/main/java/org/geysermc/geyser/entity/factory/EntityFactory.java b/core/src/main/java/org/geysermc/geyser/entity/factory/EntityFactory.java index dd18c0d2da0..c428af5f483 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/factory/EntityFactory.java +++ b/core/src/main/java/org/geysermc/geyser/entity/factory/EntityFactory.java @@ -27,7 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.session.GeyserSession; @@ -38,5 +38,5 @@ */ public interface EntityFactory { - T create(GeyserSession session, int javaId, long bedrockId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw); + T create(GeyserSession session, int javaId, long bedrockId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/AbstractArrowEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/AbstractArrowEntity.java index 28393eed3c0..82d71533ec2 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/AbstractArrowEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/AbstractArrowEntity.java @@ -28,7 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; @@ -37,7 +37,7 @@ public class AbstractArrowEntity extends Entity { - public AbstractArrowEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public AbstractArrowEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); // Set the correct texture if using the resource pack diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/AbstractWindChargeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/AbstractWindChargeEntity.java index 3eabf06e615..c95161c15be 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/AbstractWindChargeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/AbstractWindChargeEntity.java @@ -27,7 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; @@ -37,7 +37,7 @@ * the "hide until far away" aspect. */ public class AbstractWindChargeEntity extends ThrowableItemEntity { - public AbstractWindChargeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public AbstractWindChargeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/AreaEffectCloudEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/AreaEffectCloudEntity.java index f2bb8fe949a..1ded86398fc 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/AreaEffectCloudEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/AreaEffectCloudEntity.java @@ -30,7 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.MathUtils; @@ -43,7 +43,7 @@ public class AreaEffectCloudEntity extends Entity { - public AreaEffectCloudEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public AreaEffectCloudEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ArrowEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ArrowEntity.java index 845d4df5443..2e08083f7a8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ArrowEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ArrowEntity.java @@ -28,7 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.item.Potion; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; @@ -37,7 +37,7 @@ public class ArrowEntity extends AbstractArrowEntity { - public ArrowEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public ArrowEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java index 8c5526dc85d..02c90905d31 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java @@ -32,8 +32,8 @@ import org.cloudburstmc.protocol.bedrock.packet.AnimatePacket; import org.cloudburstmc.protocol.bedrock.packet.MoveEntityAbsolutePacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; @@ -72,7 +72,7 @@ public class BoatEntity extends Entity implements Leashable, Tickable { // Looks too fast and too choppy with 0.1f, which is how I believe the Microsoftian client handles it private final float ROWING_SPEED = 0.1f; - public BoatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, BoatVariant variant) { + public BoatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, BoatVariant variant) { // Initial rotation is incorrect super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position.add(0d, bedrockDefinition.offset(), 0d), motion, yaw + 90, 0, yaw + 90); this.variant = variant; @@ -94,7 +94,7 @@ protected void initializeMetadata() { @Override public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { // We don't include the rotation (y) as it causes the boat to appear sideways - setPosition(position.add(0d, this.bedrockDefinition.offset(), 0d)); + setPosition(position.add(0d, this.definition.offset(), 0d)); setYaw(yaw + 90); setHeadYaw(yaw + 90); setOnGround(isOnGround); @@ -103,7 +103,7 @@ public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYa moveEntityPacket.setRuntimeEntityId(geyserId); if (session.getPlayerEntity().getVehicle() == this && session.getPlayerEntity().isRidingInFront()) { // Minimal glitching when ClientboundMoveVehiclePacket is sent - moveEntityPacket.setPosition(position.up(EntityDefinitions.PLAYER.bedrockDefinition().offset() - this.bedrockDefinition.offset())); + moveEntityPacket.setPosition(position.up(VanillaEntities.PLAYER_ENTITY_OFFSET - this.definition.offset())); } else { moveEntityPacket.setPosition(this.position); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ChestBoatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ChestBoatEntity.java index 8b04054d51b..bc178990d65 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ChestBoatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ChestBoatEntity.java @@ -27,7 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; @@ -36,7 +36,7 @@ import java.util.UUID; public class ChestBoatEntity extends BoatEntity { - public ChestBoatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, BoatVariant variant) { + public ChestBoatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, BoatVariant variant) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, variant); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/CommandBlockMinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/CommandBlockMinecartEntity.java index 4e11a22c5ff..aca925557f9 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/CommandBlockMinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/CommandBlockMinecartEntity.java @@ -31,7 +31,7 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerType; import org.cloudburstmc.protocol.bedrock.packet.ContainerOpenPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; @@ -41,7 +41,7 @@ public class CommandBlockMinecartEntity extends DefaultBlockMinecartEntity { - public CommandBlockMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public CommandBlockMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/DefaultBlockMinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/DefaultBlockMinecartEntity.java index 865c7a35580..933ef115b3a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/DefaultBlockMinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/DefaultBlockMinecartEntity.java @@ -28,7 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; @@ -43,7 +43,7 @@ public class DefaultBlockMinecartEntity extends MinecartEntity { public int customBlockOffset = 0; public boolean showCustomBlock = false; - public DefaultBlockMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public DefaultBlockMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); dirtyMetadata.put(EntityDataTypes.CUSTOM_DISPLAY, (byte) 1); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/DisplayBaseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/DisplayBaseEntity.java index 3a752987070..77673039d0e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/DisplayBaseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/DisplayBaseEntity.java @@ -29,7 +29,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.EntityUtils; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; @@ -42,7 +42,7 @@ public class DisplayBaseEntity extends Entity { private @Nullable Vector3f baseTranslation; - public DisplayBaseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public DisplayBaseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/EnderCrystalEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/EnderCrystalEntity.java index 6b40bc4de3a..864c072c0e0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/EnderCrystalEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/EnderCrystalEntity.java @@ -30,7 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; @@ -39,7 +39,7 @@ public class EnderCrystalEntity extends Entity { - public EnderCrystalEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public EnderCrystalEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/EnderEyeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/EnderEyeEntity.java index 015e3f0993e..8bc85981ae3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/EnderEyeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/EnderEyeEntity.java @@ -29,13 +29,13 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public class EnderEyeEntity extends Entity { - public EnderEyeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public EnderEyeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index c10c41a15e8..6bb7df1883c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -28,6 +28,7 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; +import lombok.experimental.Accessors; import net.kyori.adventure.text.Component; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; @@ -47,7 +48,7 @@ import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.entity.type.GeyserEntity; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.GeyserDirtyMetadata; import org.geysermc.geyser.entity.properties.GeyserEntityProperties; import org.geysermc.geyser.entity.properties.GeyserEntityPropertyManager; @@ -85,8 +86,9 @@ public class Entity implements GeyserEntity { private static final boolean PRINT_ENTITY_SPAWN_DEBUG = Boolean.parseBoolean(System.getProperty("Geyser.PrintEntitySpawnDebug", "false")); protected final GeyserSession session; - protected final BedrockEntityDefinition bedrockDefinition; - protected EntityDefinition definition; + @Accessors(fluent = true) + protected final BedrockEntityDefinition definition; + protected EntityTypeDefinition javaDefinition; protected int entityId; protected final long geyserId; @@ -152,11 +154,11 @@ public class Entity implements GeyserEntity { protected final GeyserEntityPropertyManager propertyManager; - public Entity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, + public Entity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { this.session = session; - this.definition = definition; - this.bedrockDefinition = bedrockDefinition; + this.javaDefinition = definition; + this.definition = bedrockDefinition; this.displayName = standardDisplayName(); this.entityId = entityId; @@ -200,7 +202,7 @@ protected void setClientSideSilent() { public void spawnEntity() { AddEntityPacket addEntityPacket = new AddEntityPacket(); - addEntityPacket.setIdentifier(bedrockDefinition.identifier().toString()); + addEntityPacket.setIdentifier(definition.identifier().toString()); addEntityPacket.setRuntimeEntityId(geyserId); addEntityPacket.setUniqueEntityId(geyserId); addEntityPacket.setPosition(position); @@ -223,7 +225,7 @@ public void spawnEntity() { flagsDirty = false; if (session.getGeyser().config().debugMode() && PRINT_ENTITY_SPAWN_DEBUG) { - session.getGeyser().getLogger().debug("Spawned entity " + definition.type() + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")"); + session.getGeyser().getLogger().debug("Spawned entity " + javaDefinition.type() + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")"); } } @@ -493,7 +495,7 @@ public void setDisplayName(EntityMetadata, ?> entityMetadata } protected String standardDisplayName() { - return EntityUtils.translatedEntityName(definition.type(), session); + return EntityUtils.translatedEntityName(javaDefinition.type(), session); } protected void setNametag(@Nullable String nametag, boolean fromDisplayName) { @@ -573,8 +575,8 @@ public void setPose(Pose pose) { */ protected void setDimensionsFromPose(Pose pose) { // No flexibility options for basic entities - setBoundingBoxHeight(bedrockDefinition.height()); - setBoundingBoxWidth(bedrockDefinition.width()); + setBoundingBoxHeight(definition.height()); + setBoundingBoxWidth(definition.width()); } public boolean setBoundingBoxHeight(float height) { @@ -786,7 +788,7 @@ public void updatePropertiesBatched(Consumer consumer, boo } Objects.requireNonNull(consumer); - GeyserEntityProperties propertyDefinitions = bedrockDefinition.registeredProperties(); + GeyserEntityProperties propertyDefinitions = definition.registeredProperties(); consumer.accept(new BatchPropertyUpdater() { @Override public void update(@NonNull GeyserEntityProperty property, @Nullable T value) { @@ -828,6 +830,6 @@ public void update(@NonNull GeyserEntityProperty property, @Nullable T va @Override public Vector3f position() { - return this.position.down(bedrockDefinition.offset()); + return this.position.down(definition.offset()); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java index 93a911e9980..809c8cc60db 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java @@ -29,7 +29,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.packet.PlaySoundPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; @@ -39,7 +39,7 @@ public class EvokerFangsEntity extends Entity implements Tickable { private int limitedLife = 22; private boolean attackStarted = false; - public EvokerFangsEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public EvokerFangsEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); // As of 1.18.2 Bedrock, this line is required for the entity to be visible // 22 is the starting number on Java Edition diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ExpOrbEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ExpOrbEntity.java index 19c7749dc49..fc25b26dc88 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ExpOrbEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ExpOrbEntity.java @@ -28,14 +28,14 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public class ExpOrbEntity extends Entity { - public ExpOrbEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public ExpOrbEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); this.dirtyMetadata.put(EntityDataTypes.TRADE_EXPERIENCE, 1); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FallingBlockEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FallingBlockEntity.java index 81aeb2fabeb..08eb4d15620 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FallingBlockEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FallingBlockEntity.java @@ -29,7 +29,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; @@ -39,7 +39,7 @@ public class FallingBlockEntity extends Entity { // TODO public FallingBlockEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, BedrockEntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw, int javaId) { - super(session, entityId, geyserId, uuid, EntityDefinitions.FALLING_BLOCK, definition, position, motion, yaw, pitch, headYaw); + super(session, entityId, geyserId, uuid, VanillaEntities.FALLING_BLOCK, definition, position, motion, yaw, pitch, headYaw); this.dirtyMetadata.put(EntityDataTypes.BLOCK, session.getBlockMappings().getBedrockBlock(javaId)); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java index e3e82a4508e..631fbf73ca9 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java @@ -27,7 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; @@ -40,7 +40,7 @@ public class FireballEntity extends ThrowableEntity { */ protected int futureTicks = 3; - public FireballEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public FireballEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, Vector3f.ZERO, yaw, pitch, headYaw); float magnitude = motion.length(); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FireworkEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FireworkEntity.java index b4a22534a46..b5572c786a5 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FireworkEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FireworkEntity.java @@ -30,7 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.packet.MovementEffectPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.TooltipOptions; import org.geysermc.geyser.session.GeyserSession; @@ -46,7 +46,7 @@ public class FireworkEntity extends Entity { private boolean attachedToSession; - public FireworkEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public FireworkEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java index 77c4127ce6c..202a957adaf 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java @@ -31,7 +31,7 @@ import org.cloudburstmc.protocol.bedrock.packet.PlaySoundPacket; import org.geysermc.erosion.util.BlockPositionIterator; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.player.PlayerEntity; import org.geysermc.geyser.level.block.BlockStateValues; import org.geysermc.geyser.level.block.type.Block; @@ -57,7 +57,7 @@ public class FishingHookEntity extends ThrowableEntity { private final BoundingBox boundingBox; public FishingHookEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, BedrockEntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw, PlayerEntity owner) { - super(session, entityId, geyserId, uuid, EntityDefinitions.FISHING_BOBBER, definition, position, motion, yaw, pitch, 0f); + super(session, entityId, geyserId, uuid, VanillaEntities.FISHING_BOBBER, definition, position, motion, yaw, pitch, 0f); this.boundingBox = new BoundingBox(0.125, 0.125, 0.125, 0.25, 0.25, 0.25); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FurnaceMinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FurnaceMinecartEntity.java index 749179231fb..4f7e3346022 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FurnaceMinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FurnaceMinecartEntity.java @@ -28,7 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.level.block.Blocks; import org.geysermc.geyser.level.block.property.Properties; import org.geysermc.geyser.level.block.type.BlockState; @@ -42,7 +42,7 @@ public class FurnaceMinecartEntity extends DefaultBlockMinecartEntity { private boolean hasFuel = false; - public FurnaceMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public FurnaceMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/HangingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/HangingEntity.java index 7d5f53dbf02..b4d99216c01 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/HangingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/HangingEntity.java @@ -27,7 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction; @@ -36,7 +36,7 @@ public abstract class HangingEntity extends Entity { - public HangingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public HangingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java index 6bf34cd6eaa..a855e1d42e1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java @@ -32,8 +32,8 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.AnimatePacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.living.ArmorStandEntity; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; @@ -54,7 +54,7 @@ public class InteractionEntity extends Entity { */ private boolean response = false; - public InteractionEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public InteractionEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @@ -164,7 +164,7 @@ public void updateNameTag() { if (this.secondEntity == null) { // TODO CE make this controllable??? secondEntity = new ArmorStandEntity(session, 0, session.getEntityCache().getNextEntityId().incrementAndGet(), null, - EntityDefinitions.ARMOR_STAND, bedrockDefinition, position.up(getBoundingBoxHeight()), motion, getYaw(), getPitch(), getHeadYaw()); + VanillaEntities.ARMOR_STAND, definition, position.up(getBoundingBoxHeight()), motion, getYaw(), getPitch(), getHeadYaw()); } secondEntity.getDirtyMetadata().put(EntityDataTypes.NAME, nametag); secondEntity.getDirtyMetadata().put(EntityDataTypes.NAMETAG_ALWAYS_SHOW, isNameTagVisible ? (byte) 1 : (byte) 0); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java index 042c01a20e6..140e17025b7 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java @@ -33,7 +33,7 @@ import org.cloudburstmc.protocol.bedrock.packet.AddItemEntityPacket; import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.level.block.BlockStateValues; import org.geysermc.geyser.level.block.type.BlockState; import org.geysermc.geyser.session.GeyserSession; @@ -49,7 +49,7 @@ public class ItemEntity extends ThrowableEntity { private CompletableFuture waterLevel = CompletableFuture.completedFuture(-1); - public ItemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public ItemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @@ -62,7 +62,7 @@ public void spawnEntity() { AddItemEntityPacket itemPacket = new AddItemEntityPacket(); itemPacket.setRuntimeEntityId(geyserId); itemPacket.setUniqueEntityId(geyserId); - itemPacket.setPosition(position.add(0d, this.bedrockDefinition.offset(), 0d)); + itemPacket.setPosition(position.add(0d, this.definition.offset(), 0d)); itemPacket.setMotion(motion); itemPacket.setFromFishing(false); itemPacket.setItemInHand(item); @@ -113,10 +113,10 @@ public void setItem(EntityMetadata entityMetadata) { @Override protected void moveAbsoluteImmediate(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - float offset = bedrockDefinition.offset(); + float offset = definition.offset(); if (waterLevel.join() == 0) { // Item is in a full block of water // Move the item entity down so it doesn't float above the water - offset = -bedrockDefinition.offset(); + offset = -definition.offset(); } super.moveAbsoluteImmediate(position.add(0, offset, 0), 0, 0, 0, isOnGround, teleported); this.position = position; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java index 7f8132f441c..4e8f60bb9b9 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java @@ -35,7 +35,7 @@ import org.cloudburstmc.protocol.bedrock.packet.BlockEntityDataPacket; import org.cloudburstmc.protocol.bedrock.packet.UpdateBlockPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.item.ItemTranslator; import org.geysermc.geyser.util.InteractionResult; @@ -80,7 +80,7 @@ public class ItemFrameEntity extends HangingEntity { */ private boolean changed = true; - public ItemFrameEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public ItemFrameEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); blockDefinition = buildBlockDefinition(Direction.SOUTH); // Default to SOUTH direction, like on Java - entity metadata should correct this when necessary @@ -177,7 +177,7 @@ private NbtMap getDefaultTag() { builder.putInt("y", bedrockPosition.getY()); builder.putInt("z", bedrockPosition.getZ()); builder.putByte("isMovable", (byte) 1); - builder.putString("id", this.definition.type().is(BuiltinEntityType.GLOW_ITEM_FRAME) ? "GlowItemFrame" : "ItemFrame"); + builder.putString("id", this.javaDefinition.type().is(BuiltinEntityType.GLOW_ITEM_FRAME) ? "GlowItemFrame" : "ItemFrame"); return builder.build(); } @@ -223,7 +223,7 @@ public InteractionResult interact(Hand hand) { private BlockDefinition buildBlockDefinition(Direction direction) { NbtMapBuilder blockBuilder = NbtMap.builder() - .putString("name", this.definition.type().is(BuiltinEntityType.GLOW_ITEM_FRAME) ? "minecraft:glow_frame" : "minecraft:frame"); + .putString("name", this.javaDefinition.type().is(BuiltinEntityType.GLOW_ITEM_FRAME) ? "minecraft:glow_frame" : "minecraft:frame"); NbtMapBuilder statesBuilder = NbtMap.builder() .putInt("facing_direction", direction.ordinal()) .putByte("item_frame_map_bit", (byte) 0) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java index 40a9de0eb15..433731a746a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java @@ -27,7 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; @@ -36,7 +36,7 @@ public class LeashKnotEntity extends Entity { - public LeashKnotEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public LeashKnotEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { // Position is incorrect by default super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position.add(0.5f, 0.25f, 0.5f), motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LightningEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LightningEntity.java index a134cf07327..498d2071b83 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LightningEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LightningEntity.java @@ -28,7 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.packet.PlaySoundPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; @@ -36,7 +36,7 @@ public class LightningEntity extends Entity { - public LightningEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public LightningEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java index 469a08a8710..198d10a4c03 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java @@ -39,7 +39,7 @@ import org.cloudburstmc.protocol.bedrock.packet.MobEquipmentPacket; import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.attribute.GeyserAttributeType; import org.geysermc.geyser.entity.type.living.animal.HappyGhastEntity; import org.geysermc.geyser.entity.vehicle.ClientVehicle; @@ -106,7 +106,7 @@ public class LivingEntity extends Entity { @Setter(AccessLevel.NONE) private float attributeScale; - public LivingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public LivingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @@ -554,7 +554,7 @@ private boolean hasValidEquippableItemForSlot(EquipmentSlot slot) { if (equippable != null) { return slot == equippable.slot() && canUseSlot(slot) && - EntityUtils.equipmentUsableByEntity(session, equippable, definition.type()); + EntityUtils.equipmentUsableByEntity(session, equippable, javaDefinition.type()); } else { return slot == EquipmentSlot.MAIN_HAND && canUseSlot(EquipmentSlot.MAIN_HAND); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java index 4d81aefb69b..461efc39824 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java @@ -31,8 +31,8 @@ import org.cloudburstmc.protocol.bedrock.packet.MoveEntityDeltaPacket; import org.cloudburstmc.protocol.bedrock.packet.SetEntityMotionPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; @@ -60,7 +60,7 @@ public class MinecartEntity extends Entity implements Tickable { private int cachedStepDelay; private float cachedDelta; - public MinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public MinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position.add(0d, bedrockDefinition.offset(), 0d), motion, yaw, pitch, headYaw); } @@ -114,7 +114,7 @@ public void tick() { moveEntityPacket.setRuntimeEntityId(geyserId); moveEntityPacket.setX(position.getX()); - moveEntityPacket.setY(position.getY() + bedrockDefinition.offset()); + moveEntityPacket.setY(position.getY() + definition.offset()); moveEntityPacket.setZ(position.getZ()); moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_X); moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Y); @@ -202,7 +202,7 @@ private void updateCompletedStep() { @Override public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - super.moveAbsolute(position.add(0d, this.bedrockDefinition.offset(), 0d), yaw, pitch, headYaw, isOnGround, teleported); + super.moveAbsolute(position.add(0d, this.definition.offset(), 0d), yaw, pitch, headYaw, isOnGround, teleported); } @Override @@ -220,7 +220,7 @@ public boolean doesJumpDismount() { @Override protected InteractiveTag testInteraction(Hand hand) { - if (definition == EntityDefinitions.CHEST_MINECART || definition == EntityDefinitions.HOPPER_MINECART) { + if (javaDefinition == VanillaEntities.CHEST_MINECART || javaDefinition == VanillaEntities.HOPPER_MINECART) { return InteractiveTag.OPEN_CONTAINER; } else { if (session.isSneaking()) { @@ -237,7 +237,7 @@ protected InteractiveTag testInteraction(Hand hand) { @Override public InteractionResult interact(Hand hand) { - if (definition == EntityDefinitions.CHEST_MINECART || definition == EntityDefinitions.HOPPER_MINECART) { + if (javaDefinition == VanillaEntities.CHEST_MINECART || javaDefinition == VanillaEntities.HOPPER_MINECART) { // Opening the UI of this minecart return InteractionResult.SUCCESS; } else { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java index 4733f1e07e1..4f4b552dfc1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java @@ -28,7 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.packet.AddPaintingPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.level.PaintingType; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.registry.JavaRegistries; @@ -44,7 +44,7 @@ public class PaintingEntity extends HangingEntity { private int paintingId = -1; // Ideally this would be the default painting Java uses in their metadata, but seems to depend on the current paintings loaded in the registry private Direction direction = Direction.SOUTH; // Default to SOUTH direction, like on Java - entity metadata should correct this when necessary - public PaintingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public PaintingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/SpawnerMinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/SpawnerMinecartEntity.java index 84e1e0ef99c..9eb2c42212f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/SpawnerMinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/SpawnerMinecartEntity.java @@ -28,7 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.level.block.Blocks; import org.geysermc.geyser.session.GeyserSession; @@ -36,7 +36,7 @@ public class SpawnerMinecartEntity extends DefaultBlockMinecartEntity { - public SpawnerMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public SpawnerMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java index fe0777ea7e3..c88488496a6 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java @@ -30,7 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.SetEntityDataPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; @@ -39,18 +39,18 @@ public class TNTEntity extends Entity implements Tickable { private int currentTick; - public TNTEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public TNTEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position.add(0, bedrockDefinition.offset(), 0), motion, yaw, pitch, headYaw); } @Override public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, boolean isOnGround) { - super.moveRelative(relX, relY + bedrockDefinition.offset(), relZ, yaw, pitch, isOnGround); + super.moveRelative(relX, relY + definition.offset(), relZ, yaw, pitch, isOnGround); } @Override public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - super.moveAbsolute(position.add(Vector3f.from(0, bedrockDefinition.offset(), 0)), yaw, pitch, headYaw, isOnGround, teleported); + super.moveAbsolute(position.add(Vector3f.from(0, definition.offset(), 0)), yaw, pitch, headYaw, isOnGround, teleported); } public void setFuseLength(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java index 2ce33a1ce8a..90b217bb96d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java @@ -32,7 +32,7 @@ import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.text.MessageTranslator; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; @@ -56,13 +56,13 @@ public class TextDisplayEntity extends DisplayBaseEntity { private int lineCount; - public TextDisplayEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public TextDisplayEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position.add(0, bedrockDefinition.offset(), 0), motion, yaw, pitch, headYaw); } @Override public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, boolean isOnGround) { - super.moveRelative(relX, relY + bedrockDefinition.offset(), relZ, yaw, pitch, isOnGround); + super.moveRelative(relX, relY + definition.offset(), relZ, yaw, pitch, isOnGround); } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEggEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEggEntity.java index 87682ba9d8d..c5587f8edb9 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEggEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEggEntity.java @@ -29,13 +29,12 @@ import net.kyori.adventure.key.Key; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.living.animal.farm.TemperatureVariantAnimal; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.registry.JavaRegistries; -import org.geysermc.geyser.translator.protocol.bedrock.entity.player.BedrockSetDefaultGameTypeTranslator; import org.geysermc.mcprotocollib.protocol.data.game.Holder; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; @@ -49,7 +48,7 @@ public class ThrowableEggEntity extends ThrowableItemEntity { // Used for egg break particles private GeyserItemStack itemStack = GeyserItemStack.of(Items.EGG.javaId(), 1); - public ThrowableEggEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public ThrowableEggEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java index 8d68b9e205d..56e6bcd3314 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java @@ -31,7 +31,7 @@ import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; import org.cloudburstmc.protocol.bedrock.packet.MoveEntityDeltaPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.level.block.BlockStateValues; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; @@ -45,7 +45,7 @@ public class ThrowableEntity extends Entity implements Tickable { protected Vector3f lastJavaPosition; - public ThrowableEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public ThrowableEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); this.lastJavaPosition = position; } @@ -120,15 +120,15 @@ protected void moveAbsoluteImmediate(Vector3f position, float yaw, float pitch, */ protected float getGravity() { if (getFlag(EntityFlag.HAS_GRAVITY)) { - if (definition.is(BuiltinEntityType.LINGERING_POTION) || definition.is(BuiltinEntityType.SPLASH_POTION)) { + if (javaDefinition.is(BuiltinEntityType.LINGERING_POTION) || javaDefinition.is(BuiltinEntityType.SPLASH_POTION)) { return 0.05f; - } else if (definition.is(BuiltinEntityType.EXPERIENCE_BOTTLE)) { + } else if (javaDefinition.is(BuiltinEntityType.EXPERIENCE_BOTTLE)) { return 0.07f; - } else if (definition.is(BuiltinEntityType.FIREBALL) || definition.is(BuiltinEntityType.SHULKER_BULLET)) { + } else if (javaDefinition.is(BuiltinEntityType.FIREBALL) || javaDefinition.is(BuiltinEntityType.SHULKER_BULLET)) { return 0; - } else if (definition.is(BuiltinEntityType.SNOWBALL) || definition.is(BuiltinEntityType.EGG) || definition.is(BuiltinEntityType.ENDER_PEARL)) { + } else if (javaDefinition.is(BuiltinEntityType.SNOWBALL) || javaDefinition.is(BuiltinEntityType.EGG) || javaDefinition.is(BuiltinEntityType.ENDER_PEARL)) { return 0.03f; - } else if (definition.is(BuiltinEntityType.LLAMA_SPIT)) { + } else if (javaDefinition.is(BuiltinEntityType.LLAMA_SPIT)) { return 0.06f; } } @@ -142,12 +142,12 @@ protected float getDrag() { if (isInWater()) { return 0.8f; } else { - if (definition.is(BuiltinEntityType.LINGERING_POTION) || definition.is(BuiltinEntityType.SPLASH_POTION) || definition.is(BuiltinEntityType.EXPERIENCE_BOTTLE) - || definition.is(BuiltinEntityType.SNOWBALL) || definition.is(BuiltinEntityType.EGG) || definition.is(BuiltinEntityType.ENDER_PEARL) || definition.is(BuiltinEntityType.LLAMA_SPIT)) { + if (javaDefinition.is(BuiltinEntityType.LINGERING_POTION) || javaDefinition.is(BuiltinEntityType.SPLASH_POTION) || javaDefinition.is(BuiltinEntityType.EXPERIENCE_BOTTLE) + || javaDefinition.is(BuiltinEntityType.SNOWBALL) || javaDefinition.is(BuiltinEntityType.EGG) || javaDefinition.is(BuiltinEntityType.ENDER_PEARL) || javaDefinition.is(BuiltinEntityType.LLAMA_SPIT)) { return 0.99f; - } else if (definition.is(BuiltinEntityType.FIREBALL) || definition.is(BuiltinEntityType.SMALL_FIREBALL) || definition.is(BuiltinEntityType.DRAGON_FIREBALL)) { + } else if (javaDefinition.is(BuiltinEntityType.FIREBALL) || javaDefinition.is(BuiltinEntityType.SMALL_FIREBALL) || javaDefinition.is(BuiltinEntityType.DRAGON_FIREBALL)) { return 0.95f; - } else if (definition.is(BuiltinEntityType.SHULKER_BULLET)) { + } else if (javaDefinition.is(BuiltinEntityType.SHULKER_BULLET)) { return 1; } } @@ -164,7 +164,7 @@ protected boolean isInWater() { @Override public void despawnEntity() { - if (definition.is(BuiltinEntityType.ENDER_PEARL)) { + if (javaDefinition.is(BuiltinEntityType.ENDER_PEARL)) { LevelEventPacket particlePacket = new LevelEventPacket(); particlePacket.setType(LevelEvent.PARTICLE_TELEPORT); particlePacket.setPosition(position); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java index 49907a36c7f..e84f0603e44 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java @@ -29,8 +29,8 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; @@ -47,7 +47,7 @@ public class ThrowableItemEntity extends ThrowableEntity { private int age; private boolean invisible; - public ThrowableItemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public ThrowableItemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); setFlag(EntityFlag.INVISIBLE, true); invisible = false; @@ -67,8 +67,8 @@ private void checkVisibility() { // Prevent projectiles from blocking the player's screen if (session.isTickingFrozen()) { // This may seem odd, but it matches java edition - Vector3f playerPos = session.getPlayerEntity().getPosition().down(EntityDefinitions.PLAYER.bedrockDefinition().offset()); - setInvisible(playerPos.distanceSquared(position.add(0, bedrockDefinition.offset(), 0)) < 12.25); + Vector3f playerPos = session.getPlayerEntity().getPosition().down(VanillaEntities.PLAYER_ENTITY_OFFSET); + setInvisible(playerPos.distanceSquared(position.add(0, definition.offset(), 0)) < 12.25); } else { setInvisible(age < 2); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java index b7dbdefdef1..4387a419ce5 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java @@ -30,7 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.item.Potion; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; @@ -46,7 +46,7 @@ public class ThrownPotionEntity extends ThrowableItemEntity { private static final EnumSet NON_ENCHANTED_POTIONS = EnumSet.of(Potion.WATER, Potion.MUNDANE, Potion.THICK, Potion.AWKWARD); - public ThrownPotionEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public ThrownPotionEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @@ -73,7 +73,7 @@ public void setItem(EntityMetadata entityMetadata) { } } - boolean isLingering = definition.type().is(BuiltinEntityType.LINGERING_POTION); + boolean isLingering = javaDefinition.type().is(BuiltinEntityType.LINGERING_POTION); setFlag(EntityFlag.LINGERING, isLingering); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/TridentEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/TridentEntity.java index bb26929e60d..0c3b16eb328 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/TridentEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/TridentEntity.java @@ -27,14 +27,14 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public class TridentEntity extends AbstractArrowEntity { - public TridentEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public TridentEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java index 69cd7121cd3..b5ef8cc0c35 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java @@ -27,8 +27,8 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; @@ -37,7 +37,7 @@ public class WitherSkullEntity extends FireballEntity { private boolean isCharged; - public WitherSkullEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public WitherSkullEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); this.futureTicks = 1; @@ -48,7 +48,7 @@ public void setDangerous(BooleanEntityMetadata entityMetadata) { if (newDangerous != isCharged) { isCharged = newDangerous; // Is an entirely new entity in Bedrock but just a metadata type in Java - definition = isCharged ? EntityDefinitions.WITHER_SKULL_DANGEROUS : EntityDefinitions.WITHER_SKULL; + javaDefinition = isCharged ? VanillaEntities.WITHER_SKULL_DANGEROUS : VanillaEntities.WITHER_SKULL; despawnEntity(); spawnEntity(); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AbstractFishEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AbstractFishEntity.java index fc61550f170..97edd9c1bd4 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AbstractFishEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AbstractFishEntity.java @@ -29,7 +29,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.EntityUtils; @@ -40,7 +40,7 @@ public class AbstractFishEntity extends WaterEntity { - public AbstractFishEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public AbstractFishEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); setFlag(EntityFlag.CAN_SWIM, true); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java index ace43f2c571..4d6624a54c4 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java @@ -28,7 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; @@ -36,7 +36,7 @@ public class AgeableEntity extends CreatureEntity { - public AgeableEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public AgeableEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @@ -52,8 +52,8 @@ public void setBaby(BooleanEntityMetadata entityMetadata) { setScale(isBaby ? getBabySize() : getAdultSize()); setFlag(EntityFlag.BABY, isBaby); - setBoundingBoxHeight(bedrockDefinition.height() * (isBaby ? getBabySize() : getAdultSize())); - setBoundingBoxWidth(bedrockDefinition.width() * (isBaby ? getBabySize() : getAdultSize())); + setBoundingBoxHeight(definition.height() * (isBaby ? getBabySize() : getAdultSize())); + setBoundingBoxWidth(definition.width() * (isBaby ? getBabySize() : getAdultSize())); } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableWaterEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableWaterEntity.java index e082701dec0..4fbe8b9f876 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableWaterEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableWaterEntity.java @@ -27,13 +27,13 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public abstract class AgeableWaterEntity extends AgeableEntity { - public AgeableWaterEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public AgeableWaterEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java index cc5577bb707..c7ee9752086 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java @@ -29,7 +29,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; @@ -43,7 +43,7 @@ public class AllayEntity extends MobEntity { private boolean canDuplicate; - public AllayEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public AllayEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AmbientEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AmbientEntity.java index 4ecdb6f3e29..2990aa5dc1a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AmbientEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AmbientEntity.java @@ -27,14 +27,14 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public class AmbientEntity extends MobEntity { - public AmbientEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public AmbientEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java index 595436794e9..222230af8a1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java @@ -33,8 +33,8 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.LivingEntity; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; @@ -89,7 +89,7 @@ public class ArmorStandEntity extends LivingEntity { */ private boolean positionUpdateRequired = false; - public ArmorStandEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public ArmorStandEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @@ -158,8 +158,8 @@ public void setArmorStandFlags(ByteEntityMetadata entityMetadata) { setBoundingBoxWidth(0.0f); setBoundingBoxHeight(0.0f); } else { - setBoundingBoxWidth(bedrockDefinition.width()); - setBoundingBoxHeight(bedrockDefinition.height()); + setBoundingBoxWidth(definition.width()); + setBoundingBoxHeight(definition.height()); } updateMountOffset(); @@ -345,7 +345,7 @@ private void updateSecondEntityStatus(boolean sendMetadata) { // Create the second entity. It doesn't need to worry about the items, but it does need to worry about // the metadata as it will hold the name tag. secondEntity = new ArmorStandEntity(session, 0, session.getEntityCache().getNextEntityId().incrementAndGet(), null, - EntityDefinitions.ARMOR_STAND, EntityDefinitions.ARMADILLO.bedrockDefinition(), position, motion, getYaw(), getPitch(), getHeadYaw()); + VanillaEntities.ARMOR_STAND, VanillaEntities.ARMADILLO.defaultBedrockDefinition(), position, motion, getYaw(), getPitch(), getHeadYaw()); secondEntity.primaryEntity = false; } // Copy metadata @@ -422,7 +422,7 @@ public float getYOffset() { if (!positionRequiresOffset || isMarker || secondEntity != null) { return 0; } - return bedrockDefinition.height() * getScale(); + return definition.height() * getScale(); } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/BatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/BatEntity.java index cb03d3cfcc3..ed927701c55 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/BatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/BatEntity.java @@ -28,7 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; @@ -36,7 +36,7 @@ public class BatEntity extends AmbientEntity { - public BatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public BatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/CopperGolemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/CopperGolemEntity.java index 7f25638300b..57010750e90 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/CopperGolemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/CopperGolemEntity.java @@ -28,7 +28,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.properties.type.BooleanProperty; import org.geysermc.geyser.entity.properties.type.EnumProperty; import org.geysermc.geyser.impl.IdentifierImpl; @@ -80,7 +80,7 @@ public enum OxidationLevelState { OXIDIZED } - public CopperGolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public CopperGolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/CreatureEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/CreatureEntity.java index 149612f4048..84f8e227618 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/CreatureEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/CreatureEntity.java @@ -27,14 +27,14 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public class CreatureEntity extends MobEntity { - public CreatureEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public CreatureEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/DolphinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/DolphinEntity.java index 6bd837c3bcb..ff0525f0aae 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/DolphinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/DolphinEntity.java @@ -28,7 +28,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; @@ -39,7 +39,7 @@ import java.util.UUID; public class DolphinEntity extends AgeableWaterEntity { - public DolphinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public DolphinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/FlyingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/FlyingEntity.java index 9e00ba24cb5..91848044f29 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/FlyingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/FlyingEntity.java @@ -27,14 +27,14 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public class FlyingEntity extends MobEntity { - public FlyingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public FlyingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/GlowSquidEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/GlowSquidEntity.java index e4ef0500fad..6c01cfc759b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/GlowSquidEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/GlowSquidEntity.java @@ -27,13 +27,13 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public class GlowSquidEntity extends SquidEntity { - public GlowSquidEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public GlowSquidEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/GolemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/GolemEntity.java index 468a52009d0..315298159d2 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/GolemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/GolemEntity.java @@ -27,14 +27,14 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public class GolemEntity extends CreatureEntity { - public GolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public GolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/IronGolemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/IronGolemEntity.java index eed7df38808..d103126c092 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/IronGolemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/IronGolemEntity.java @@ -30,7 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.session.GeyserSession; @@ -41,7 +41,7 @@ public class IronGolemEntity extends GolemEntity { - public IronGolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public IronGolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); // Indicate that we should show cracks through a resource pack setFlag(EntityFlag.BRIBED, true); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java index 0cf8f9a6596..a69f5cc2c88 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java @@ -28,14 +28,14 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public class MagmaCubeEntity extends SlimeEntity { - public MagmaCubeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public MagmaCubeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java index 69d3e66dc5a..2b7617ff947 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java @@ -30,7 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.Leashable; import org.geysermc.geyser.entity.type.LivingEntity; import org.geysermc.geyser.inventory.GeyserItemStack; @@ -56,7 +56,7 @@ public class MobEntity extends LivingEntity implements Leashable { */ private long leashHolderBedrockId; - public MobEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public MobEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/SlimeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/SlimeEntity.java index af90c50fc77..0072b71342c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/SlimeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/SlimeEntity.java @@ -27,7 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; @@ -35,7 +35,7 @@ public class SlimeEntity extends MobEntity { - public SlimeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public SlimeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/SnowGolemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/SnowGolemEntity.java index 4c428723d5d..54049df30b3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/SnowGolemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/SnowGolemEntity.java @@ -29,7 +29,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.session.GeyserSession; @@ -42,7 +42,7 @@ public class SnowGolemEntity extends GolemEntity { - public SnowGolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public SnowGolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java index 5408756c262..60ff8805da5 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java @@ -29,7 +29,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.MoveEntityDeltaPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.level.block.BlockStateValues; import org.geysermc.geyser.session.GeyserSession; @@ -43,7 +43,7 @@ public class SquidEntity extends AgeableWaterEntity implements Tickable { private CompletableFuture inWater = CompletableFuture.completedFuture(Boolean.FALSE); - public SquidEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public SquidEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/TadpoleEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/TadpoleEntity.java index 71d25527a21..64cd09a05f9 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/TadpoleEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/TadpoleEntity.java @@ -28,7 +28,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; @@ -39,7 +39,7 @@ import java.util.UUID; public class TadpoleEntity extends AbstractFishEntity { - public TadpoleEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public TadpoleEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/WaterEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/WaterEntity.java index d32aef79c5f..c8a76125dd0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/WaterEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/WaterEntity.java @@ -27,14 +27,14 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public class WaterEntity extends CreatureEntity { - public WaterEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public WaterEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AnimalEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AnimalEntity.java index 41144663b12..e1f23e7912e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AnimalEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AnimalEntity.java @@ -31,7 +31,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.living.AgeableEntity; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.type.Item; @@ -45,7 +45,7 @@ public abstract class AnimalEntity extends AgeableEntity { - public AnimalEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public AnimalEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/ArmadilloEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/ArmadilloEntity.java index b36c9e991b8..786e4e0f606 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/ArmadilloEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/ArmadilloEntity.java @@ -28,7 +28,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.properties.type.EnumProperty; import org.geysermc.geyser.impl.IdentifierImpl; import org.geysermc.geyser.item.type.Item; @@ -52,7 +52,7 @@ public class ArmadilloEntity extends AnimalEntity { private ArmadilloState armadilloState = ArmadilloState.IDLE; public ArmadilloEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, - EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AxolotlEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AxolotlEntity.java index ad9e79e2928..c5f12f96ae9 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AxolotlEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AxolotlEntity.java @@ -31,7 +31,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; @@ -46,7 +46,7 @@ import java.util.UUID; public class AxolotlEntity extends AnimalEntity { - public AxolotlEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public AxolotlEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/BeeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/BeeEntity.java index 41bfc94974d..7f5c83b7b7d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/BeeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/BeeEntity.java @@ -32,7 +32,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.properties.type.BooleanProperty; import org.geysermc.geyser.impl.IdentifierImpl; import org.geysermc.geyser.item.type.Item; @@ -51,7 +51,7 @@ public class BeeEntity extends AnimalEntity { false ); - public BeeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public BeeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FoxEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FoxEntity.java index caa8051b25c..42e521d7281 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FoxEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FoxEntity.java @@ -30,7 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; @@ -42,7 +42,7 @@ public class FoxEntity extends AnimalEntity { - public FoxEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public FoxEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FrogEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FrogEntity.java index 9debe57e130..22d4ebe6cb2 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FrogEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FrogEntity.java @@ -30,7 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; @@ -45,7 +45,7 @@ import java.util.UUID; public class FrogEntity extends AnimalEntity implements VariantIntHolder { - public FrogEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public FrogEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java index 08ff9d73e26..718fee7f8d3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java @@ -32,7 +32,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.type.Item; @@ -54,7 +54,7 @@ public class GoatEntity extends AnimalEntity { private boolean hasLeftHorn; private boolean hasRightHorn; - public GoatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public GoatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HappyGhastEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HappyGhastEntity.java index da49a8647d1..910dfbc95bc 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HappyGhastEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HappyGhastEntity.java @@ -33,7 +33,7 @@ import org.cloudburstmc.protocol.bedrock.data.AttributeData; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.properties.type.BooleanProperty; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; @@ -72,7 +72,7 @@ public class HappyGhastEntity extends AnimalEntity implements ClientVehicle { private final HappyGhastVehicleComponent vehicleComponent = new HappyGhastVehicleComponent(this, 0.0f); private boolean staysStill; - public HappyGhastEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public HappyGhastEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HoglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HoglinEntity.java index 31861a6093f..2775c9a3f3e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HoglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HoglinEntity.java @@ -30,7 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; @@ -42,7 +42,7 @@ public class HoglinEntity extends AnimalEntity { private boolean isImmuneToZombification; - public HoglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public HoglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); dirtyMetadata.put(EntityDataTypes.TARGET_EID, session.getPlayerEntity().getGeyserId()); setFlag(EntityFlag.SHAKING, isShaking()); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/MooshroomEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/MooshroomEntity.java index 15530059525..61044aaea86 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/MooshroomEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/MooshroomEntity.java @@ -30,7 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.packet.AddEntityPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.living.animal.farm.CowEntity; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; @@ -46,7 +46,7 @@ public class MooshroomEntity extends CowEntity { private boolean isBrown = false; - public MooshroomEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public MooshroomEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java index 4d1f6677a94..49c4435b625 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java @@ -30,7 +30,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; @@ -44,7 +44,7 @@ public class OcelotEntity extends AnimalEntity { - public OcelotEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public OcelotEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PandaEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PandaEntity.java index 477ad8d3c16..8307c174886 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PandaEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PandaEntity.java @@ -33,7 +33,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; @@ -51,7 +51,7 @@ public class PandaEntity extends AnimalEntity { private Gene mainGene = Gene.NORMAL; private Gene hiddenGene = Gene.NORMAL; - public PandaEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public PandaEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PolarBearEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PolarBearEntity.java index 6a6af6b8c1e..6a316175eb1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PolarBearEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PolarBearEntity.java @@ -28,7 +28,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.Tag; @@ -37,7 +37,7 @@ public class PolarBearEntity extends AnimalEntity { - public PolarBearEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public PolarBearEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PufferFishEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PufferFishEntity.java index b4bf53017fc..48d5ad5a330 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PufferFishEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PufferFishEntity.java @@ -28,7 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.living.AbstractFishEntity; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; @@ -37,7 +37,7 @@ public class PufferFishEntity extends AbstractFishEntity { - public PufferFishEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public PufferFishEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/RabbitEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/RabbitEntity.java index d389786d88b..75c3234653e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/RabbitEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/RabbitEntity.java @@ -31,7 +31,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; @@ -44,7 +44,7 @@ public class RabbitEntity extends AnimalEntity { private boolean isKillerBunny; - public RabbitEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public RabbitEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SheepEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SheepEntity.java index 3821b65eb71..7fb6271d2a2 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SheepEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SheepEntity.java @@ -31,7 +31,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.type.DyeItem; @@ -49,7 +49,7 @@ public class SheepEntity extends AnimalEntity { private int color; - public SheepEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public SheepEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java index cb7ede4cf67..6fe729a244b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java @@ -33,7 +33,7 @@ import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; @@ -48,11 +48,11 @@ public class SnifferEntity extends AnimalEntity implements Tickable { private static final int DIG_END = 120; private static final int DIG_START = DIG_END - 34; - private final float DIGGING_HEIGHT = bedrockDefinition.height() - 0.4f; + private final float DIGGING_HEIGHT = definition.height() - 0.4f; private Pose pose = Pose.STANDING; // Needed to call setDimensions for DIGGING state private int digTicks; - public SnifferEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public SnifferEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @@ -66,7 +66,7 @@ public void setPose(Pose pose) { protected void setDimensionsFromPose(Pose pose) { if (getFlag(EntityFlag.DIGGING)) { setBoundingBoxHeight(DIGGING_HEIGHT); - setBoundingBoxWidth(bedrockDefinition.width()); + setBoundingBoxWidth(definition.width()); } else { super.setDimensionsFromPose(pose); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java index 161c90bc4ea..da15a9bc8a9 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java @@ -31,7 +31,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.entity.type.player.PlayerEntity; @@ -59,7 +59,7 @@ public class StriderEntity extends AnimalEntity implements Tickable, ClientVehic private final BoostableVehicleComponent vehicleComponent = new BoostableVehicleComponent<>(this, 1.0f); private boolean isCold = false; - public StriderEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public StriderEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); setFlag(EntityFlag.FIRE_IMMUNE, true); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TropicalFishEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TropicalFishEntity.java index b9c9e5ec79a..8387f2f613c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TropicalFishEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TropicalFishEntity.java @@ -30,7 +30,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.living.AbstractFishEntity; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; @@ -49,7 +49,7 @@ public class TropicalFishEntity extends AbstractFishEntity { private static final List VARIANT_NAMES = ImmutableList.of("kob", "sunstreak", "snooper", "dasher", "brinely", "spotty", "flopper", "stripey", "glitter", "blockfish", "betty", "clayfish"); private static final List COLOR_NAMES = ImmutableList.of("white", "orange", "magenta", "light_blue", "yellow", "lime", "pink", "gray", "light_gray", "cyan", "purple", "blue", "brown", "green", "red", "black"); - public TropicalFishEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public TropicalFishEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TurtleEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TurtleEntity.java index a423517167c..0cbf46fa881 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TurtleEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TurtleEntity.java @@ -29,7 +29,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; @@ -40,7 +40,7 @@ public class TurtleEntity extends AnimalEntity { - public TurtleEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public TurtleEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/ChickenEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/ChickenEntity.java index eb08d31a1ac..8807609e5a9 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/ChickenEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/ChickenEntity.java @@ -28,7 +28,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.registry.JavaRegistries; @@ -40,7 +40,7 @@ public class ChickenEntity extends TemperatureVariantAnimal { - public ChickenEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public ChickenEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/CowEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/CowEntity.java index 9a5113a4260..45c6d3ac593 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/CowEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/CowEntity.java @@ -31,7 +31,7 @@ import org.cloudburstmc.protocol.bedrock.data.SoundEvent; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.type.Item; @@ -48,7 +48,7 @@ public class CowEntity extends TemperatureVariantAnimal { - public CowEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public CowEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/PigEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/PigEntity.java index 13070610493..2c9b75ab281 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/PigEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/PigEntity.java @@ -31,7 +31,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.entity.type.player.PlayerEntity; import org.geysermc.geyser.entity.vehicle.BoostableVehicleComponent; @@ -57,7 +57,7 @@ public class PigEntity extends TemperatureVariantAnimal implements Tickable, ClientVehicle { private final BoostableVehicleComponent vehicleComponent = new BoostableVehicleComponent<>(this, 1.0f); - public PigEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public PigEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/TemperatureVariantAnimal.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/TemperatureVariantAnimal.java index d5f64edfae3..d51e4af2b7a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/TemperatureVariantAnimal.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/TemperatureVariantAnimal.java @@ -27,7 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.properties.type.EnumProperty; import org.geysermc.geyser.entity.type.living.animal.AnimalEntity; import org.geysermc.geyser.entity.type.living.animal.VariantHolder; @@ -47,7 +47,7 @@ public abstract class TemperatureVariantAnimal extends AnimalEntity implements V public static final RegistryCache.RegistryReader VARIANT_READER = VariantHolder.reader(BuiltInVariant.class, BuiltInVariant.TEMPERATE); - public TemperatureVariantAnimal(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, + public TemperatureVariantAnimal(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java index c8d8b59d2de..b2995000bcd 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java @@ -35,7 +35,7 @@ import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket; import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.attribute.GeyserAttributeType; import org.geysermc.geyser.entity.type.living.animal.AnimalEntity; import org.geysermc.geyser.input.InputLocksFlag; @@ -55,7 +55,7 @@ public class AbstractHorseEntity extends AnimalEntity { - public AbstractHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public AbstractHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); // Specifies the size of the entity's inventory. Required to place slots in the entity. diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java index fa962b31a0a..a24748790d7 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java @@ -35,7 +35,7 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerType; import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.attribute.GeyserAttributeType; import org.geysermc.geyser.entity.vehicle.CamelVehicleComponent; import org.geysermc.geyser.entity.vehicle.ClientVehicle; @@ -58,7 +58,7 @@ public class CamelEntity extends AbstractHorseEntity implements ClientVehicle { private final CamelVehicleComponent vehicleComponent = new CamelVehicleComponent(this); - public CamelEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public CamelEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); dirtyMetadata.put(EntityDataTypes.CONTAINER_TYPE, (byte) ContainerType.HORSE.getId()); @@ -114,8 +114,8 @@ public void setPose(Pose pose) { @Override protected void setDimensionsFromPose(Pose pose) { if (pose == Pose.SITTING) { - setBoundingBoxHeight(bedrockDefinition.height() - SITTING_HEIGHT_DIFFERENCE); - setBoundingBoxWidth(bedrockDefinition.width()); + setBoundingBoxHeight(definition.height() - SITTING_HEIGHT_DIFFERENCE); + setBoundingBoxWidth(definition.width()); } else { super.setDimensionsFromPose(pose); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ChestedHorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ChestedHorseEntity.java index f39256cb2b9..68d8eecad50 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ChestedHorseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ChestedHorseEntity.java @@ -29,7 +29,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.session.GeyserSession; @@ -38,7 +38,7 @@ public class ChestedHorseEntity extends AbstractHorseEntity { - public ChestedHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public ChestedHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/HorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/HorseEntity.java index d20a52e2a90..c16572dc699 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/HorseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/HorseEntity.java @@ -28,7 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.EquipmentSlot; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; @@ -37,7 +37,7 @@ public class HorseEntity extends AbstractHorseEntity { - public HorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public HorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/LlamaEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/LlamaEntity.java index a4c6803f070..cb32d85b9a0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/LlamaEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/LlamaEntity.java @@ -30,7 +30,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; @@ -48,7 +48,7 @@ public class LlamaEntity extends ChestedHorseEntity { @Getter private int strength = 1; - public LlamaEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public LlamaEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); dirtyMetadata.put(EntityDataTypes.CONTAINER_STRENGTH_MODIFIER, 3); // Presumably 3 slots for every 1 strength diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/SkeletonHorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/SkeletonHorseEntity.java index c559d61a345..4cd9435181d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/SkeletonHorseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/SkeletonHorseEntity.java @@ -28,7 +28,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; @@ -38,7 +38,7 @@ import java.util.UUID; public class SkeletonHorseEntity extends AbstractHorseEntity { - public SkeletonHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public SkeletonHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/TraderLlamaEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/TraderLlamaEntity.java index 0c2029d3663..0dea0b3b09c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/TraderLlamaEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/TraderLlamaEntity.java @@ -28,14 +28,14 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public class TraderLlamaEntity extends LlamaEntity { - public TraderLlamaEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public TraderLlamaEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ZombieHorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ZombieHorseEntity.java index f5c7ebc296e..f35b9146531 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ZombieHorseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ZombieHorseEntity.java @@ -28,7 +28,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; @@ -38,7 +38,7 @@ import java.util.UUID; public class ZombieHorseEntity extends AbstractHorseEntity { - public ZombieHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public ZombieHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java index dbf14f73e61..2bd3a8b5049 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java @@ -31,7 +31,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.living.animal.VariantIntHolder; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.type.Item; @@ -53,7 +53,7 @@ public class CatEntity extends TameableEntity implements VariantIntHolder { private byte collarColor = 14; // Red - default - public CatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public CatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java index e349e8271ea..d5c2fde03f1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java @@ -30,7 +30,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.session.GeyserSession; @@ -43,7 +43,7 @@ import java.util.UUID; public class ParrotEntity extends TameableEntity { - public ParrotEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public ParrotEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/TameableEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/TameableEntity.java index 43ac740fe67..5ae6db58d8b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/TameableEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/TameableEntity.java @@ -30,7 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.living.animal.AnimalEntity; import org.geysermc.geyser.session.GeyserSession; @@ -47,7 +47,7 @@ public abstract class TameableEntity extends AnimalEntity { @Getter protected long ownerBedrockId; - public TameableEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public TameableEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java index 18901e3b6bd..0f164d341f0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java @@ -32,7 +32,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.properties.type.StringEnumProperty; import org.geysermc.geyser.entity.type.living.animal.VariantIntHolder; import org.geysermc.geyser.impl.IdentifierImpl; @@ -81,7 +81,7 @@ public class WolfEntity extends TameableEntity implements VariantIntHolder { private HolderSet repairableItems = null; private boolean isCurseOfBinding = false; - public WolfEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public WolfEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/AbstractMerchantEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/AbstractMerchantEntity.java index 9a148e4cc91..241bfd61e94 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/AbstractMerchantEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/AbstractMerchantEntity.java @@ -29,8 +29,8 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.living.AgeableEntity; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; @@ -43,7 +43,7 @@ public class AbstractMerchantEntity extends AgeableEntity { - public AbstractMerchantEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public AbstractMerchantEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } @@ -56,7 +56,7 @@ public boolean canBeLeashed() { @Override protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (!itemInHand.is(Items.VILLAGER_SPAWN_EGG) - && (definition != EntityDefinitions.VILLAGER || !getFlag(EntityFlag.SLEEPING) && ((VillagerEntity) this).isCanTradeWith())) { + && (javaDefinition != VanillaEntities.VILLAGER || !getFlag(EntityFlag.SLEEPING) && ((VillagerEntity) this).isCanTradeWith())) { // An additional check we know cannot work if (!isBaby()) { return InteractiveTag.TRADE; @@ -69,8 +69,8 @@ protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserI @Override protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (!itemInHand.is(Items.VILLAGER_SPAWN_EGG) - && (definition != EntityDefinitions.VILLAGER || !getFlag(EntityFlag.SLEEPING)) - && (definition != EntityDefinitions.WANDERING_TRADER || !getFlag(EntityFlag.BABY))) { + && (javaDefinition != VanillaEntities.VILLAGER || !getFlag(EntityFlag.SLEEPING)) + && (javaDefinition != VanillaEntities.WANDERING_TRADER || !getFlag(EntityFlag.BABY))) { // Trading time return InteractionResult.SUCCESS; } else { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java index 976a5b6b827..dc078e7ee77 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java @@ -33,7 +33,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.MoveEntityAbsolutePacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.level.block.property.Properties; import org.geysermc.geyser.level.block.type.BedBlock; import org.geysermc.geyser.level.block.type.BlockState; @@ -89,7 +89,7 @@ public class VillagerEntity extends AbstractMerchantEntity { @Getter private boolean canTradeWith; - public VillagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public VillagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/AbstractSkeletonEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/AbstractSkeletonEntity.java index 42d82e7ee26..26ffd3930f3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/AbstractSkeletonEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/AbstractSkeletonEntity.java @@ -29,7 +29,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; @@ -38,7 +38,7 @@ public class AbstractSkeletonEntity extends MonsterEntity { - public AbstractSkeletonEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public AbstractSkeletonEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BasePiglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BasePiglinEntity.java index f812217ce12..c471d1673f0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BasePiglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BasePiglinEntity.java @@ -29,7 +29,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; @@ -39,7 +39,7 @@ public class BasePiglinEntity extends MonsterEntity { private boolean isImmuneToZombification; - public BasePiglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public BasePiglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); // Both TARGET_EID and BLOCK are needed for melee attack animation dirtyMetadata.put(EntityDataTypes.BLOCK, session.getBlockMappings().getDefinition(1)); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BlazeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BlazeEntity.java index 4175472d252..0e8b49b6577 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BlazeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BlazeEntity.java @@ -28,7 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; @@ -36,7 +36,7 @@ public class BlazeEntity extends MonsterEntity { - public BlazeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public BlazeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BoggedEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BoggedEntity.java index be1fd36bba8..b76be064120 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BoggedEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BoggedEntity.java @@ -29,7 +29,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.session.GeyserSession; @@ -43,7 +43,7 @@ public class BoggedEntity extends AbstractSkeletonEntity { private boolean sheared = false; - public BoggedEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public BoggedEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BreezeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BreezeEntity.java index 4850a467d56..cb435346b36 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BreezeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BreezeEntity.java @@ -28,14 +28,14 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.Pose; import java.util.UUID; public class BreezeEntity extends MonsterEntity { - public BreezeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public BreezeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java index da309a3db80..e34d17b8c6c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java @@ -32,7 +32,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.LevelEventGenericPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.properties.type.EnumProperty; import org.geysermc.geyser.entity.properties.type.IntProperty; import org.geysermc.geyser.impl.IdentifierImpl; @@ -64,7 +64,7 @@ public class CreakingEntity extends MonsterEntity { private Vector3i homePosition; - public CreakingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public CreakingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java index a59e036db2c..d6b9bc0efd7 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java @@ -30,7 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.SoundEvent; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; @@ -49,7 +49,7 @@ public class CreeperEntity extends MonsterEntity { */ private boolean ignitedByFlintAndSteel = false; - public CreeperEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public CreeperEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ElderGuardianEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ElderGuardianEntity.java index 17da37bf897..1fd1cd0fcb3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ElderGuardianEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ElderGuardianEntity.java @@ -28,14 +28,14 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public class ElderGuardianEntity extends GuardianEntity { - public ElderGuardianEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public ElderGuardianEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java index a6314ae9480..e9402c136ba 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java @@ -36,7 +36,7 @@ import org.cloudburstmc.protocol.bedrock.packet.PlaySoundPacket; import org.cloudburstmc.protocol.bedrock.packet.SpawnParticleEffectPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.entity.type.living.MobEntity; import org.geysermc.geyser.session.GeyserSession; @@ -85,7 +85,7 @@ public class EnderDragonEntity extends MobEntity implements Tickable { private float wingPosition; private float lastWingPosition; - public EnderDragonEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public EnderDragonEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java index 3de7d9c8db9..c74f38deb26 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java @@ -28,14 +28,14 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.session.GeyserSession; public class EnderDragonPartEntity extends Entity { public EnderDragonPartEntity(GeyserSession session, int entityId, long geyserId, float width, float height) { - super(session, entityId, geyserId, null, EntityDefinitions.ENDER_DRAGON_PART, EntityDefinitions.ENDER_DRAGON.bedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0); + super(session, entityId, geyserId, null, VanillaEntities.ENDER_DRAGON_PART, VanillaEntities.ENDER_DRAGON.defaultBedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0); dirtyMetadata.put(EntityDataTypes.WIDTH, width); dirtyMetadata.put(EntityDataTypes.HEIGHT, height); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EndermanEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EndermanEntity.java index f66f4846d47..81ded8dc8f2 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EndermanEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EndermanEntity.java @@ -32,7 +32,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; @@ -41,7 +41,7 @@ public class EndermanEntity extends MonsterEntity { - public EndermanEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public EndermanEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GhastEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GhastEntity.java index 984610c9741..da8acbe5bf4 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GhastEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GhastEntity.java @@ -28,7 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.living.FlyingEntity; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; @@ -37,7 +37,7 @@ public class GhastEntity extends FlyingEntity { - public GhastEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public GhastEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GiantEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GiantEntity.java index a245560ddda..7b705d438d1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GiantEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GiantEntity.java @@ -27,14 +27,14 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public class GiantEntity extends MonsterEntity { - public GiantEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public GiantEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GuardianEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GuardianEntity.java index a5552af673d..7cb6b2b8789 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GuardianEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GuardianEntity.java @@ -28,7 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; @@ -37,7 +37,7 @@ public class GuardianEntity extends MonsterEntity { - public GuardianEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public GuardianEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/MonsterEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/MonsterEntity.java index 77111e290b2..178d2b24a62 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/MonsterEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/MonsterEntity.java @@ -27,7 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.living.CreatureEntity; import org.geysermc.geyser.session.GeyserSession; @@ -35,7 +35,7 @@ public class MonsterEntity extends CreatureEntity { - public MonsterEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public MonsterEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java index 288aa2e1aa8..d33385187e5 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java @@ -27,7 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.living.FlyingEntity; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; @@ -35,17 +35,17 @@ import java.util.UUID; public class PhantomEntity extends FlyingEntity { - public PhantomEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public PhantomEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } public void setPhantomScale(IntEntityMetadata entityMetadata) { int size = entityMetadata.getPrimitiveValue(); float modelScale = 1f + 0.15f * size; - float boundsScale = (1f + (0.2f * size) / bedrockDefinition.width()) / modelScale; + float boundsScale = (1f + (0.2f * size) / definition.width()) / modelScale; - setBoundingBoxWidth(boundsScale * bedrockDefinition.width()); - setBoundingBoxHeight(boundsScale * bedrockDefinition.height()); + setBoundingBoxWidth(boundsScale * definition.width()); + setBoundingBoxHeight(boundsScale * definition.height()); setScale(modelScale); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PiglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PiglinEntity.java index 7272038052d..e3c4f93632b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PiglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PiglinEntity.java @@ -33,7 +33,7 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; import org.cloudburstmc.protocol.bedrock.packet.MobEquipmentPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.session.GeyserSession; @@ -48,7 +48,7 @@ public class PiglinEntity extends BasePiglinEntity { - public PiglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public PiglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ShulkerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ShulkerEntity.java index 3f4ce19aed2..f30244b2bec 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ShulkerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ShulkerEntity.java @@ -29,7 +29,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.living.GolemEntity; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; @@ -40,7 +40,7 @@ public class ShulkerEntity extends GolemEntity { - public ShulkerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public ShulkerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); // Indicate that invisibility should be fixed through the resource pack setFlag(EntityFlag.BRIBED, true); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SkeletonEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SkeletonEntity.java index fc40a6b8af0..8f22c45c33d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SkeletonEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SkeletonEntity.java @@ -28,7 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; @@ -37,7 +37,7 @@ public class SkeletonEntity extends AbstractSkeletonEntity { private boolean convertingToStray = false; - public SkeletonEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public SkeletonEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SpiderEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SpiderEntity.java index dcc07b47b7d..30ff746a27d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SpiderEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SpiderEntity.java @@ -28,7 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; @@ -36,7 +36,7 @@ public class SpiderEntity extends MonsterEntity { - public SpiderEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public SpiderEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/VexEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/VexEntity.java index f0a655ffaca..cabe6e51309 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/VexEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/VexEntity.java @@ -28,7 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; @@ -36,7 +36,7 @@ public class VexEntity extends MonsterEntity { - public VexEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public VexEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WardenEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WardenEntity.java index 148b06d2278..c104f7ced59 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WardenEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WardenEntity.java @@ -31,7 +31,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.PlaySoundPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.MathUtils; @@ -47,7 +47,7 @@ public class WardenEntity extends MonsterEntity implements Tickable { private int sonicBoomTickDuration; - public WardenEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public WardenEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WitherEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WitherEntity.java index effca7601f3..cd83525e1f2 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WitherEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WitherEntity.java @@ -29,7 +29,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; @@ -38,7 +38,7 @@ public class WitherEntity extends MonsterEntity { - public WitherEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public WitherEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java index d718cfdb207..b928bb8bbe9 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java @@ -29,7 +29,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; @@ -37,7 +37,7 @@ public class ZoglinEntity extends MonsterEntity { - public ZoglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public ZoglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); dirtyMetadata.put(EntityDataTypes.TARGET_EID, session.getPlayerEntity().getGeyserId()); } @@ -55,7 +55,7 @@ public void setBaby(BooleanEntityMetadata entityMetadata) { @Override public float getBoundingBoxHeight() { float scale = getFlag(EntityFlag.BABY) ? 0.55f : 1f; - return scale * bedrockDefinition.height(); + return scale * definition.height(); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieEntity.java index 8b65af6a745..da431bc8069 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieEntity.java @@ -28,7 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; @@ -37,7 +37,7 @@ public class ZombieEntity extends MonsterEntity { private boolean convertingToDrowned = false; - public ZombieEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public ZombieEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieVillagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieVillagerEntity.java index c626fe04d36..10e6c506d37 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieVillagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieVillagerEntity.java @@ -30,7 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.living.merchant.VillagerEntity; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; @@ -46,7 +46,7 @@ public class ZombieVillagerEntity extends ZombieEntity { - public ZombieVillagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public ZombieVillagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombifiedPiglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombifiedPiglinEntity.java index d712913ad0c..f88c33c136a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombifiedPiglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombifiedPiglinEntity.java @@ -28,14 +28,14 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public class ZombifiedPiglinEntity extends ZombieEntity { - public ZombifiedPiglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public ZombifiedPiglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); setFlag(EntityFlag.FIRE_IMMUNE, true); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/AbstractIllagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/AbstractIllagerEntity.java index 9d0ad6e1c67..e93c992e433 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/AbstractIllagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/AbstractIllagerEntity.java @@ -27,14 +27,14 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; public class AbstractIllagerEntity extends RaidParticipantEntity { - public AbstractIllagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public AbstractIllagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/PillagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/PillagerEntity.java index 190a85c3380..2a03469900a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/PillagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/PillagerEntity.java @@ -29,7 +29,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.session.GeyserSession; @@ -40,7 +40,7 @@ public class PillagerEntity extends AbstractIllagerEntity { - public PillagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public PillagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RaidParticipantEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RaidParticipantEntity.java index af58e202c89..097dc463d1d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RaidParticipantEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RaidParticipantEntity.java @@ -27,7 +27,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.living.monster.MonsterEntity; import org.geysermc.geyser.session.GeyserSession; @@ -35,7 +35,7 @@ public class RaidParticipantEntity extends MonsterEntity { - public RaidParticipantEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public RaidParticipantEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RavagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RavagerEntity.java index 7b1dd8dc2dd..56ce0f324a5 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RavagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RavagerEntity.java @@ -28,7 +28,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; @@ -36,7 +36,7 @@ public class RavagerEntity extends RaidParticipantEntity { - public RavagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public RavagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/SpellcasterIllagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/SpellcasterIllagerEntity.java index f43ba95671c..fcf42ab673f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/SpellcasterIllagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/SpellcasterIllagerEntity.java @@ -29,8 +29,8 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; @@ -41,10 +41,10 @@ public class SpellcasterIllagerEntity extends AbstractIllagerEntity { private static final int ATTACK_PARTICLE_COLOR = (102 << 16) | (77 << 8) | 89; private static final int WOLOLO_PARTICLE_COLOR = (179 << 16) | (128 << 8) | 51; - public SpellcasterIllagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public SpellcasterIllagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); // OptionalPack usage - setFlag(EntityFlag.BRIBED, this.definition == EntityDefinitions.ILLUSIONER); + setFlag(EntityFlag.BRIBED, this.javaDefinition == VanillaEntities.ILLUSIONER); } public void setSpellType(ByteEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/VindicatorEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/VindicatorEntity.java index d48ddd91f39..54447c4a6d3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/VindicatorEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/VindicatorEntity.java @@ -29,7 +29,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; @@ -37,7 +37,7 @@ public class VindicatorEntity extends AbstractIllagerEntity { - public VindicatorEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public VindicatorEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); dirtyMetadata.put(EntityDataTypes.TARGET_EID, session.getPlayerEntity().getGeyserId()); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java index 7339161d5ad..38abf9819f4 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java @@ -41,8 +41,8 @@ import org.cloudburstmc.protocol.bedrock.packet.AddPlayerPacket; import org.cloudburstmc.protocol.bedrock.packet.MovePlayerPacket; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.LivingEntity; import org.geysermc.geyser.level.block.Blocks; import org.geysermc.geyser.session.GeyserSession; @@ -94,7 +94,7 @@ public class AvatarEntity extends LivingEntity { BASE_ABILITY_LAYER = Collections.singletonList(abilityLayer); } - public AvatarEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, + public AvatarEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw, String username) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); this.username = username; @@ -115,7 +115,7 @@ public void spawnEntity() { addPlayerPacket.setUsername(username); addPlayerPacket.setRuntimeEntityId(geyserId); addPlayerPacket.setUniqueEntityId(geyserId); - addPlayerPacket.setPosition(position.sub(0, bedrockDefinition.offset(), 0)); + addPlayerPacket.setPosition(position.sub(0, definition.offset(), 0)); addPlayerPacket.setRotation(getBedrockRotation()); addPlayerPacket.setMotion(motion); addPlayerPacket.setHand(ItemTranslator.translateToBedrock(session, getMainHandItem())); @@ -181,7 +181,7 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float if (getFlag(EntityFlag.SLEEPING)) { if (bedPosition != null && (bedPosition.getY() == 0 || bedPosition.distanceSquared(position.toInt()) > 4)) { // Force the player movement by using a teleport - movePlayerPacket.setPosition(Vector3f.from(position.getX(), position.getY() - bedrockDefinition.offset() + 0.2f, position.getZ())); + movePlayerPacket.setPosition(Vector3f.from(position.getX(), position.getY() - definition.offset() + 0.2f, position.getZ())); movePlayerPacket.setMode(MovePlayerPacket.Mode.TELEPORT); } } @@ -200,7 +200,7 @@ public void setPosition(Vector3f position) { // Messes with Bedrock if we send this to the client itself, though. super.setPosition(position.up(0.2f)); } else { - super.setPosition(position.add(0, bedrockDefinition.offset(), 0)); + super.setPosition(position.add(0, definition.offset(), 0)); } } @@ -319,7 +319,7 @@ public void setPose(Pose pose) { if (pose == Pose.SWIMMING) { // This is just for, so we know if player is swimming or crawling. - if (session.getGeyser().getWorldManager().blockAt(session, position.down(EntityDefinitions.PLAYER.offset()).toInt()).is(Blocks.WATER)) { + if (session.getGeyser().getWorldManager().blockAt(session, position.down(VanillaEntities.PLAYER_ENTITY_OFFSET).toInt()).is(Blocks.WATER)) { setFlag(EntityFlag.SWIMMING, true); } else { setFlag(EntityFlag.CRAWLING, true); @@ -345,11 +345,11 @@ public void setDimensionsFromPose(Pose pose) { switch (pose) { case SNEAKING -> { height = SNEAKING_POSE_HEIGHT; - width = bedrockDefinition.width(); + width = definition.width(); } case FALL_FLYING, SPIN_ATTACK, SWIMMING -> { height = 0.6f; - width = bedrockDefinition.width(); + width = definition.width(); } case DYING -> { height = 0.2f; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/MannequinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/MannequinEntity.java index de080eaa62d..d97f4a8d2eb 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/MannequinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/MannequinEntity.java @@ -28,7 +28,7 @@ import net.kyori.adventure.text.Component; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.ResolvableProfile; @@ -38,7 +38,7 @@ public class MannequinEntity extends AvatarEntity { - public MannequinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public MannequinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw, ""); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java index e64edabf4c3..e1752391845 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java @@ -35,7 +35,7 @@ import org.cloudburstmc.protocol.bedrock.packet.SetEntityLinkPacket; import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket; import org.geysermc.geyser.api.entity.type.player.GeyserPlayerEntity; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.attribute.GeyserAttributeType; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.living.animal.tameable.ParrotEntity; @@ -68,8 +68,7 @@ public class PlayerEntity extends AvatarEntity implements GeyserPlayerEntity { public PlayerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw, String username, @Nullable String texturesProperty) { - // TODO allow changing bedrock player definition??? - super(session, entityId, geyserId, uuid, EntityDefinitions.PLAYER, EntityDefinitions.PLAYER.bedrockDefinition(), position, motion, yaw, pitch, headYaw, username); + super(session, entityId, geyserId, uuid, VanillaEntities.PLAYER, VanillaEntities.PLAYER.defaultBedrockDefinition(), position, motion, yaw, pitch, headYaw, username); this.texturesProperty = texturesProperty; } @@ -164,7 +163,7 @@ protected void setParrot(OptionalInt variant, boolean isLeft) { // The parrot is a separate entity in Bedrock, but part of the player entity in Java // TODO CE allow customizing? ParrotEntity parrot = new ParrotEntity(session, 0, session.getEntityCache().getNextEntityId().incrementAndGet(), - null, EntityDefinitions.PARROT, EntityDefinitions.PARROT.bedrockDefinition(), position, motion, getYaw(), getPitch(), getHeadYaw()); + null, VanillaEntities.PARROT, VanillaEntities.PARROT.defaultBedrockDefinition(), position, motion, getYaw(), getPitch(), getHeadYaw()); parrot.spawnEntity(); parrot.getDirtyMetadata().put(EntityDataTypes.VARIANT, variant.getAsInt()); // Different position whether the parrot is left or right @@ -224,11 +223,6 @@ public UUID getTabListUuid() { return getUuid(); } - @Override - public Vector3f position() { - return this.position.down(bedrockDefinition.offset()); - } - // From 1.21.8 code, should be correct since some pose should be prioritized. public Pose getDesiredPose() { if (this.getBedPosition() != null) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java index dafc32fbff1..a19de69e9f1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java @@ -38,7 +38,7 @@ import org.cloudburstmc.protocol.bedrock.packet.MovePlayerPacket; import org.cloudburstmc.protocol.bedrock.packet.SetEntityMotionPacket; import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.attribute.GeyserAttributeType; import org.geysermc.geyser.entity.type.BoatEntity; import org.geysermc.geyser.entity.type.Entity; @@ -163,7 +163,7 @@ public void setYaw(float yaw) { @Override public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, float headYaw, boolean isOnGround) { super.moveRelative(relX, relY, relZ, yaw, pitch, headYaw, isOnGround); - session.getCollisionManager().updatePlayerBoundingBox(this.position.down(bedrockDefinition.offset())); + session.getCollisionManager().updatePlayerBoundingBox(this.position.down(definition.offset())); } @Override @@ -175,7 +175,7 @@ public void setPosition(Vector3f position) { session.setNoClip(false); } } - this.position = position.add(0, bedrockDefinition.offset(), 0); + this.position = position.add(0, definition.offset(), 0); } /** @@ -218,7 +218,7 @@ public void setPositionManual(Vector3f position) { this.position = position; // Player is "above" the void so they're not supposed to no clip. - if (session.isNoClip() && position.getY() - EntityDefinitions.PLAYER.bedrockDefinition().offset() >= session.getBedrockDimension().minY() - 5) { + if (session.isNoClip() && position.getY() - VanillaEntities.PLAYER_ENTITY_OFFSET >= session.getBedrockDimension().minY() - 5) { session.setNoClip(false); } } @@ -471,8 +471,8 @@ public void setVehicle(Entity entity) { entity.setBoundingBoxHeight(0.5625F); entity.updateBedrockMetadata(); } else if (entity == null && this.vehicle instanceof BoatEntity) { - this.vehicle.setBoundingBoxWidth(this.vehicle.getDefinition().bedrockDefinition().width()); - this.vehicle.setBoundingBoxHeight(this.vehicle.getDefinition().bedrockDefinition().height()); + this.vehicle.setBoundingBoxWidth(this.vehicle.getJavaDefinition().defaultBedrockDefinition().width()); + this.vehicle.setBoundingBoxHeight(this.vehicle.getJavaDefinition().defaultBedrockDefinition().height()); this.vehicle.updateBedrockMetadata(); } @@ -489,7 +489,7 @@ public void setVehicle(Entity entity) { public float getJumpVelocity() { float velocity = 0.42F; - if (session.getGeyser().getWorldManager().blockAt(session, this.getPosition().sub(0, EntityDefinitions.PLAYER.bedrockDefinition().offset() + 0.1F, 0).toInt()).is(Blocks.HONEY_BLOCK)) { + if (session.getGeyser().getWorldManager().blockAt(session, this.getPosition().sub(0, VanillaEntities.PLAYER_ENTITY_OFFSET + 0.1F, 0).toInt()).is(Blocks.HONEY_BLOCK)) { velocity *= 0.6F; } @@ -500,7 +500,7 @@ public boolean isOnClimbableBlock() { if (session.getGameMode() == GameMode.SPECTATOR) { return false; } - Vector3i pos = getPosition().down(EntityDefinitions.PLAYER.bedrockDefinition().offset()).toInt(); + Vector3i pos = getPosition().down(VanillaEntities.PLAYER_ENTITY_OFFSET).toInt(); BlockState state = session.getGeyser().getWorldManager().blockAt(session, pos); if (state.block().is(session, BlockTag.CLIMBABLE)) { return true; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/SkullPlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/SkullPlayerEntity.java index 20559637c6b..ea3c6e7ea49 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/SkullPlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/SkullPlayerEntity.java @@ -28,21 +28,15 @@ import lombok.Getter; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3i; -import org.cloudburstmc.protocol.bedrock.data.GameType; -import org.cloudburstmc.protocol.bedrock.data.PlayerPermission; -import org.cloudburstmc.protocol.bedrock.data.command.CommandPermission; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.cloudburstmc.protocol.bedrock.packet.AddPlayerPacket; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.level.block.property.Properties; import org.geysermc.geyser.level.block.type.BlockState; import org.geysermc.geyser.level.block.type.WallSkullBlock; import org.geysermc.geyser.level.physics.Direction; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.SkullCache; -import org.geysermc.geyser.skin.SkullSkinManager; -import org.geysermc.geyser.translator.item.ItemTranslator; import java.util.Objects; import java.util.UUID; @@ -61,7 +55,7 @@ public class SkullPlayerEntity extends AvatarEntity { private Vector3i skullPosition; public SkullPlayerEntity(GeyserSession session, long geyserId) { - super(session, 0, geyserId, UUID.randomUUID(), EntityDefinitions.PLAYER, EntityDefinitions.PLAYER.bedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, ""); + super(session, 0, geyserId, UUID.randomUUID(), VanillaEntities.PLAYER, VanillaEntities.PLAYER.defaultBedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, ""); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java index 7472bd35491..db0b638f433 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java +++ b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java @@ -218,7 +218,7 @@ protected ObjectDoublePair updateFluidMovement(VehicleContext ctx) { double lavaHeight = getFluidHeightAndApplyMovement(ctx, iter, Fluid.LAVA, vehicle.getSession().getDimensionType().ultrawarm() ? 0.007 : 0.007 / 3, min.getY()); // Apply upward motion if the vehicle is a Strider, and it is submerged in lava - if (lavaHeight > 0 && vehicle.getDefinition().type().is(BuiltinEntityType.STRIDER)) { + if (lavaHeight > 0 && vehicle.getJavaDefinition().type().is(BuiltinEntityType.STRIDER)) { Vector3i blockPos = ctx.centerPos().toInt(); if (!CollisionManager.FLUID_COLLISION.isBelow(blockPos.getY(), boundingBox) || ctx.getBlock(blockPos.up()).is(Blocks.LAVA)) { vehicle.setMotion(vehicle.getMotion().mul(0.5f).add(0, 0.05f, 0)); diff --git a/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java b/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java index b5ca4bd1d98..3be41ed0c47 100644 --- a/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java +++ b/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java @@ -36,7 +36,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.MovePlayerPacket; import org.geysermc.erosion.util.BlockPositionIterator; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.player.PlayerEntity; import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; import org.geysermc.geyser.entity.vehicle.ClientVehicle; @@ -166,7 +166,7 @@ public BoundingBox getActiveBoundingBox() { } // We need to parse the float as a string since casting a float to a double causes us to // lose precision and thus, causes players to get stuck when walking near walls - double javaY = Double.parseDouble(Float.toString(bedrockPosition.getY() - EntityDefinitions.PLAYER.bedrockDefinition().offset())); + double javaY = Double.parseDouble(Float.toString(bedrockPosition.getY() - VanillaEntities.PLAYER_ENTITY_OFFSET)); Vector3d position = Vector3d.from(Double.parseDouble(Float.toString(bedrockPosition.getX())), javaY, Double.parseDouble(Float.toString(bedrockPosition.getZ()))); diff --git a/core/src/main/java/org/geysermc/geyser/registry/Registries.java b/core/src/main/java/org/geysermc/geyser/registry/Registries.java index 6da58d56667..f5722a43b6a 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/Registries.java +++ b/core/src/main/java/org/geysermc/geyser/registry/Registries.java @@ -39,8 +39,8 @@ import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.util.Identifier; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; -import org.geysermc.geyser.entity.GeyserCustomEntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.GeyserCustomEntityTypeDefinition; import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.inventory.recipe.GeyserRecipe; import org.geysermc.geyser.item.type.Item; @@ -127,10 +127,9 @@ public final class Registries { * A map containing all entity types and their respective Geyser definitions */ // Is a Reference2ObjectMap since GeyserEntityType, the implementation of JavaEntityType, only ever keeps one instance per registered entity type - // TODO rename to VANILLA_ENTITY_DEFINITIONS - public static final SimpleMappedRegistry> ENTITY_DEFINITIONS = SimpleMappedRegistry.create(RegistryLoaders.empty(Reference2ObjectOpenHashMap::new)); + public static final SimpleMappedRegistry> ENTITY_DEFINITIONS = SimpleMappedRegistry.create(RegistryLoaders.empty(Reference2ObjectOpenHashMap::new)); - public static final ListRegistry> CUSTOM_ENTITY_DEFINITIONS = ListRegistry.create(RegistryLoaders.empty(ArrayList::new)); + public static final ListRegistry> CUSTOM_ENTITY_DEFINITIONS = ListRegistry.create(RegistryLoaders.empty(ArrayList::new)); public static final SimpleMappedRegistry BEDROCK_ENTITY_DEFINITIONS = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new)); @@ -142,7 +141,7 @@ public final class Registries { /** * A map containing all Java entity identifiers and their respective Geyser definitions */ - public static final SimpleMappedRegistry> JAVA_ENTITY_IDENTIFIERS = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new)); + public static final SimpleMappedRegistry> JAVA_ENTITY_IDENTIFIERS = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new)); /** * A registry containing all the Java packet translators. diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index 9fdf43a2425..44e1ccb4c24 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -125,7 +125,7 @@ import org.geysermc.geyser.command.CommandRegistry; import org.geysermc.geyser.command.GeyserCommandSource; import org.geysermc.geyser.configuration.GeyserConfig; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.GeyserEntityData; import org.geysermc.geyser.entity.attribute.GeyserAttributeType; import org.geysermc.geyser.entity.type.BoatEntity; @@ -2179,7 +2179,7 @@ public float getEyeHeight() { FALL_FLYING, // Elytra SPIN_ATTACK -> 0.4f; // Trident spin attack case SLEEPING -> 0.2f; - default -> EntityDefinitions.PLAYER.bedrockDefinition().offset(); // 1.62F + default -> VanillaEntities.PLAYER_ENTITY_OFFSET; // 1.62F }; } diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/BlockBreakHandler.java b/core/src/main/java/org/geysermc/geyser/session/cache/BlockBreakHandler.java index f33d8ed5917..dc383d40188 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/BlockBreakHandler.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/BlockBreakHandler.java @@ -43,7 +43,7 @@ import org.cloudburstmc.protocol.bedrock.packet.PlayerAuthInputPacket; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.block.custom.CustomBlockState; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.ItemFrameEntity; import org.geysermc.geyser.inventory.GeyserItemStack; @@ -491,7 +491,7 @@ protected boolean canBreak(Vector3i vector, BlockState state, PlayerActionType a } Vector3f playerPosition = session.getPlayerEntity().getPosition(); - playerPosition = playerPosition.down(EntityDefinitions.PLAYER.bedrockDefinition().offset() - session.getEyeHeight()); + playerPosition = playerPosition.down(VanillaEntities.PLAYER_ENTITY_OFFSET - session.getEyeHeight()); return BedrockInventoryTransactionTranslator.canInteractWithBlock(session, playerPosition, vector); } diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java b/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java index cd6bb6bca10..0bc8810bc5b 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java @@ -35,7 +35,7 @@ import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; import lombok.Getter; import lombok.Setter; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.player.PlayerEntity; import org.geysermc.geyser.level.physics.Axis; import org.geysermc.geyser.level.physics.BoundingBox; @@ -168,7 +168,7 @@ public boolean isPassingIntoBorderBoundaries(Vector3f newPosition, boolean adjus PlayerEntity playerEntity = session.getPlayerEntity(); // Move the player back, but allow gravity to take place // Teleported = true makes going back better, but disconnects the player from their mounted entity - playerEntity.moveAbsolute(Vector3f.from(playerEntity.getPosition().getX(), (newPosition.getY() - EntityDefinitions.PLAYER.bedrockDefinition().offset()), playerEntity.getPosition().getZ()), + playerEntity.moveAbsolute(Vector3f.from(playerEntity.getPosition().getX(), (newPosition.getY() - VanillaEntities.PLAYER_ENTITY_OFFSET), playerEntity.getPosition().getZ()), playerEntity.getYaw(), playerEntity.getPitch(), playerEntity.getHeadYaw(), playerEntity.isOnGround(), playerEntity.getVehicle() == null); } return isInWorldBorder; @@ -325,7 +325,7 @@ public void drawWall() { } private void drawWall(Vector3f position, boolean drawWallX) { - int initialY = (int) (position.getY() - EntityDefinitions.PLAYER.bedrockDefinition().offset() - 1); + int initialY = (int) (position.getY() - VanillaEntities.PLAYER_ENTITY_OFFSET - 1); for (int y = initialY; y < (initialY + 5); y++) { if (drawWallX) { float x = position.getX(); diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java index abd349d82fb..8a8677333d7 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java @@ -35,7 +35,7 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.action.CraftRecipeAction; import org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponse; import org.cloudburstmc.protocol.bedrock.packet.SetEntityLinkPacket; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.inventory.*; import org.geysermc.geyser.inventory.updater.InventoryUpdater; @@ -99,7 +99,7 @@ public boolean prepareInventory(GeyserSession session, MerchantContainer contain long geyserId = session.getEntityCache().getNextEntityId().incrementAndGet(); Vector3f pos = session.getPlayerEntity().getPosition().sub(0, 3, 0); - Entity villager = new Entity(session, 0, geyserId, null, EntityDefinitions.VILLAGER, EntityDefinitions.VILLAGER.bedrockDefinition(), pos, Vector3f.ZERO, 0f, 0f, 0f) { + Entity villager = new Entity(session, 0, geyserId, null, VanillaEntities.VILLAGER, VanillaEntities.VILLAGER.defaultBedrockDefinition(), pos, Vector3f.ZERO, 0f, 0f, 0f) { @Override protected void initializeMetadata() { dirtyMetadata.put(EntityDataTypes.SCALE, 0f); diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SpawnerBlockEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SpawnerBlockEntityTranslator.java index 7fbc7dda01f..fc9f93f2ac3 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SpawnerBlockEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SpawnerBlockEntityTranslator.java @@ -31,7 +31,7 @@ import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtMapBuilder; import org.cloudburstmc.protocol.bedrock.packet.UpdateBlockPacket; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.level.block.type.BlockState; import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.session.GeyserSession; @@ -118,10 +118,10 @@ private static void translateSpawnData(@NonNull NbtMapBuilder builder, @Nullable // As of 1.19.3, spawners can be empty builder.put("EntityIdentifier", entityId); - EntityDefinition definition = Registries.JAVA_ENTITY_IDENTIFIERS.get(entityId); + EntityTypeDefinition definition = Registries.JAVA_ENTITY_IDENTIFIERS.get(entityId); if (definition != null) { - builder.putFloat("DisplayEntityWidth", definition.bedrockDefinition().width()); - builder.putFloat("DisplayEntityHeight", definition.bedrockDefinition().height()); + builder.putFloat("DisplayEntityWidth", definition.defaultBedrockDefinition().width()); + builder.putFloat("DisplayEntityHeight", definition.defaultBedrockDefinition().height()); builder.putFloat("DisplayEntityScale", 1.0f); } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java index b5ad06f7c7f..fbfd1c268f0 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java @@ -27,7 +27,7 @@ import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtMapBuilder; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.level.block.type.BlockState; import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.session.GeyserSession; @@ -47,9 +47,9 @@ public void translateTag(GeyserSession session, NbtMapBuilder bedrockNbt, NbtMap return; } NbtMapBuilder spawnData = NbtMap.builder(); - EntityDefinition definition = Registries.JAVA_ENTITY_IDENTIFIERS.get(entityData.getString("id")); + EntityTypeDefinition definition = Registries.JAVA_ENTITY_IDENTIFIERS.get(entityData.getString("id")); if (definition != null) { - spawnData.putString("TypeId", definition.bedrockDefinition().identifier().toString()); + spawnData.putString("TypeId", definition.defaultBedrockDefinition().identifier().toString()); } spawnData.putInt("Weight", entityData.getInt("Size", 1)); // ??? presumably since these are the only other two extra attributes bedrockNbt.putCompound("spawn_data", spawnData.build()); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java index 897eccda17c..3d8ab411fe0 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java @@ -43,7 +43,7 @@ import org.cloudburstmc.protocol.bedrock.packet.InventoryTransactionPacket; import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket; import org.cloudburstmc.protocol.bedrock.packet.PlaySoundPacket; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.ItemFrameEntity; import org.geysermc.geyser.inventory.GeyserItemStack; @@ -249,7 +249,7 @@ public void translate(GeyserSession session, InventoryTransactionPacket packet) // As of 1.21, Paper does not have any additional range checks that would inconvenience normal players. Vector3f playerPosition = session.getPlayerEntity().getPosition(); - playerPosition = playerPosition.down(EntityDefinitions.PLAYER.bedrockDefinition().offset() - session.getEyeHeight()); + playerPosition = playerPosition.down(VanillaEntities.PLAYER_ENTITY_OFFSET - session.getEyeHeight()); if (!canInteractWithBlock(session, playerPosition, packetBlockPosition)) { BlockUtils.restoreCorrectBlock(session, blockPos); @@ -479,7 +479,7 @@ public void translate(GeyserSession session, InventoryTransactionPacket packet) } int entityId; - if (entity.getDefinition() == EntityDefinitions.ENDER_DRAGON) { + if (entity.getJavaDefinition() == VanillaEntities.ENDER_DRAGON) { // Redirects the attack to its body entity, this only happens when // attacking the underbelly of the ender dragon entityId = entity.getEntityId() + 3; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java index 9dce0d5467b..453ea5e6c0c 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java @@ -30,7 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.PlayerAuthInputData; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.PlayerAuthInputPacket; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.BoatEntity; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; @@ -60,7 +60,7 @@ static void translate(GeyserSession session, PlayerAuthInputPacket packet) { // Ignore movement packets until Bedrock's position matches the teleported position if (session.getUnconfirmedTeleport() != null) { - session.confirmTeleport(packet.getPosition().sub(0, EntityDefinitions.PLAYER.bedrockDefinition().offset(), 0)); + session.confirmTeleport(packet.getPosition().sub(0, VanillaEntities.PLAYER_ENTITY_OFFSET, 0)); return; } @@ -125,7 +125,7 @@ static void translate(GeyserSession session, PlayerAuthInputPacket packet) { // Therefore, we're fixing this by allowing player to no clip to clip through the floor, not only this fixed the issue but // player y velocity should match java perfectly, much better than teleport player right down :) // Shouldn't mess with anything because beyond this point there is nothing to collide and not even entities since they're prob dead. - if (packet.getPosition().getY() - EntityDefinitions.PLAYER.bedrockDefinition().offset() < session.getBedrockDimension().minY() - 5) { + if (packet.getPosition().getY() - VanillaEntities.PLAYER_ENTITY_OFFSET< session.getBedrockDimension().minY() - 5) { // Ensuring that we still can collide with collidable entity that are also in the void (eg: boat, shulker) boolean possibleOnGround = false; @@ -146,7 +146,7 @@ static void translate(GeyserSession session, PlayerAuthInputPacket packet) { final BoundingBox entityBoundingBox = new BoundingBox(0, 0, 0, other.getBoundingBoxWidth(), other.getBoundingBoxHeight(), other.getBoundingBoxWidth()); // Also offset the position down for boat as their position is offset. - entityBoundingBox.translate(other.getPosition().down(other instanceof BoatEntity ? other.getDefinition().bedrockDefinition().offset() : 0).toDouble()); + entityBoundingBox.translate(other.getPosition().down(other instanceof BoatEntity ? other.getJavaDefinition().defaultBedrockDefinition().offset() : 0).toDouble()); if (entityBoundingBox.checkIntersection(boundingBox)) { possibleOnGround = true; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java index 3006096c6fc..14f1bd212ed 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java @@ -290,7 +290,7 @@ private static void processVehicleInput(GeyserSession session, PlayerAuthInputPa Vector3f position = vehicle.getPosition(); if (vehicle instanceof BoatEntity) { - position = position.down(vehicle.getDefinition().offset()); + position = position.down(vehicle.definition().offset()); } final BoundingBox box = new BoundingBox( @@ -327,7 +327,7 @@ private static void processVehicleInput(GeyserSession session, PlayerAuthInputPa if (vehicle instanceof BoatEntity) { // Remove some Y position to prevents boats flying up - vehiclePosition = vehiclePosition.down(vehicle.getBedrockDefinition().offset()); + vehiclePosition = vehiclePosition.down(vehicle.definition().offset()); } vehicle.setPosition(vehiclePosition); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java index 517674a6e2d..b5f5dd8ca96 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java @@ -25,10 +25,15 @@ package org.geysermc.geyser.translator.protocol.java.entity; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.api.entity.GeyserEntityDefinition; +import org.geysermc.geyser.api.entity.JavaEntityType; +import org.geysermc.geyser.api.event.java.ServerSpawnEntityEvent; import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.FallingBlockEntity; @@ -50,6 +55,9 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundAddEntityPacket; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicReference; + @Translator(packet = ClientboundAddEntityPacket.class) public class JavaAddEntityTranslator extends PacketTranslator { @@ -63,7 +71,7 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) return; } - EntityDefinition definition = getEntityDefinition(session, type, packet); + EntityTypeDefinition definition = Registries.ENTITY_DEFINITIONS.get(type); if (definition == null) { session.getGeyser().getLogger().warning("Could not find an entity definition for add entity packet " + packet); return; @@ -76,7 +84,6 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) float headYaw = packet.getHeadYaw(); if (type.is(BuiltinEntityType.PLAYER)) { - PlayerEntity entity; if (packet.getUuid().equals(session.getPlayerEntity().getUuid())) { // Server is sending a fake version of the current player @@ -109,7 +116,38 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) return; } - BedrockEntityDefinition bedrockDefinition = definition.bedrockDefinition(); + BedrockEntityDefinition bedrockDefinition = definition.defaultBedrockDefinition(); + AtomicReference eventDefinition = new AtomicReference<>(bedrockDefinition); + GeyserImpl.getInstance().getEventBus().fire(new ServerSpawnEntityEvent(session) { + + @Override + public int entityId() { + return packet.getEntityId(); + } + + @Override + public @NonNull UUID uuid() { + return packet.getUuid(); + } + + @Override + public @NonNull JavaEntityType entityType() { + return type; + } + + @Override + public @Nullable GeyserEntityDefinition entityDefinition() { + return eventDefinition.get(); + } + + @Override + public void entityDefinition(@Nullable GeyserEntityDefinition entityDefinition) { + eventDefinition.set(entityDefinition); + } + }); + + if (eventDefinition.get() != bedrockDefinition) { + } Entity entity; if (type.is(BuiltinEntityType.FALLING_BLOCK)) { @@ -145,15 +183,4 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) session.getEntityCache().spawnEntity(entity); } - - private static EntityDefinition getEntityDefinition(GeyserSession session, GeyserEntityType entityType, ClientboundAddEntityPacket packet) { -// EntitySpawnPredicateContext context = new GeyserEntitySpawnPredicateContext(session, entityType, packet); -// for (GeyserCustomEntityDefinition customEntityDefinition : Registries.CUSTOM_ENTITY_DEFINITIONS) { -// if (customEntityDefinition.test(context)) { -// return customEntityDefinition; -// } -// } - // TODO custom entities mf - return Registries.ENTITY_DEFINITIONS.get(entityType); - } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java index af365a40144..2c09c4fa5c1 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java @@ -39,7 +39,7 @@ import org.cloudburstmc.protocol.bedrock.packet.SetEntityDataPacket; import org.cloudburstmc.protocol.bedrock.packet.SetEntityMotionPacket; import org.geysermc.geyser.GeyserImpl; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.EvokerFangsEntity; import org.geysermc.geyser.entity.type.FishingHookEntity; @@ -109,7 +109,7 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet for (int i = 0; i < 6; i++) { session.sendUpstreamPacket(particlePacket); } - } else if (entity.getDefinition() == EntityDefinitions.SNOWBALL) { + } else if (entity.getJavaDefinition() == VanillaEntities.SNOWBALL) { LevelEventPacket particlePacket = new LevelEventPacket(); particlePacket.setType(ParticleType.SNOWBALL_POOF); particlePacket.setPosition(entity.getPosition()); @@ -198,7 +198,7 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet return; case SHEEP_GRAZE_OR_TNT_CART_EXPLODE: - if (entity.getDefinition() == EntityDefinitions.SHEEP) { + if (entity.getJavaDefinition() == VanillaEntities.SHEEP) { entityEventPacket.setType(EntityEventType.EAT_GRASS); } else { entityEventPacket.setType(EntityEventType.PRIME_TNT_MINECART); @@ -216,23 +216,23 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet case VILLAGER_SWEAT: LevelEventPacket levelEventPacket = new LevelEventPacket(); levelEventPacket.setType(ParticleType.WATER_SPLASH); - levelEventPacket.setPosition(entity.getPosition().up(entity.getBedrockDefinition().height())); + levelEventPacket.setPosition(entity.getPosition().up(entity.definition().height())); session.sendUpstreamPacket(levelEventPacket); return; case IRON_GOLEM_EMPTY_HAND: entityEventPacket.setType(EntityEventType.GOLEM_FLOWER_WITHDRAW); break; case ATTACK: - if (entity.getDefinition() == EntityDefinitions.IRON_GOLEM || entity.getDefinition() == EntityDefinitions.EVOKER_FANGS - || entity.getDefinition() == EntityDefinitions.WARDEN) { + if (entity.getJavaDefinition() == VanillaEntities.IRON_GOLEM || entity.getJavaDefinition() == VanillaEntities.EVOKER_FANGS + || entity.getJavaDefinition() == VanillaEntities.WARDEN) { entityEventPacket.setType(EntityEventType.ATTACK_START); - if (entity.getDefinition() == EntityDefinitions.EVOKER_FANGS) { + if (entity.getJavaDefinition() == VanillaEntities.EVOKER_FANGS) { ((EvokerFangsEntity) entity).setAttackStarted(); } } break; case RABBIT_JUMP_OR_MINECART_SPAWNER_DELAY_RESET: - if (entity.getDefinition() == EntityDefinitions.RABBIT) { + if (entity.getJavaDefinition() == VanillaEntities.RABBIT) { // This doesn't match vanilla Bedrock behavior but I'm unsure how to make it better // I assume part of the problem is that Bedrock uses a duration and Java just says the rabbit is jumping SetEntityDataPacket dataPacket = new SetEntityDataPacket(); @@ -266,12 +266,12 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet } return; case GOAT_LOWERING_HEAD: - if (entity.getDefinition() == EntityDefinitions.GOAT) { + if (entity.getJavaDefinition() == VanillaEntities.GOAT) { entityEventPacket.setType(EntityEventType.ATTACK_START); } break; case GOAT_STOP_LOWERING_HEAD: - if (entity.getDefinition() == EntityDefinitions.GOAT) { + if (entity.getJavaDefinition() == VanillaEntities.GOAT) { entityEventPacket.setType(EntityEventType.ATTACK_STOP); } break; @@ -283,7 +283,7 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet } break; case WARDEN_RECEIVE_SIGNAL: - if (entity.getDefinition() == EntityDefinitions.WARDEN) { + if (entity.getJavaDefinition() == VanillaEntities.WARDEN) { entityEventPacket.setType(EntityEventType.VIBRATION_DETECTED); } break; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityDataTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityDataTranslator.java index 3ba9369efa2..e384477f578 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityDataTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityDataTranslator.java @@ -25,7 +25,7 @@ package org.geysermc.geyser.translator.protocol.java.entity; -import org.geysermc.geyser.entity.EntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.protocol.PacketTranslator; @@ -42,18 +42,18 @@ public void translate(GeyserSession session, ClientboundSetEntityDataPacket pack Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId()); if (entity == null) return; - EntityDefinition definition = entity.getDefinition(); + EntityTypeDefinition definition = entity.getJavaDefinition(); for (EntityMetadata metadata : packet.getMetadata()) { if (metadata.getId() >= definition.translators().size()) { if (session.getGeyser().config().debugMode()) { // Minecraft client just ignores these - session.getGeyser().getLogger().warning("Metadata ID " + metadata.getId() + " is out of bounds of known entity metadata size " + definition.translators().size() + " for entity type " + entity.getDefinition().type()); + session.getGeyser().getLogger().warning("Metadata ID " + metadata.getId() + " is out of bounds of known entity metadata size " + definition.translators().size() + " for entity type " + entity.getJavaDefinition().type()); session.getGeyser().getLogger().debug(metadata.toString()); } continue; } - ((EntityDefinition) definition).translateMetadata(entity, metadata); + ((EntityTypeDefinition) definition).translateMetadata(entity, metadata); } entity.updateBedrockMetadata(); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEquipmentTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEquipmentTranslator.java index af41d49ccb1..2c806d7bed5 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEquipmentTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEquipmentTranslator.java @@ -50,7 +50,7 @@ public void translate(GeyserSession session, ClientboundSetEquipmentPacket packe if (!(entity instanceof LivingEntity livingEntity)) { session.getGeyser().getLogger().debug("Attempted to add armor to a non-living entity (" + - entity.getBedrockDefinition().identifier() + ")."); + entity.getDefinition().identifier() + ")."); return; } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java index b5809d673c2..16a038ec7b0 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java @@ -29,7 +29,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityLinkData; import org.cloudburstmc.protocol.bedrock.packet.SetEntityLinkPacket; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.vehicle.ClientVehicle; import org.geysermc.geyser.session.GeyserSession; @@ -59,7 +59,7 @@ public void translate(GeyserSession session, ClientboundSetPassengersPacket pack if (passenger == session.getPlayerEntity()) { session.getPlayerEntity().setVehicle(entity); // We need to confirm teleports before entering a vehicle, or else we will likely exit right out - session.confirmTeleport(passenger.getPosition().down(EntityDefinitions.PLAYER.bedrockDefinition().offset())); + session.confirmTeleport(passenger.getPosition().down(VanillaEntities.PLAYER_ENTITY_OFFSET)); if (entity instanceof ClientVehicle clientVehicle) { clientVehicle.getVehicleComponent().onMount(); @@ -125,8 +125,8 @@ public void translate(GeyserSession session, ClientboundSetPassengersPacket pack entity.setPassengers(newPassengers); - if (entity.getDefinition().is(BuiltinEntityType.HORSE) || entity.getDefinition().is(BuiltinEntityType.SKELETON_HORSE) || entity.getDefinition().is(BuiltinEntityType.DONKEY) - || entity.getDefinition().is(BuiltinEntityType.MULE) || entity.getDefinition().is(BuiltinEntityType.RAVAGER)) { + if (entity.getJavaDefinition().is(BuiltinEntityType.HORSE) || entity.getJavaDefinition().is(BuiltinEntityType.SKELETON_HORSE) || entity.getJavaDefinition().is(BuiltinEntityType.DONKEY) + || entity.getJavaDefinition().is(BuiltinEntityType.MULE) || entity.getJavaDefinition().is(BuiltinEntityType.RAVAGER)) { entity.getDirtyMetadata().put(EntityDataTypes.SEAT_ROTATION_OFFSET_DEGREES, 181.0f); entity.updateBedrockMetadata(); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java index e9c790deef1..3b5de520bca 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java @@ -31,7 +31,7 @@ import org.cloudburstmc.protocol.bedrock.packet.MovePlayerPacket; import org.cloudburstmc.protocol.bedrock.packet.RespawnPacket; import org.cloudburstmc.protocol.bedrock.packet.SetEntityMotionPacket; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.TeleportCache; @@ -58,7 +58,7 @@ public void translate(GeyserSession session, ClientboundPlayerPositionPacket pac position = position.add( packet.getRelatives().contains(PositionElement.X) ? entity.getPosition().getX() : 0, - packet.getRelatives().contains(PositionElement.Y) ? entity.getPosition().getY() - EntityDefinitions.PLAYER.bedrockDefinition().offset() : 0, + packet.getRelatives().contains(PositionElement.Y) ? entity.getPosition().getY() - VanillaEntities.PLAYER_ENTITY_OFFSET : 0, packet.getRelatives().contains(PositionElement.Z) ? entity.getPosition().getZ() : 0); float newPitch = MathUtils.clamp(packet.getXRot() + (packet.getRelatives().contains(PositionElement.X_ROT) ? entity.getPitch() : 0), -90, 90); @@ -116,9 +116,9 @@ public void translate(GeyserSession session, ClientboundPlayerPositionPacket pac return; } - session.getGeyser().getLogger().debug("Teleport (" + teleportId + ") from " + entity.getPosition().getX() + " " + (entity.getPosition().getY() - EntityDefinitions.PLAYER.bedrockDefinition().offset()) + " " + entity.getPosition().getZ()); + session.getGeyser().getLogger().debug("Teleport (" + teleportId + ") from " + entity.getPosition().getX() + " " + (entity.getPosition().getY() - VanillaEntities.PLAYER_ENTITY_OFFSET) + " " + entity.getPosition().getZ()); - Vector3f lastPlayerPosition = entity.getPosition().down(EntityDefinitions.PLAYER.bedrockDefinition().offset()); + Vector3f lastPlayerPosition = entity.getPosition().down(VanillaEntities.PLAYER_ENTITY_OFFSET); float lastPlayerPitch = entity.getPitch(); float lastPlayerYaw = entity.getYaw(); Vector3f teleportDestination = position.toFloat(); @@ -155,7 +155,7 @@ public void translate(GeyserSession session, ClientboundPlayerPositionPacket pac session.setUnconfirmedTeleport(new TeleportCache(teleportDestination, deltaMovement, newPitch, newYaw, teleportId, type)); } - session.getGeyser().getLogger().debug("to " + entity.getPosition().getX() + " " + (entity.getPosition().getY() - EntityDefinitions.PLAYER.bedrockDefinition().offset()) + " " + entity.getPosition().getZ()); + session.getGeyser().getLogger().debug("to " + entity.getPosition().getX() + " " + (entity.getPosition().getY() - VanillaEntities.PLAYER_ENTITY_OFFSET) + " " + entity.getPosition().getZ()); } private void acceptTeleport(GeyserSession session, Vector3d position, float yaw, float pitch, int id) { diff --git a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java index 6da60d885ff..abcf596506a 100644 --- a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java @@ -33,8 +33,8 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.api.util.Identifier; -import org.geysermc.geyser.entity.EntityDefinition; -import org.geysermc.geyser.entity.EntityDefinitions; +import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.entity.type.BoatEntity; import org.geysermc.geyser.entity.type.ChestBoatEntity; @@ -60,6 +60,9 @@ import java.util.UUID; public final class EntityUtils { + + public static final float PLAYER_ENTITY_OFFSET = 1.62F; + /** * A constant array of the two hands that a player can interact with an entity. */ @@ -109,7 +112,7 @@ private static float getMountedHeightOffset(Entity mount) { float height = mount.getBoundingBoxHeight(); float mountedHeightOffset = height * 0.75f; - EntityDefinition definition = mount.getDefinition(); + EntityTypeDefinition definition = mount.getJavaDefinition(); if (definition.is(BuiltinEntityType.CAMEL)) { boolean isBaby = mount.getFlag(EntityFlag.BABY); mountedHeightOffset = height - (isBaby ? 0.35f : 0.6f); @@ -146,7 +149,7 @@ private static float getMountedHeightOffset(Entity mount) { private static float getHeightOffset(Entity passenger) { boolean isBaby; - EntityDefinition definition = passenger.getDefinition(); + EntityTypeDefinition definition = passenger.getJavaDefinition(); if (definition.is(BuiltinEntityType.ALLAY) || definition.is(BuiltinEntityType.VEX)) { return 0.4f; } else if (definition.is(BuiltinEntityType.SKELETON) || definition.is(BuiltinEntityType.STRAY) || definition.is(BuiltinEntityType.WITHER_SKELETON)) { @@ -173,7 +176,7 @@ private static float getHeightOffset(Entity passenger) { return -0.35f; } else if (definition.is(BuiltinEntityType.SHULKER)) { Entity vehicle = passenger.getVehicle(); - if (vehicle instanceof BoatEntity || vehicle.getDefinition() == EntityDefinitions.MINECART) { + if (vehicle instanceof BoatEntity || vehicle.getJavaDefinition() == VanillaEntities.MINECART) { return 0.1875f - getMountedHeightOffset(vehicle); } } @@ -196,7 +199,7 @@ public static void updateMountOffset(Entity passenger, Entity mount, boolean rid float xOffset = 0; float yOffset = mountedHeightOffset + heightOffset; float zOffset = 0; - EntityDefinition mountDefinition = mount.getDefinition(); + EntityTypeDefinition mountDefinition = mount.getJavaDefinition(); if (mountDefinition.is(BuiltinEntityType.CAMEL)) { zOffset = 0.5f; if (passengers > 1) { @@ -264,30 +267,30 @@ public static void updateMountOffset(Entity passenger, Entity mount, boolean rid * Horses are tinier * Players, Minecarts, and Boats have different origins */ - EntityDefinition passengerDefinition = passenger.getDefinition(); + EntityTypeDefinition passengerDefinition = passenger.getJavaDefinition(); if (mountDefinition.is(BuiltinEntityType.PLAYER)) { - yOffset -= EntityDefinitions.PLAYER.bedrockDefinition().offset(); + yOffset -= VanillaEntities.PLAYER_ENTITY_OFFSET; } if (passengerDefinition.is(BuiltinEntityType.PLAYER)) { - yOffset += EntityDefinitions.PLAYER.bedrockDefinition().offset(); + yOffset += VanillaEntities.PLAYER_ENTITY_OFFSET; } if (mountDefinition.is(BuiltinEntityType.MINECART) || mountDefinition.is(BuiltinEntityType.HOPPER_MINECART) || mountDefinition.is(BuiltinEntityType.TNT_MINECART) || mountDefinition.is(BuiltinEntityType.CHEST_MINECART) || mountDefinition.is(BuiltinEntityType.FURNACE_MINECART) || mountDefinition.is(BuiltinEntityType.SPAWNER_MINECART) || mountDefinition.is(BuiltinEntityType.COMMAND_BLOCK_MINECART)) { - yOffset -= mount.getDefinition().bedrockDefinition().height() * 0.5f; + yOffset -= mount.getJavaDefinition().defaultBedrockDefinition().height() * 0.5f; } if (passengerDefinition.is(BuiltinEntityType.MINECART) || passengerDefinition.is(BuiltinEntityType.HOPPER_MINECART) || passengerDefinition.is(BuiltinEntityType.TNT_MINECART) || passengerDefinition.is(BuiltinEntityType.CHEST_MINECART) || passengerDefinition.is(BuiltinEntityType.FURNACE_MINECART) || passengerDefinition.is(BuiltinEntityType.SPAWNER_MINECART) || passengerDefinition.is(BuiltinEntityType.COMMAND_BLOCK_MINECART) || passengerDefinition.is(BuiltinEntityType.SHULKER)) { - yOffset += passenger.getDefinition().bedrockDefinition().height() * 0.5f; + yOffset += passenger.getJavaDefinition().defaultBedrockDefinition().height() * 0.5f; } else if (passengerDefinition.is(BuiltinEntityType.FALLING_BLOCK)) { yOffset += 0.995f; } if (mount instanceof BoatEntity) { - yOffset -= mount.getDefinition().bedrockDefinition().height() * 0.5f; + yOffset -= mount.getJavaDefinition().defaultBedrockDefinition().height() * 0.5f; } if (passenger instanceof BoatEntity) { - yOffset += passenger.getDefinition().bedrockDefinition().height() * 0.5f; + yOffset += passenger.getJavaDefinition().defaultBedrockDefinition().height() * 0.5f; } if (mount instanceof ArmorStandEntity armorStand) { yOffset -= armorStand.getYOffset(); diff --git a/core/src/main/resources/languages b/core/src/main/resources/languages index 4ce8ad58ea7..daa21574283 160000 --- a/core/src/main/resources/languages +++ b/core/src/main/resources/languages @@ -1 +1 @@ -Subproject commit 4ce8ad58ea7ab779d613a64862956d6d0563a8e3 +Subproject commit daa215742837ca1c16ef34e724bba98b6bc047a9 From 142cbaee71ed9d5670c02fde51ab45d7a511c40d Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sun, 23 Nov 2025 17:54:18 +0100 Subject: [PATCH 12/62] Continue splitting bedrock entities from java types --- .../entity/BedrockEntityDefinition.java | 3 +- .../entity/BedrockEntityDefinitions.java | 33 +++++++++++++++++++ .../geyser/entity/GeyserEntityType.java | 6 ---- .../geyser/entity/VanillaEntities.java | 24 +++++++++----- .../geyser/entity/VanillaEntityType.java | 29 +++++++++------- .../properties/GeyserEntityProperties.java | 5 ++- .../entity/properties/type/PropertyType.java | 3 +- .../geysermc/geyser/entity/type/Entity.java | 6 ++-- .../geyser/entity/type/WitherSkullEntity.java | 6 ++-- .../entity/JavaSetEquipmentTranslator.java | 2 +- 10 files changed, 80 insertions(+), 37 deletions(-) create mode 100644 core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java index 5b79994312c..8e2cdf9b6f7 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java @@ -30,6 +30,7 @@ import lombok.Setter; import lombok.experimental.Accessors; import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.api.entity.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.util.Identifier; @@ -102,7 +103,7 @@ public Builder identifier(Identifier identifier) { return this; } - public Builder properties(GeyserEntityProperties.Builder propertiesBuilder) { + public Builder properties(GeyserEntityProperties.@Nullable Builder propertiesBuilder) { this.propertiesBuilder = propertiesBuilder; return this; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java new file mode 100644 index 00000000000..3228a68a82a --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.entity; + +public class BedrockEntityDefinitions { + + // TODO re-usable Bedrock entity definitions?????????? + // Or rather... looking up otherwise?? + +} diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java index caae00c105f..2dcc7b183b0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java @@ -53,12 +53,6 @@ public record GeyserEntityType(Identifier identifier, int javaId) implements Jav private static final Int2ObjectMap CUSTOM = new Int2ObjectOpenHashMap<>(); private static final Object2ObjectMap CUSTOM_BY_IDENTIFIER = new Object2ObjectOpenHashMap<>(); - public GeyserEntityType { - if (!VANILLA.containsValue(this) && !CUSTOM.containsKey(javaId)) { - throw new IllegalCallerException("Public constructor of GeyserEntityType should not be used; use one of the static factory methods instead"); - } - } - private GeyserEntityType(BuiltinEntityType builtin) { this(IdentifierImpl.of(builtin.name().toLowerCase(Locale.ROOT)), builtin.id()); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntities.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntities.java index 6140b971d36..ef299f49331 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntities.java +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntities.java @@ -168,6 +168,7 @@ import org.geysermc.geyser.entity.type.player.AvatarEntity; import org.geysermc.geyser.entity.type.player.MannequinEntity; import org.geysermc.geyser.entity.type.player.PlayerEntity; +import org.geysermc.geyser.impl.IdentifierImpl; import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.translator.text.MessageTranslator; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataTypes; @@ -335,10 +336,6 @@ public final class VanillaEntities { * Is not sent over the network */ public static final VanillaEntityType ENDER_DRAGON_PART; - /** - * Special Bedrock type - */ - public static final VanillaEntityType WITHER_SKULL_DANGEROUS; public static final float PLAYER_ENTITY_OFFSET; @@ -469,7 +466,7 @@ public final class VanillaEntities { INTERACTION = VanillaEntityType.inherited(InteractionEntity::new, entityBase) .type(BuiltinEntityType.INTERACTION) .heightAndWidth(1.0f) // default size until server specifies otherwise - .bedrockIdentifier("minecraft:armor_stand") + .bedrockDefinition(ARMOR_STAND.defaultBedrockDefinition()) .addTranslator(MetadataTypes.FLOAT, InteractionEntity::setWidth) .addTranslator(MetadataTypes.FLOAT, InteractionEntity::setHeight) .addTranslator(MetadataTypes.BOOLEAN, InteractionEntity::setResponse) @@ -613,8 +610,19 @@ public final class VanillaEntities { .heightAndWidth(0.3125f) .addTranslator(MetadataTypes.BOOLEAN, WitherSkullEntity::setDangerous) .build(); - WITHER_SKULL_DANGEROUS = VanillaEntityType.inherited(WITHER_SKULL.factory(), WITHER_SKULL) - .build(false); + + // Bedrock exclusive entity + IdentifierImpl dangerousSkull = IdentifierImpl.of("wither_skull_dangerous"); + BedrockEntityDefinition bedrockDefinition = BedrockEntityDefinition.builder() + .height(WITHER_SKULL.height) + .width(WITHER_SKULL.width) + .offset(WITHER_SKULL.offset) + .identifier(dangerousSkull) + .build(); + Registries.BEDROCK_ENTITY_DEFINITIONS.get().put(dangerousSkull, bedrockDefinition); + +// WITHER_SKULL_DANGEROUS = VanillaEntityType.inherited(WITHER_SKULL.factory(), WITHER_SKULL) +// .build(false); } // Boats @@ -1246,7 +1254,7 @@ public final class VanillaEntities { // As of 1.18 these don't track entity data at all ENDER_DRAGON_PART = VanillaEntityType.builder(null) - .bedrockIdentifier("minecraft:armor_stand") // Emulated + .bedrockDefinition(ARMOR_STAND.defaultBedrockDefinition()) // Emulated .build(false); // Never sent over the network PLAYER_ENTITY_OFFSET = PLAYER.defaultBedrockDefinition().offset(); diff --git a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java index 41b8ae45c3b..c590bb81c2c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java @@ -70,6 +70,7 @@ public static Builder inherited(EntityFactory factory, public static class Builder extends EntityTypeDefinition.Builder { protected GeyserEntityType type; + protected BedrockEntityDefinition bedrockDefinition; protected Builder(EntityFactory factory) { super(factory); @@ -128,6 +129,11 @@ public Builder addTranslator(EntityMetadataTranslator translator) { return (Builder) super.addTranslator(translator); } + public Builder bedrockDefinition(BedrockEntityDefinition bedrockDefinition) { + this.bedrockDefinition = bedrockDefinition; + return this; + } + @Override public VanillaEntityType build() { return build(true); @@ -136,8 +142,17 @@ public VanillaEntityType build() { private void validateTypeAndIdentifier() { if (type == null) { throw new IllegalStateException("Missing entity type!"); - } else if (bedrockIdentifier == null) { - bedrockIdentifier = type.identifier().toString(); + } + + if (bedrockDefinition == null) { + bedrockDefinition = BedrockEntityDefinition.builder() + .height(height) + .width(width) + .properties(propertiesBuilder) + .offset(offset) + .identifier(Identifier.of(bedrockIdentifier)) + .build(); + Registries.BEDROCK_ENTITY_DEFINITIONS.get().put(Identifier.of(bedrockIdentifier), bedrockDefinition); } } @@ -148,16 +163,6 @@ private void validateTypeAndIdentifier() { public VanillaEntityType build(boolean register) { validateTypeAndIdentifier(); - BedrockEntityDefinition bedrockDefinition = BedrockEntityDefinition.builder() - .height(height) - .width(width) - .properties(propertiesBuilder) - .offset(offset) - .identifier(Identifier.of(bedrockIdentifier)) - .build(); - // TODO TEST!!! - Registries.BEDROCK_ENTITY_DEFINITIONS.get().put(Identifier.of(bedrockIdentifier), bedrockDefinition); - VanillaEntityType definition = new VanillaEntityType<>(factory, type, bedrockDefinition, translators); if (register && definition.entityType() != null) { Registries.ENTITY_DEFINITIONS.get().putIfAbsent(definition.entityType(), definition); diff --git a/core/src/main/java/org/geysermc/geyser/entity/properties/GeyserEntityProperties.java b/core/src/main/java/org/geysermc/geyser/entity/properties/GeyserEntityProperties.java index 5d9563f3a46..4ad955fa6bc 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/properties/GeyserEntityProperties.java +++ b/core/src/main/java/org/geysermc/geyser/entity/properties/GeyserEntityProperties.java @@ -31,7 +31,6 @@ import lombok.EqualsAndHashCode; import lombok.ToString; import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtMapBuilder; import org.cloudburstmc.nbt.NbtType; @@ -106,7 +105,7 @@ public int getPropertyIndex(String name) { } public static class Builder { - private GeyserEntityProperties properties; + private GeyserEntityProperties properties = new GeyserEntityProperties(); private final String identifier; public Builder(String identifier) { @@ -122,7 +121,7 @@ public Builder add(@NonNull PropertyType proper return this; } - public @Nullable GeyserEntityProperties build() { + public @NonNull GeyserEntityProperties build() { return properties; } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/properties/type/PropertyType.java b/core/src/main/java/org/geysermc/geyser/entity/properties/type/PropertyType.java index cd147127305..55af16bb248 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/properties/type/PropertyType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/properties/type/PropertyType.java @@ -38,7 +38,8 @@ public interface PropertyType javaDefinition; protected int entityId; @@ -152,7 +152,7 @@ public class Entity implements GeyserEntity { @Setter(AccessLevel.PROTECTED) // For players private boolean flagsDirty = false; - protected final GeyserEntityPropertyManager propertyManager; + protected final @Nullable GeyserEntityPropertyManager propertyManager; public Entity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { @@ -171,7 +171,7 @@ public Entity(GeyserSession session, int entityId, long geyserId, UUID uuid, Ent this.valid = false; // TODO null or empty check - this.propertyManager = bedrockDefinition.registeredProperties() == null ? null : new GeyserEntityPropertyManager(bedrockDefinition.registeredProperties()); + this.propertyManager = bedrockDefinition.registeredProperties().isEmpty() ? null : new GeyserEntityPropertyManager(bedrockDefinition.registeredProperties()); setPosition(position); setAirSupply(getMaxAir()); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java index b5ef8cc0c35..3a9a08a5d2f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java @@ -28,7 +28,8 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.entity.VanillaEntities; +import org.geysermc.geyser.impl.IdentifierImpl; +import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; @@ -36,6 +37,7 @@ public class WitherSkullEntity extends FireballEntity { private boolean isCharged; + private static final IdentifierImpl DANGEROUS_SKULL = IdentifierImpl.of("wither_skull_dangerous"); public WitherSkullEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); @@ -48,7 +50,7 @@ public void setDangerous(BooleanEntityMetadata entityMetadata) { if (newDangerous != isCharged) { isCharged = newDangerous; // Is an entirely new entity in Bedrock but just a metadata type in Java - javaDefinition = isCharged ? VanillaEntities.WITHER_SKULL_DANGEROUS : VanillaEntities.WITHER_SKULL; + definition = isCharged ? Registries.BEDROCK_ENTITY_DEFINITIONS.get(DANGEROUS_SKULL) : javaDefinition.defaultBedrockDefinition(); despawnEntity(); spawnEntity(); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEquipmentTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEquipmentTranslator.java index 2c806d7bed5..ea5dfec5f68 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEquipmentTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEquipmentTranslator.java @@ -50,7 +50,7 @@ public void translate(GeyserSession session, ClientboundSetEquipmentPacket packe if (!(entity instanceof LivingEntity livingEntity)) { session.getGeyser().getLogger().debug("Attempted to add armor to a non-living entity (" + - entity.getDefinition().identifier() + ")."); + entity.definition().identifier() + ")."); return; } From 8ff763ba66a7022416d6eb9392b8710a8e8b20b7 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Tue, 25 Nov 2025 22:34:05 +0100 Subject: [PATCH 13/62] Width, height and offset should be tied to the Java entity type; and can now be modified in the ServerSpawnEntityEvent --- .../api/connection/GeyserConnection.java | 15 +- .../geyser/api/entity/EntityData.java | 11 +- .../api/entity/GeyserEntityDefinition.java | 19 --- .../entity/custom/CustomEntityDefinition.java | 38 +---- .../type/player/GeyserPlayerEntity.java | 2 - .../event/java/ServerSpawnEntityEvent.java | 33 ++++ .../lifecycle/GeyserDefineEntitiesEvent.java | 2 +- .../GeyserDefineEntityPropertiesEvent.java | 22 +-- .../entity/BedrockEntityDefinition.java | 28 +--- .../entity/BedrockEntityDefinitions.java | 17 ++ ...llaEntityBase.java => EntityTypeBase.java} | 21 +-- .../geyser/entity/EntityTypeDefinition.java | 8 +- .../GeyserCustomEntityTypeDefinition.java | 7 +- .../geyser/entity/VanillaEntities.java | 62 ++++--- .../geyser/entity/VanillaEntityBases.java | 66 ++++---- .../geyser/entity/VanillaEntityType.java | 25 ++- .../geyser/entity/factory/EntityFactory.java | 9 +- .../entity/spawn/EntitySpawnContext.java | 153 ++++++++++++++++++ .../entity/type/AbstractArrowEntity.java | 12 +- .../entity/type/AbstractWindChargeEntity.java | 11 +- .../entity/type/AreaEffectCloudEntity.java | 11 +- .../geyser/entity/type/ArrowEntity.java | 11 +- .../geyser/entity/type/BoatEntity.java | 16 +- .../geyser/entity/type/ChestBoatEntity.java | 11 +- .../type/CommandBlockMinecartEntity.java | 11 +- .../type/DefaultBlockMinecartEntity.java | 11 +- .../geyser/entity/type/DisplayBaseEntity.java | 9 +- .../entity/type/EnderCrystalEntity.java | 10 +- .../geyser/entity/type/EnderEyeEntity.java | 11 +- .../geysermc/geyser/entity/type/Entity.java | 59 ++++--- .../geyser/entity/type/EvokerFangsEntity.java | 10 +- .../geyser/entity/type/ExpOrbEntity.java | 11 +- .../entity/type/FallingBlockEntity.java | 12 +- .../geyser/entity/type/FireballEntity.java | 11 +- .../geyser/entity/type/FireworkEntity.java | 10 +- .../geyser/entity/type/FishingHookEntity.java | 9 +- .../entity/type/FurnaceMinecartEntity.java | 11 +- .../geyser/entity/type/HangingEntity.java | 11 +- .../geyser/entity/type/InteractionEntity.java | 13 +- .../geyser/entity/type/ItemEntity.java | 15 +- .../geyser/entity/type/ItemFrameEntity.java | 14 +- .../geyser/entity/type/LeashKnotEntity.java | 12 +- .../geyser/entity/type/LightningEntity.java | 10 +- .../geyser/entity/type/LivingEntity.java | 11 +- .../geyser/entity/type/MinecartEntity.java | 18 +-- .../geyser/entity/type/PaintingEntity.java | 10 +- .../entity/type/SpawnerMinecartEntity.java | 11 +- .../geyser/entity/type/TNTEntity.java | 15 +- .../geyser/entity/type/TextDisplayEntity.java | 13 +- .../entity/type/ThrowableEggEntity.java | 10 +- .../geyser/entity/type/ThrowableEntity.java | 30 ++-- .../entity/type/ThrowableItemEntity.java | 12 +- .../entity/type/ThrownPotionEntity.java | 12 +- .../geyser/entity/type/TridentEntity.java | 11 +- .../geyser/entity/type/WitherSkullEntity.java | 13 +- .../type/living/AbstractFishEntity.java | 5 +- .../entity/type/living/AgeableEntity.java | 14 +- .../type/living/AgeableWaterEntity.java | 11 +- .../entity/type/living/AllayEntity.java | 11 +- .../entity/type/living/AmbientEntity.java | 11 +- .../entity/type/living/ArmorStandEntity.java | 19 +-- .../geyser/entity/type/living/BatEntity.java | 11 +- .../entity/type/living/CopperGolemEntity.java | 11 +- .../entity/type/living/CreatureEntity.java | 11 +- .../entity/type/living/DolphinEntity.java | 11 +- .../entity/type/living/FlyingEntity.java | 11 +- .../entity/type/living/GlowSquidEntity.java | 11 +- .../entity/type/living/GolemEntity.java | 11 +- .../entity/type/living/IronGolemEntity.java | 11 +- .../entity/type/living/MagmaCubeEntity.java | 10 +- .../geyser/entity/type/living/MobEntity.java | 10 +- .../entity/type/living/SlimeEntity.java | 11 +- .../entity/type/living/SnowGolemEntity.java | 11 +- .../entity/type/living/SquidEntity.java | 9 +- .../entity/type/living/TadpoleEntity.java | 11 +- .../entity/type/living/WaterEntity.java | 11 +- .../type/living/animal/AnimalEntity.java | 11 +- .../type/living/animal/ArmadilloEntity.java | 11 +- .../type/living/animal/AxolotlEntity.java | 11 +- .../entity/type/living/animal/BeeEntity.java | 11 +- .../entity/type/living/animal/FoxEntity.java | 11 +- .../entity/type/living/animal/FrogEntity.java | 10 +- .../entity/type/living/animal/GoatEntity.java | 11 +- .../type/living/animal/HappyGhastEntity.java | 9 +- .../type/living/animal/HoglinEntity.java | 11 +- .../type/living/animal/MooshroomEntity.java | 11 +- .../type/living/animal/OcelotEntity.java | 11 +- .../type/living/animal/PandaEntity.java | 11 +- .../type/living/animal/PolarBearEntity.java | 11 +- .../type/living/animal/PufferFishEntity.java | 11 +- .../type/living/animal/RabbitEntity.java | 11 +- .../type/living/animal/SheepEntity.java | 11 +- .../type/living/animal/SnifferEntity.java | 15 +- .../type/living/animal/StriderEntity.java | 10 +- .../living/animal/TropicalFishEntity.java | 10 +- .../type/living/animal/TurtleEntity.java | 11 +- .../living/animal/farm/ChickenEntity.java | 11 +- .../type/living/animal/farm/CowEntity.java | 11 +- .../type/living/animal/farm/PigEntity.java | 10 +- .../animal/farm/TemperatureVariantAnimal.java | 12 +- .../animal/horse/AbstractHorseEntity.java | 11 +- .../type/living/animal/horse/CamelEntity.java | 14 +- .../animal/horse/ChestedHorseEntity.java | 11 +- .../type/living/animal/horse/HorseEntity.java | 11 +- .../type/living/animal/horse/LlamaEntity.java | 11 +- .../animal/horse/SkeletonHorseEntity.java | 11 +- .../animal/horse/TraderLlamaEntity.java | 11 +- .../animal/horse/ZombieHorseEntity.java | 11 +- .../living/animal/tameable/CatEntity.java | 11 +- .../living/animal/tameable/ParrotEntity.java | 11 +- .../animal/tameable/TameableEntity.java | 9 +- .../living/animal/tameable/WolfEntity.java | 10 +- .../merchant/AbstractMerchantEntity.java | 17 +- .../type/living/merchant/VillagerEntity.java | 9 +- .../monster/AbstractSkeletonEntity.java | 11 +- .../type/living/monster/BasePiglinEntity.java | 11 +- .../type/living/monster/BlazeEntity.java | 11 +- .../type/living/monster/BoggedEntity.java | 11 +- .../type/living/monster/BreezeEntity.java | 11 +- .../type/living/monster/CreakingEntity.java | 10 +- .../type/living/monster/CreeperEntity.java | 11 +- .../living/monster/ElderGuardianEntity.java | 11 +- .../living/monster/EnderDragonEntity.java | 9 +- .../living/monster/EnderDragonPartEntity.java | 9 +- .../type/living/monster/EndermanEntity.java | 11 +- .../type/living/monster/GhastEntity.java | 11 +- .../type/living/monster/GiantEntity.java | 11 +- .../type/living/monster/GuardianEntity.java | 11 +- .../type/living/monster/MonsterEntity.java | 11 +- .../type/living/monster/PhantomEntity.java | 17 +- .../type/living/monster/PiglinEntity.java | 11 +- .../type/living/monster/ShulkerEntity.java | 5 +- .../type/living/monster/SkeletonEntity.java | 11 +- .../type/living/monster/SpiderEntity.java | 11 +- .../entity/type/living/monster/VexEntity.java | 11 +- .../type/living/monster/WardenEntity.java | 10 +- .../type/living/monster/WitherEntity.java | 11 +- .../type/living/monster/ZoglinEntity.java | 13 +- .../type/living/monster/ZombieEntity.java | 11 +- .../living/monster/ZombieVillagerEntity.java | 11 +- .../living/monster/ZombifiedPiglinEntity.java | 11 +- .../monster/raid/AbstractIllagerEntity.java | 11 +- .../living/monster/raid/PillagerEntity.java | 11 +- .../monster/raid/RaidParticipantEntity.java | 11 +- .../living/monster/raid/RavagerEntity.java | 10 +- .../raid/SpellcasterIllagerEntity.java | 13 +- .../living/monster/raid/VindicatorEntity.java | 11 +- .../entity/type/player/AvatarEntity.java | 20 +-- .../entity/type/player/MannequinEntity.java | 10 +- .../entity/type/player/PlayerEntity.java | 11 +- .../type/player/SessionPlayerEntity.java | 12 +- .../entity/type/player/SkullPlayerEntity.java | 7 +- .../entity/vehicle/VehicleComponent.java | 2 +- .../geyser/session/GeyserSession.java | 10 ++ .../geyser/session/cache/SkullCache.java | 12 +- .../MerchantInventoryTranslator.java | 14 +- .../entity/SpawnerBlockEntityTranslator.java | 4 +- ...BedrockInventoryTransactionTranslator.java | 3 +- .../player/input/BedrockMovePlayer.java | 2 +- .../BedrockPlayerAuthInputTranslator.java | 4 +- .../java/entity/JavaAddEntityTranslator.java | 75 ++------- .../entity/JavaEntityEventTranslator.java | 22 +-- .../entity/JavaSetEntityDataTranslator.java | 4 +- .../entity/JavaSetPassengersTranslator.java | 4 +- .../JavaPlayerInfoUpdateTranslator.java | 15 +- .../org/geysermc/geyser/util/EntityUtils.java | 18 +-- core/src/main/resources/languages | 2 +- .../util/GeyserMockContextScoreboard.java | 29 ++-- 168 files changed, 932 insertions(+), 1397 deletions(-) rename core/src/main/java/org/geysermc/geyser/entity/{VanillaEntityBase.java => EntityTypeBase.java} (90%) create mode 100644 core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java diff --git a/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java b/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java index 23971305d37..648ede4d2a5 100644 --- a/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java +++ b/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java @@ -58,7 +58,7 @@ public interface GeyserConnection extends Connection, CommandSource { /** * Exposes the {@link EntityData} for this connection. - * It allows you to get entities by their Java entity ID, show emotes, and get the player entity. + * It allows you to look up other entities through various methods. * * @return the EntityData for this connection. */ @@ -238,4 +238,17 @@ public interface GeyserConnection extends Connection, CommandSource { @Deprecated @NonNull Set fogEffects(); + + /** + * Gets the {@link GeyserPlayerEntity} of this connection. + * + * @return the {@link GeyserPlayerEntity} of this connection + */ + @NonNull GeyserPlayerEntity playerEntity(); + + /** + * Sends a request to the Java server to switch the items in the main and offhand. + * There is no guarantee of the server accepting the request. + */ + void requestHandSwap(); } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java b/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java index a4c2717d319..30f2335ff18 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java @@ -63,11 +63,8 @@ public interface EntityData { void showEmote(@NonNull GeyserPlayerEntity emoter, @NonNull String emoteId); /** - * Gets the {@link GeyserPlayerEntity} of this connection. - * - * @return the {@link GeyserPlayerEntity} of this connection + * @deprecated use {@link GeyserConnection#playerEntity()} */ - // TODO move to GeyserConnection @NonNull GeyserPlayerEntity playerEntity(); /** @@ -79,7 +76,6 @@ public interface EntityData { * @param owner the owner of the lock * @return if the movement is locked after this method call */ - // TODO move to GeyserConnection boolean lockMovement(boolean lock, @NonNull UUID owner); /** @@ -87,13 +83,10 @@ public interface EntityData { * * @return whether the movement is locked */ - // TODO move to GeyserConnection boolean isMovementLocked(); /** - * Sends a request to the Java server to switch the items in the main and offhand. - * There is no guarantee of the server accepting the request. + * @deprecated use {@link GeyserConnection#requestHandSwap()} ()} */ - // TODO move to GeyserConnection void switchHands(); } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/GeyserEntityDefinition.java b/api/src/main/java/org/geysermc/geyser/api/entity/GeyserEntityDefinition.java index 3d6514e1701..0090f26e5fa 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/GeyserEntityDefinition.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/GeyserEntityDefinition.java @@ -45,25 +45,6 @@ public interface GeyserEntityDefinition { */ List> properties(); - /** - * @return the width of the entity - */ - float width(); - - /** - * @return the height of the entity - */ - float height(); - - /** - * The vertical offset applied by Geyser - * to entities to ensure they don't clip - * in the ground due to Java vs Bedrock differences. - * - * @return the offset of the entity - */ - float offset(); - /** * @return whether this entity is a vanilla entity */ diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java index 0b7a50bccb8..e32c257fb86 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java @@ -25,9 +25,7 @@ package org.geysermc.geyser.api.entity.custom; -import org.checkerframework.checker.index.qual.Positive; import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.common.returnsreceiver.qual.This; import org.geysermc.geyser.api.GeyserApi; import org.geysermc.geyser.api.entity.GeyserEntityDefinition; import org.geysermc.geyser.api.util.Identifier; @@ -54,41 +52,7 @@ static Builder builder(@NonNull Identifier bedrockIdentifier) { interface Builder { - /** - * Sets the width of this entity. - * - * @param width the width of this entity - * @return the builder - */ - @This - Builder width(@Positive float width); - - /** - * Sets the height of this entity. - * - * @param height the height of this entity - * @return the builder - */ - @This - Builder height(@Positive float height); - - /** - * Sets the height and with of this entity. - * - * @param value the width and height - * @return the builder - */ - @This - Builder heightAndWidth(@Positive float value); - - /** - * Sets the offset of this entity. - * - * @param offset the offset of this entity - * @return the builder - */ - @This - Builder offset(@Positive float offset); + // TODO needed? /** * Builds the entity definition. diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/type/player/GeyserPlayerEntity.java b/api/src/main/java/org/geysermc/geyser/api/entity/type/player/GeyserPlayerEntity.java index 0c92843cf37..da2e286090b 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/type/player/GeyserPlayerEntity.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/type/player/GeyserPlayerEntity.java @@ -28,6 +28,4 @@ import org.geysermc.geyser.api.entity.type.GeyserEntity; public interface GeyserPlayerEntity extends GeyserEntity { - - // TODO expose skin data here?? } diff --git a/api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java index e165feeaebf..f0bb3b6d916 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.api.event.java; +import org.checkerframework.checker.index.qual.NonNegative; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.api.connection.GeyserConnection; @@ -81,4 +82,36 @@ public ServerSpawnEntityEvent(@NonNull GeyserConnection connection) { */ public abstract void entityDefinition(@Nullable GeyserEntityDefinition entityDefinition); + /** + * @return the width of the entity + */ + public abstract float width(); + + /** + * @return the height of the entity + */ + public abstract float height(); + + /** + * The vertical offset applied by Geyser to ensure the Bedrock entity doesn't clip + * into the ground due to Java vs Bedrock differences. + * + * @return the offset of the entity + */ + public abstract float offset(); + + /** + * Sets the width of the entity. + */ + public abstract void width(@NonNegative float width); + + /** + * Sets the height of the entity. + */ + public abstract void height(@NonNegative float height); + + /** + * Sets the vertical offset applied by Geyser to avoid clipping + */ + public abstract void offset(@NonNegative float offset); } diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java index 8e6e1e9dd70..f48038b1541 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java @@ -67,5 +67,5 @@ default void register(CustomEntityDefinition.Builder builder) { * @param javaEntityType the identifier of the Java entity type * @param javaId the network id of this entity type */ - void registerEntityType(@NonNull Identifier javaEntityType, int javaId); + void registerEntityType(@NonNull Identifier javaEntityType, int javaId, CustomEntityDefinition defaultDefinition); } diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntityPropertiesEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntityPropertiesEvent.java index ef8380041ec..763c98e2fb0 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntityPropertiesEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntityPropertiesEvent.java @@ -84,7 +84,7 @@ public interface GeyserDefineEntityPropertiesEvent extends Event { * so far for the given entity type. This includes entity properties used for vanilla gameplay, * such as those used for creaking animations. * - * @param entityType the Java edition entity type identifier + * @param entityType the Bedrock edition entity type identifier * @return an unmodifiable collection of registered properties * * @since 2.9.0 @@ -94,7 +94,7 @@ public interface GeyserDefineEntityPropertiesEvent extends Event { /** * Registers a {@code float}-backed entity property. * - * @param entityType the Java edition entity type identifier + * @param entityType the Bedrock edition entity type identifier * @param propertyIdentifier the unique property identifier * @param min the minimum allowed value (inclusive) * @param max the maximum allowed value (inclusive) @@ -109,7 +109,7 @@ public interface GeyserDefineEntityPropertiesEvent extends Event { * Registers a {@code float}-backed entity property with a default value set to the minimum value. * @see #registerFloatProperty(Identifier, Identifier, float, float, Float) * - * @param entityType the Java edition entity type identifier + * @param entityType the Bedrock edition entity type identifier * @param propertyIdentifier the unique property identifier * @param min the minimum allowed value (inclusive) * @param max the maximum allowed value (inclusive) @@ -124,7 +124,7 @@ default GeyserFloatEntityProperty registerFloatProperty(@NonNull Identifier enti /** * Registers an {@code int}-backed entity property. * - * @param entityType the Java edition entity type identifier + * @param entityType the Bedrock edition entity type identifier * @param propertyIdentifier the unique property identifier * @param min the minimum allowed value (inclusive) * @param max the maximum allowed value (inclusive) @@ -138,7 +138,7 @@ default GeyserFloatEntityProperty registerFloatProperty(@NonNull Identifier enti /** * Registers an {@code int}-backed entity property with a default value set to the minimum value. * - * @param entityType the Java edition entity type identifier + * @param entityType the Bedrock edition entity type identifier * @param propertyIdentifier the unique property identifier * @param min the minimum allowed value (inclusive) * @param max the maximum allowed value (inclusive) @@ -153,7 +153,7 @@ default GeyserIntEntityProperty registerIntegerProperty(@NonNull Identifier enti /** * Registers a {@code boolean}-backed entity property. * - * @param entityType the Java edition entity type identifier + * @param entityType the Bedrock edition entity type identifier * @param propertyIdentifier the unique property identifier * @param defaultValue the default boolean value * @return the created boolean property handle @@ -166,7 +166,7 @@ default GeyserIntEntityProperty registerIntegerProperty(@NonNull Identifier enti * Registers a {@code boolean}-backed entity property with a default of {@code false}. * @see #registerBooleanProperty(Identifier, Identifier, boolean) * - * @param entityType the Java edition entity type identifier + * @param entityType the Bedrock edition entity type identifier * @param propertyIdentifier the unique property identifier * @return the created boolean property * @since 2.9.0 @@ -182,7 +182,7 @@ default GeyserBooleanEntityProperty registerBooleanProperty(@NonNull Identifier * the first enum value is set as the default. * @see GeyserEnumEntityProperty for further limitations * - * @param entityType the Java edition entity type identifier + * @param entityType the Bedrock edition entity type identifier * @param propertyIdentifier the unique property identifier * @param enumClass the enum class that defines allowed values * @param defaultValue the default enum value, or {@code null} for the first enum value to be the default @@ -197,7 +197,7 @@ default GeyserBooleanEntityProperty registerBooleanProperty(@NonNull Identifier * Registers a typed {@linkplain Enum enum}-backed entity property with the first value set as the default. * @see #registerEnumProperty(Identifier, Identifier, Class, Enum) * - * @param entityType the Java edition entity type identifier + * @param entityType the Bedrock edition entity type identifier * @param propertyIdentifier the unique property identifier * @param enumClass the enum class that defines allowed values * @param the enum type @@ -215,7 +215,7 @@ default > GeyserEnumEntityProperty registerEnumProperty(@No * on entity spawn. The default must be one of the values in {@code values}. * @see GeyserStringEnumProperty * - * @param entityType the Java edition entity type identifier + * @param entityType the Bedrock edition entity type identifier * @param propertyIdentifier the unique property identifier * @param values the allowed string values * @param defaultValue the default string value, or {@code null} for the first value to be used @@ -229,7 +229,7 @@ default > GeyserEnumEntityProperty registerEnumProperty(@No * Registers a string-backed "enum-like" entity property with the first value as the default. * @see #registerEnumProperty(Identifier, Identifier, List, String) * - * @param entityType the Java edition entity type identifier + * @param entityType the Bedrock edition entity type identifier * @param propertyIdentifier the unique property identifier * @param values the allowed string values * @return the created string-enum property handle diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java index 8e2cdf9b6f7..a578dac99a3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java @@ -43,16 +43,10 @@ public class BedrockEntityDefinition implements GeyserEntityDefinition { private final @NonNull Identifier identifier; private final @NonNull GeyserEntityProperties registeredProperties; - private final float width; - private final float height; - private final float offset; - public BedrockEntityDefinition(@NonNull Identifier identifier, @NonNull GeyserEntityProperties registeredProperties, float width, float height, float offset) { + public BedrockEntityDefinition(@NonNull Identifier identifier, @NonNull GeyserEntityProperties registeredProperties) { this.identifier = identifier; this.registeredProperties = registeredProperties; - this.width = width; - this.height = height; - this.offset = offset; } public static Builder builder() { @@ -74,30 +68,12 @@ public boolean vanilla() { public static class Builder { private Identifier identifier; - private float width; - private float height; - private float offset = 0.00001f; @Setter(AccessLevel.NONE) protected GeyserEntityProperties.Builder propertiesBuilder; public Builder() { } - public Builder height(float height) { - this.height = height; - return this; - } - - public Builder width(float width) { - this.width = width; - return this; - } - - public Builder offset(float offset) { - this.offset = offset + 0.00001f; - return this; - } - public Builder identifier(Identifier identifier) { this.identifier = identifier; return this; @@ -109,7 +85,7 @@ public Builder properties(GeyserEntityProperties.@Nullable Builder propertiesBui } BedrockEntityDefinition build() { - return new BedrockEntityDefinition(identifier, propertiesBuilder != null ? propertiesBuilder.build() : new GeyserEntityProperties(), width, height, offset); + return new BedrockEntityDefinition(identifier, propertiesBuilder != null ? propertiesBuilder.build() : new GeyserEntityProperties()); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java index 3228a68a82a..2dee52b0812 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java @@ -25,9 +25,26 @@ package org.geysermc.geyser.entity; +import org.geysermc.geyser.impl.IdentifierImpl; + +/** + * Most Bedrock entities are registered in {@link VanillaEntities} - however, some are + * done here to be able to re-use the same bedrock entity across multiple Java types + */ public class BedrockEntityDefinitions { // TODO re-usable Bedrock entity definitions?????????? // Or rather... looking up otherwise?? + public static final BedrockEntityDefinition ARMOR_STAND; + + static { + ARMOR_STAND = BedrockEntityDefinition.builder() + .identifier(IdentifierImpl.of("armor_stand")) + .build(); + } + + public static void init() { + // no-op + } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityBase.java b/core/src/main/java/org/geysermc/geyser/entity/EntityTypeBase.java similarity index 90% rename from core/src/main/java/org/geysermc/geyser/entity/VanillaEntityBase.java rename to core/src/main/java/org/geysermc/geyser/entity/EntityTypeBase.java index d07086ff6ea..6c583307df2 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityBase.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityTypeBase.java @@ -42,14 +42,15 @@ @EqualsAndHashCode @ToString -public class VanillaEntityBase { - final float width; - final float height; - final float offset; - @Getter @Accessors(fluent = true) +@Getter +@Accessors(fluent = true) +public class EntityTypeBase { + protected final float width; + protected final float height; + protected final float offset; protected final List> translators; - public VanillaEntityBase(float width, float height, float offset, List> translators) { + public EntityTypeBase(float width, float height, float offset, List> translators) { this.width = width; this.height = height; this.offset = offset; @@ -62,7 +63,7 @@ public static Builder baseBuilder(Class clazz) { // Unused param so Java knows what entity we're talking about @SuppressWarnings("unused") - public static Builder baseInherited(Class clazz, VanillaEntityBase parent) { + public static Builder baseInherited(Class clazz, EntityTypeBase parent) { return new Builder(parent.width, parent.height, parent.offset, new ObjectArrayList<>(parent.translators)); } @@ -75,7 +76,7 @@ public void translateMetadata(T entity, EntityMetadata addTranslator(EntityMetadataTranslator translator) { return this; } - public VanillaEntityBase build() { - return new VanillaEntityBase<>(width, height, offset, translators); + public EntityTypeBase build() { + return new EntityTypeBase<>(width, height, offset, translators); } } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityTypeDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/EntityTypeDefinition.java index e990d4ba73e..225be45bd04 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityTypeDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityTypeDefinition.java @@ -54,13 +54,13 @@ @Accessors(fluent = true) @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public abstract class EntityTypeDefinition extends VanillaEntityBase { +public abstract class EntityTypeDefinition extends EntityTypeBase { private final EntityFactory factory; private final GeyserEntityType type; private final BedrockEntityDefinition defaultBedrockDefinition; - public EntityTypeDefinition(EntityFactory factory, GeyserEntityType type, BedrockEntityDefinition defaultBedrockDefinition, List> translators) { - super(defaultBedrockDefinition.width(), defaultBedrockDefinition.height(), defaultBedrockDefinition.offset(), translators); + public EntityTypeDefinition(EntityFactory factory, GeyserEntityType type, float width, float height, float offset, BedrockEntityDefinition defaultBedrockDefinition, List> translators) { + super(width, height, offset, translators); this.type = type; this.factory = factory; this.defaultBedrockDefinition = defaultBedrockDefinition; @@ -70,7 +70,7 @@ public EntityTypeDefinition(EntityFactory factory, GeyserEntityType type, Bed @Setter @Accessors(fluent = true, chain = true) - public static abstract class Builder extends VanillaEntityBase.Builder { + public static abstract class Builder extends EntityTypeBase.Builder { protected final EntityFactory factory; protected String bedrockIdentifier; @Setter(AccessLevel.NONE) diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityTypeDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityTypeDefinition.java index 3314a46ec84..6f0d95e5da3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityTypeDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityTypeDefinition.java @@ -40,18 +40,15 @@ @Accessors(fluent = true) @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -// TODO CHANGE TO ONLY APPLY THIS TO NON-VANILLA TYPES! +// TODO public class GeyserCustomEntityTypeDefinition extends EntityTypeDefinition { public GeyserCustomEntityTypeDefinition(EntityFactory factory, GeyserEntityType type, BedrockEntityDefinition definition, List> translators) { - super(factory, type, definition, translators); + super(factory, type, 0, 0,0, definition, translators); } @Override public boolean is(BuiltinEntityType builtinEntityType) { return false; } - - // TODO: - // - handle } diff --git a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntities.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntities.java index ef299f49331..df3176ea2af 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntities.java +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntities.java @@ -340,7 +340,7 @@ public final class VanillaEntities { public static final float PLAYER_ENTITY_OFFSET; static { - VanillaEntityBase entityBase = EntityTypeDefinition.baseBuilder(Entity.class) + EntityTypeBase entityBase = EntityTypeDefinition.baseBuilder(Entity.class) .addTranslator(MetadataTypes.BYTE, Entity::setFlags) .addTranslator(MetadataTypes.INT, Entity::setAir) // Air/bubbles .addTranslator(MetadataTypes.OPTIONAL_COMPONENT, Entity::setDisplayName) @@ -435,7 +435,7 @@ public final class VanillaEntities { .addTranslator(MetadataTypes.INT, TNTEntity::setFuseLength) .build(); - VanillaEntityBase displayBase = VanillaEntityBase.baseInherited(DisplayBaseEntity.class, entityBase) + EntityTypeBase displayBase = EntityTypeBase.baseInherited(DisplayBaseEntity.class, entityBase) .addTranslator(null) // Interpolation delay .addTranslator(null) // Transformation interpolation duration .addTranslator(null) // Position/Rotation interpolation duration @@ -454,7 +454,7 @@ public final class VanillaEntities { .build(); TEXT_DISPLAY = VanillaEntityType.inherited(TextDisplayEntity::new, displayBase) .type(BuiltinEntityType.TEXT_DISPLAY) - .bedrockIdentifier("minecraft:armor_stand") + .bedrockDefinition(BedrockEntityDefinitions.ARMOR_STAND) .offset(-0.5f) .addTranslator(MetadataTypes.COMPONENT, TextDisplayEntity::setText) .addTranslator(null) // Line width @@ -466,13 +466,13 @@ public final class VanillaEntities { INTERACTION = VanillaEntityType.inherited(InteractionEntity::new, entityBase) .type(BuiltinEntityType.INTERACTION) .heightAndWidth(1.0f) // default size until server specifies otherwise - .bedrockDefinition(ARMOR_STAND.defaultBedrockDefinition()) + .bedrockDefinition(BedrockEntityDefinitions.ARMOR_STAND) .addTranslator(MetadataTypes.FLOAT, InteractionEntity::setWidth) .addTranslator(MetadataTypes.FLOAT, InteractionEntity::setHeight) .addTranslator(MetadataTypes.BOOLEAN, InteractionEntity::setResponse) .build(); - VanillaEntityBase fireballBase = VanillaEntityBase.baseInherited(FireballEntity.class, entityBase) + EntityTypeBase fireballBase = EntityTypeBase.baseInherited(FireballEntity.class, entityBase) .addTranslator(null) // Item .build(); FIREBALL = VanillaEntityType.inherited(FireballEntity::new, fireballBase) @@ -484,7 +484,7 @@ public final class VanillaEntities { .heightAndWidth(0.3125f) .build(); - VanillaEntityBase throwableItemBase = VanillaEntityBase.baseInherited(ThrowableItemEntity.class, entityBase) + EntityTypeBase throwableItemBase = EntityTypeBase.baseInherited(ThrowableItemEntity.class, entityBase) .addTranslator(MetadataTypes.ITEM_STACK, ThrowableItemEntity::setItem) .build(); EGG = VanillaEntityType.inherited(ThrowableEggEntity::new, throwableItemBase) @@ -528,7 +528,7 @@ public final class VanillaEntities { .heightAndWidth(0.3125f) .build(); - VanillaEntityBase abstractArrowBase = VanillaEntityBase.baseInherited(AbstractArrowEntity.class, entityBase) + EntityTypeBase abstractArrowBase = EntityTypeBase.baseInherited(AbstractArrowEntity.class, entityBase) .addTranslator(MetadataTypes.BYTE, AbstractArrowEntity::setArrowFlags) .addTranslator(null) // "Piercing level" .addTranslator(null) // If the arrow is in the ground @@ -550,7 +550,7 @@ public final class VanillaEntities { .addTranslator(MetadataTypes.BOOLEAN, (tridentEntity, entityMetadata) -> tridentEntity.setFlag(EntityFlag.ENCHANTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .build(); - VanillaEntityBase hangingEntityBase = VanillaEntityBase.baseInherited(HangingEntity.class, entityBase) + EntityTypeBase hangingEntityBase = EntityTypeBase.baseInherited(HangingEntity.class, entityBase) .addTranslator(MetadataTypes.DIRECTION, HangingEntity::setDirectionMetadata) .build(); @@ -614,9 +614,6 @@ public final class VanillaEntities { // Bedrock exclusive entity IdentifierImpl dangerousSkull = IdentifierImpl.of("wither_skull_dangerous"); BedrockEntityDefinition bedrockDefinition = BedrockEntityDefinition.builder() - .height(WITHER_SKULL.height) - .width(WITHER_SKULL.width) - .offset(WITHER_SKULL.offset) .identifier(dangerousSkull) .build(); Registries.BEDROCK_ENTITY_DEFINITIONS.get().put(dangerousSkull, bedrockDefinition); @@ -627,7 +624,7 @@ public final class VanillaEntities { // Boats { - VanillaEntityBase boatBase = VanillaEntityBase.baseInherited(BoatEntity.class, entityBase) + EntityTypeBase boatBase = EntityTypeBase.baseInherited(BoatEntity.class, entityBase) .height(0.6f).width(1.6f) .offset(0.35f) .addTranslator(MetadataTypes.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityDataTypes.HURT_TICKS, entityMetadata.getValue())) // Time since last hit @@ -651,7 +648,7 @@ public final class VanillaEntities { SPRUCE_BOAT = buildBoat(boatBase, BuiltinEntityType.SPRUCE_BOAT, BoatEntity.BoatVariant.SPRUCE); PALE_OAK_BOAT = buildBoat(boatBase, BuiltinEntityType.PALE_OAK_BOAT, BoatEntity.BoatVariant.PALE_OAK); - VanillaEntityBase chestBoatBase = VanillaEntityBase.baseInherited(ChestBoatEntity.class, boatBase) + EntityTypeBase chestBoatBase = EntityTypeBase.baseInherited(ChestBoatEntity.class, boatBase) .build(); ACACIA_CHEST_BOAT = buildChestBoat(chestBoatBase, BuiltinEntityType.ACACIA_CHEST_BOAT, BoatEntity.BoatVariant.ACACIA); @@ -666,7 +663,7 @@ public final class VanillaEntities { PALE_OAK_CHEST_BOAT = buildChestBoat(chestBoatBase, BuiltinEntityType.PALE_OAK_CHEST_BOAT, BoatEntity.BoatVariant.PALE_OAK); } - VanillaEntityBase livingEntityBase = VanillaEntityBase.baseInherited(LivingEntity.class, entityBase) + EntityTypeBase livingEntityBase = EntityTypeBase.baseInherited(LivingEntity.class, entityBase) .addTranslator(MetadataTypes.BYTE, LivingEntity::setLivingEntityFlags) .addTranslator(MetadataTypes.FLOAT, LivingEntity::setHealth) .addTranslator(MetadataTypes.PARTICLES, LivingEntity::setParticles) @@ -679,6 +676,7 @@ public final class VanillaEntities { ARMOR_STAND = VanillaEntityType.inherited(ArmorStandEntity::new, livingEntityBase) .type(BuiltinEntityType.ARMOR_STAND) + .bedrockDefinition(BedrockEntityDefinitions.ARMOR_STAND) .height(1.975f).width(0.5f) .addTranslator(MetadataTypes.BYTE, ArmorStandEntity::setArmorStandFlags) .addTranslator(MetadataTypes.ROTATIONS, ArmorStandEntity::setHeadRotation) @@ -689,7 +687,7 @@ public final class VanillaEntities { .addTranslator(MetadataTypes.ROTATIONS, ArmorStandEntity::setRightLegRotation) .build(); - VanillaEntityBase avatarEntityBase = VanillaEntityBase.baseInherited(AvatarEntity.class, livingEntityBase) + EntityTypeBase avatarEntityBase = EntityTypeBase.baseInherited(AvatarEntity.class, livingEntityBase) .height(1.8f).width(0.6f) .offset(1.62f) .addTranslator(null) // Player main hand @@ -711,7 +709,7 @@ public final class VanillaEntities { .addTranslator(MetadataTypes.OPTIONAL_UNSIGNED_INT, PlayerEntity::setRightParrot) .build(); - VanillaEntityBase mobEntityBase = VanillaEntityBase.baseInherited(MobEntity.class, livingEntityBase) + EntityTypeBase mobEntityBase = EntityTypeBase.baseInherited(MobEntity.class, livingEntityBase) .addTranslator(MetadataTypes.BYTE, MobEntity::setMobFlags) .build(); @@ -921,7 +919,7 @@ public final class VanillaEntities { .type(BuiltinEntityType.MAGMA_CUBE) .build(); - VanillaEntityBase abstractFishEntityBase = VanillaEntityBase.baseInherited(AbstractFishEntity.class, mobEntityBase) + EntityTypeBase abstractFishEntityBase = EntityTypeBase.baseInherited(AbstractFishEntity.class, mobEntityBase) .addTranslator(null) // From bucket .build(); COD = VanillaEntityType.inherited(AbstractFishEntity::new, abstractFishEntityBase) @@ -949,7 +947,7 @@ public final class VanillaEntities { .addTranslator(MetadataTypes.INT, TropicalFishEntity::setFishVariant) .build(); - VanillaEntityBase abstractPiglinEntityBase = VanillaEntityBase.baseInherited(BasePiglinEntity.class, mobEntityBase) + EntityTypeBase abstractPiglinEntityBase = EntityTypeBase.baseInherited(BasePiglinEntity.class, mobEntityBase) .addTranslator(MetadataTypes.BOOLEAN, BasePiglinEntity::setImmuneToZombification) .build(); PIGLIN = VanillaEntityType.inherited(PiglinEntity::new, abstractPiglinEntityBase) @@ -964,10 +962,10 @@ public final class VanillaEntities { .height(1.95f).width(0.6f) .build(); - VanillaEntityBase raidParticipantEntityBase = VanillaEntityBase.baseInherited(RaidParticipantEntity.class, mobEntityBase) + EntityTypeBase raidParticipantEntityBase = EntityTypeBase.baseInherited(RaidParticipantEntity.class, mobEntityBase) .addTranslator(null) // Celebrating //TODO .build(); - VanillaEntityBase spellcasterEntityBase = VanillaEntityBase.baseInherited(SpellcasterIllagerEntity.class, raidParticipantEntityBase) + EntityTypeBase spellcasterEntityBase = EntityTypeBase.baseInherited(SpellcasterIllagerEntity.class, raidParticipantEntityBase) .addTranslator(MetadataTypes.BYTE, SpellcasterIllagerEntity::setSpellType) .build(); EVOKER = VanillaEntityType.inherited(SpellcasterIllagerEntity::new, spellcasterEntityBase) @@ -1003,7 +1001,7 @@ public final class VanillaEntities { .build(); } - VanillaEntityBase ageableEntityBase = VanillaEntityBase.baseInherited(AgeableEntity.class, mobEntityBase) + EntityTypeBase ageableEntityBase = EntityTypeBase.baseInherited(AgeableEntity.class, mobEntityBase) .addTranslator(MetadataTypes.BOOLEAN, AgeableEntity::setBaby) .build(); @@ -1178,7 +1176,7 @@ public final class VanillaEntities { // Horses { - VanillaEntityBase abstractHorseEntityBase = VanillaEntityBase.baseInherited(AbstractHorseEntity.class, ageableEntityBase) + EntityTypeBase abstractHorseEntityBase = EntityTypeBase.baseInherited(AbstractHorseEntity.class, ageableEntityBase) .addTranslator(MetadataTypes.BYTE, AbstractHorseEntity::setHorseFlags) .build(); CAMEL = VanillaEntityType.inherited(CamelEntity::new, abstractHorseEntityBase) @@ -1200,7 +1198,7 @@ public final class VanillaEntities { .type(BuiltinEntityType.ZOMBIE_HORSE) .height(1.6f).width(1.3965f) .build(); - VanillaEntityBase chestedHorseEntityBase = VanillaEntityBase.baseInherited(ChestedHorseEntity.class, abstractHorseEntityBase) + EntityTypeBase chestedHorseEntityBase = EntityTypeBase.baseInherited(ChestedHorseEntity.class, abstractHorseEntityBase) .addTranslator(MetadataTypes.BOOLEAN, (horseEntity, entityMetadata) -> horseEntity.setFlag(EntityFlag.CHESTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .build(); DONKEY = VanillaEntityType.inherited(ChestedHorseEntity::new, chestedHorseEntityBase) @@ -1223,7 +1221,7 @@ public final class VanillaEntities { .build(); } - VanillaEntityBase tameableEntityBase = VanillaEntityBase.baseInherited(TameableEntity.class, ageableEntityBase) + EntityTypeBase tameableEntityBase = EntityTypeBase.baseInherited(TameableEntity.class, ageableEntityBase) .addTranslator(MetadataTypes.BYTE, TameableEntity::setTameableFlags) .addTranslator(MetadataTypes.OPTIONAL_LIVING_ENTITY_REFERENCE, TameableEntity::setOwner) .build(); @@ -1254,25 +1252,23 @@ public final class VanillaEntities { // As of 1.18 these don't track entity data at all ENDER_DRAGON_PART = VanillaEntityType.builder(null) - .bedrockDefinition(ARMOR_STAND.defaultBedrockDefinition()) // Emulated + .bedrockDefinition(BedrockEntityDefinitions.ARMOR_STAND) // Emulated .build(false); // Never sent over the network - PLAYER_ENTITY_OFFSET = PLAYER.defaultBedrockDefinition().offset(); + PLAYER_ENTITY_OFFSET = PLAYER.offset(); Registries.JAVA_ENTITY_IDENTIFIERS.get().put("minecraft:marker", null); // We don't need an entity definition for this as it is never sent over the network } - private static VanillaEntityType buildBoat(VanillaEntityBase base, BuiltinEntityType BuiltinEntityType, BoatEntity.BoatVariant variant) { - return VanillaEntityType.inherited((session, javaId, bedrockId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw) -> - new BoatEntity(session, javaId, bedrockId, uuid, definition, bedrockDefinition, position, motion, yaw, variant), base) + private static VanillaEntityType buildBoat(EntityTypeBase base, BuiltinEntityType BuiltinEntityType, BoatEntity.BoatVariant variant) { + return VanillaEntityType.inherited(context -> new BoatEntity(context, variant), base) .type(BuiltinEntityType) .bedrockIdentifier("minecraft:boat") .build(); } - private static VanillaEntityType buildChestBoat(VanillaEntityBase base, BuiltinEntityType BuiltinEntityType, BoatEntity.BoatVariant variant) { - return VanillaEntityType.inherited((session, javaId, bedrockId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw) -> - new ChestBoatEntity(session, javaId, bedrockId, uuid, definition, bedrockDefinition, position, motion, yaw, variant), base) + private static VanillaEntityType buildChestBoat(EntityTypeBase base, BuiltinEntityType BuiltinEntityType, BoatEntity.BoatVariant variant) { + return VanillaEntityType.inherited(context -> new ChestBoatEntity(context, variant), base) .type(BuiltinEntityType) .bedrockIdentifier("minecraft:chest_boat") .build(); @@ -1297,7 +1293,7 @@ public void register(@NonNull CustomEntityDefinition customEntityDefinition) { } @Override - public void registerEntityType(@NonNull Identifier javaEntityType, int javaId) { + public void registerEntityType(@NonNull Identifier javaEntityType, int javaId, CustomEntityDefinition definition) { GeyserEntityType.createCustomAndRegister(javaEntityType, javaId); // TODO allow extending vanilla entities? diff --git a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityBases.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityBases.java index 9b973614c0f..cac8ce5c5c1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityBases.java +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityBases.java @@ -48,23 +48,23 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.FloatEntityMetadata; public final class VanillaEntityBases { - public static final VanillaEntityBase ENTITY; - public static final VanillaEntityBase DISPLAY; - public static final VanillaEntityBase FIREBALL; - public static final VanillaEntityBase THROWABLE; - public static final VanillaEntityBase HANGING; - public static final VanillaEntityBase BOAT; - public static final VanillaEntityBase CHEST_BOAT; - public static final VanillaEntityBase LIVING_ENTITY; - public static final VanillaEntityBase AVATAR; - public static final VanillaEntityBase MOB; - public static final VanillaEntityBase FISH; - public static final VanillaEntityBase PIGLIN; - public static final VanillaEntityBase RAID_PARTICIPANT; - public static final VanillaEntityBase SPELLCASTER; - public static final VanillaEntityBase AGEABLE; - public static final VanillaEntityBase HORSE; - public static final VanillaEntityBase TAMABLE; + public static final EntityTypeBase ENTITY; + public static final EntityTypeBase DISPLAY; + public static final EntityTypeBase FIREBALL; + public static final EntityTypeBase THROWABLE; + public static final EntityTypeBase HANGING; + public static final EntityTypeBase BOAT; + public static final EntityTypeBase CHEST_BOAT; + public static final EntityTypeBase LIVING_ENTITY; + public static final EntityTypeBase AVATAR; + public static final EntityTypeBase MOB; + public static final EntityTypeBase FISH; + public static final EntityTypeBase PIGLIN; + public static final EntityTypeBase RAID_PARTICIPANT; + public static final EntityTypeBase SPELLCASTER; + public static final EntityTypeBase AGEABLE; + public static final EntityTypeBase HORSE; + public static final EntityTypeBase TAMABLE; static { ENTITY = EntityTypeDefinition.baseBuilder(Entity.class) @@ -77,7 +77,7 @@ public final class VanillaEntityBases { .addTranslator(MetadataTypes.POSE, (entity, entityMetadata) -> entity.setPose(entityMetadata.getValue())) .addTranslator(MetadataTypes.INT, Entity::setFreezing) .build(); - DISPLAY = VanillaEntityBase.baseInherited(DisplayBaseEntity.class, ENTITY) + DISPLAY = EntityTypeBase.baseInherited(DisplayBaseEntity.class, ENTITY) .addTranslator(null) // Interpolation delay .addTranslator(null) // Transformation interpolation duration .addTranslator(null) // Position/Rotation interpolation duration @@ -94,16 +94,16 @@ public final class VanillaEntityBases { .addTranslator(null) // Height .addTranslator(null) // Glow color override .build(); - FIREBALL = VanillaEntityBase.baseInherited(FireballEntity.class, ENTITY) + FIREBALL = EntityTypeBase.baseInherited(FireballEntity.class, ENTITY) .addTranslator(null) // Item .build(); - THROWABLE = VanillaEntityBase.baseInherited(ThrowableItemEntity.class, ENTITY) + THROWABLE = EntityTypeBase.baseInherited(ThrowableItemEntity.class, ENTITY) .addTranslator(MetadataTypes.ITEM_STACK, ThrowableItemEntity::setItem) .build(); - HANGING = VanillaEntityBase.baseInherited(HangingEntity.class, ENTITY) + HANGING = EntityTypeBase.baseInherited(HangingEntity.class, ENTITY) .addTranslator(MetadataTypes.DIRECTION, HangingEntity::setDirectionMetadata) .build(); - BOAT = VanillaEntityBase.baseInherited(BoatEntity.class, ENTITY) + BOAT = EntityTypeBase.baseInherited(BoatEntity.class, ENTITY) .height(0.6f).width(1.6f) .offset(0.35f) .addTranslator(MetadataTypes.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityDataTypes.HURT_TICKS, entityMetadata.getValue())) // Time since last hit @@ -115,9 +115,9 @@ public final class VanillaEntityBases { .addTranslator(MetadataTypes.BOOLEAN, BoatEntity::setPaddlingRight) .addTranslator(MetadataTypes.INT, (boatEntity, entityMetadata) -> boatEntity.getDirtyMetadata().put(EntityDataTypes.BOAT_BUBBLE_TIME, entityMetadata.getValue())) // May not actually do anything .build(); - CHEST_BOAT = VanillaEntityBase.baseInherited(ChestBoatEntity.class, BOAT) + CHEST_BOAT = EntityTypeBase.baseInherited(ChestBoatEntity.class, BOAT) .build(); - LIVING_ENTITY = VanillaEntityBase.baseInherited(LivingEntity.class, ENTITY) + LIVING_ENTITY = EntityTypeBase.baseInherited(LivingEntity.class, ENTITY) .addTranslator(MetadataTypes.BYTE, LivingEntity::setLivingEntityFlags) .addTranslator(MetadataTypes.FLOAT, LivingEntity::setHealth) .addTranslator(MetadataTypes.PARTICLES, LivingEntity::setParticles) @@ -127,34 +127,34 @@ public final class VanillaEntityBases { .addTranslator(null) // Stinger count .addTranslator(MetadataTypes.OPTIONAL_BLOCK_POS, LivingEntity::setBedPosition) .build(); - AVATAR = VanillaEntityBase.baseInherited(AvatarEntity.class, LIVING_ENTITY) + AVATAR = EntityTypeBase.baseInherited(AvatarEntity.class, LIVING_ENTITY) .height(1.8f).width(0.6f) .offset(1.62f) .addTranslator(null) // Player main hand .addTranslator(MetadataTypes.BYTE, AvatarEntity::setSkinVisibility) .build(); - MOB = VanillaEntityBase.baseInherited(MobEntity.class, LIVING_ENTITY) + MOB = EntityTypeBase.baseInherited(MobEntity.class, LIVING_ENTITY) .addTranslator(MetadataTypes.BYTE, MobEntity::setMobFlags) .build(); - FISH = VanillaEntityBase.baseInherited(AbstractFishEntity.class, MOB) + FISH = EntityTypeBase.baseInherited(AbstractFishEntity.class, MOB) .addTranslator(null) // From bucket .build(); - PIGLIN = VanillaEntityBase.baseInherited(BasePiglinEntity.class, MOB) + PIGLIN = EntityTypeBase.baseInherited(BasePiglinEntity.class, MOB) .addTranslator(MetadataTypes.BOOLEAN, BasePiglinEntity::setImmuneToZombification) .build(); - RAID_PARTICIPANT = VanillaEntityBase.baseInherited(RaidParticipantEntity.class, MOB) + RAID_PARTICIPANT = EntityTypeBase.baseInherited(RaidParticipantEntity.class, MOB) .addTranslator(null) // Celebrating //TODO .build(); - SPELLCASTER = VanillaEntityBase.baseInherited(SpellcasterIllagerEntity.class, RAID_PARTICIPANT) + SPELLCASTER = EntityTypeBase.baseInherited(SpellcasterIllagerEntity.class, RAID_PARTICIPANT) .addTranslator(MetadataTypes.BYTE, SpellcasterIllagerEntity::setSpellType) .build(); - AGEABLE = VanillaEntityBase.baseInherited(AgeableEntity.class, MOB) + AGEABLE = EntityTypeBase.baseInherited(AgeableEntity.class, MOB) .addTranslator(MetadataTypes.BOOLEAN, AgeableEntity::setBaby) .build(); - HORSE = VanillaEntityBase.baseInherited(AbstractHorseEntity.class, AGEABLE) + HORSE = EntityTypeBase.baseInherited(AbstractHorseEntity.class, AGEABLE) .addTranslator(MetadataTypes.BYTE, AbstractHorseEntity::setHorseFlags) .build(); - TAMABLE = VanillaEntityBase.baseInherited(TameableEntity.class, AGEABLE) + TAMABLE = EntityTypeBase.baseInherited(TameableEntity.class, AGEABLE) .addTranslator(MetadataTypes.BYTE, TameableEntity::setTameableFlags) .addTranslator(MetadataTypes.OPTIONAL_LIVING_ENTITY_REFERENCE, TameableEntity::setOwner) .build(); diff --git a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java index c590bb81c2c..60e34261205 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java @@ -50,8 +50,8 @@ public class VanillaEntityType extends EntityTypeDefinition { private final GeyserEntityType entityType; - public VanillaEntityType(EntityFactory factory, GeyserEntityType entityType, BedrockEntityDefinition bedrockDefinition, List> translators) { - super(factory, entityType, bedrockDefinition, translators); + public VanillaEntityType(EntityFactory factory, GeyserEntityType entityType, float width, float height, float offset, BedrockEntityDefinition bedrockDefinition, List> translators) { + super(factory, entityType, width, height, offset, bedrockDefinition, translators); this.entityType = entityType; } @@ -64,7 +64,7 @@ public static Builder builder(EntityFactory factory) { return new Builder<>(factory); } - public static Builder inherited(EntityFactory factory, VanillaEntityBase parent) { + public static Builder inherited(EntityFactory factory, EntityTypeBase parent) { return new Builder<>(factory, parent.width, parent.height, parent.offset, new ObjectArrayList<>(parent.translators)); } @@ -139,31 +139,24 @@ public VanillaEntityType build() { return build(true); } - private void validateTypeAndIdentifier() { + /** + * @param register whether to register this entity in the Registries for entity types. Generally this should be + * set to false if we're not expecting this entity to spawn from the network. + */ + public VanillaEntityType build(boolean register) { if (type == null) { throw new IllegalStateException("Missing entity type!"); } if (bedrockDefinition == null) { bedrockDefinition = BedrockEntityDefinition.builder() - .height(height) - .width(width) .properties(propertiesBuilder) - .offset(offset) .identifier(Identifier.of(bedrockIdentifier)) .build(); Registries.BEDROCK_ENTITY_DEFINITIONS.get().put(Identifier.of(bedrockIdentifier), bedrockDefinition); } - } - - /** - * @param register whether to register this entity in the Registries for entity types. Generally this should be - * set to false if we're not expecting this entity to spawn from the network. - */ - public VanillaEntityType build(boolean register) { - validateTypeAndIdentifier(); - VanillaEntityType definition = new VanillaEntityType<>(factory, type, bedrockDefinition, translators); + VanillaEntityType definition = new VanillaEntityType<>(factory, type, width, height, offset, bedrockDefinition, translators); if (register && definition.entityType() != null) { Registries.ENTITY_DEFINITIONS.get().putIfAbsent(definition.entityType(), definition); Registries.JAVA_ENTITY_IDENTIFIERS.get().putIfAbsent(type.identifier().toString(), definition); diff --git a/core/src/main/java/org/geysermc/geyser/entity/factory/EntityFactory.java b/core/src/main/java/org/geysermc/geyser/entity/factory/EntityFactory.java index c428af5f483..e84d2a97f63 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/factory/EntityFactory.java +++ b/core/src/main/java/org/geysermc/geyser/entity/factory/EntityFactory.java @@ -25,18 +25,13 @@ package org.geysermc.geyser.entity.factory; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.Entity; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; /** * Represents a constructor to create an entity. */ public interface EntityFactory { - T create(GeyserSession session, int javaId, long bedrockId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw); + T create(EntitySpawnContext context); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java new file mode 100644 index 00000000000..0feb834b4e8 --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.entity.spawn; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; +import org.checkerframework.checker.index.qual.NonNegative; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.cloudburstmc.math.vector.Vector3f; +import org.cloudburstmc.protocol.common.util.TriFunction; +import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.api.entity.GeyserEntityDefinition; +import org.geysermc.geyser.api.entity.JavaEntityType; +import org.geysermc.geyser.api.event.java.ServerSpawnEntityEvent; +import org.geysermc.geyser.entity.BedrockEntityDefinition; +import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.type.Entity; +import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundAddEntityPacket; + +import java.util.UUID; + +@Getter +@Setter +@Accessors(fluent = true) +@AllArgsConstructor +public class EntitySpawnContext { + private final GeyserSession session; + private final EntityTypeDefinition entityTypeDefinition; + private int javaId; + private final UUID uuid; + private BedrockEntityDefinition bedrockEntityDefinition; + private Vector3f position; + private Vector3f motion; + private float yaw; + private float pitch; + private float headYaw; + private float height; + private float width; + private float offset; + private long geyserId; + + public static final TriFunction, EntitySpawnContext> DUMMY_CONTEXT = ((session, uuid, definition) -> + new EntitySpawnContext(session, definition, 0, uuid, definition.defaultBedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, definition.height(), + definition.width(), definition.offset(), session.getEntityCache().getNextEntityId().incrementAndGet())); + + public static EntitySpawnContext fromPacket(GeyserSession session, EntityTypeDefinition definition, ClientboundAddEntityPacket packet) { + Vector3f position = Vector3f.from(packet.getX(), packet.getY(), packet.getZ()); + Vector3f motion = packet.getMovement().toFloat(); + return new EntitySpawnContext(session, definition, packet.getEntityId(), packet.getUuid(), definition.defaultBedrockDefinition(), + position, motion, packet.getYaw(), packet.getPitch(), packet.getHeadYaw(), definition.height(), definition.width(), definition.offset(), 0); + } + + public static EntitySpawnContext inherited(GeyserSession session, EntityTypeDefinition definition, Entity base, Vector3f position) { + return new EntitySpawnContext(session, definition, 0, null, definition.defaultBedrockDefinition(), position, + base.getMotion(), base.getYaw(), base.getPitch(), base.getHeadYaw(), definition.height(), definition.width(), definition.offset(), + session.getEntityCache().getNextEntityId().incrementAndGet()); + } + + public void callEvent() { + GeyserImpl.getInstance().getEventBus().fire(new ServerSpawnEntityEvent(session) { + + @Override + public int entityId() { + return javaId; + } + + @Override + public @NonNull UUID uuid() { + return uuid; + } + + @Override + public @NonNull JavaEntityType entityType() { + return entityTypeDefinition.type(); + } + + @Override + public @Nullable GeyserEntityDefinition entityDefinition() { + return bedrockEntityDefinition; + } + + @Override + public void entityDefinition(@Nullable GeyserEntityDefinition entityDefinition) { + if (entityDefinition == null) { + bedrockEntityDefinition = null; + } else { + if (entityDefinition instanceof BedrockEntityDefinition bed) { + bedrockEntityDefinition = bed; + } else { + throw new IllegalStateException("Unknown implementation of GeyserEntityDefinition"); + } + } + } + + @Override + public float width() { + return width; + } + + @Override + public float height() { + return height; + } + + @Override + public float offset() { + return offset; + } + + @Override + public void width(@NonNegative float newWidth) { + width = newWidth; + } + + @Override + public void height(@NonNegative float newHeight) { + height = newHeight; + } + + @Override + public void offset(@NonNegative float newOffset) { + offset = newOffset; + } + }); + } +} diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/AbstractArrowEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/AbstractArrowEntity.java index 82d71533ec2..eeaf2eb3354 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/AbstractArrowEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/AbstractArrowEntity.java @@ -27,21 +27,17 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; -import java.util.UUID; - public class AbstractArrowEntity extends Entity { - public AbstractArrowEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public AbstractArrowEntity(EntitySpawnContext context) { + super(context); // Set the correct texture if using the resource pack - setFlag(EntityFlag.BRIBED, definition.type().is(BuiltinEntityType.SPECTRAL_ARROW)); + setFlag(EntityFlag.BRIBED, javaTypeDefinition.type().is(BuiltinEntityType.SPECTRAL_ARROW)); setMotion(motion); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/AbstractWindChargeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/AbstractWindChargeEntity.java index c95161c15be..217b28a2221 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/AbstractWindChargeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/AbstractWindChargeEntity.java @@ -25,20 +25,15 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; /** * Note that, as of 1.21, a wind charge entity does not actually implement the thrown item. We're just reusing * the "hide until far away" aspect. */ public class AbstractWindChargeEntity extends ThrowableItemEntity { - public AbstractWindChargeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public AbstractWindChargeEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/AreaEffectCloudEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/AreaEffectCloudEntity.java index 1ded86398fc..2d421ae17f2 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/AreaEffectCloudEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/AreaEffectCloudEntity.java @@ -25,26 +25,21 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.ParticleType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.registry.Registries; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.MathUtils; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.FloatEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.level.particle.ColorParticleData; import org.geysermc.mcprotocollib.protocol.data.game.level.particle.Particle; -import java.util.UUID; - public class AreaEffectCloudEntity extends Entity { - public AreaEffectCloudEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public AreaEffectCloudEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ArrowEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ArrowEntity.java index 2e08083f7a8..28909b6e9ab 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ArrowEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ArrowEntity.java @@ -25,20 +25,15 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.item.Potion; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; -import java.util.UUID; - public class ArrowEntity extends AbstractArrowEntity { - public ArrowEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ArrowEntity(EntitySpawnContext context) { + super(context); } public void setPotionEffectColor(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java index 02c90905d31..0f289964ace 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java @@ -31,9 +31,8 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.AnimatePacket; import org.cloudburstmc.protocol.bedrock.packet.MoveEntityAbsolutePacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.VanillaEntities; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; @@ -41,8 +40,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundPaddleBoatPacket; -import java.util.UUID; - public class BoatEntity extends Entity implements Leashable, Tickable { /** @@ -72,9 +69,12 @@ public class BoatEntity extends Entity implements Leashable, Tickable { // Looks too fast and too choppy with 0.1f, which is how I believe the Microsoftian client handles it private final float ROWING_SPEED = 0.1f; - public BoatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, BoatVariant variant) { + public BoatEntity(EntitySpawnContext context, BoatVariant variant) { // Initial rotation is incorrect - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position.add(0d, bedrockDefinition.offset(), 0d), motion, yaw + 90, 0, yaw + 90); + super(context); + setPosition(position.up(offset)); + setYaw(yaw + 90); + setHeadYaw(yaw + 90); this.variant = variant; dirtyMetadata.put(EntityDataTypes.VARIANT, variant.ordinal()); @@ -94,7 +94,7 @@ protected void initializeMetadata() { @Override public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { // We don't include the rotation (y) as it causes the boat to appear sideways - setPosition(position.add(0d, this.definition.offset(), 0d)); + setPosition(position.add(0d, offset(), 0d)); setYaw(yaw + 90); setHeadYaw(yaw + 90); setOnGround(isOnGround); @@ -103,7 +103,7 @@ public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYa moveEntityPacket.setRuntimeEntityId(geyserId); if (session.getPlayerEntity().getVehicle() == this && session.getPlayerEntity().isRidingInFront()) { // Minimal glitching when ClientboundMoveVehiclePacket is sent - moveEntityPacket.setPosition(position.up(VanillaEntities.PLAYER_ENTITY_OFFSET - this.definition.offset())); + moveEntityPacket.setPosition(position.up(VanillaEntities.PLAYER_ENTITY_OFFSET - offset())); } else { moveEntityPacket.setPosition(this.position); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ChestBoatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ChestBoatEntity.java index bc178990d65..35155d76b36 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ChestBoatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ChestBoatEntity.java @@ -25,19 +25,14 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class ChestBoatEntity extends BoatEntity { - public ChestBoatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, BoatVariant variant) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, variant); + public ChestBoatEntity(EntitySpawnContext context, BoatVariant variant) { + super(context, variant); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/CommandBlockMinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/CommandBlockMinecartEntity.java index aca925557f9..d37df9e2fa8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/CommandBlockMinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/CommandBlockMinecartEntity.java @@ -25,24 +25,19 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerType; import org.cloudburstmc.protocol.bedrock.packet.ContainerOpenPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class CommandBlockMinecartEntity extends DefaultBlockMinecartEntity { - public CommandBlockMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public CommandBlockMinecartEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/DefaultBlockMinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/DefaultBlockMinecartEntity.java index 933ef115b3a..fc883c26bba 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/DefaultBlockMinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/DefaultBlockMinecartEntity.java @@ -25,15 +25,10 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; -import java.util.UUID; - /** * This class is used as a base for minecarts with a default block to display like furnaces and spawners */ @@ -43,8 +38,8 @@ public class DefaultBlockMinecartEntity extends MinecartEntity { public int customBlockOffset = 0; public boolean showCustomBlock = false; - public DefaultBlockMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public DefaultBlockMinecartEntity(EntitySpawnContext context) { + super(context); dirtyMetadata.put(EntityDataTypes.CUSTOM_DISPLAY, (byte) 1); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/DisplayBaseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/DisplayBaseEntity.java index 77673039d0e..cb7d29e728a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/DisplayBaseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/DisplayBaseEntity.java @@ -28,22 +28,19 @@ import net.kyori.adventure.text.Component; import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.util.EntityUtils; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import java.util.Optional; -import java.util.UUID; public class DisplayBaseEntity extends Entity { private @Nullable Vector3f baseTranslation; - public DisplayBaseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public DisplayBaseEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/EnderCrystalEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/EnderCrystalEntity.java index 864c072c0e0..294337c6d31 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/EnderCrystalEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/EnderCrystalEntity.java @@ -25,22 +25,18 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import java.util.Optional; -import java.util.UUID; public class EnderCrystalEntity extends Entity { - public EnderCrystalEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public EnderCrystalEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/EnderEyeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/EnderEyeEntity.java index 8bc85981ae3..4d043358b00 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/EnderEyeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/EnderEyeEntity.java @@ -26,17 +26,12 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; public class EnderEyeEntity extends Entity { - public EnderEyeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public EnderEyeEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index b741e1b4643..b35c563abbc 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -44,6 +44,7 @@ import org.cloudburstmc.protocol.bedrock.packet.MoveEntityDeltaPacket; import org.cloudburstmc.protocol.bedrock.packet.RemoveEntityPacket; import org.cloudburstmc.protocol.bedrock.packet.SetEntityDataPacket; +import org.geysermc.geyser.api.entity.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.property.BatchPropertyUpdater; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.entity.type.GeyserEntity; @@ -53,6 +54,7 @@ import org.geysermc.geyser.entity.properties.GeyserEntityProperties; import org.geysermc.geyser.entity.properties.GeyserEntityPropertyManager; import org.geysermc.geyser.entity.properties.type.PropertyType; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.MobEntity; import org.geysermc.geyser.entity.type.player.PlayerEntity; import org.geysermc.geyser.item.Items; @@ -87,8 +89,8 @@ public class Entity implements GeyserEntity { protected final GeyserSession session; @Accessors(fluent = true) - protected BedrockEntityDefinition definition; - protected EntityTypeDefinition javaDefinition; + protected BedrockEntityDefinition bedrockDefinition; + protected EntityTypeDefinition javaTypeDefinition; protected int entityId; protected final long geyserId; @@ -152,22 +154,32 @@ public class Entity implements GeyserEntity { @Setter(AccessLevel.PROTECTED) // For players private boolean flagsDirty = false; + @Accessors(fluent = true) + protected float width; + @Accessors(fluent = true) + protected float height; + @Accessors(fluent = true) + protected float offset; + protected final @Nullable GeyserEntityPropertyManager propertyManager; - public Entity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, - Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - this.session = session; - this.javaDefinition = definition; - this.definition = bedrockDefinition; + public Entity(EntitySpawnContext context) { + this.session = context.session(); + this.javaTypeDefinition = context.entityTypeDefinition(); + this.bedrockDefinition = context.bedrockEntityDefinition(); this.displayName = standardDisplayName(); - this.entityId = entityId; - this.geyserId = geyserId; - this.uuid = uuid; - this.motion = motion; - this.yaw = yaw; - this.pitch = pitch; - this.headYaw = headYaw; + this.entityId = context.javaId(); + this.geyserId = session.getEntityCache().getNextEntityId().incrementAndGet(); + this.uuid = context.uuid(); + this.motion = context.motion(); + this.yaw = context.yaw(); + this.pitch = context.pitch(); + this.headYaw = context.headYaw(); + + this.width = context.width(); + this.height = context.height(); + this.offset = context.offset(); this.valid = false; // TODO null or empty check @@ -202,7 +214,7 @@ protected void setClientSideSilent() { public void spawnEntity() { AddEntityPacket addEntityPacket = new AddEntityPacket(); - addEntityPacket.setIdentifier(definition.identifier().toString()); + addEntityPacket.setIdentifier(bedrockDefinition.identifier().toString()); addEntityPacket.setRuntimeEntityId(geyserId); addEntityPacket.setUniqueEntityId(geyserId); addEntityPacket.setPosition(position); @@ -225,7 +237,7 @@ public void spawnEntity() { flagsDirty = false; if (session.getGeyser().config().debugMode() && PRINT_ENTITY_SPAWN_DEBUG) { - session.getGeyser().getLogger().debug("Spawned entity " + javaDefinition.type() + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")"); + session.getGeyser().getLogger().debug("Spawned entity " + javaTypeDefinition.type() + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")"); } } @@ -495,7 +507,7 @@ public void setDisplayName(EntityMetadata, ?> entityMetadata } protected String standardDisplayName() { - return EntityUtils.translatedEntityName(javaDefinition.type(), session); + return EntityUtils.translatedEntityName(javaTypeDefinition.type(), session); } protected void setNametag(@Nullable String nametag, boolean fromDisplayName) { @@ -575,8 +587,8 @@ public void setPose(Pose pose) { */ protected void setDimensionsFromPose(Pose pose) { // No flexibility options for basic entities - setBoundingBoxHeight(definition.height()); - setBoundingBoxWidth(definition.width()); + setBoundingBoxHeight(height); + setBoundingBoxWidth(width); } public boolean setBoundingBoxHeight(float height) { @@ -788,7 +800,7 @@ public void updatePropertiesBatched(Consumer consumer, boo } Objects.requireNonNull(consumer); - GeyserEntityProperties propertyDefinitions = definition.registeredProperties(); + GeyserEntityProperties propertyDefinitions = bedrockDefinition.registeredProperties(); consumer.accept(new BatchPropertyUpdater() { @Override public void update(@NonNull GeyserEntityProperty property, @Nullable T value) { @@ -828,8 +840,13 @@ public void update(@NonNull GeyserEntityProperty property, @Nullable T va return uuid; } + @Override + public GeyserEntityDefinition definition() { + return bedrockDefinition; + } + @Override public Vector3f position() { - return this.position.down(definition.offset()); + return this.position.down(offset); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java index 809c8cc60db..ed8f1fe4f15 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java @@ -25,22 +25,18 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.packet.PlaySoundPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; -import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; public class EvokerFangsEntity extends Entity implements Tickable { private int limitedLife = 22; private boolean attackStarted = false; - public EvokerFangsEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public EvokerFangsEntity(EntitySpawnContext context) { + super(context); // As of 1.18.2 Bedrock, this line is required for the entity to be visible // 22 is the starting number on Java Edition dirtyMetadata.put(EntityDataTypes.DATA_LIFETIME_TICKS, this.limitedLife); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ExpOrbEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ExpOrbEntity.java index fc25b26dc88..098a79f8c0b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ExpOrbEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ExpOrbEntity.java @@ -25,18 +25,13 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; public class ExpOrbEntity extends Entity { - public ExpOrbEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ExpOrbEntity(EntitySpawnContext context) { + super(context); this.dirtyMetadata.put(EntityDataTypes.TRADE_EXPERIENCE, 1); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FallingBlockEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FallingBlockEntity.java index 08eb4d15620..fb522271ce8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FallingBlockEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FallingBlockEntity.java @@ -25,21 +25,15 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.VanillaEntities; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; -import java.util.UUID; - public class FallingBlockEntity extends Entity { - // TODO - public FallingBlockEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, BedrockEntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw, int javaId) { - super(session, entityId, geyserId, uuid, VanillaEntities.FALLING_BLOCK, definition, position, motion, yaw, pitch, headYaw); + public FallingBlockEntity(EntitySpawnContext context, int javaId) { + super(context); this.dirtyMetadata.put(EntityDataTypes.BLOCK, session.getBlockMappings().getBedrockBlock(javaId)); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java index 631fbf73ca9..ed2cec25611 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java @@ -26,11 +26,7 @@ package org.geysermc.geyser.entity.type; import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; public class FireballEntity extends ThrowableEntity { private final Vector3f acceleration; @@ -40,8 +36,9 @@ public class FireballEntity extends ThrowableEntity { */ protected int futureTicks = 3; - public FireballEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, Vector3f.ZERO, yaw, pitch, headYaw); + public FireballEntity(EntitySpawnContext context) { + super(context); + setMotion(Vector3f.ZERO); float magnitude = motion.length(); if (magnitude != 0) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FireworkEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FireworkEntity.java index b5572c786a5..438e43074e3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FireworkEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FireworkEntity.java @@ -25,29 +25,25 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.MovementEffectType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.packet.MovementEffectPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.TooltipOptions; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.item.BedrockItemBuilder; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents; import java.util.OptionalInt; -import java.util.UUID; public class FireworkEntity extends Entity { private boolean attachedToSession; - public FireworkEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public FireworkEntity(EntitySpawnContext context) { + super(context); } public void setFireworkItem(EntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java index 202a957adaf..7db12a1f6e0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java @@ -30,8 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.packet.PlaySoundPacket; import org.geysermc.erosion.util.BlockPositionIterator; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.VanillaEntities; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.player.PlayerEntity; import org.geysermc.geyser.level.block.BlockStateValues; import org.geysermc.geyser.level.block.type.Block; @@ -41,7 +40,6 @@ import org.geysermc.geyser.util.BlockUtils; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; -import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; public class FishingHookEntity extends ThrowableEntity { @@ -56,8 +54,9 @@ public class FishingHookEntity extends ThrowableEntity { private final BoundingBox boundingBox; - public FishingHookEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, BedrockEntityDefinition definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw, PlayerEntity owner) { - super(session, entityId, geyserId, uuid, VanillaEntities.FISHING_BOBBER, definition, position, motion, yaw, pitch, 0f); + public FishingHookEntity(EntitySpawnContext context, PlayerEntity owner) { + super(context); + setHeadYaw(0); this.boundingBox = new BoundingBox(0.125, 0.125, 0.125, 0.25, 0.25, 0.25); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FurnaceMinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FurnaceMinecartEntity.java index 4f7e3346022..310805f1852 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FurnaceMinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FurnaceMinecartEntity.java @@ -25,25 +25,20 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.level.block.Blocks; import org.geysermc.geyser.level.block.property.Properties; import org.geysermc.geyser.level.block.type.BlockState; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class FurnaceMinecartEntity extends DefaultBlockMinecartEntity { private boolean hasFuel = false; - public FurnaceMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public FurnaceMinecartEntity(EntitySpawnContext context) { + super(context); } public void setHasFuel(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/HangingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/HangingEntity.java index b4d99216c01..8b5dba29d7f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/HangingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/HangingEntity.java @@ -25,19 +25,14 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction; -import java.util.UUID; - public abstract class HangingEntity extends Entity { - public HangingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public HangingEntity(EntitySpawnContext context) { + super(context); } public void setDirectionMetadata(EntityMetadata direction) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java index a855e1d42e1..f1a69772d3c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java @@ -31,11 +31,9 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.AnimatePacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.VanillaEntities; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.ArmorStandEntity; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; @@ -44,7 +42,6 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundSwingPacket; import java.util.Optional; -import java.util.UUID; public class InteractionEntity extends Entity { @@ -54,8 +51,8 @@ public class InteractionEntity extends Entity { */ private boolean response = false; - public InteractionEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public InteractionEntity(EntitySpawnContext context) { + super(context); } /** @@ -162,9 +159,7 @@ public void updateNameTag() { } if (this.secondEntity == null) { - // TODO CE make this controllable??? - secondEntity = new ArmorStandEntity(session, 0, session.getEntityCache().getNextEntityId().incrementAndGet(), null, - VanillaEntities.ARMOR_STAND, definition, position.up(getBoundingBoxHeight()), motion, getYaw(), getPitch(), getHeadYaw()); + secondEntity = new ArmorStandEntity(EntitySpawnContext.inherited(session, VanillaEntities.ARMOR_STAND, this, position.up(getBoundingBoxHeight()))); } secondEntity.getDirtyMetadata().put(EntityDataTypes.NAME, nametag); secondEntity.getDirtyMetadata().put(EntityDataTypes.NAMETAG_ALWAYS_SHOW, isNameTagVisible ? (byte) 1 : (byte) 0); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java index 140e17025b7..5b5cb7b2827 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java @@ -32,16 +32,13 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; import org.cloudburstmc.protocol.bedrock.packet.AddItemEntityPacket; import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.level.block.BlockStateValues; import org.geysermc.geyser.level.block.type.BlockState; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.item.ItemTranslator; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; -import java.util.UUID; import java.util.concurrent.CompletableFuture; public class ItemEntity extends ThrowableEntity { @@ -49,8 +46,8 @@ public class ItemEntity extends ThrowableEntity { private CompletableFuture waterLevel = CompletableFuture.completedFuture(-1); - public ItemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ItemEntity(EntitySpawnContext context) { + super(context); } @Override @@ -62,7 +59,7 @@ public void spawnEntity() { AddItemEntityPacket itemPacket = new AddItemEntityPacket(); itemPacket.setRuntimeEntityId(geyserId); itemPacket.setUniqueEntityId(geyserId); - itemPacket.setPosition(position.add(0d, this.definition.offset(), 0d)); + itemPacket.setPosition(position.add(0d, offset(), 0d)); itemPacket.setMotion(motion); itemPacket.setFromFishing(false); itemPacket.setItemInHand(item); @@ -113,10 +110,10 @@ public void setItem(EntityMetadata entityMetadata) { @Override protected void moveAbsoluteImmediate(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - float offset = definition.offset(); + float offset = offset(); if (waterLevel.join() == 0) { // Item is in a full block of water // Move the item entity down so it doesn't float above the water - offset = -definition.offset(); + offset = -offset(); } super.moveAbsoluteImmediate(position.add(0, offset, 0), 0, 0, 0, isOnGround, teleported); this.position = position; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java index 4e8f60bb9b9..3093af41d8d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java @@ -26,7 +26,6 @@ package org.geysermc.geyser.entity.type; import lombok.Getter; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtMapBuilder; @@ -34,8 +33,7 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; import org.cloudburstmc.protocol.bedrock.packet.BlockEntityDataPacket; import org.cloudburstmc.protocol.bedrock.packet.UpdateBlockPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.item.ItemTranslator; import org.geysermc.geyser.util.InteractionResult; @@ -47,8 +45,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; -import java.util.UUID; - /** * Item frames are an entity in Java but a block entity in Bedrock. */ @@ -80,8 +76,8 @@ public class ItemFrameEntity extends HangingEntity { */ private boolean changed = true; - public ItemFrameEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ItemFrameEntity(EntitySpawnContext context) { + super(context); blockDefinition = buildBlockDefinition(Direction.SOUTH); // Default to SOUTH direction, like on Java - entity metadata should correct this when necessary bedrockPosition = Vector3i.from(position.getFloorX(), position.getFloorY(), position.getFloorZ()); @@ -177,7 +173,7 @@ private NbtMap getDefaultTag() { builder.putInt("y", bedrockPosition.getY()); builder.putInt("z", bedrockPosition.getZ()); builder.putByte("isMovable", (byte) 1); - builder.putString("id", this.javaDefinition.type().is(BuiltinEntityType.GLOW_ITEM_FRAME) ? "GlowItemFrame" : "ItemFrame"); + builder.putString("id", this.javaTypeDefinition.is(BuiltinEntityType.GLOW_ITEM_FRAME) ? "GlowItemFrame" : "ItemFrame"); return builder.build(); } @@ -223,7 +219,7 @@ public InteractionResult interact(Hand hand) { private BlockDefinition buildBlockDefinition(Direction direction) { NbtMapBuilder blockBuilder = NbtMap.builder() - .putString("name", this.javaDefinition.type().is(BuiltinEntityType.GLOW_ITEM_FRAME) ? "minecraft:glow_frame" : "minecraft:frame"); + .putString("name", this.javaTypeDefinition.is(BuiltinEntityType.GLOW_ITEM_FRAME) ? "minecraft:glow_frame" : "minecraft:frame"); NbtMapBuilder statesBuilder = NbtMap.builder() .putInt("facing_direction", direction.ordinal()) .putByte("item_frame_map_bit", (byte) 0) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java index 433731a746a..52a699a7e52 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java @@ -25,20 +25,16 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class LeashKnotEntity extends Entity { - public LeashKnotEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { + public LeashKnotEntity(EntitySpawnContext context) { + super(context); // Position is incorrect by default - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position.add(0.5f, 0.25f, 0.5f), motion, yaw, pitch, headYaw); + setPosition(position.add(0.5f, 0.25f, 0.5f)); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LightningEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LightningEntity.java index 498d2071b83..981c237b48f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LightningEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LightningEntity.java @@ -25,19 +25,15 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.packet.PlaySoundPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; -import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; public class LightningEntity extends Entity { - public LightningEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public LightningEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java index 198d10a4c03..3aca69320e5 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java @@ -29,7 +29,6 @@ import lombok.Getter; import lombok.Setter; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.protocol.bedrock.data.AttributeData; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; @@ -38,9 +37,8 @@ import org.cloudburstmc.protocol.bedrock.packet.MobArmorEquipmentPacket; import org.cloudburstmc.protocol.bedrock.packet.MobEquipmentPacket; import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.attribute.GeyserAttributeType; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.animal.HappyGhastEntity; import org.geysermc.geyser.entity.vehicle.ClientVehicle; import org.geysermc.geyser.entity.vehicle.HappyGhastVehicleComponent; @@ -76,7 +74,6 @@ import java.util.EnumMap; import java.util.List; import java.util.Optional; -import java.util.UUID; @Getter @Setter @@ -106,8 +103,8 @@ public class LivingEntity extends Entity { @Setter(AccessLevel.NONE) private float attributeScale; - public LivingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public LivingEntity(EntitySpawnContext context) { + super(context); } public GeyserItemStack getItemInSlot(EquipmentSlot slot) { @@ -554,7 +551,7 @@ private boolean hasValidEquippableItemForSlot(EquipmentSlot slot) { if (equippable != null) { return slot == equippable.slot() && canUseSlot(slot) && - EntityUtils.equipmentUsableByEntity(session, equippable, javaDefinition.type()); + EntityUtils.equipmentUsableByEntity(session, equippable, javaTypeDefinition.type()); } else { return slot == EquipmentSlot.MAIN_HAND && canUseSlot(EquipmentSlot.MAIN_HAND); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java index 461efc39824..1f69e21718f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java @@ -30,10 +30,8 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.packet.MoveEntityDeltaPacket; import org.cloudburstmc.protocol.bedrock.packet.SetEntityMotionPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.VanillaEntities; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.geyser.util.MathUtils; @@ -44,7 +42,6 @@ import java.util.LinkedList; import java.util.List; -import java.util.UUID; public class MinecartEntity extends Entity implements Tickable { private static final int POS_ROT_LERP_TICKS = 3; @@ -60,8 +57,9 @@ public class MinecartEntity extends Entity implements Tickable { private int cachedStepDelay; private float cachedDelta; - public MinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position.add(0d, bedrockDefinition.offset(), 0d), motion, yaw, pitch, headYaw); + public MinecartEntity(EntitySpawnContext context) { + super(context); + setPosition(position.up(offset)); } public void setCustomBlock(IntEntityMetadata entityMetadata) { @@ -114,7 +112,7 @@ public void tick() { moveEntityPacket.setRuntimeEntityId(geyserId); moveEntityPacket.setX(position.getX()); - moveEntityPacket.setY(position.getY() + definition.offset()); + moveEntityPacket.setY(position.getY() + offset()); moveEntityPacket.setZ(position.getZ()); moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_X); moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Y); @@ -202,7 +200,7 @@ private void updateCompletedStep() { @Override public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - super.moveAbsolute(position.add(0d, this.definition.offset(), 0d), yaw, pitch, headYaw, isOnGround, teleported); + super.moveAbsolute(position.up(offset), yaw, pitch, headYaw, isOnGround, teleported); } @Override @@ -220,7 +218,7 @@ public boolean doesJumpDismount() { @Override protected InteractiveTag testInteraction(Hand hand) { - if (javaDefinition == VanillaEntities.CHEST_MINECART || javaDefinition == VanillaEntities.HOPPER_MINECART) { + if (javaTypeDefinition == VanillaEntities.CHEST_MINECART || javaTypeDefinition == VanillaEntities.HOPPER_MINECART) { return InteractiveTag.OPEN_CONTAINER; } else { if (session.isSneaking()) { @@ -237,7 +235,7 @@ protected InteractiveTag testInteraction(Hand hand) { @Override public InteractionResult interact(Hand hand) { - if (javaDefinition == VanillaEntities.CHEST_MINECART || javaDefinition == VanillaEntities.HOPPER_MINECART) { + if (javaTypeDefinition == VanillaEntities.CHEST_MINECART || javaTypeDefinition == VanillaEntities.HOPPER_MINECART) { // Opening the UI of this minecart return InteractionResult.SUCCESS; } else { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java index 4f4b552dfc1..f3e9e5fd744 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java @@ -27,25 +27,21 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.packet.AddPaintingPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.level.PaintingType; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.registry.JavaRegistries; import org.geysermc.mcprotocollib.protocol.data.game.Holder; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.PaintingVariant; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ObjectEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction; -import java.util.UUID; - public class PaintingEntity extends HangingEntity { private static final double OFFSET = -0.46875; private int paintingId = -1; // Ideally this would be the default painting Java uses in their metadata, but seems to depend on the current paintings loaded in the registry private Direction direction = Direction.SOUTH; // Default to SOUTH direction, like on Java - entity metadata should correct this when necessary - public PaintingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public PaintingEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/SpawnerMinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/SpawnerMinecartEntity.java index 9eb2c42212f..59b28b62cec 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/SpawnerMinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/SpawnerMinecartEntity.java @@ -25,19 +25,14 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.level.block.Blocks; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; public class SpawnerMinecartEntity extends DefaultBlockMinecartEntity { - public SpawnerMinecartEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public SpawnerMinecartEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java index c88488496a6..9d88967e37b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java @@ -29,28 +29,25 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.SetEntityDataPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; -import java.util.UUID; - public class TNTEntity extends Entity implements Tickable { private int currentTick; - public TNTEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position.add(0, bedrockDefinition.offset(), 0), motion, yaw, pitch, headYaw); + public TNTEntity(EntitySpawnContext context) { + super(context); + setPosition(position.up(offset)); } @Override public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, boolean isOnGround) { - super.moveRelative(relX, relY + definition.offset(), relZ, yaw, pitch, isOnGround); + super.moveRelative(relX, relY + offset(), relZ, yaw, pitch, isOnGround); } @Override public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - super.moveAbsolute(position.add(Vector3f.from(0, definition.offset(), 0)), yaw, pitch, headYaw, isOnGround, teleported); + super.moveAbsolute(position.add(Vector3f.from(0, offset(), 0)), yaw, pitch, headYaw, isOnGround, teleported); } public void setFuseLength(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java index 90b217bb96d..303b2f7461e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java @@ -31,15 +31,11 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.translator.text.MessageTranslator; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.jetbrains.annotations.Nullable; -import java.util.UUID; - // Note: 1.19.4 requires that the billboard is set to something in order to show, on Java Edition @Getter public class TextDisplayEntity extends DisplayBaseEntity { @@ -56,13 +52,14 @@ public class TextDisplayEntity extends DisplayBaseEntity { private int lineCount; - public TextDisplayEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position.add(0, bedrockDefinition.offset(), 0), motion, yaw, pitch, headYaw); + public TextDisplayEntity(EntitySpawnContext context) { + super(context); + setPosition(position.up(offset)); } @Override public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, boolean isOnGround) { - super.moveRelative(relX, relY + definition.offset(), relZ, yaw, pitch, isOnGround); + super.moveRelative(relX, relY + offset(), relZ, yaw, pitch, isOnGround); } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEggEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEggEntity.java index c5587f8edb9..e6e4d66cd51 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEggEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEggEntity.java @@ -27,9 +27,7 @@ import lombok.Getter; import net.kyori.adventure.key.Key; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.animal.farm.TemperatureVariantAnimal; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; @@ -40,16 +38,14 @@ import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes; -import java.util.UUID; - @Getter public class ThrowableEggEntity extends ThrowableItemEntity { // Used for egg break particles private GeyserItemStack itemStack = GeyserItemStack.of(Items.EGG.javaId(), 1); - public ThrowableEggEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ThrowableEggEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java index 56e6bcd3314..38545807473 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java @@ -30,14 +30,10 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; import org.cloudburstmc.protocol.bedrock.packet.MoveEntityDeltaPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.level.block.BlockStateValues; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; -import java.util.UUID; - /** * Used as a class for any object-like entity that moves as a projectile */ @@ -45,8 +41,8 @@ public class ThrowableEntity extends Entity implements Tickable { protected Vector3f lastJavaPosition; - public ThrowableEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ThrowableEntity(EntitySpawnContext context) { + super(context); this.lastJavaPosition = position; } @@ -120,15 +116,15 @@ protected void moveAbsoluteImmediate(Vector3f position, float yaw, float pitch, */ protected float getGravity() { if (getFlag(EntityFlag.HAS_GRAVITY)) { - if (javaDefinition.is(BuiltinEntityType.LINGERING_POTION) || javaDefinition.is(BuiltinEntityType.SPLASH_POTION)) { + if (javaTypeDefinition.is(BuiltinEntityType.LINGERING_POTION) || javaTypeDefinition.is(BuiltinEntityType.SPLASH_POTION)) { return 0.05f; - } else if (javaDefinition.is(BuiltinEntityType.EXPERIENCE_BOTTLE)) { + } else if (javaTypeDefinition.is(BuiltinEntityType.EXPERIENCE_BOTTLE)) { return 0.07f; - } else if (javaDefinition.is(BuiltinEntityType.FIREBALL) || javaDefinition.is(BuiltinEntityType.SHULKER_BULLET)) { + } else if (javaTypeDefinition.is(BuiltinEntityType.FIREBALL) || javaTypeDefinition.is(BuiltinEntityType.SHULKER_BULLET)) { return 0; - } else if (javaDefinition.is(BuiltinEntityType.SNOWBALL) || javaDefinition.is(BuiltinEntityType.EGG) || javaDefinition.is(BuiltinEntityType.ENDER_PEARL)) { + } else if (javaTypeDefinition.is(BuiltinEntityType.SNOWBALL) || javaTypeDefinition.is(BuiltinEntityType.EGG) || javaTypeDefinition.is(BuiltinEntityType.ENDER_PEARL)) { return 0.03f; - } else if (javaDefinition.is(BuiltinEntityType.LLAMA_SPIT)) { + } else if (javaTypeDefinition.is(BuiltinEntityType.LLAMA_SPIT)) { return 0.06f; } } @@ -142,12 +138,12 @@ protected float getDrag() { if (isInWater()) { return 0.8f; } else { - if (javaDefinition.is(BuiltinEntityType.LINGERING_POTION) || javaDefinition.is(BuiltinEntityType.SPLASH_POTION) || javaDefinition.is(BuiltinEntityType.EXPERIENCE_BOTTLE) - || javaDefinition.is(BuiltinEntityType.SNOWBALL) || javaDefinition.is(BuiltinEntityType.EGG) || javaDefinition.is(BuiltinEntityType.ENDER_PEARL) || javaDefinition.is(BuiltinEntityType.LLAMA_SPIT)) { + if (javaTypeDefinition.is(BuiltinEntityType.LINGERING_POTION) || javaTypeDefinition.is(BuiltinEntityType.SPLASH_POTION) || javaTypeDefinition.is(BuiltinEntityType.EXPERIENCE_BOTTLE) + || javaTypeDefinition.is(BuiltinEntityType.SNOWBALL) || javaTypeDefinition.is(BuiltinEntityType.EGG) || javaTypeDefinition.is(BuiltinEntityType.ENDER_PEARL) || javaTypeDefinition.is(BuiltinEntityType.LLAMA_SPIT)) { return 0.99f; - } else if (javaDefinition.is(BuiltinEntityType.FIREBALL) || javaDefinition.is(BuiltinEntityType.SMALL_FIREBALL) || javaDefinition.is(BuiltinEntityType.DRAGON_FIREBALL)) { + } else if (javaTypeDefinition.is(BuiltinEntityType.FIREBALL) || javaTypeDefinition.is(BuiltinEntityType.SMALL_FIREBALL) || javaTypeDefinition.is(BuiltinEntityType.DRAGON_FIREBALL)) { return 0.95f; - } else if (javaDefinition.is(BuiltinEntityType.SHULKER_BULLET)) { + } else if (javaTypeDefinition.is(BuiltinEntityType.SHULKER_BULLET)) { return 1; } } @@ -164,7 +160,7 @@ protected boolean isInWater() { @Override public void despawnEntity() { - if (javaDefinition.is(BuiltinEntityType.ENDER_PEARL)) { + if (javaTypeDefinition.is(BuiltinEntityType.ENDER_PEARL)) { LevelEventPacket particlePacket = new LevelEventPacket(); particlePacket.setType(LevelEvent.PARTICLE_TELEPORT); particlePacket.setPosition(position); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java index e84f0603e44..8b273176f0d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java @@ -28,15 +28,11 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.VanillaEntities; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; -import java.util.UUID; - /** * Used as a class for any projectile entity that looks like an item */ @@ -47,8 +43,8 @@ public class ThrowableItemEntity extends ThrowableEntity { private int age; private boolean invisible; - public ThrowableItemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ThrowableItemEntity(EntitySpawnContext context) { + super(context); setFlag(EntityFlag.INVISIBLE, true); invisible = false; age = 0; @@ -68,7 +64,7 @@ private void checkVisibility() { if (session.isTickingFrozen()) { // This may seem odd, but it matches java edition Vector3f playerPos = session.getPlayerEntity().getPosition().down(VanillaEntities.PLAYER_ENTITY_OFFSET); - setInvisible(playerPos.distanceSquared(position.add(0, definition.offset(), 0)) < 12.25); + setInvisible(playerPos.distanceSquared(position.add(0, offset, 0)) < 12.25); } else { setInvisible(age < 2); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java index 4387a419ce5..b4913f44051 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrownPotionEntity.java @@ -25,14 +25,11 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.GeyserImpl; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.item.Potion; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; @@ -41,13 +38,12 @@ import org.geysermc.mcprotocollib.protocol.data.game.item.component.PotionContents; import java.util.EnumSet; -import java.util.UUID; public class ThrownPotionEntity extends ThrowableItemEntity { private static final EnumSet NON_ENCHANTED_POTIONS = EnumSet.of(Potion.WATER, Potion.MUNDANE, Potion.THICK, Potion.AWKWARD); - public ThrownPotionEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ThrownPotionEntity(EntitySpawnContext context) { + super(context); } @Override @@ -73,7 +69,7 @@ public void setItem(EntityMetadata entityMetadata) { } } - boolean isLingering = javaDefinition.type().is(BuiltinEntityType.LINGERING_POTION); + boolean isLingering = javaTypeDefinition.type().is(BuiltinEntityType.LINGERING_POTION); setFlag(EntityFlag.LINGERING, isLingering); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/TridentEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/TridentEntity.java index 0c3b16eb328..ecb0e560471 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/TridentEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/TridentEntity.java @@ -25,16 +25,11 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; public class TridentEntity extends AbstractArrowEntity { - public TridentEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public TridentEntity(EntitySpawnContext context) { + super(context); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java index 3a9a08a5d2f..ee4568efd5f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/WitherSkullEntity.java @@ -25,22 +25,17 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.impl.IdentifierImpl; import org.geysermc.geyser.registry.Registries; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; -import java.util.UUID; - public class WitherSkullEntity extends FireballEntity { private boolean isCharged; private static final IdentifierImpl DANGEROUS_SKULL = IdentifierImpl.of("wither_skull_dangerous"); - public WitherSkullEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public WitherSkullEntity(EntitySpawnContext context) { + super(context); this.futureTicks = 1; } @@ -50,7 +45,7 @@ public void setDangerous(BooleanEntityMetadata entityMetadata) { if (newDangerous != isCharged) { isCharged = newDangerous; // Is an entirely new entity in Bedrock but just a metadata type in Java - definition = isCharged ? Registries.BEDROCK_ENTITY_DEFINITIONS.get(DANGEROUS_SKULL) : javaDefinition.defaultBedrockDefinition(); + bedrockDefinition = isCharged ? Registries.BEDROCK_ENTITY_DEFINITIONS.get(DANGEROUS_SKULL) : javaTypeDefinition.defaultBedrockDefinition(); despawnEntity(); spawnEntity(); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AbstractFishEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AbstractFishEntity.java index 97edd9c1bd4..32ea64c048a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AbstractFishEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AbstractFishEntity.java @@ -30,6 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.EntityUtils; @@ -40,8 +41,8 @@ public class AbstractFishEntity extends WaterEntity { - public AbstractFishEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public AbstractFishEntity(EntitySpawnContext context) { + super(context); setFlag(EntityFlag.CAN_SWIM, true); setFlag(EntityFlag.BREATHING, true); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java index 4d6624a54c4..85d1bbddf03 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java @@ -25,19 +25,15 @@ package org.geysermc.geyser.entity.type.living; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; -import java.util.UUID; - public class AgeableEntity extends CreatureEntity { - public AgeableEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public AgeableEntity(EntitySpawnContext context) { + super(context); } @Override @@ -52,8 +48,8 @@ public void setBaby(BooleanEntityMetadata entityMetadata) { setScale(isBaby ? getBabySize() : getAdultSize()); setFlag(EntityFlag.BABY, isBaby); - setBoundingBoxHeight(definition.height() * (isBaby ? getBabySize() : getAdultSize())); - setBoundingBoxWidth(definition.width() * (isBaby ? getBabySize() : getAdultSize())); + setBoundingBoxHeight(height * (isBaby ? getBabySize() : getAdultSize())); + setBoundingBoxWidth(width * (isBaby ? getBabySize() : getAdultSize())); } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableWaterEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableWaterEntity.java index 4fbe8b9f876..49d75ac26f2 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableWaterEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableWaterEntity.java @@ -25,16 +25,11 @@ package org.geysermc.geyser.entity.type.living; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; public abstract class AgeableWaterEntity extends AgeableEntity { - public AgeableWaterEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public AgeableWaterEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java index c7ee9752086..07fd83b44dd 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java @@ -26,25 +26,20 @@ package org.geysermc.geyser.entity.type.living; import org.checkerframework.checker.nullness.qual.NonNull; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class AllayEntity extends MobEntity { private boolean canDuplicate; - public AllayEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public AllayEntity(EntitySpawnContext context) { + super(context); } public void setDancing(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AmbientEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AmbientEntity.java index 2990aa5dc1a..12b3fdf7435 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AmbientEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AmbientEntity.java @@ -25,17 +25,12 @@ package org.geysermc.geyser.entity.type.living; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; public class AmbientEntity extends MobEntity { - public AmbientEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public AmbientEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java index 222230af8a1..60c21386cf8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java @@ -32,14 +32,12 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.VanillaEntities; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.LivingEntity; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.scoreboard.Team; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.MathUtils; import org.geysermc.mcprotocollib.protocol.data.game.entity.EquipmentSlot; @@ -49,7 +47,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; import java.util.Optional; -import java.util.UUID; public class ArmorStandEntity extends LivingEntity { @@ -89,8 +86,8 @@ public class ArmorStandEntity extends LivingEntity { */ private boolean positionUpdateRequired = false; - public ArmorStandEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ArmorStandEntity(EntitySpawnContext context) { + super(context); } @Override @@ -158,8 +155,8 @@ public void setArmorStandFlags(ByteEntityMetadata entityMetadata) { setBoundingBoxWidth(0.0f); setBoundingBoxHeight(0.0f); } else { - setBoundingBoxWidth(definition.width()); - setBoundingBoxHeight(definition.height()); + setBoundingBoxWidth(width); + setBoundingBoxHeight(height); } updateMountOffset(); @@ -344,8 +341,8 @@ private void updateSecondEntityStatus(boolean sendMetadata) { if (secondEntity == null) { // Create the second entity. It doesn't need to worry about the items, but it does need to worry about // the metadata as it will hold the name tag. - secondEntity = new ArmorStandEntity(session, 0, session.getEntityCache().getNextEntityId().incrementAndGet(), null, - VanillaEntities.ARMOR_STAND, VanillaEntities.ARMADILLO.defaultBedrockDefinition(), position, motion, getYaw(), getPitch(), getHeadYaw()); + // TODO + secondEntity = new ArmorStandEntity(EntitySpawnContext.inherited(session, VanillaEntities.ARMOR_STAND, this, position)); secondEntity.primaryEntity = false; } // Copy metadata @@ -422,7 +419,7 @@ public float getYOffset() { if (!positionRequiresOffset || isMarker || secondEntity != null) { return 0; } - return definition.height() * getScale(); + return height * getScale(); } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/BatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/BatEntity.java index ed927701c55..30b2039fc1d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/BatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/BatEntity.java @@ -25,19 +25,14 @@ package org.geysermc.geyser.entity.type.living; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; -import java.util.UUID; - public class BatEntity extends AmbientEntity { - public BatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public BatEntity(EntitySpawnContext context) { + super(context); } public void setBatFlags(ByteEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/CopperGolemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/CopperGolemEntity.java index 57010750e90..b7658c2220d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/CopperGolemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/CopperGolemEntity.java @@ -26,15 +26,12 @@ package org.geysermc.geyser.entity.type.living; import org.checkerframework.checker.nullness.qual.NonNull; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.properties.type.BooleanProperty; import org.geysermc.geyser.entity.properties.type.EnumProperty; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.impl.IdentifierImpl; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; @@ -45,8 +42,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.WeatheringCopperState; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class CopperGolemEntity extends GolemEntity { public static final BooleanProperty HAS_FLOWER_PROPERTY = new BooleanProperty( IdentifierImpl.of("has_flower"), @@ -80,8 +75,8 @@ public enum OxidationLevelState { OXIDIZED } - public CopperGolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public CopperGolemEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/CreatureEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/CreatureEntity.java index 84f8e227618..f14aa572e51 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/CreatureEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/CreatureEntity.java @@ -25,16 +25,11 @@ package org.geysermc.geyser.entity.type.living; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; public class CreatureEntity extends MobEntity { - public CreatureEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public CreatureEntity(EntitySpawnContext context) { + super(context); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/DolphinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/DolphinEntity.java index ff0525f0aae..c2d33add87e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/DolphinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/DolphinEntity.java @@ -26,21 +26,16 @@ package org.geysermc.geyser.entity.type.living; import org.checkerframework.checker.nullness.qual.NonNull; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class DolphinEntity extends AgeableWaterEntity { - public DolphinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public DolphinEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/FlyingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/FlyingEntity.java index 91848044f29..1b42b38ea32 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/FlyingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/FlyingEntity.java @@ -25,16 +25,11 @@ package org.geysermc.geyser.entity.type.living; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; public class FlyingEntity extends MobEntity { - public FlyingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public FlyingEntity(EntitySpawnContext context) { + super(context); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/GlowSquidEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/GlowSquidEntity.java index 6c01cfc759b..289e5885c6f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/GlowSquidEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/GlowSquidEntity.java @@ -25,15 +25,10 @@ package org.geysermc.geyser.entity.type.living; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; public class GlowSquidEntity extends SquidEntity { - public GlowSquidEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public GlowSquidEntity(EntitySpawnContext context) { + super(context); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/GolemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/GolemEntity.java index 315298159d2..c953165a6f4 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/GolemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/GolemEntity.java @@ -25,16 +25,11 @@ package org.geysermc.geyser.entity.type.living; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; public class GolemEntity extends CreatureEntity { - public GolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public GolemEntity(EntitySpawnContext context) { + super(context); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/IronGolemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/IronGolemEntity.java index d103126c092..2b330907909 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/IronGolemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/IronGolemEntity.java @@ -26,23 +26,18 @@ package org.geysermc.geyser.entity.type.living; import org.checkerframework.checker.nullness.qual.NonNull; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class IronGolemEntity extends GolemEntity { - public IronGolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public IronGolemEntity(EntitySpawnContext context) { + super(context); // Indicate that we should show cracks through a resource pack setFlag(EntityFlag.BRIBED, true); // Required, or else the overlay is black diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java index a69f5cc2c88..a19f06cd0cb 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java @@ -27,16 +27,12 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; public class MagmaCubeEntity extends SlimeEntity { - public MagmaCubeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public MagmaCubeEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java index 2b7617ff947..c427c7649ad 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java @@ -26,11 +26,9 @@ package org.geysermc.geyser.entity.type.living; import org.checkerframework.checker.nullness.qual.NonNull; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.Leashable; import org.geysermc.geyser.entity.type.LivingEntity; import org.geysermc.geyser.inventory.GeyserItemStack; @@ -48,16 +46,14 @@ import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes; import org.geysermc.mcprotocollib.protocol.data.game.item.component.Equippable; -import java.util.UUID; - public class MobEntity extends LivingEntity implements Leashable { /** * If another mob is holding this mob by a leash, this variable tracks their Bedrock entity ID. */ private long leashHolderBedrockId; - public MobEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public MobEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/SlimeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/SlimeEntity.java index 0072b71342c..8ea22aa0b6a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/SlimeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/SlimeEntity.java @@ -25,18 +25,13 @@ package org.geysermc.geyser.entity.type.living; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; -import java.util.UUID; - public class SlimeEntity extends MobEntity { - public SlimeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public SlimeEntity(EntitySpawnContext context) { + super(context); } public void setSlimeScale(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/SnowGolemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/SnowGolemEntity.java index 54049df30b3..06257cce217 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/SnowGolemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/SnowGolemEntity.java @@ -26,24 +26,19 @@ package org.geysermc.geyser.entity.type.living; import org.checkerframework.checker.nullness.qual.NonNull; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class SnowGolemEntity extends GolemEntity { - public SnowGolemEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public SnowGolemEntity(EntitySpawnContext context) { + super(context); } public void setSnowGolemFlags(ByteEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java index 60ff8805da5..93442ed76b7 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java @@ -28,13 +28,10 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.MoveEntityDeltaPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.level.block.BlockStateValues; -import org.geysermc.geyser.session.GeyserSession; -import java.util.UUID; import java.util.concurrent.CompletableFuture; public class SquidEntity extends AgeableWaterEntity implements Tickable { @@ -43,8 +40,8 @@ public class SquidEntity extends AgeableWaterEntity implements Tickable { private CompletableFuture inWater = CompletableFuture.completedFuture(Boolean.FALSE); - public SquidEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public SquidEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/TadpoleEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/TadpoleEntity.java index 64cd09a05f9..470a2513da8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/TadpoleEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/TadpoleEntity.java @@ -26,21 +26,16 @@ package org.geysermc.geyser.entity.type.living; import org.checkerframework.checker.nullness.qual.NonNull; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class TadpoleEntity extends AbstractFishEntity { - public TadpoleEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public TadpoleEntity(EntitySpawnContext context) { + super(context); } @NonNull diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/WaterEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/WaterEntity.java index c8a76125dd0..7032639ed08 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/WaterEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/WaterEntity.java @@ -25,17 +25,12 @@ package org.geysermc.geyser.entity.type.living; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; public class WaterEntity extends CreatureEntity { - public WaterEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public WaterEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AnimalEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AnimalEntity.java index e1f23e7912e..2021e42632e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AnimalEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AnimalEntity.java @@ -27,26 +27,21 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.AgeableEntity; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.Tag; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public abstract class AnimalEntity extends AgeableEntity { - public AnimalEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public AnimalEntity(EntitySpawnContext context) { + super(context); } protected final boolean canEat(GeyserItemStack itemStack) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/ArmadilloEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/ArmadilloEntity.java index 786e4e0f606..0f896c03f46 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/ArmadilloEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/ArmadilloEntity.java @@ -26,19 +26,15 @@ package org.geysermc.geyser.entity.type.living.animal; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.properties.type.EnumProperty; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.impl.IdentifierImpl; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.ArmadilloState; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ObjectEntityMetadata; -import java.util.UUID; import java.util.concurrent.TimeUnit; public class ArmadilloEntity extends AnimalEntity { @@ -51,9 +47,8 @@ public class ArmadilloEntity extends AnimalEntity { private ArmadilloState armadilloState = ArmadilloState.IDLE; - public ArmadilloEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, - EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ArmadilloEntity(EntitySpawnContext context) { + super(context); } public void setArmadilloState(ObjectEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AxolotlEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AxolotlEntity.java index c5f12f96ae9..367374bc0dc 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AxolotlEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AxolotlEntity.java @@ -27,14 +27,11 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; import org.geysermc.geyser.util.EntityUtils; @@ -43,11 +40,9 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class AxolotlEntity extends AnimalEntity { - public AxolotlEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public AxolotlEntity(EntitySpawnContext context) { + super(context); } public void setVariant(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/BeeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/BeeEntity.java index 7f5c83b7b7d..023050c7d25 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/BeeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/BeeEntity.java @@ -26,24 +26,19 @@ package org.geysermc.geyser.entity.type.living.animal; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.properties.type.BooleanProperty; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.impl.IdentifierImpl; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; -import java.util.UUID; - public class BeeEntity extends AnimalEntity { public static final BooleanProperty NECTAR_PROPERTY = new BooleanProperty( @@ -51,8 +46,8 @@ public class BeeEntity extends AnimalEntity { false ); - public BeeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public BeeEntity(EntitySpawnContext context) { + super(context); } public void setBeeFlags(ByteEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FoxEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FoxEntity.java index 42e521d7281..dd85bf511b1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FoxEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FoxEntity.java @@ -26,24 +26,19 @@ package org.geysermc.geyser.entity.type.living.animal; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; -import java.util.UUID; - public class FoxEntity extends AnimalEntity { - public FoxEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public FoxEntity(EntitySpawnContext context) { + super(context); } public void setFoxVariant(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FrogEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FrogEntity.java index 22d4ebe6cb2..8eca99dfc9e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FrogEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FrogEntity.java @@ -26,14 +26,11 @@ package org.geysermc.geyser.entity.type.living.animal; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.registry.JavaRegistries; import org.geysermc.geyser.session.cache.registry.JavaRegistryKey; import org.geysermc.geyser.session.cache.tags.ItemTag; @@ -42,11 +39,10 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ObjectEntityMetadata; import java.util.OptionalInt; -import java.util.UUID; public class FrogEntity extends AnimalEntity implements VariantIntHolder { - public FrogEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public FrogEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java index 718fee7f8d3..6800fb617e3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java @@ -27,16 +27,13 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.SoundEvent; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; import org.geysermc.geyser.util.InteractionResult; @@ -44,8 +41,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class GoatEntity extends AnimalEntity { private static final float LONG_JUMPING_HEIGHT = 1.3f * 0.7f; private static final float LONG_JUMPING_WIDTH = 0.9f * 0.7f; @@ -54,8 +49,8 @@ public class GoatEntity extends AnimalEntity { private boolean hasLeftHorn; private boolean hasRightHorn; - public GoatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public GoatEntity(EntitySpawnContext context) { + super(context); } public void setScreamer(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HappyGhastEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HappyGhastEntity.java index 910dfbc95bc..d3a056ea9d1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HappyGhastEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HappyGhastEntity.java @@ -32,9 +32,8 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.AttributeData; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.properties.type.BooleanProperty; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; import org.geysermc.geyser.entity.vehicle.ClientVehicle; @@ -44,7 +43,6 @@ import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; import org.geysermc.geyser.util.AttributeUtils; @@ -57,7 +55,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; import java.util.List; -import java.util.UUID; public class HappyGhastEntity extends AnimalEntity implements ClientVehicle { @@ -72,8 +69,8 @@ public class HappyGhastEntity extends AnimalEntity implements ClientVehicle { private final HappyGhastVehicleComponent vehicleComponent = new HappyGhastVehicleComponent(this, 0.0f); private boolean staysStill; - public HappyGhastEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public HappyGhastEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HoglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HoglinEntity.java index 2775c9a3f3e..3d26b0551b6 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HoglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HoglinEntity.java @@ -26,24 +26,19 @@ package org.geysermc.geyser.entity.type.living.animal; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; -import java.util.UUID; - public class HoglinEntity extends AnimalEntity { private boolean isImmuneToZombification; - public HoglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public HoglinEntity(EntitySpawnContext context) { + super(context); dirtyMetadata.put(EntityDataTypes.TARGET_EID, session.getPlayerEntity().getGeyserId()); setFlag(EntityFlag.SHAKING, isShaking()); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/MooshroomEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/MooshroomEntity.java index 61044aaea86..c4fa800fa05 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/MooshroomEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/MooshroomEntity.java @@ -26,28 +26,23 @@ package org.geysermc.geyser.entity.type.living.animal; import org.checkerframework.checker.nullness.qual.NonNull; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.packet.AddEntityPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.animal.farm.CowEntity; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class MooshroomEntity extends CowEntity { private boolean isBrown = false; - public MooshroomEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public MooshroomEntity(EntitySpawnContext context) { + super(context); } public void setMooshroomVariant(IntEntityMetadata metadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java index 49c4435b625..b3deed39289 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java @@ -27,25 +27,20 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class OcelotEntity extends AnimalEntity { - public OcelotEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public OcelotEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PandaEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PandaEntity.java index 8307c174886..a56cf41b78c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PandaEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PandaEntity.java @@ -27,16 +27,13 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; import org.geysermc.geyser.util.InteractionResult; @@ -45,14 +42,12 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class PandaEntity extends AnimalEntity { private Gene mainGene = Gene.NORMAL; private Gene hiddenGene = Gene.NORMAL; - public PandaEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public PandaEntity(EntitySpawnContext context) { + super(context); } public void setEatingCounter(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PolarBearEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PolarBearEntity.java index 6a316175eb1..431a519332c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PolarBearEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PolarBearEntity.java @@ -26,19 +26,14 @@ package org.geysermc.geyser.entity.type.living.animal; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.Tag; -import java.util.UUID; - public class PolarBearEntity extends AnimalEntity { - public PolarBearEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public PolarBearEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PufferFishEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PufferFishEntity.java index 48d5ad5a330..ade3928473f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PufferFishEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PufferFishEntity.java @@ -25,20 +25,15 @@ package org.geysermc.geyser.entity.type.living.animal; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.AbstractFishEntity; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; -import java.util.UUID; - public class PufferFishEntity extends AbstractFishEntity { - public PufferFishEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public PufferFishEntity(EntitySpawnContext context) { + super(context); } public void setPufferfishSize(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/RabbitEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/RabbitEntity.java index 75c3234653e..cbf97582524 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/RabbitEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/RabbitEntity.java @@ -27,25 +27,20 @@ import net.kyori.adventure.key.Key; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; import org.geysermc.geyser.util.EntityUtils; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; -import java.util.UUID; - public class RabbitEntity extends AnimalEntity { private boolean isKillerBunny; - public RabbitEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public RabbitEntity(EntitySpawnContext context) { + super(context); } public void setRabbitVariant(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SheepEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SheepEntity.java index 7fb6271d2a2..e550150df3e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SheepEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SheepEntity.java @@ -27,16 +27,13 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.type.DyeItem; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; import org.geysermc.geyser.util.InteractionResult; @@ -44,13 +41,11 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class SheepEntity extends AnimalEntity { private int color; - public SheepEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public SheepEntity(EntitySpawnContext context) { + super(context); } public void setSheepFlags(ByteEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java index 6fe729a244b..a6abd5fa2a6 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java @@ -32,28 +32,25 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.Pose; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.SnifferState; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ObjectEntityMetadata; -import java.util.UUID; - public class SnifferEntity extends AnimalEntity implements Tickable { private static final int DIG_END = 120; private static final int DIG_START = DIG_END - 34; - private final float DIGGING_HEIGHT = definition.height() - 0.4f; + private final float DIGGING_HEIGHT; private Pose pose = Pose.STANDING; // Needed to call setDimensions for DIGGING state private int digTicks; - public SnifferEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public SnifferEntity(EntitySpawnContext context) { + super(context); + DIGGING_HEIGHT = height - 0.4f; } @Override @@ -66,7 +63,7 @@ public void setPose(Pose pose) { protected void setDimensionsFromPose(Pose pose) { if (getFlag(EntityFlag.DIGGING)) { setBoundingBoxHeight(DIGGING_HEIGHT); - setBoundingBoxWidth(definition.width()); + setBoundingBoxWidth(width); } else { super.setDimensionsFromPose(pose); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java index da15a9bc8a9..3318cb9bf15 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java @@ -30,8 +30,7 @@ import org.cloudburstmc.math.vector.Vector2f; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.entity.type.player.PlayerEntity; @@ -41,7 +40,6 @@ import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; import org.geysermc.geyser.util.EntityUtils; @@ -52,15 +50,13 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class StriderEntity extends AnimalEntity implements Tickable, ClientVehicle { private final BoostableVehicleComponent vehicleComponent = new BoostableVehicleComponent<>(this, 1.0f); private boolean isCold = false; - public StriderEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public StriderEntity(EntitySpawnContext context) { + super(context); setFlag(EntityFlag.FIRE_IMMUNE, true); setFlag(EntityFlag.BREATHING, true); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TropicalFishEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TropicalFishEntity.java index 8387f2f613c..edffee803f6 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TropicalFishEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TropicalFishEntity.java @@ -27,16 +27,12 @@ import com.google.common.collect.ImmutableList; import it.unimi.dsi.fastutil.ints.IntList; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.AbstractFishEntity; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; import java.util.List; -import java.util.UUID; public class TropicalFishEntity extends AbstractFishEntity { @@ -49,8 +45,8 @@ public class TropicalFishEntity extends AbstractFishEntity { private static final List VARIANT_NAMES = ImmutableList.of("kob", "sunstreak", "snooper", "dasher", "brinely", "spotty", "flopper", "stripey", "glitter", "blockfish", "betty", "clayfish"); private static final List COLOR_NAMES = ImmutableList.of("white", "orange", "magenta", "light_blue", "yellow", "lime", "pink", "gray", "light_gray", "cyan", "purple", "blue", "brown", "green", "red", "black"); - public TropicalFishEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public TropicalFishEntity(EntitySpawnContext context) { + super(context); } public void setFishVariant(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TurtleEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TurtleEntity.java index 0cbf46fa881..d245d4c5663 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TurtleEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/TurtleEntity.java @@ -26,22 +26,17 @@ package org.geysermc.geyser.entity.type.living.animal; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; -import java.util.UUID; - public class TurtleEntity extends AnimalEntity { - public TurtleEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public TurtleEntity(EntitySpawnContext context) { + super(context); } public void setPregnant(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/ChickenEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/ChickenEntity.java index 8807609e5a9..80612d667e2 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/ChickenEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/ChickenEntity.java @@ -26,22 +26,17 @@ package org.geysermc.geyser.entity.type.living.animal.farm; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.registry.JavaRegistries; import org.geysermc.geyser.session.cache.registry.JavaRegistryKey; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; -import java.util.UUID; - public class ChickenEntity extends TemperatureVariantAnimal { - public ChickenEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ChickenEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/CowEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/CowEntity.java index 45c6d3ac593..76ffdde24de 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/CowEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/CowEntity.java @@ -27,15 +27,12 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.SoundEvent; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.registry.JavaRegistries; import org.geysermc.geyser.session.cache.registry.JavaRegistryKey; import org.geysermc.geyser.session.cache.tags.ItemTag; @@ -44,12 +41,10 @@ import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class CowEntity extends TemperatureVariantAnimal { - public CowEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public CowEntity(EntitySpawnContext context) { + super(context); } @NonNull diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/PigEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/PigEntity.java index 2c9b75ab281..83a618bcc97 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/PigEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/PigEntity.java @@ -30,8 +30,7 @@ import org.cloudburstmc.math.vector.Vector2f; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.entity.type.player.PlayerEntity; import org.geysermc.geyser.entity.vehicle.BoostableVehicleComponent; @@ -40,7 +39,6 @@ import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.registry.JavaRegistries; import org.geysermc.geyser.session.cache.registry.JavaRegistryKey; import org.geysermc.geyser.session.cache.tags.ItemTag; @@ -52,13 +50,11 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class PigEntity extends TemperatureVariantAnimal implements Tickable, ClientVehicle { private final BoostableVehicleComponent vehicleComponent = new BoostableVehicleComponent<>(this, 1.0f); - public PigEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public PigEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/TemperatureVariantAnimal.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/TemperatureVariantAnimal.java index d51e4af2b7a..1634d914e32 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/TemperatureVariantAnimal.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/TemperatureVariantAnimal.java @@ -25,18 +25,13 @@ package org.geysermc.geyser.entity.type.living.animal.farm; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.properties.type.EnumProperty; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.animal.AnimalEntity; import org.geysermc.geyser.entity.type.living.animal.VariantHolder; import org.geysermc.geyser.impl.IdentifierImpl; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.RegistryCache; -import java.util.UUID; - public abstract class TemperatureVariantAnimal extends AnimalEntity implements VariantHolder { public static final EnumProperty TEMPERATE_VARIANT_PROPERTY = new EnumProperty<>( @@ -47,9 +42,8 @@ public abstract class TemperatureVariantAnimal extends AnimalEntity implements V public static final RegistryCache.RegistryReader VARIANT_READER = VariantHolder.reader(BuiltInVariant.class, BuiltInVariant.TEMPERATE); - public TemperatureVariantAnimal(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, - Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public TemperatureVariantAnimal(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java index b2995000bcd..db982247d59 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java @@ -27,22 +27,19 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerType; import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket; import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.attribute.GeyserAttributeType; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.animal.AnimalEntity; import org.geysermc.geyser.input.InputLocksFlag; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; import org.geysermc.geyser.util.InteractionResult; @@ -51,12 +48,10 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class AbstractHorseEntity extends AnimalEntity { - public AbstractHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public AbstractHorseEntity(EntitySpawnContext context) { + super(context); // Specifies the size of the entity's inventory. Required to place slots in the entity. dirtyMetadata.put(EntityDataTypes.CONTAINER_SIZE, getContainerBaseSize()); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java index a24748790d7..8b315dc00af 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java @@ -34,14 +34,12 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerType; import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.attribute.GeyserAttributeType; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.vehicle.CamelVehicleComponent; import org.geysermc.geyser.entity.vehicle.ClientVehicle; import org.geysermc.geyser.entity.vehicle.VehicleComponent; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.Attribute; @@ -51,15 +49,13 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.LongEntityMetadata; -import java.util.UUID; - public class CamelEntity extends AbstractHorseEntity implements ClientVehicle { public static final float SITTING_HEIGHT_DIFFERENCE = 1.43F; private final CamelVehicleComponent vehicleComponent = new CamelVehicleComponent(this); - public CamelEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public CamelEntity(EntitySpawnContext context) { + super(context); dirtyMetadata.put(EntityDataTypes.CONTAINER_TYPE, (byte) ContainerType.HORSE.getId()); @@ -114,8 +110,8 @@ public void setPose(Pose pose) { @Override protected void setDimensionsFromPose(Pose pose) { if (pose == Pose.SITTING) { - setBoundingBoxHeight(definition.height() - SITTING_HEIGHT_DIFFERENCE); - setBoundingBoxWidth(definition.width()); + setBoundingBoxHeight(height - SITTING_HEIGHT_DIFFERENCE); + setBoundingBoxWidth(width); } else { super.setDimensionsFromPose(pose); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ChestedHorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ChestedHorseEntity.java index 68d8eecad50..ddd10857af9 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ChestedHorseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ChestedHorseEntity.java @@ -26,20 +26,15 @@ package org.geysermc.geyser.entity.type.living.animal.horse; import org.checkerframework.checker.nullness.qual.NonNull; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; public class ChestedHorseEntity extends AbstractHorseEntity { - public ChestedHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ChestedHorseEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/HorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/HorseEntity.java index c16572dc699..8e02cd9b74d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/HorseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/HorseEntity.java @@ -25,20 +25,15 @@ package org.geysermc.geyser.entity.type.living.animal.horse; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.EquipmentSlot; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; -import java.util.UUID; - public class HorseEntity extends AbstractHorseEntity { - public HorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public HorseEntity(EntitySpawnContext context) { + super(context); } public void setHorseVariant(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/LlamaEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/LlamaEntity.java index cb32d85b9a0..59c0cdafb47 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/LlamaEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/LlamaEntity.java @@ -27,20 +27,15 @@ import lombok.Getter; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; import org.geysermc.geyser.util.MathUtils; import org.geysermc.mcprotocollib.protocol.data.game.entity.EquipmentSlot; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; -import java.util.UUID; - public class LlamaEntity extends ChestedHorseEntity { /** * Used to calculate inventory size @@ -48,8 +43,8 @@ public class LlamaEntity extends ChestedHorseEntity { @Getter private int strength = 1; - public LlamaEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public LlamaEntity(EntitySpawnContext context) { + super(context); dirtyMetadata.put(EntityDataTypes.CONTAINER_STRENGTH_MODIFIER, 3); // Presumably 3 slots for every 1 strength } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/SkeletonHorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/SkeletonHorseEntity.java index 4cd9435181d..8e2a2613f9d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/SkeletonHorseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/SkeletonHorseEntity.java @@ -26,20 +26,15 @@ package org.geysermc.geyser.entity.type.living.animal.horse; import org.checkerframework.checker.nullness.qual.NonNull; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class SkeletonHorseEntity extends AbstractHorseEntity { - public SkeletonHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public SkeletonHorseEntity(EntitySpawnContext context) { + super(context); } @NonNull diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/TraderLlamaEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/TraderLlamaEntity.java index 0dea0b3b09c..f4d6ebe3de0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/TraderLlamaEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/TraderLlamaEntity.java @@ -25,18 +25,13 @@ package org.geysermc.geyser.entity.type.living.animal.horse; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; public class TraderLlamaEntity extends LlamaEntity { - public TraderLlamaEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public TraderLlamaEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ZombieHorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ZombieHorseEntity.java index f35b9146531..3d13e7cf967 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ZombieHorseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ZombieHorseEntity.java @@ -26,20 +26,15 @@ package org.geysermc.geyser.entity.type.living.animal.horse; import org.checkerframework.checker.nullness.qual.NonNull; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class ZombieHorseEntity extends AbstractHorseEntity { - public ZombieHorseEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ZombieHorseEntity(EntitySpawnContext context) { + super(context); } @NonNull diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java index 2bd3a8b5049..9719f212199 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java @@ -27,15 +27,12 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.animal.VariantIntHolder; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.registry.JavaRegistries; import org.geysermc.geyser.session.cache.registry.JavaRegistryKey; import org.geysermc.geyser.session.cache.tags.ItemTag; @@ -47,14 +44,12 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class CatEntity extends TameableEntity implements VariantIntHolder { private byte collarColor = 14; // Red - default - public CatEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public CatEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java index d5c2fde03f1..5952b563ba2 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java @@ -27,24 +27,19 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.Tag; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class ParrotEntity extends TameableEntity { - public ParrotEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ParrotEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/TameableEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/TameableEntity.java index 5ae6db58d8b..b13584078e5 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/TameableEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/TameableEntity.java @@ -26,14 +26,11 @@ package org.geysermc.geyser.entity.type.living.animal.tameable; import lombok.Getter; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.living.animal.AnimalEntity; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; @@ -47,8 +44,8 @@ public abstract class TameableEntity extends AnimalEntity { @Getter protected long ownerBedrockId; - public TameableEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public TameableEntity(EntitySpawnContext context) { + super(context); } public void setTameableFlags(ByteEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java index 0f164d341f0..67b2521cd52 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java @@ -27,13 +27,11 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.properties.type.StringEnumProperty; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.animal.VariantIntHolder; import org.geysermc.geyser.impl.IdentifierImpl; import org.geysermc.geyser.inventory.GeyserItemStack; @@ -41,7 +39,6 @@ import org.geysermc.geyser.item.enchantment.EnchantmentComponent; import org.geysermc.geyser.item.type.DyeItem; import org.geysermc.geyser.item.type.Item; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.registry.JavaRegistries; import org.geysermc.geyser.session.cache.registry.JavaRegistryKey; import org.geysermc.geyser.session.cache.tags.ItemTag; @@ -59,7 +56,6 @@ import java.util.Collections; import java.util.List; -import java.util.UUID; public class WolfEntity extends TameableEntity implements VariantIntHolder { @@ -81,8 +77,8 @@ public class WolfEntity extends TameableEntity implements VariantIntHolder { private HolderSet repairableItems = null; private boolean isCurseOfBinding = false; - public WolfEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public WolfEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/AbstractMerchantEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/AbstractMerchantEntity.java index 241bfd61e94..4cd7b05d372 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/AbstractMerchantEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/AbstractMerchantEntity.java @@ -26,25 +26,20 @@ package org.geysermc.geyser.entity.type.living.merchant; import org.checkerframework.checker.nullness.qual.NonNull; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.VanillaEntities; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.AgeableEntity; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class AbstractMerchantEntity extends AgeableEntity { - public AbstractMerchantEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public AbstractMerchantEntity(EntitySpawnContext context) { + super(context); } @Override @@ -56,7 +51,7 @@ public boolean canBeLeashed() { @Override protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (!itemInHand.is(Items.VILLAGER_SPAWN_EGG) - && (javaDefinition != VanillaEntities.VILLAGER || !getFlag(EntityFlag.SLEEPING) && ((VillagerEntity) this).isCanTradeWith())) { + && (javaTypeDefinition != VanillaEntities.VILLAGER || !getFlag(EntityFlag.SLEEPING) && ((VillagerEntity) this).isCanTradeWith())) { // An additional check we know cannot work if (!isBaby()) { return InteractiveTag.TRADE; @@ -69,8 +64,8 @@ protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserI @Override protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (!itemInHand.is(Items.VILLAGER_SPAWN_EGG) - && (javaDefinition != VanillaEntities.VILLAGER || !getFlag(EntityFlag.SLEEPING)) - && (javaDefinition != VanillaEntities.WANDERING_TRADER || !getFlag(EntityFlag.BABY))) { + && (javaTypeDefinition != VanillaEntities.VILLAGER || !getFlag(EntityFlag.SLEEPING)) + && (javaTypeDefinition != VanillaEntities.WANDERING_TRADER || !getFlag(EntityFlag.BABY))) { // Trading time return InteractionResult.SUCCESS; } else { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java index dc078e7ee77..70898292b32 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java @@ -32,17 +32,14 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.MoveEntityAbsolutePacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.level.block.property.Properties; import org.geysermc.geyser.level.block.type.BedBlock; import org.geysermc.geyser.level.block.type.BlockState; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.VillagerData; import java.util.Optional; -import java.util.UUID; public class VillagerEntity extends AbstractMerchantEntity { /** @@ -89,8 +86,8 @@ public class VillagerEntity extends AbstractMerchantEntity { @Getter private boolean canTradeWith; - public VillagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public VillagerEntity(EntitySpawnContext context) { + super(context); } public void setVillagerData(EntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/AbstractSkeletonEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/AbstractSkeletonEntity.java index 26ffd3930f3..2a8e393314a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/AbstractSkeletonEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/AbstractSkeletonEntity.java @@ -25,21 +25,16 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.item.Items; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; -import java.util.UUID; - public class AbstractSkeletonEntity extends MonsterEntity { - public AbstractSkeletonEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public AbstractSkeletonEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BasePiglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BasePiglinEntity.java index c471d1673f0..fff876e5877 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BasePiglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BasePiglinEntity.java @@ -25,22 +25,17 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; -import java.util.UUID; - public class BasePiglinEntity extends MonsterEntity { private boolean isImmuneToZombification; - public BasePiglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public BasePiglinEntity(EntitySpawnContext context) { + super(context); // Both TARGET_EID and BLOCK are needed for melee attack animation dirtyMetadata.put(EntityDataTypes.BLOCK, session.getBlockMappings().getDefinition(1)); setFlag(EntityFlag.SHAKING, isShaking()); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BlazeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BlazeEntity.java index 0e8b49b6577..241f6d29314 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BlazeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BlazeEntity.java @@ -25,19 +25,14 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; -import java.util.UUID; - public class BlazeEntity extends MonsterEntity { - public BlazeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public BlazeEntity(EntitySpawnContext context) { + super(context); } public void setBlazeFlags(ByteEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BoggedEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BoggedEntity.java index b76be064120..3ec382eb4b8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BoggedEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BoggedEntity.java @@ -26,25 +26,20 @@ package org.geysermc.geyser.entity.type.living.monster; import org.checkerframework.checker.nullness.qual.NonNull; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class BoggedEntity extends AbstractSkeletonEntity { private boolean sheared = false; - public BoggedEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public BoggedEntity(EntitySpawnContext context) { + super(context); } public void setSheared(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BreezeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BreezeEntity.java index cb435346b36..38c6b3bb8a5 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BreezeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BreezeEntity.java @@ -25,18 +25,13 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.Pose; -import java.util.UUID; - public class BreezeEntity extends MonsterEntity { - public BreezeEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public BreezeEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java index e34d17b8c6c..5ca0af19a6f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java @@ -25,23 +25,19 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.protocol.bedrock.data.LevelEvent; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.LevelEventGenericPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.properties.type.EnumProperty; import org.geysermc.geyser.entity.properties.type.IntProperty; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.impl.IdentifierImpl; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataType; import java.util.Optional; -import java.util.UUID; public class CreakingEntity extends MonsterEntity { @@ -64,8 +60,8 @@ public class CreakingEntity extends MonsterEntity { private Vector3i homePosition; - public CreakingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public CreakingEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java index d6b9bc0efd7..d6214d35c9a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java @@ -26,13 +26,10 @@ package org.geysermc.geyser.entity.type.living.monster; import org.checkerframework.checker.nullness.qual.NonNull; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.SoundEvent; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; @@ -40,8 +37,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class CreeperEntity extends MonsterEntity { /** * Whether the creeper has been ignited and is using {@link #setIgnited(BooleanEntityMetadata)}. @@ -49,8 +44,8 @@ public class CreeperEntity extends MonsterEntity { */ private boolean ignitedByFlintAndSteel = false; - public CreeperEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public CreeperEntity(EntitySpawnContext context) { + super(context); } public void setSwelling(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ElderGuardianEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ElderGuardianEntity.java index 1fd1cd0fcb3..de98b91ee76 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ElderGuardianEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ElderGuardianEntity.java @@ -25,18 +25,13 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; public class ElderGuardianEntity extends GuardianEntity { - public ElderGuardianEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ElderGuardianEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java index e9402c136ba..3921e5a9e4e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java @@ -35,18 +35,15 @@ import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; import org.cloudburstmc.protocol.bedrock.packet.PlaySoundPacket; import org.cloudburstmc.protocol.bedrock.packet.SpawnParticleEffectPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.Tickable; import org.geysermc.geyser.entity.type.living.MobEntity; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.DimensionUtils; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.FloatEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; import java.util.Optional; import java.util.Random; -import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicLong; @@ -85,8 +82,8 @@ public class EnderDragonEntity extends MobEntity implements Tickable { private float wingPosition; private float lastWingPosition; - public EnderDragonEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public EnderDragonEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java index c74f38deb26..07ace32dd62 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java @@ -28,18 +28,25 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.entity.BedrockEntityDefinitions; import org.geysermc.geyser.entity.VanillaEntities; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.session.GeyserSession; public class EnderDragonPartEntity extends Entity { public EnderDragonPartEntity(GeyserSession session, int entityId, long geyserId, float width, float height) { - super(session, entityId, geyserId, null, VanillaEntities.ENDER_DRAGON_PART, VanillaEntities.ENDER_DRAGON.defaultBedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0); + super(dragonPartSpawnContext(session, entityId, geyserId, width, height)); dirtyMetadata.put(EntityDataTypes.WIDTH, width); dirtyMetadata.put(EntityDataTypes.HEIGHT, height); setFlag(EntityFlag.INVISIBLE, true); setFlag(EntityFlag.FIRE_IMMUNE, true); } + + public static EntitySpawnContext dragonPartSpawnContext(GeyserSession session, int entityId, long geyserId, float width, float height) { + return new EntitySpawnContext(session, VanillaEntities.ENDER_DRAGON_PART, entityId, null, + BedrockEntityDefinitions.ARMOR_STAND, Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, height, width, 0, geyserId); + } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EndermanEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EndermanEntity.java index 81ded8dc8f2..6dbd904db4b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EndermanEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EndermanEntity.java @@ -25,24 +25,19 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.SoundEvent; import org.cloudburstmc.protocol.bedrock.data.definitions.BlockDefinition; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; -import java.util.UUID; - public class EndermanEntity extends MonsterEntity { - public EndermanEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public EndermanEntity(EntitySpawnContext context) { + super(context); } public void setCarriedBlock(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GhastEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GhastEntity.java index da8acbe5bf4..2962dd1c0fa 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GhastEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GhastEntity.java @@ -25,20 +25,15 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.FlyingEntity; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; -import java.util.UUID; - public class GhastEntity extends FlyingEntity { - public GhastEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public GhastEntity(EntitySpawnContext context) { + super(context); } public void setGhastAttacking(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GiantEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GiantEntity.java index 7b705d438d1..659c3ea9aa1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GiantEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GiantEntity.java @@ -25,17 +25,12 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; public class GiantEntity extends MonsterEntity { - public GiantEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public GiantEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GuardianEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GuardianEntity.java index 7cb6b2b8789..551c83c4822 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GuardianEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GuardianEntity.java @@ -25,20 +25,15 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.Entity; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; -import java.util.UUID; - public class GuardianEntity extends MonsterEntity { - public GuardianEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public GuardianEntity(EntitySpawnContext context) { + super(context); } public void setGuardianTarget(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/MonsterEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/MonsterEntity.java index 178d2b24a62..70aecb475b8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/MonsterEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/MonsterEntity.java @@ -25,18 +25,13 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.CreatureEntity; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; public class MonsterEntity extends CreatureEntity { - public MonsterEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public MonsterEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java index d33385187e5..e2d287c6520 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java @@ -25,27 +25,22 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.FlyingEntity; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; -import java.util.UUID; - public class PhantomEntity extends FlyingEntity { - public PhantomEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public PhantomEntity(EntitySpawnContext context) { + super(context); } public void setPhantomScale(IntEntityMetadata entityMetadata) { int size = entityMetadata.getPrimitiveValue(); float modelScale = 1f + 0.15f * size; - float boundsScale = (1f + (0.2f * size) / definition.width()) / modelScale; + float boundsScale = (1f + (0.2f * size) / width) / modelScale; - setBoundingBoxWidth(boundsScale * definition.width()); - setBoundingBoxHeight(boundsScale * definition.height()); + setBoundingBoxWidth(boundsScale * width); + setBoundingBoxHeight(boundsScale * height); setScale(modelScale); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PiglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PiglinEntity.java index e3c4f93632b..79c9fecf0d2 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PiglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PiglinEntity.java @@ -26,17 +26,14 @@ package org.geysermc.geyser.entity.type.living.monster; import org.checkerframework.checker.nullness.qual.NonNull; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerId; import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; import org.cloudburstmc.protocol.bedrock.packet.MobEquipmentPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; @@ -44,12 +41,10 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes; -import java.util.UUID; - public class PiglinEntity extends BasePiglinEntity { - public PiglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public PiglinEntity(EntitySpawnContext context) { + super(context); } public void setBaby(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ShulkerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ShulkerEntity.java index f30244b2bec..0925e6c0206 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ShulkerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ShulkerEntity.java @@ -30,6 +30,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.GolemEntity; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; @@ -40,8 +41,8 @@ public class ShulkerEntity extends GolemEntity { - public ShulkerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ShulkerEntity(EntitySpawnContext context) { + super(context); // Indicate that invisibility should be fixed through the resource pack setFlag(EntityFlag.BRIBED, true); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SkeletonEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SkeletonEntity.java index 8f22c45c33d..dcba5313d30 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SkeletonEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SkeletonEntity.java @@ -25,20 +25,15 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; -import java.util.UUID; - public class SkeletonEntity extends AbstractSkeletonEntity { private boolean convertingToStray = false; - public SkeletonEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public SkeletonEntity(EntitySpawnContext context) { + super(context); } public void setConvertingToStray(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SpiderEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SpiderEntity.java index 30ff746a27d..4096f186cb0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SpiderEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/SpiderEntity.java @@ -25,19 +25,14 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; -import java.util.UUID; - public class SpiderEntity extends MonsterEntity { - public SpiderEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public SpiderEntity(EntitySpawnContext context) { + super(context); } public void setSpiderFlags(ByteEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/VexEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/VexEntity.java index cabe6e51309..8e39263aeef 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/VexEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/VexEntity.java @@ -25,19 +25,14 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; -import java.util.UUID; - public class VexEntity extends MonsterEntity { - public VexEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public VexEntity(EntitySpawnContext context) { + super(context); } public void setVexFlags(ByteEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WardenEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WardenEntity.java index c104f7ced59..8f3c2ff71f4 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WardenEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WardenEntity.java @@ -26,19 +26,15 @@ package org.geysermc.geyser.entity.type.living.monster; import org.cloudburstmc.math.GenericMath; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.PlaySoundPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.Tickable; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.MathUtils; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.Pose; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; -import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; public class WardenEntity extends MonsterEntity implements Tickable { @@ -47,8 +43,8 @@ public class WardenEntity extends MonsterEntity implements Tickable { private int sonicBoomTickDuration; - public WardenEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public WardenEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WitherEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WitherEntity.java index cd83525e1f2..4145f097682 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WitherEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WitherEntity.java @@ -25,21 +25,16 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.Entity; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata; -import java.util.UUID; - public class WitherEntity extends MonsterEntity { - public WitherEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public WitherEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java index b928bb8bbe9..c87c7b499f9 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java @@ -25,20 +25,15 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; -import java.util.UUID; - public class ZoglinEntity extends MonsterEntity { - public ZoglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ZoglinEntity(EntitySpawnContext context) { + super(context); dirtyMetadata.put(EntityDataTypes.TARGET_EID, session.getPlayerEntity().getGeyserId()); } @@ -55,7 +50,7 @@ public void setBaby(BooleanEntityMetadata entityMetadata) { @Override public float getBoundingBoxHeight() { float scale = getFlag(EntityFlag.BABY) ? 0.55f : 1f; - return scale * definition.height(); + return scale * height; } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieEntity.java index da431bc8069..c3588e8ef99 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieEntity.java @@ -25,20 +25,15 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; -import java.util.UUID; - public class ZombieEntity extends MonsterEntity { private boolean convertingToDrowned = false; - public ZombieEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ZombieEntity(EntitySpawnContext context) { + super(context); } public void setZombieBaby(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieVillagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieVillagerEntity.java index 10e6c506d37..3b3b66c797f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieVillagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieVillagerEntity.java @@ -26,15 +26,12 @@ package org.geysermc.geyser.entity.type.living.monster; import org.checkerframework.checker.nullness.qual.NonNull; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.merchant.VillagerEntity; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; @@ -42,12 +39,10 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; -import java.util.UUID; - public class ZombieVillagerEntity extends ZombieEntity { - public ZombieVillagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ZombieVillagerEntity(EntitySpawnContext context) { + super(context); } public void setTransforming(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombifiedPiglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombifiedPiglinEntity.java index f88c33c136a..8cbb490cf77 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombifiedPiglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombifiedPiglinEntity.java @@ -25,18 +25,13 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; public class ZombifiedPiglinEntity extends ZombieEntity { - public ZombifiedPiglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public ZombifiedPiglinEntity(EntitySpawnContext context) { + super(context); setFlag(EntityFlag.FIRE_IMMUNE, true); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/AbstractIllagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/AbstractIllagerEntity.java index e93c992e433..e840386d3c0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/AbstractIllagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/AbstractIllagerEntity.java @@ -25,16 +25,11 @@ package org.geysermc.geyser.entity.type.living.monster.raid; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; public class AbstractIllagerEntity extends RaidParticipantEntity { - public AbstractIllagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public AbstractIllagerEntity(EntitySpawnContext context) { + super(context); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/PillagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/PillagerEntity.java index 2a03469900a..8da9fb438f3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/PillagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/PillagerEntity.java @@ -25,23 +25,18 @@ package org.geysermc.geyser.entity.type.living.monster.raid; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes; -import java.util.UUID; - public class PillagerEntity extends AbstractIllagerEntity { - public PillagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public PillagerEntity(EntitySpawnContext context) { + super(context); } public void setChargingCrossbow(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RaidParticipantEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RaidParticipantEntity.java index 097dc463d1d..63acf522cde 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RaidParticipantEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RaidParticipantEntity.java @@ -25,17 +25,12 @@ package org.geysermc.geyser.entity.type.living.monster.raid; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.monster.MonsterEntity; -import org.geysermc.geyser.session.GeyserSession; - -import java.util.UUID; public class RaidParticipantEntity extends MonsterEntity { - public RaidParticipantEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public RaidParticipantEntity(EntitySpawnContext context) { + super(context); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RavagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RavagerEntity.java index 56ce0f324a5..151a64eec4e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RavagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/RavagerEntity.java @@ -25,19 +25,15 @@ package org.geysermc.geyser.entity.type.living.monster.raid; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; -import java.util.UUID; import java.util.concurrent.TimeUnit; public class RavagerEntity extends RaidParticipantEntity { - public RavagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public RavagerEntity(EntitySpawnContext context) { + super(context); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/SpellcasterIllagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/SpellcasterIllagerEntity.java index fcf42ab673f..d421b35b9ce 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/SpellcasterIllagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/SpellcasterIllagerEntity.java @@ -25,26 +25,21 @@ package org.geysermc.geyser.entity.type.living.monster.raid; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.VanillaEntities; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; -import java.util.UUID; - public class SpellcasterIllagerEntity extends AbstractIllagerEntity { private static final int SUMMON_VEX_PARTICLE_COLOR = (179 << 16) | (179 << 8) | 204; private static final int ATTACK_PARTICLE_COLOR = (102 << 16) | (77 << 8) | 89; private static final int WOLOLO_PARTICLE_COLOR = (179 << 16) | (128 << 8) | 51; - public SpellcasterIllagerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public SpellcasterIllagerEntity(EntitySpawnContext context) { + super(context); // OptionalPack usage - setFlag(EntityFlag.BRIBED, this.javaDefinition == VanillaEntities.ILLUSIONER); + setFlag(EntityFlag.BRIBED, javaTypeDefinition == VanillaEntities.ILLUSIONER); } public void setSpellType(ByteEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/VindicatorEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/VindicatorEntity.java index 54447c4a6d3..dc26d55a6d8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/VindicatorEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/VindicatorEntity.java @@ -25,20 +25,15 @@ package org.geysermc.geyser.entity.type.living.monster.raid; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata; -import java.util.UUID; - public class VindicatorEntity extends AbstractIllagerEntity { - public VindicatorEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public VindicatorEntity(EntitySpawnContext context) { + super(context); dirtyMetadata.put(EntityDataTypes.TARGET_EID, session.getPlayerEntity().getGeyserId()); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java index 38abf9819f4..bb241798a94 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java @@ -40,12 +40,10 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.AddPlayerPacket; import org.cloudburstmc.protocol.bedrock.packet.MovePlayerPacket; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.VanillaEntities; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.LivingEntity; import org.geysermc.geyser.level.block.Blocks; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.skin.SkinManager; import org.geysermc.geyser.skin.SkullSkinManager; import org.geysermc.geyser.translator.item.ItemTranslator; @@ -61,7 +59,6 @@ import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.UUID; public class AvatarEntity extends LivingEntity { public static final float SNEAKING_POSE_HEIGHT = 1.5f; @@ -94,9 +91,8 @@ public class AvatarEntity extends LivingEntity { BASE_ABILITY_LAYER = Collections.singletonList(abilityLayer); } - public AvatarEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, - Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw, String username) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + public AvatarEntity(EntitySpawnContext context, String username) { + super(context); this.username = username; this.nametag = username; } @@ -115,7 +111,7 @@ public void spawnEntity() { addPlayerPacket.setUsername(username); addPlayerPacket.setRuntimeEntityId(geyserId); addPlayerPacket.setUniqueEntityId(geyserId); - addPlayerPacket.setPosition(position.sub(0, definition.offset(), 0)); + addPlayerPacket.setPosition(position.sub(0, offset(), 0)); addPlayerPacket.setRotation(getBedrockRotation()); addPlayerPacket.setMotion(motion); addPlayerPacket.setHand(ItemTranslator.translateToBedrock(session, getMainHandItem())); @@ -181,7 +177,7 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float if (getFlag(EntityFlag.SLEEPING)) { if (bedPosition != null && (bedPosition.getY() == 0 || bedPosition.distanceSquared(position.toInt()) > 4)) { // Force the player movement by using a teleport - movePlayerPacket.setPosition(Vector3f.from(position.getX(), position.getY() - definition.offset() + 0.2f, position.getZ())); + movePlayerPacket.setPosition(Vector3f.from(position.getX(), position.getY() - offset + 0.2f, position.getZ())); movePlayerPacket.setMode(MovePlayerPacket.Mode.TELEPORT); } } @@ -200,7 +196,7 @@ public void setPosition(Vector3f position) { // Messes with Bedrock if we send this to the client itself, though. super.setPosition(position.up(0.2f)); } else { - super.setPosition(position.add(0, definition.offset(), 0)); + super.setPosition(position.add(0, offset, 0)); } } @@ -345,11 +341,11 @@ public void setDimensionsFromPose(Pose pose) { switch (pose) { case SNEAKING -> { height = SNEAKING_POSE_HEIGHT; - width = definition.width(); + width = width(); } case FALL_FLYING, SPIN_ATTACK, SWIMMING -> { height = 0.6f; - width = definition.width(); + width = width(); } case DYING -> { height = 0.2f; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/MannequinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/MannequinEntity.java index d97f4a8d2eb..a98754596d5 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/MannequinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/MannequinEntity.java @@ -26,20 +26,16 @@ package org.geysermc.geyser.entity.type.player; import net.kyori.adventure.text.Component; -import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.entity.BedrockEntityDefinition; -import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.ResolvableProfile; import java.util.Optional; -import java.util.UUID; public class MannequinEntity extends AvatarEntity { - public MannequinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityTypeDefinition definition, BedrockEntityDefinition bedrockDefinition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) { - super(session, entityId, geyserId, uuid, definition, bedrockDefinition, position, motion, yaw, pitch, headYaw, ""); + public MannequinEntity(EntitySpawnContext context) { + super(context, ""); } public void setProfile(EntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java index e1752391845..6b2e5cd9d7f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java @@ -37,9 +37,9 @@ import org.geysermc.geyser.api.entity.type.player.GeyserPlayerEntity; import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.attribute.GeyserAttributeType; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.living.animal.tameable.ParrotEntity; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.Pose; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.FloatEntityMetadata; @@ -66,9 +66,8 @@ public class PlayerEntity extends AvatarEntity implements GeyserPlayerEntity { */ private boolean listed = false; - public PlayerEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, Vector3f position, - Vector3f motion, float yaw, float pitch, float headYaw, String username, @Nullable String texturesProperty) { - super(session, entityId, geyserId, uuid, VanillaEntities.PLAYER, VanillaEntities.PLAYER.defaultBedrockDefinition(), position, motion, yaw, pitch, headYaw, username); + public PlayerEntity(EntitySpawnContext context, String username, @Nullable String texturesProperty) { + super(context, username); this.texturesProperty = texturesProperty; } @@ -161,9 +160,7 @@ protected void setParrot(OptionalInt variant, boolean isLeft) { return; } // The parrot is a separate entity in Bedrock, but part of the player entity in Java - // TODO CE allow customizing? - ParrotEntity parrot = new ParrotEntity(session, 0, session.getEntityCache().getNextEntityId().incrementAndGet(), - null, VanillaEntities.PARROT, VanillaEntities.PARROT.defaultBedrockDefinition(), position, motion, getYaw(), getPitch(), getHeadYaw()); + ParrotEntity parrot = new ParrotEntity(EntitySpawnContext.inherited(session, VanillaEntities.PARROT, this, position)); parrot.spawnEntity(); parrot.getDirtyMetadata().put(EntityDataTypes.VARIANT, variant.getAsInt()); // Different position whether the parrot is left or right diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java index a19de69e9f1..343142c1893 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java @@ -40,6 +40,7 @@ import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket; import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.attribute.GeyserAttributeType; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.BoatEntity; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.LivingEntity; @@ -131,7 +132,8 @@ public class SessionPlayerEntity extends PlayerEntity { private float javaYaw; public SessionPlayerEntity(GeyserSession session) { - super(session, -1, 1, null, Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, null, null); + super(new EntitySpawnContext(session, VanillaEntities.PLAYER, -1, null, VanillaEntities.PLAYER.defaultBedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, + 0, 0, 0, VanillaEntities.PLAYER.height(), VanillaEntities.PLAYER.width(), VanillaEntities.PLAYER.offset(), 1), null, null); valid = true; } @@ -163,7 +165,7 @@ public void setYaw(float yaw) { @Override public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, float headYaw, boolean isOnGround) { super.moveRelative(relX, relY, relZ, yaw, pitch, headYaw, isOnGround); - session.getCollisionManager().updatePlayerBoundingBox(this.position.down(definition.offset())); + session.getCollisionManager().updatePlayerBoundingBox(this.position.down(offset)); } @Override @@ -175,7 +177,7 @@ public void setPosition(Vector3f position) { session.setNoClip(false); } } - this.position = position.add(0, definition.offset(), 0); + this.position = position.add(0, offset, 0); } /** @@ -471,8 +473,8 @@ public void setVehicle(Entity entity) { entity.setBoundingBoxHeight(0.5625F); entity.updateBedrockMetadata(); } else if (entity == null && this.vehicle instanceof BoatEntity) { - this.vehicle.setBoundingBoxWidth(this.vehicle.getJavaDefinition().defaultBedrockDefinition().width()); - this.vehicle.setBoundingBoxHeight(this.vehicle.getJavaDefinition().defaultBedrockDefinition().height()); + this.vehicle.setBoundingBoxWidth(this.vehicle.width()); + this.vehicle.setBoundingBoxHeight(this.vehicle.height()); this.vehicle.updateBedrockMetadata(); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/SkullPlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/SkullPlayerEntity.java index ea3c6e7ea49..1fa354caa85 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/SkullPlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/SkullPlayerEntity.java @@ -30,12 +30,11 @@ import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.VanillaEntities; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.level.block.property.Properties; import org.geysermc.geyser.level.block.type.BlockState; import org.geysermc.geyser.level.block.type.WallSkullBlock; import org.geysermc.geyser.level.physics.Direction; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.SkullCache; import java.util.Objects; @@ -54,8 +53,8 @@ public class SkullPlayerEntity extends AvatarEntity { @Getter private Vector3i skullPosition; - public SkullPlayerEntity(GeyserSession session, long geyserId) { - super(session, 0, geyserId, UUID.randomUUID(), VanillaEntities.PLAYER, VanillaEntities.PLAYER.defaultBedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, ""); + public SkullPlayerEntity(EntitySpawnContext context) { + super(context, ""); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java index db0b638f433..5b24e718ce3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java +++ b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java @@ -218,7 +218,7 @@ protected ObjectDoublePair updateFluidMovement(VehicleContext ctx) { double lavaHeight = getFluidHeightAndApplyMovement(ctx, iter, Fluid.LAVA, vehicle.getSession().getDimensionType().ultrawarm() ? 0.007 : 0.007 / 3, min.getY()); // Apply upward motion if the vehicle is a Strider, and it is submerged in lava - if (lavaHeight > 0 && vehicle.getJavaDefinition().type().is(BuiltinEntityType.STRIDER)) { + if (lavaHeight > 0 && vehicle.getJavaTypeDefinition().is(BuiltinEntityType.STRIDER)) { Vector3i blockPos = ctx.centerPos().toInt(); if (!CollisionManager.FLUID_COLLISION.isBelow(blockPos.getY(), boundingBox) || ctx.getBlock(blockPos.up()).is(Blocks.LAVA)) { vehicle.setMotion(vehicle.getMotion().mul(0.5f).add(0, 0.05f, 0)); diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index 44e1ccb4c24..ca11bb5c865 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -2391,6 +2391,16 @@ public void removeFog(String... fogNameSpaces) { return this.cameraData.fogEffects(); } + @Override + public @NonNull GeyserPlayerEntity playerEntity() { + return playerEntity; + } + + @Override + public void requestHandSwap() { + requestOffhandSwap(); + } + @Override public int ping() { // Can otherwise cause issues if the player isn't logged in yet / already left diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/SkullCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/SkullCache.java index b0e8194088b..671437b2c52 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/SkullCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/SkullCache.java @@ -35,6 +35,8 @@ import org.cloudburstmc.protocol.bedrock.data.definitions.BlockDefinition; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.block.custom.CustomBlockState; +import org.geysermc.geyser.entity.VanillaEntities; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.player.SkullPlayerEntity; import org.geysermc.geyser.level.block.property.Properties; import org.geysermc.geyser.level.block.type.BlockState; @@ -46,7 +48,12 @@ import org.geysermc.mcprotocollib.auth.GameProfile; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.UUID; public class SkullCache { private final int maxVisibleSkulls; @@ -197,8 +204,7 @@ private void assignSkullEntity(Skull skull) { } if (!cullingEnabled || totalSkullEntities < maxVisibleSkulls) { // Create a new entity - long geyserId = session.getEntityCache().getNextEntityId().incrementAndGet(); - skull.entity = new SkullPlayerEntity(session, geyserId); + skull.entity = new SkullPlayerEntity(EntitySpawnContext.DUMMY_CONTEXT.apply(session, UUID.randomUUID(), VanillaEntities.PLAYER)); skull.entity.spawnEntity(); skull.entity.updateSkull(skull); totalSkullEntities++; diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java index 8a8677333d7..a59b22c387f 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java @@ -25,7 +25,6 @@ package org.geysermc.geyser.translator.inventory; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityLinkData; import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerSlotType; @@ -36,8 +35,11 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.response.ItemStackResponse; import org.cloudburstmc.protocol.bedrock.packet.SetEntityLinkPacket; import org.geysermc.geyser.entity.VanillaEntities; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.Entity; -import org.geysermc.geyser.inventory.*; +import org.geysermc.geyser.inventory.BedrockContainerSlot; +import org.geysermc.geyser.inventory.MerchantContainer; +import org.geysermc.geyser.inventory.SlotType; import org.geysermc.geyser.inventory.updater.InventoryUpdater; import org.geysermc.geyser.inventory.updater.UIInventoryUpdater; import org.geysermc.geyser.session.GeyserSession; @@ -96,10 +98,10 @@ public SlotType getSlotType(int javaSlot) { @Override public boolean prepareInventory(GeyserSession session, MerchantContainer container) { if (container.getVillager() == null) { - long geyserId = session.getEntityCache().getNextEntityId().incrementAndGet(); - Vector3f pos = session.getPlayerEntity().getPosition().sub(0, 3, 0); + var context = EntitySpawnContext.DUMMY_CONTEXT.apply(session, null, VanillaEntities.VILLAGER); + context.position(session.getPlayerEntity().getPosition().sub(0, 3, 0)); - Entity villager = new Entity(session, 0, geyserId, null, VanillaEntities.VILLAGER, VanillaEntities.VILLAGER.defaultBedrockDefinition(), pos, Vector3f.ZERO, 0f, 0f, 0f) { + Entity villager = new Entity(context) { @Override protected void initializeMetadata() { dirtyMetadata.put(EntityDataTypes.SCALE, 0f); @@ -111,7 +113,7 @@ protected void initializeMetadata() { SetEntityLinkPacket linkPacket = new SetEntityLinkPacket(); EntityLinkData.Type type = EntityLinkData.Type.PASSENGER; - linkPacket.setEntityLink(new EntityLinkData(session.getPlayerEntity().getGeyserId(), geyserId, type, true, false, 0f)); + linkPacket.setEntityLink(new EntityLinkData(session.getPlayerEntity().getGeyserId(), context.geyserId(), type, true, false, 0f)); session.sendUpstreamPacket(linkPacket); container.setVillager(villager); diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SpawnerBlockEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SpawnerBlockEntityTranslator.java index fc9f93f2ac3..82ef4c0eddb 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SpawnerBlockEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SpawnerBlockEntityTranslator.java @@ -120,8 +120,8 @@ private static void translateSpawnData(@NonNull NbtMapBuilder builder, @Nullable EntityTypeDefinition definition = Registries.JAVA_ENTITY_IDENTIFIERS.get(entityId); if (definition != null) { - builder.putFloat("DisplayEntityWidth", definition.defaultBedrockDefinition().width()); - builder.putFloat("DisplayEntityHeight", definition.defaultBedrockDefinition().height()); + builder.putFloat("DisplayEntityWidth", definition.width()); + builder.putFloat("DisplayEntityHeight", definition.height()); builder.putFloat("DisplayEntityScale", 1.0f); } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java index 3d8ab411fe0..d4fd6ad1929 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java @@ -81,6 +81,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.InteractAction; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.PlayerAction; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import org.geysermc.mcprotocollib.protocol.data.game.item.HashedStack; import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes; import org.geysermc.mcprotocollib.protocol.data.game.item.component.InstrumentComponent; @@ -479,7 +480,7 @@ public void translate(GeyserSession session, InventoryTransactionPacket packet) } int entityId; - if (entity.getJavaDefinition() == VanillaEntities.ENDER_DRAGON) { + if (entity.getJavaTypeDefinition().is(BuiltinEntityType.ENDER_DRAGON)) { // Redirects the attack to its body entity, this only happens when // attacking the underbelly of the ender dragon entityId = entity.getEntityId() + 3; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java index 453ea5e6c0c..4800d256de1 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java @@ -146,7 +146,7 @@ static void translate(GeyserSession session, PlayerAuthInputPacket packet) { final BoundingBox entityBoundingBox = new BoundingBox(0, 0, 0, other.getBoundingBoxWidth(), other.getBoundingBoxHeight(), other.getBoundingBoxWidth()); // Also offset the position down for boat as their position is offset. - entityBoundingBox.translate(other.getPosition().down(other instanceof BoatEntity ? other.getJavaDefinition().defaultBedrockDefinition().offset() : 0).toDouble()); + entityBoundingBox.translate(other.getPosition().down(other instanceof BoatEntity ? other.offset() : 0).toDouble()); if (entityBoundingBox.checkIntersection(boundingBox)) { possibleOnGround = true; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java index 14f1bd212ed..8e98c2b6c42 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java @@ -290,7 +290,7 @@ private static void processVehicleInput(GeyserSession session, PlayerAuthInputPa Vector3f position = vehicle.getPosition(); if (vehicle instanceof BoatEntity) { - position = position.down(vehicle.definition().offset()); + position = position.down(vehicle.offset()); } final BoundingBox box = new BoundingBox( @@ -327,7 +327,7 @@ private static void processVehicleInput(GeyserSession session, PlayerAuthInputPa if (vehicle instanceof BoatEntity) { // Remove some Y position to prevents boats flying up - vehiclePosition = vehiclePosition.down(vehicle.definition().offset()); + vehiclePosition = vehiclePosition.down(vehicle.offset()); } vehicle.setPosition(vehiclePosition); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java index b5f5dd8ca96..e02160c5880 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java @@ -25,16 +25,11 @@ package org.geysermc.geyser.translator.protocol.java.entity; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.GeyserImpl; -import org.geysermc.geyser.api.entity.GeyserEntityDefinition; -import org.geysermc.geyser.api.entity.JavaEntityType; -import org.geysermc.geyser.api.event.java.ServerSpawnEntityEvent; -import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.GeyserEntityType; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.FallingBlockEntity; import org.geysermc.geyser.entity.type.FishingHookEntity; @@ -55,9 +50,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundAddEntityPacket; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicReference; - @Translator(packet = ClientboundAddEntityPacket.class) public class JavaAddEntityTranslator extends PacketTranslator { @@ -77,19 +69,12 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) return; } - Vector3f position = Vector3f.from(packet.getX(), packet.getY(), packet.getZ()); - Vector3f motion = packet.getMovement().toFloat(); - float yaw = packet.getYaw(); - float pitch = packet.getPitch(); - float headYaw = packet.getHeadYaw(); - + EntitySpawnContext context = EntitySpawnContext.fromPacket(session, definition, packet); if (type.is(BuiltinEntityType.PLAYER)) { PlayerEntity entity; if (packet.getUuid().equals(session.getPlayerEntity().getUuid())) { // Server is sending a fake version of the current player - entity = new PlayerEntity(session, packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), - session.getPlayerEntity().getUuid(), position, motion, yaw, pitch, headYaw, session.getPlayerEntity().getUsername(), - session.getPlayerEntity().getTexturesProperty()); + entity = new PlayerEntity(context, session.getPlayerEntity().getUsername(), session.getPlayerEntity().getTexturesProperty()); } else { entity = session.getEntityCache().getPlayerEntity(packet.getUuid()); if (entity == null) { @@ -100,11 +85,11 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) } entity.setEntityId(packet.getEntityId()); - entity.setPosition(position); - entity.setYaw(yaw); - entity.setPitch(pitch); - entity.setHeadYaw(headYaw); - entity.setMotion(motion); + entity.setPosition(Vector3f.from(packet.getX(), packet.getY(), packet.getZ())); + entity.setYaw(packet.getYaw()); + entity.setPitch(packet.getPitch()); + entity.setHeadYaw(packet.getHeadYaw()); + entity.setMotion(packet.getMovement().toFloat()); } entity.sendPlayer(); @@ -116,57 +101,27 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) return; } - BedrockEntityDefinition bedrockDefinition = definition.defaultBedrockDefinition(); - AtomicReference eventDefinition = new AtomicReference<>(bedrockDefinition); - GeyserImpl.getInstance().getEventBus().fire(new ServerSpawnEntityEvent(session) { - - @Override - public int entityId() { - return packet.getEntityId(); - } - - @Override - public @NonNull UUID uuid() { - return packet.getUuid(); - } - - @Override - public @NonNull JavaEntityType entityType() { - return type; - } - - @Override - public @Nullable GeyserEntityDefinition entityDefinition() { - return eventDefinition.get(); - } - - @Override - public void entityDefinition(@Nullable GeyserEntityDefinition entityDefinition) { - eventDefinition.set(entityDefinition); - } - }); - - if (eventDefinition.get() != bedrockDefinition) { + context.callEvent(); + if (context.bedrockEntityDefinition() == null) { + // TODO log warn + return; } Entity entity; if (type.is(BuiltinEntityType.FALLING_BLOCK)) { - entity = new FallingBlockEntity(session, packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), packet.getUuid(), - bedrockDefinition, position, motion, yaw, pitch, headYaw, ((FallingBlockData) packet.getData()).getId()); + entity = new FallingBlockEntity(context, ((FallingBlockData) packet.getData()).getId()); } else if (type.is(BuiltinEntityType.FISHING_BOBBER)) { // Fishing bobbers need the owner for the line int ownerEntityId = ((ProjectileData) packet.getData()).getOwnerId(); Entity owner = session.getEntityCache().getEntityByJavaId(ownerEntityId); // Java clients only spawn fishing hooks with a player as its owner if (owner instanceof PlayerEntity) { - entity = new FishingHookEntity(session, packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), packet.getUuid(), - bedrockDefinition, position, motion, yaw, pitch, headYaw, (PlayerEntity) owner); + entity = new FishingHookEntity(context, (PlayerEntity) owner); } else { return; } } else { - entity = definition.factory().create(session, packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), - packet.getUuid(), definition, bedrockDefinition, position, motion, yaw, pitch, headYaw); + entity = definition.factory().create(context); // This is done over entity metadata in modern versions, but is still sent over network in the spawn packet if (entity instanceof HangingEntity hanging) { diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java index 2c09c4fa5c1..9f8b8bd65fe 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java @@ -39,7 +39,6 @@ import org.cloudburstmc.protocol.bedrock.packet.SetEntityDataPacket; import org.cloudburstmc.protocol.bedrock.packet.SetEntityMotionPacket; import org.geysermc.geyser.GeyserImpl; -import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.EvokerFangsEntity; import org.geysermc.geyser.entity.type.FishingHookEntity; @@ -55,6 +54,7 @@ import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.Translator; import org.geysermc.geyser.util.InventoryUtils; +import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundEntityEventPacket; import java.util.Collections; @@ -109,7 +109,7 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet for (int i = 0; i < 6; i++) { session.sendUpstreamPacket(particlePacket); } - } else if (entity.getJavaDefinition() == VanillaEntities.SNOWBALL) { + } else if (entity.getJavaTypeDefinition().is(BuiltinEntityType.SNOWBALL)) { LevelEventPacket particlePacket = new LevelEventPacket(); particlePacket.setType(ParticleType.SNOWBALL_POOF); particlePacket.setPosition(entity.getPosition()); @@ -198,7 +198,7 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet return; case SHEEP_GRAZE_OR_TNT_CART_EXPLODE: - if (entity.getJavaDefinition() == VanillaEntities.SHEEP) { + if (entity.getJavaTypeDefinition().is(BuiltinEntityType.SHEEP)) { entityEventPacket.setType(EntityEventType.EAT_GRASS); } else { entityEventPacket.setType(EntityEventType.PRIME_TNT_MINECART); @@ -216,23 +216,23 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet case VILLAGER_SWEAT: LevelEventPacket levelEventPacket = new LevelEventPacket(); levelEventPacket.setType(ParticleType.WATER_SPLASH); - levelEventPacket.setPosition(entity.getPosition().up(entity.definition().height())); + levelEventPacket.setPosition(entity.getPosition().up(entity.height())); session.sendUpstreamPacket(levelEventPacket); return; case IRON_GOLEM_EMPTY_HAND: entityEventPacket.setType(EntityEventType.GOLEM_FLOWER_WITHDRAW); break; case ATTACK: - if (entity.getJavaDefinition() == VanillaEntities.IRON_GOLEM || entity.getJavaDefinition() == VanillaEntities.EVOKER_FANGS - || entity.getJavaDefinition() == VanillaEntities.WARDEN) { + if (entity.getJavaTypeDefinition().is(BuiltinEntityType.IRON_GOLEM) || entity.getJavaTypeDefinition().is(BuiltinEntityType.EVOKER_FANGS) + || entity.getJavaTypeDefinition().is(BuiltinEntityType.WARDEN)) { entityEventPacket.setType(EntityEventType.ATTACK_START); - if (entity.getJavaDefinition() == VanillaEntities.EVOKER_FANGS) { + if (entity.getJavaTypeDefinition().is(BuiltinEntityType.EVOKER_FANGS)) { ((EvokerFangsEntity) entity).setAttackStarted(); } } break; case RABBIT_JUMP_OR_MINECART_SPAWNER_DELAY_RESET: - if (entity.getJavaDefinition() == VanillaEntities.RABBIT) { + if (entity.getJavaTypeDefinition().is(BuiltinEntityType.RABBIT)) { // This doesn't match vanilla Bedrock behavior but I'm unsure how to make it better // I assume part of the problem is that Bedrock uses a duration and Java just says the rabbit is jumping SetEntityDataPacket dataPacket = new SetEntityDataPacket(); @@ -266,12 +266,12 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet } return; case GOAT_LOWERING_HEAD: - if (entity.getJavaDefinition() == VanillaEntities.GOAT) { + if (entity.getJavaTypeDefinition().is(BuiltinEntityType.GOAT)) { entityEventPacket.setType(EntityEventType.ATTACK_START); } break; case GOAT_STOP_LOWERING_HEAD: - if (entity.getJavaDefinition() == VanillaEntities.GOAT) { + if (entity.getJavaTypeDefinition().is(BuiltinEntityType.GOAT)) { entityEventPacket.setType(EntityEventType.ATTACK_STOP); } break; @@ -283,7 +283,7 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet } break; case WARDEN_RECEIVE_SIGNAL: - if (entity.getJavaDefinition() == VanillaEntities.WARDEN) { + if (entity.getJavaTypeDefinition().is(BuiltinEntityType.WARDEN)) { entityEventPacket.setType(EntityEventType.VIBRATION_DETECTED); } break; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityDataTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityDataTranslator.java index e384477f578..c76c83ff111 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityDataTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityDataTranslator.java @@ -42,12 +42,12 @@ public void translate(GeyserSession session, ClientboundSetEntityDataPacket pack Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId()); if (entity == null) return; - EntityTypeDefinition definition = entity.getJavaDefinition(); + EntityTypeDefinition definition = entity.getJavaTypeDefinition(); for (EntityMetadata metadata : packet.getMetadata()) { if (metadata.getId() >= definition.translators().size()) { if (session.getGeyser().config().debugMode()) { // Minecraft client just ignores these - session.getGeyser().getLogger().warning("Metadata ID " + metadata.getId() + " is out of bounds of known entity metadata size " + definition.translators().size() + " for entity type " + entity.getJavaDefinition().type()); + session.getGeyser().getLogger().warning("Metadata ID " + metadata.getId() + " is out of bounds of known entity metadata size " + definition.translators().size() + " for entity type " + entity.getJavaTypeDefinition().type()); session.getGeyser().getLogger().debug(metadata.toString()); } continue; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java index 16a038ec7b0..5b166c7464e 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java @@ -125,8 +125,8 @@ public void translate(GeyserSession session, ClientboundSetPassengersPacket pack entity.setPassengers(newPassengers); - if (entity.getJavaDefinition().is(BuiltinEntityType.HORSE) || entity.getJavaDefinition().is(BuiltinEntityType.SKELETON_HORSE) || entity.getJavaDefinition().is(BuiltinEntityType.DONKEY) - || entity.getJavaDefinition().is(BuiltinEntityType.MULE) || entity.getJavaDefinition().is(BuiltinEntityType.RAVAGER)) { + if (entity.getJavaTypeDefinition().is(BuiltinEntityType.HORSE) || entity.getJavaTypeDefinition().is(BuiltinEntityType.SKELETON_HORSE) || entity.getJavaTypeDefinition().is(BuiltinEntityType.DONKEY) + || entity.getJavaTypeDefinition().is(BuiltinEntityType.MULE) || entity.getJavaTypeDefinition().is(BuiltinEntityType.RAVAGER)) { entity.getDirtyMetadata().put(EntityDataTypes.SEAT_ROTATION_OFFSET_DEGREES, 181.0f); entity.updateBedrockMetadata(); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerInfoUpdateTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerInfoUpdateTranslator.java index db7ad390ba3..de796d0781a 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerInfoUpdateTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerInfoUpdateTranslator.java @@ -26,9 +26,10 @@ package org.geysermc.geyser.translator.protocol.java.entity.player; import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.packet.PlayerListPacket; import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.entity.VanillaEntities; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.player.PlayerEntity; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.skin.SkinManager; @@ -77,15 +78,9 @@ public void translate(GeyserSession session, ClientboundPlayerInfoUpdatePacket p } else { // It's a new player playerEntity = new PlayerEntity( - session, - -1, - session.getEntityCache().getNextEntityId().incrementAndGet(), - id, - Vector3f.ZERO, - Vector3f.ZERO, - 0, 0, 0, - name, - texturesProperty + EntitySpawnContext.DUMMY_CONTEXT.apply(session, id, VanillaEntities.PLAYER), + name, + texturesProperty ); session.getEntityCache().addPlayerEntity(playerEntity); diff --git a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java index abcf596506a..3380e489435 100644 --- a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java @@ -112,7 +112,7 @@ private static float getMountedHeightOffset(Entity mount) { float height = mount.getBoundingBoxHeight(); float mountedHeightOffset = height * 0.75f; - EntityTypeDefinition definition = mount.getJavaDefinition(); + EntityTypeDefinition definition = mount.getJavaTypeDefinition(); if (definition.is(BuiltinEntityType.CAMEL)) { boolean isBaby = mount.getFlag(EntityFlag.BABY); mountedHeightOffset = height - (isBaby ? 0.35f : 0.6f); @@ -149,7 +149,7 @@ private static float getMountedHeightOffset(Entity mount) { private static float getHeightOffset(Entity passenger) { boolean isBaby; - EntityTypeDefinition definition = passenger.getJavaDefinition(); + EntityTypeDefinition definition = passenger.getJavaTypeDefinition(); if (definition.is(BuiltinEntityType.ALLAY) || definition.is(BuiltinEntityType.VEX)) { return 0.4f; } else if (definition.is(BuiltinEntityType.SKELETON) || definition.is(BuiltinEntityType.STRAY) || definition.is(BuiltinEntityType.WITHER_SKELETON)) { @@ -176,7 +176,7 @@ private static float getHeightOffset(Entity passenger) { return -0.35f; } else if (definition.is(BuiltinEntityType.SHULKER)) { Entity vehicle = passenger.getVehicle(); - if (vehicle instanceof BoatEntity || vehicle.getJavaDefinition() == VanillaEntities.MINECART) { + if (vehicle instanceof BoatEntity || vehicle.getJavaTypeDefinition() == VanillaEntities.MINECART) { return 0.1875f - getMountedHeightOffset(vehicle); } } @@ -199,7 +199,7 @@ public static void updateMountOffset(Entity passenger, Entity mount, boolean rid float xOffset = 0; float yOffset = mountedHeightOffset + heightOffset; float zOffset = 0; - EntityTypeDefinition mountDefinition = mount.getJavaDefinition(); + EntityTypeDefinition mountDefinition = mount.getJavaTypeDefinition(); if (mountDefinition.is(BuiltinEntityType.CAMEL)) { zOffset = 0.5f; if (passengers > 1) { @@ -267,7 +267,7 @@ public static void updateMountOffset(Entity passenger, Entity mount, boolean rid * Horses are tinier * Players, Minecarts, and Boats have different origins */ - EntityTypeDefinition passengerDefinition = passenger.getJavaDefinition(); + EntityTypeDefinition passengerDefinition = passenger.getJavaTypeDefinition(); if (mountDefinition.is(BuiltinEntityType.PLAYER)) { yOffset -= VanillaEntities.PLAYER_ENTITY_OFFSET; } @@ -277,20 +277,20 @@ public static void updateMountOffset(Entity passenger, Entity mount, boolean rid if (mountDefinition.is(BuiltinEntityType.MINECART) || mountDefinition.is(BuiltinEntityType.HOPPER_MINECART) || mountDefinition.is(BuiltinEntityType.TNT_MINECART) || mountDefinition.is(BuiltinEntityType.CHEST_MINECART) || mountDefinition.is(BuiltinEntityType.FURNACE_MINECART) || mountDefinition.is(BuiltinEntityType.SPAWNER_MINECART) || mountDefinition.is(BuiltinEntityType.COMMAND_BLOCK_MINECART)) { - yOffset -= mount.getJavaDefinition().defaultBedrockDefinition().height() * 0.5f; + yOffset -= mount.height() * 0.5f; } if (passengerDefinition.is(BuiltinEntityType.MINECART) || passengerDefinition.is(BuiltinEntityType.HOPPER_MINECART) || passengerDefinition.is(BuiltinEntityType.TNT_MINECART) || passengerDefinition.is(BuiltinEntityType.CHEST_MINECART) || passengerDefinition.is(BuiltinEntityType.FURNACE_MINECART) || passengerDefinition.is(BuiltinEntityType.SPAWNER_MINECART) || passengerDefinition.is(BuiltinEntityType.COMMAND_BLOCK_MINECART) || passengerDefinition.is(BuiltinEntityType.SHULKER)) { - yOffset += passenger.getJavaDefinition().defaultBedrockDefinition().height() * 0.5f; + yOffset += passenger.height() * 0.5f; } else if (passengerDefinition.is(BuiltinEntityType.FALLING_BLOCK)) { yOffset += 0.995f; } if (mount instanceof BoatEntity) { - yOffset -= mount.getJavaDefinition().defaultBedrockDefinition().height() * 0.5f; + yOffset -= mount.height() * 0.5f; } if (passenger instanceof BoatEntity) { - yOffset += passenger.getJavaDefinition().defaultBedrockDefinition().height() * 0.5f; + yOffset += passenger.height() * 0.5f; } if (mount instanceof ArmorStandEntity armorStand) { yOffset -= armorStand.getYOffset(); diff --git a/core/src/main/resources/languages b/core/src/main/resources/languages index daa21574283..4ce8ad58ea7 160000 --- a/core/src/main/resources/languages +++ b/core/src/main/resources/languages @@ -1 +1 @@ -Subproject commit daa215742837ca1c16ef34e724bba98b6bc047a9 +Subproject commit 4ce8ad58ea7ab779d613a64862956d6d0563a8e3 diff --git a/core/src/test/java/org/geysermc/geyser/scoreboard/network/util/GeyserMockContextScoreboard.java b/core/src/test/java/org/geysermc/geyser/scoreboard/network/util/GeyserMockContextScoreboard.java index 8135039185d..54702a853e4 100644 --- a/core/src/test/java/org/geysermc/geyser/scoreboard/network/util/GeyserMockContextScoreboard.java +++ b/core/src/test/java/org/geysermc/geyser/scoreboard/network/util/GeyserMockContextScoreboard.java @@ -25,20 +25,11 @@ package org.geysermc.geyser.scoreboard.network.util; -import static org.geysermc.geyser.scoreboard.network.util.AssertUtils.assertNextPacketType; -import static org.geysermc.geyser.scoreboard.network.util.AssertUtils.assertNoNextPacket; -import static org.geysermc.geyser.scoreboard.network.util.GeyserMockContext.mockContext; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -import java.util.UUID; -import java.util.function.Consumer; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.packet.AddPlayerPacket; import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket; import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.entity.VanillaEntities; +import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.player.PlayerEntity; import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; import org.geysermc.geyser.session.GeyserSession; @@ -47,6 +38,17 @@ import org.geysermc.geyser.session.cache.waypoint.WaypointCache; import org.mockito.stubbing.Answer; +import java.util.UUID; +import java.util.function.Consumer; + +import static org.geysermc.geyser.scoreboard.network.util.AssertUtils.assertNextPacketType; +import static org.geysermc.geyser.scoreboard.network.util.AssertUtils.assertNoNextPacket; +import static org.geysermc.geyser.scoreboard.network.util.GeyserMockContext.mockContext; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + public class GeyserMockContextScoreboard { public static void mockContextScoreboard(Consumer geyserContext) { mockContext(context -> { @@ -96,7 +98,10 @@ public static PlayerEntity spawnPlayerSilently(GeyserMockContext context, String } public static PlayerEntity spawnPlayer(GeyserMockContext context, String username, long geyserId) { - var playerEntity = spy(new PlayerEntity(context.session(), (int) geyserId, geyserId, UUID.randomUUID(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, username, null)); + EntitySpawnContext entitySpawnContext = EntitySpawnContext.DUMMY_CONTEXT.apply(context.session(), UUID.randomUUID(), VanillaEntities.PLAYER); + entitySpawnContext.geyserId(geyserId); + entitySpawnContext.javaId((int) geyserId); + var playerEntity = spy(new PlayerEntity(entitySpawnContext, username, null)); var entityCache = context.mockOrSpy(EntityCache.class); entityCache.addPlayerEntity(playerEntity); From b2739e19481721f1d4de0465c42e36690883d778 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Wed, 26 Nov 2025 17:08:05 +0100 Subject: [PATCH 14/62] More work on events, closer to working --- .../geyser/api/entity/JavaEntityType.java | 18 ++ .../entity/custom/CustomJavaEntityType.java | 53 +++++ .../lifecycle/GeyserDefineEntitiesEvent.java | 8 +- .../entity/BedrockEntityDefinition.java | 4 + .../entity/BedrockEntityDefinitions.java | 23 ++- .../geyser/entity/GeyserEntityType.java | 100 +++++++++- ...va => NonVanillaEntityTypeDefinition.java} | 4 +- .../geyser/entity/VanillaEntities.java | 169 ++-------------- .../geyser/entity/VanillaEntityType.java | 14 +- .../geysermc/geyser/impl/IdentifierImpl.java | 9 + .../geysermc/geyser/registry/Registries.java | 14 +- .../java/entity/JavaAddEntityTranslator.java | 2 +- .../org/geysermc/geyser/util/EntityUtils.java | 188 +++++++++++++++++- 13 files changed, 425 insertions(+), 181 deletions(-) create mode 100644 api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java rename core/src/main/java/org/geysermc/geyser/entity/{GeyserCustomEntityTypeDefinition.java => NonVanillaEntityTypeDefinition.java} (86%) diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java index 2f84372f2f7..b2c120c0880 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java @@ -25,6 +25,8 @@ package org.geysermc.geyser.api.entity; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.geysermc.geyser.api.GeyserApi; import org.geysermc.geyser.api.util.Identifier; /** @@ -47,6 +49,16 @@ public interface JavaEntityType { */ boolean vanilla(); + /** + * @return the width of the Java entity + */ + float width(); + + /** + * @return the height of the Java entity + */ + float height(); + /** * Compares two entity identifiers. * @@ -56,4 +68,10 @@ public interface JavaEntityType { default boolean is(Identifier javaIdentifier) { return identifier().equals(javaIdentifier); } + + @Nullable GeyserEntityDefinition defaultBedrockDefinition(); + + static JavaEntityType ofVanilla(Identifier identifier) { + return GeyserApi.api().provider(JavaEntityType.class, identifier); + } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java new file mode 100644 index 00000000000..f9144ac9a2e --- /dev/null +++ b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.api.entity.custom; + +import org.checkerframework.checker.index.qual.NonNegative; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.geysermc.geyser.api.entity.GeyserEntityDefinition; +import org.geysermc.geyser.api.entity.JavaEntityType; +import org.geysermc.geyser.api.util.Identifier; + +public interface CustomJavaEntityType extends JavaEntityType { + + @Override + default boolean vanilla() { + return false; + }; + + interface Builder { + + Builder type(Identifier entityType); + + Builder javaId(int javaId); + + Builder width(@NonNegative float width); + + Builder height(@NonNegative float height); + + Builder defaultBedrockDefinition(@Nullable GeyserEntityDefinition defaultBedrockDefinition); + } +} diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java index f48038b1541..156d0dd7bd9 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java @@ -29,9 +29,10 @@ import org.geysermc.event.Event; import org.geysermc.geyser.api.entity.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; -import org.geysermc.geyser.api.util.Identifier; +import org.geysermc.geyser.api.entity.custom.CustomJavaEntityType; import java.util.Collection; +import java.util.function.Consumer; /** * Called when entities are defined within Geyser. @@ -64,8 +65,7 @@ default void register(CustomEntityDefinition.Builder builder) { /** * Registers a non-vanilla Java entity type. * - * @param javaEntityType the identifier of the Java entity type - * @param javaId the network id of this entity type + * @param builderConsumer the builder for the non-vanilla type */ - void registerEntityType(@NonNull Identifier javaEntityType, int javaId, CustomEntityDefinition defaultDefinition); + void registerEntityType(Consumer builderConsumer); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java index a578dac99a3..95ce91092c4 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java @@ -53,6 +53,10 @@ public static Builder builder() { return new Builder(); } + public static BedrockEntityDefinition of(Identifier identifier) { + return builder().identifier(identifier).build(); + } + @Override public List> properties() { if (registeredProperties.isEmpty()) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java index 2dee52b0812..0bfcdd0a70b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java @@ -32,15 +32,26 @@ * done here to be able to re-use the same bedrock entity across multiple Java types */ public class BedrockEntityDefinitions { - - // TODO re-usable Bedrock entity definitions?????????? - // Or rather... looking up otherwise?? public static final BedrockEntityDefinition ARMOR_STAND; + public static final BedrockEntityDefinition ARROW; + public static final BedrockEntityDefinition BOAT; + public static final BedrockEntityDefinition CHEST_BOAT; + public static final BedrockEntityDefinition EVOCATION_ILLAGER; + public static final BedrockEntityDefinition LLAMA; + public static final BedrockEntityDefinition MINECART; + public static final BedrockEntityDefinition SPLASH_POTION; + public static final BedrockEntityDefinition ZOMBIE; static { - ARMOR_STAND = BedrockEntityDefinition.builder() - .identifier(IdentifierImpl.of("armor_stand")) - .build(); + ARMOR_STAND = BedrockEntityDefinition.of(IdentifierImpl.of("armor_stand")); + ARROW = BedrockEntityDefinition.of(IdentifierImpl.of("arrow")); + BOAT = BedrockEntityDefinition.of(IdentifierImpl.of("boat")); + CHEST_BOAT = BedrockEntityDefinition.of(IdentifierImpl.of("chest_boat")); + EVOCATION_ILLAGER = BedrockEntityDefinition.of(IdentifierImpl.of("evocation_illager")); + LLAMA = BedrockEntityDefinition.of(IdentifierImpl.of("llama")); + MINECART = BedrockEntityDefinition.of(IdentifierImpl.of("minecraft")); + SPLASH_POTION = BedrockEntityDefinition.of(IdentifierImpl.of("splash_position")); + ZOMBIE = BedrockEntityDefinition.of(IdentifierImpl.of("zombie")); } public static void init() { diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java index 2dcc7b183b0..1b3d2e2571f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java @@ -29,14 +29,18 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import lombok.Getter; import net.kyori.adventure.key.Key; import org.checkerframework.checker.index.qual.NonNegative; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.Constants; +import org.geysermc.geyser.api.entity.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.JavaEntityType; +import org.geysermc.geyser.api.entity.custom.CustomJavaEntityType; import org.geysermc.geyser.api.util.Identifier; import org.geysermc.geyser.impl.IdentifierImpl; +import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.util.MinecraftKey; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.EntityType; @@ -46,7 +50,7 @@ import java.util.Map; import java.util.Objects; -public record GeyserEntityType(Identifier identifier, int javaId) implements JavaEntityType { +public record GeyserEntityType(Identifier identifier, int javaId) implements CustomJavaEntityType, JavaEntityType { private static final Identifier UNREGISTERED = IdentifierImpl.of(Constants.GEYSER_CUSTOM_NAMESPACE, "unregistered_sadface"); private static final Map VANILLA = new EnumMap<>(BuiltinEntityType.class); @@ -70,6 +74,33 @@ public boolean vanilla() { return VANILLA.containsValue(this); } + @Override + public float width() { + var definition = Registries.JAVA_ENTITY_TYPES.get(this); + if (definition == null) { + throw new IllegalStateException("No entity definition registered for " + this); + } + return definition.width(); + } + + @Override + public float height() { + var definition = Registries.JAVA_ENTITY_TYPES.get(this); + if (definition == null) { + throw new IllegalStateException("No entity definition registered for " + this); + } + return definition.height(); + } + + @Override + public @Nullable GeyserEntityDefinition defaultBedrockDefinition() { + var definition = Registries.JAVA_ENTITY_TYPES.get(this); + if (definition == null) { + throw new IllegalStateException("No entity definition registered for " + this); + } + return definition.defaultBedrockDefinition(); + } + public boolean is(EntityType type) { return javaId == type.id(); } @@ -111,8 +142,10 @@ public static GeyserEntityType of(EntityType type) { } @SuppressWarnings("ConstantValue") - public static GeyserEntityType createCustomAndRegister(@NonNull Identifier javaIdentifier, @NonNegative int javaId) { - Objects.requireNonNull(javaIdentifier, "javaIdentifier may not be null"); + public static GeyserEntityType createCustomAndRegister(Builder builder) { + Identifier javaIdentifier = Objects.requireNonNull(builder.identifier, "javaIdentifier may not be null"); + int javaId = builder.javaId; + if (javaIdentifier.vanilla()) { throw new IllegalArgumentException("Cannot register custom entity type in vanilla namespace!" + javaIdentifier); } else if (javaId < 0) { @@ -127,4 +160,65 @@ public static GeyserEntityType createCustomAndRegister(@NonNull Identifier javaI CUSTOM_BY_IDENTIFIER.put(javaIdentifier, type); return type; } + + @Getter + public static class Builder implements CustomJavaEntityType.Builder { + private Identifier identifier; + private int javaId; + private float width; + private float height; + private GeyserEntityDefinition defaultBedrockDefinition; + + @Override + public CustomJavaEntityType.Builder type(@NonNull Identifier entityType) { + Objects.requireNonNull(entityType, "entityType may not be null"); + if (entityType.vanilla()) { + throw new IllegalArgumentException("Cannot register custom entity type in vanilla namespace!" + entityType); + } + if (CUSTOM_BY_IDENTIFIER.containsKey(entityType)) { + throw new IllegalArgumentException("Custom entity type with identifier " + entityType + " already exists!"); + } + this.identifier = entityType; + return this; + } + + @Override + public CustomJavaEntityType.Builder javaId(int javaId) { + if (javaId < 0) { + throw new IllegalArgumentException("Invalid custom entity type id (may not be negative): " + javaId); + } + if (javaId < BuiltinEntityType.VALUES.length) { + throw new IllegalArgumentException("Invalid custom entity type id (conflicts with vanilla entity type): " + javaId); + } + if (CUSTOM.containsKey(javaId)) { + throw new IllegalArgumentException("Custom entity type with id " + javaId + " already exists!"); + } + this.javaId = javaId; + return this; + } + + @Override + public CustomJavaEntityType.Builder width(@NonNegative float width) { + if (width < 0) { + throw new IllegalArgumentException("Invalid custom entity type width (may not be negative): " + width); + } + this.width = width; + return this; + } + + @Override + public CustomJavaEntityType.Builder height(@NonNegative float height) { + if (height < 0) { + throw new IllegalArgumentException("Invalid custom entity type height (may not be negative): " + height); + } + this.height = height; + return this; + } + + @Override + public CustomJavaEntityType.Builder defaultBedrockDefinition(@Nullable GeyserEntityDefinition defaultBedrockDefinition) { + this.defaultBedrockDefinition = defaultBedrockDefinition; + return this; + } + } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityTypeDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/NonVanillaEntityTypeDefinition.java similarity index 86% rename from core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityTypeDefinition.java rename to core/src/main/java/org/geysermc/geyser/entity/NonVanillaEntityTypeDefinition.java index 6f0d95e5da3..3365848733b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserCustomEntityTypeDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/NonVanillaEntityTypeDefinition.java @@ -41,9 +41,9 @@ @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) // TODO -public class GeyserCustomEntityTypeDefinition extends EntityTypeDefinition { +public class NonVanillaEntityTypeDefinition extends EntityTypeDefinition { - public GeyserCustomEntityTypeDefinition(EntityFactory factory, GeyserEntityType type, BedrockEntityDefinition definition, List> translators) { + public NonVanillaEntityTypeDefinition(EntityFactory factory, GeyserEntityType type, BedrockEntityDefinition definition, List> translators) { super(factory, type, 0, 0,0, definition, translators); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntities.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntities.java index df3176ea2af..7042aa2d1a5 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntities.java +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntities.java @@ -25,26 +25,9 @@ package org.geysermc.geyser.entity; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.GeyserImpl; -import org.geysermc.geyser.api.entity.GeyserEntityDefinition; -import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; -import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; -import org.geysermc.geyser.api.entity.property.type.GeyserFloatEntityProperty; -import org.geysermc.geyser.api.entity.property.type.GeyserStringEnumProperty; -import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; -import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntityPropertiesEvent; -import org.geysermc.geyser.api.util.Identifier; import org.geysermc.geyser.entity.factory.EntityFactory; -import org.geysermc.geyser.entity.properties.type.BooleanProperty; -import org.geysermc.geyser.entity.properties.type.EnumProperty; -import org.geysermc.geyser.entity.properties.type.FloatProperty; -import org.geysermc.geyser.entity.properties.type.IntProperty; -import org.geysermc.geyser.entity.properties.type.PropertyType; -import org.geysermc.geyser.entity.properties.type.StringEnumProperty; import org.geysermc.geyser.entity.type.AbstractArrowEntity; import org.geysermc.geyser.entity.type.AbstractWindChargeEntity; import org.geysermc.geyser.entity.type.AreaEffectCloudEntity; @@ -171,16 +154,12 @@ import org.geysermc.geyser.impl.IdentifierImpl; import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.translator.text.MessageTranslator; +import org.geysermc.geyser.util.EntityUtils; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataTypes; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.FloatEntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - public final class VanillaEntities { public static final VanillaEntityType ACACIA_BOAT; public static final VanillaEntityType ACACIA_CHEST_BOAT; @@ -504,12 +483,12 @@ public final class VanillaEntities { SPLASH_POTION = VanillaEntityType.inherited(ThrownPotionEntity::new, throwableItemBase) .type(BuiltinEntityType.SPLASH_POTION) .heightAndWidth(0.25f) - .bedrockIdentifier("minecraft:splash_potion") + .bedrockDefinition(BedrockEntityDefinitions.SPLASH_POTION) .build(); LINGERING_POTION = VanillaEntityType.inherited(ThrownPotionEntity::new, throwableItemBase) .type(BuiltinEntityType.LINGERING_POTION) .heightAndWidth(0.25f) - .bedrockIdentifier("minecraft:splash_potion") + .bedrockDefinition(BedrockEntityDefinitions.SPLASH_POTION) .build(); SNOWBALL = VanillaEntityType.inherited(ThrowableItemEntity::new, throwableItemBase) .type(BuiltinEntityType.SNOWBALL) @@ -536,12 +515,13 @@ public final class VanillaEntities { ARROW = VanillaEntityType.inherited(ArrowEntity::new, abstractArrowBase) .type(BuiltinEntityType.ARROW) .heightAndWidth(0.25f) + .bedrockDefinition(BedrockEntityDefinitions.ARROW) .addTranslator(MetadataTypes.INT, ArrowEntity::setPotionEffectColor) .build(); SPECTRAL_ARROW = VanillaEntityType.inherited(AbstractArrowEntity::new, abstractArrowBase) .type(BuiltinEntityType.SPECTRAL_ARROW) .heightAndWidth(0.25f) - .bedrockIdentifier("minecraft:arrow") + .bedrockDefinition(BedrockEntityDefinitions.ARROW) .build(); TRIDENT = VanillaEntityType.inherited(TridentEntity::new, abstractArrowBase) // TODO remove class .type(BuiltinEntityType.TRIDENT) @@ -573,6 +553,7 @@ public final class VanillaEntities { .type(BuiltinEntityType.MINECART) .height(0.7f).width(0.98f) .offset(0.35f) + .bedrockDefinition(BedrockEntityDefinitions.MINECART) .addTranslator(MetadataTypes.INT, (minecartEntity, entityMetadata) -> minecartEntity.getDirtyMetadata().put(EntityDataTypes.STRUCTURAL_INTEGRITY, entityMetadata.getValue())) .addTranslator(MetadataTypes.INT, (minecartEntity, entityMetadata) -> minecartEntity.getDirtyMetadata().put(EntityDataTypes.HURT_DIRECTION, entityMetadata.getValue())) // Direction in which the minecart is shaking .addTranslator(MetadataTypes.FLOAT, (minecartEntity, entityMetadata) -> @@ -591,7 +572,7 @@ public final class VanillaEntities { .build(); FURNACE_MINECART = VanillaEntityType.inherited(FurnaceMinecartEntity::new, MINECART) .type(BuiltinEntityType.FURNACE_MINECART) - .bedrockIdentifier("minecraft:minecart") + .bedrockDefinition(BedrockEntityDefinitions.MINECART) .addTranslator(MetadataTypes.BOOLEAN, FurnaceMinecartEntity::setHasFuel) .build(); HOPPER_MINECART = VanillaEntityType.inherited(MINECART.factory(), MINECART) @@ -599,7 +580,7 @@ public final class VanillaEntities { .build(); SPAWNER_MINECART = VanillaEntityType.inherited(SpawnerMinecartEntity::new, MINECART) .type(BuiltinEntityType.SPAWNER_MINECART) - .bedrockIdentifier("minecraft:minecart") + .bedrockDefinition(BedrockEntityDefinitions.MINECART) .build(); TNT_MINECART = VanillaEntityType.inherited(MINECART.factory(), MINECART) .type(BuiltinEntityType.TNT_MINECART) @@ -617,9 +598,6 @@ public final class VanillaEntities { .identifier(dangerousSkull) .build(); Registries.BEDROCK_ENTITY_DEFINITIONS.get().put(dangerousSkull, bedrockDefinition); - -// WITHER_SKULL_DANGEROUS = VanillaEntityType.inherited(WITHER_SKULL.factory(), WITHER_SKULL) -// .build(false); } // Boats @@ -791,7 +769,7 @@ public final class VanillaEntities { .type(BuiltinEntityType.GIANT) .height(1.8f).width(1.6f) .offset(1.62f) - .bedrockIdentifier("minecraft:zombie") + .bedrockDefinition(BedrockEntityDefinitions.ZOMBIE) .build(); IRON_GOLEM = VanillaEntityType.inherited(IronGolemEntity::new, mobEntityBase) .type(BuiltinEntityType.IRON_GOLEM) @@ -872,6 +850,7 @@ public final class VanillaEntities { .type(BuiltinEntityType.ZOMBIE) .height(1.8f).width(0.6f) .offset(1.62f) + .bedrockDefinition(BedrockEntityDefinitions.ZOMBIE) .addTranslator(MetadataTypes.BOOLEAN, ZombieEntity::setZombieBaby) .addTranslator(null) // "set special type", doesn't do anything .addTranslator(MetadataTypes.BOOLEAN, ZombieEntity::setConvertingToDrowned) @@ -971,12 +950,12 @@ public final class VanillaEntities { EVOKER = VanillaEntityType.inherited(SpellcasterIllagerEntity::new, spellcasterEntityBase) .type(BuiltinEntityType.EVOKER) .height(1.95f).width(0.6f) - .bedrockIdentifier("minecraft:evocation_illager") + .bedrockDefinition(BedrockEntityDefinitions.EVOCATION_ILLAGER) .build(); ILLUSIONER = VanillaEntityType.inherited(SpellcasterIllagerEntity::new, spellcasterEntityBase) .type(BuiltinEntityType.ILLUSIONER) .height(1.95f).width(0.6f) - .bedrockIdentifier("minecraft:evocation_illager") + .bedrockDefinition(BedrockEntityDefinitions.EVOCATION_ILLAGER) .build(); PILLAGER = VanillaEntityType.inherited(PillagerEntity::new, raidParticipantEntityBase) .type(BuiltinEntityType.PILLAGER) @@ -1139,7 +1118,7 @@ public final class VanillaEntities { VanillaEntityType abstractVillagerEntityBase = VanillaEntityType.inherited(AbstractMerchantEntity::new, ageableEntityBase) .addTranslator(null) // Unhappy ticks - .build(); + .build(false); VILLAGER = VanillaEntityType.inherited(VillagerEntity::new, abstractVillagerEntityBase) .type(BuiltinEntityType.VILLAGER) .height(1.8f).width(0.6f) @@ -1212,12 +1191,13 @@ public final class VanillaEntities { LLAMA = VanillaEntityType.inherited(LlamaEntity::new, chestedHorseEntityBase) .type(BuiltinEntityType.LLAMA) .height(1.87f).width(0.9f) + .bedrockDefinition(BedrockEntityDefinitions.LLAMA) .addTranslator(MetadataTypes.INT, LlamaEntity::setStrength) .addTranslator(MetadataTypes.INT, (entity, entityMetadata) -> entity.getDirtyMetadata().put(EntityDataTypes.VARIANT, entityMetadata.getValue())) .build(); TRADER_LLAMA = VanillaEntityType.inherited(TraderLlamaEntity::new, LLAMA) .type(BuiltinEntityType.TRADER_LLAMA) - .bedrockIdentifier("minecraft:llama") + .bedrockDefinition(BedrockEntityDefinitions.LLAMA) .build(); } @@ -1263,132 +1243,19 @@ public final class VanillaEntities { private static VanillaEntityType buildBoat(EntityTypeBase base, BuiltinEntityType BuiltinEntityType, BoatEntity.BoatVariant variant) { return VanillaEntityType.inherited(context -> new BoatEntity(context, variant), base) .type(BuiltinEntityType) - .bedrockIdentifier("minecraft:boat") + .bedrockDefinition(BedrockEntityDefinitions.BOAT) .build(); } private static VanillaEntityType buildChestBoat(EntityTypeBase base, BuiltinEntityType BuiltinEntityType, BoatEntity.BoatVariant variant) { return VanillaEntityType.inherited(context -> new ChestBoatEntity(context, variant), base) .type(BuiltinEntityType) - .bedrockIdentifier("minecraft:chest_boat") + .bedrockDefinition(BedrockEntityDefinitions.CHEST_BOAT) .build(); } public static void init() { - // entities would be initialized before these events are called - GeyserImpl.getInstance().getEventBus().fire(new GeyserDefineEntitiesEvent() { - - @Override - public Collection entities() { - return Collections.unmodifiableCollection(Registries.BEDROCK_ENTITY_DEFINITIONS.get().values()); - } - - @Override - public void register(@NonNull CustomEntityDefinition customEntityDefinition) { - Objects.requireNonNull(customEntityDefinition); - if (!(customEntityDefinition instanceof GeyserCustomEntityTypeDefinition geyserCustomEntityDefinition)) { - throw new IllegalStateException("Unknown custom entity definition: " + customEntityDefinition); - } - Registries.CUSTOM_ENTITY_DEFINITIONS.register(Registries.CUSTOM_ENTITY_DEFINITIONS.get().size(), geyserCustomEntityDefinition); - } - - @Override - public void registerEntityType(@NonNull Identifier javaEntityType, int javaId, CustomEntityDefinition definition) { - GeyserEntityType.createCustomAndRegister(javaEntityType, javaId); - - // TODO allow extending vanilla entities? - - } - }); - - GeyserImpl.getInstance().getEventBus().fire(new GeyserDefineEntityPropertiesEvent() { - @Override - public GeyserFloatEntityProperty registerFloatProperty(@NonNull Identifier identifier, @NonNull Identifier propertyId, float min, float max, @Nullable Float defaultValue) { - Objects.requireNonNull(identifier); - Objects.requireNonNull(propertyId); - if (propertyId.vanilla()) { - throw new IllegalArgumentException("Cannot register custom property in vanilla namespace! " + propertyId); - } - FloatProperty property = new FloatProperty(propertyId, max, min, defaultValue); - registerProperty(identifier, property); - return property; - } - - @Override - public IntProperty registerIntegerProperty(@NonNull Identifier identifier, @NonNull Identifier propertyId, int min, int max, @Nullable Integer defaultValue) { - Objects.requireNonNull(identifier); - Objects.requireNonNull(propertyId); - if (propertyId.vanilla()) { - throw new IllegalArgumentException("Cannot register custom property in vanilla namespace! " + propertyId); - } - IntProperty property = new IntProperty(propertyId, max, min, defaultValue); - registerProperty(identifier, property); - return property; - } - - @Override - public BooleanProperty registerBooleanProperty(@NonNull Identifier identifier, @NonNull Identifier propertyId, boolean defaultValue) { - Objects.requireNonNull(identifier); - Objects.requireNonNull(propertyId); - if (propertyId.vanilla()) { - throw new IllegalArgumentException("Cannot register custom property in vanilla namespace! " + propertyId); - } - BooleanProperty property = new BooleanProperty(propertyId, defaultValue); - registerProperty(identifier, property); - return property; - } - - @Override - public > EnumProperty registerEnumProperty(@NonNull Identifier identifier, @NonNull Identifier propertyId, @NonNull Class enumClass, @Nullable E defaultValue) { - Objects.requireNonNull(identifier); - Objects.requireNonNull(propertyId); - Objects.requireNonNull(enumClass); - if (propertyId.vanilla()) { - throw new IllegalArgumentException("Cannot register custom property in vanilla namespace! " + propertyId); - } - EnumProperty property = new EnumProperty<>(propertyId, enumClass, defaultValue == null ? enumClass.getEnumConstants()[0] : defaultValue); - registerProperty(identifier, property); - return property; - } - - @Override - public GeyserStringEnumProperty registerEnumProperty(@NonNull Identifier identifier, @NonNull Identifier propertyId, @NonNull List values, @Nullable String defaultValue) { - Objects.requireNonNull(identifier); - Objects.requireNonNull(propertyId); - Objects.requireNonNull(values); - if (propertyId.vanilla()) { - throw new IllegalArgumentException("Cannot register custom property in vanilla namespace! " + propertyId); - } - StringEnumProperty property = new StringEnumProperty(propertyId, values, defaultValue); - registerProperty(identifier, property); - return property; - } - - @Override - public Collection> properties(@NonNull Identifier identifier) { - Objects.requireNonNull(identifier); - var definition = Registries.BEDROCK_ENTITY_DEFINITIONS.get(identifier); - if (definition == null) { - throw new IllegalArgumentException("Unknown entity type: " + identifier); - } - return List.copyOf(definition.registeredProperties().getProperties()); - } - }); - - for (var definition : Registries.BEDROCK_ENTITY_DEFINITIONS.get().values()) { - if (definition.registeredProperties() != null) { - Registries.BEDROCK_ENTITY_PROPERTIES.get().add(definition.registeredProperties().toNbtMap(definition.identifier().toString())); - } - } - } - - private static void registerProperty(Identifier entityType, PropertyType property) { - var definition = Registries.BEDROCK_ENTITY_DEFINITIONS.get(entityType); - if (definition == null) { - throw new IllegalArgumentException("Unknown entity type: " + entityType); - } - - definition.registeredProperties().add(entityType.toString(), property); + EntityUtils.callEntityEvents(); } private VanillaEntities() { diff --git a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java index 60e34261205..acd35c07c28 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java @@ -34,6 +34,7 @@ import org.geysermc.geyser.entity.factory.EntityFactory; import org.geysermc.geyser.entity.properties.type.PropertyType; import org.geysermc.geyser.entity.type.Entity; +import org.geysermc.geyser.impl.IdentifierImpl; import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.translator.entity.EntityMetadataTranslator; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; @@ -144,21 +145,26 @@ public VanillaEntityType build() { * set to false if we're not expecting this entity to spawn from the network. */ public VanillaEntityType build(boolean register) { - if (type == null) { + if (register && type == null) { throw new IllegalStateException("Missing entity type!"); } if (bedrockDefinition == null) { + Identifier identifier = bedrockIdentifier == null ? type.identifier() : IdentifierImpl.parse(bedrockIdentifier); + if (Registries.BEDROCK_ENTITY_DEFINITIONS.get().containsKey(identifier)) { + throw new IllegalStateException("Duplicate bedrock identifier: " + bedrockIdentifier); + } + bedrockDefinition = BedrockEntityDefinition.builder() .properties(propertiesBuilder) - .identifier(Identifier.of(bedrockIdentifier)) + .identifier(identifier) .build(); - Registries.BEDROCK_ENTITY_DEFINITIONS.get().put(Identifier.of(bedrockIdentifier), bedrockDefinition); + Registries.BEDROCK_ENTITY_DEFINITIONS.get().put(identifier, bedrockDefinition); } VanillaEntityType definition = new VanillaEntityType<>(factory, type, width, height, offset, bedrockDefinition, translators); if (register && definition.entityType() != null) { - Registries.ENTITY_DEFINITIONS.get().putIfAbsent(definition.entityType(), definition); + Registries.JAVA_ENTITY_TYPES.get().putIfAbsent(definition.entityType(), definition); Registries.JAVA_ENTITY_IDENTIFIERS.get().putIfAbsent(type.identifier().toString(), definition); } return definition; diff --git a/core/src/main/java/org/geysermc/geyser/impl/IdentifierImpl.java b/core/src/main/java/org/geysermc/geyser/impl/IdentifierImpl.java index ef06bd67360..66c6edda77b 100644 --- a/core/src/main/java/org/geysermc/geyser/impl/IdentifierImpl.java +++ b/core/src/main/java/org/geysermc/geyser/impl/IdentifierImpl.java @@ -45,6 +45,15 @@ public static IdentifierImpl of(String namespace, String value) throws IllegalAr } } + public static IdentifierImpl parse(String value) { + Objects.requireNonNull(value, "value cannot be null!"); + try { + return new IdentifierImpl(MinecraftKey.key(value)); + } catch (InvalidKeyException exception) { + throw new IllegalArgumentException(exception); + } + } + // FIXME using the identifier interface from the API breaks tests public static IdentifierImpl of(String value) { return of(Identifier.DEFAULT_NAMESPACE, value); diff --git a/core/src/main/java/org/geysermc/geyser/registry/Registries.java b/core/src/main/java/org/geysermc/geyser/registry/Registries.java index f5722a43b6a..8aae79dad90 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/Registries.java +++ b/core/src/main/java/org/geysermc/geyser/registry/Registries.java @@ -40,7 +40,6 @@ import org.geysermc.geyser.api.util.Identifier; import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.entity.GeyserCustomEntityTypeDefinition; import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.inventory.recipe.GeyserRecipe; import org.geysermc.geyser.item.type.Item; @@ -123,13 +122,15 @@ public final class Registries { */ public static final SimpleMappedDeferredRegistry BLOCK_ENTITIES = SimpleMappedDeferredRegistry.create("org.geysermc.geyser.translator.level.block.entity.BlockEntity", BlockEntityRegistryLoader::new); + /** + * A map containing all Java entity identifiers and their respective Geyser definitions + */ + public static final SimpleMappedRegistry> JAVA_ENTITY_IDENTIFIERS = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new)); /** * A map containing all entity types and their respective Geyser definitions */ // Is a Reference2ObjectMap since GeyserEntityType, the implementation of JavaEntityType, only ever keeps one instance per registered entity type - public static final SimpleMappedRegistry> ENTITY_DEFINITIONS = SimpleMappedRegistry.create(RegistryLoaders.empty(Reference2ObjectOpenHashMap::new)); - - public static final ListRegistry> CUSTOM_ENTITY_DEFINITIONS = ListRegistry.create(RegistryLoaders.empty(ArrayList::new)); + public static final SimpleMappedRegistry> JAVA_ENTITY_TYPES = SimpleMappedRegistry.create(RegistryLoaders.empty(Reference2ObjectOpenHashMap::new)); public static final SimpleMappedRegistry BEDROCK_ENTITY_DEFINITIONS = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new)); @@ -138,11 +139,6 @@ public final class Registries { */ public static final SimpleRegistry> BEDROCK_ENTITY_PROPERTIES = SimpleRegistry.create(RegistryLoaders.empty(HashSet::new)); - /** - * A map containing all Java entity identifiers and their respective Geyser definitions - */ - public static final SimpleMappedRegistry> JAVA_ENTITY_IDENTIFIERS = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new)); - /** * A registry containing all the Java packet translators. */ diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java index e02160c5880..0d97af97b71 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java @@ -63,7 +63,7 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) return; } - EntityTypeDefinition definition = Registries.ENTITY_DEFINITIONS.get(type); + EntityTypeDefinition definition = Registries.JAVA_ENTITY_TYPES.get(type); if (definition == null) { session.getGeyser().getLogger().warning("Could not find an entity definition for add entity packet " + packet); return; diff --git a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java index 3380e489435..13523d39eea 100644 --- a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java @@ -29,13 +29,31 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; +import org.cloudburstmc.nbt.NbtMap; +import org.cloudburstmc.nbt.NbtType; import org.cloudburstmc.protocol.bedrock.data.GameType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.api.entity.GeyserEntityDefinition; +import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; +import org.geysermc.geyser.api.entity.custom.CustomJavaEntityType; +import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; +import org.geysermc.geyser.api.entity.property.type.GeyserFloatEntityProperty; +import org.geysermc.geyser.api.entity.property.type.GeyserStringEnumProperty; +import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; +import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntityPropertiesEvent; import org.geysermc.geyser.api.util.Identifier; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityTypeDefinition; -import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.GeyserEntityType; +import org.geysermc.geyser.entity.VanillaEntities; +import org.geysermc.geyser.entity.properties.type.BooleanProperty; +import org.geysermc.geyser.entity.properties.type.EnumProperty; +import org.geysermc.geyser.entity.properties.type.FloatProperty; +import org.geysermc.geyser.entity.properties.type.IntProperty; +import org.geysermc.geyser.entity.properties.type.PropertyType; +import org.geysermc.geyser.entity.properties.type.StringEnumProperty; import org.geysermc.geyser.entity.type.BoatEntity; import org.geysermc.geyser.entity.type.ChestBoatEntity; import org.geysermc.geyser.entity.type.Entity; @@ -46,6 +64,7 @@ import org.geysermc.geyser.entity.type.living.animal.horse.CamelEntity; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; +import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.registry.JavaRegistries; import org.geysermc.geyser.session.cache.tags.GeyserHolderSet; @@ -56,11 +75,19 @@ import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; import org.geysermc.mcprotocollib.protocol.data.game.item.component.Equippable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; import java.util.Locale; +import java.util.Objects; import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; public final class EntityUtils { + private static final AtomicInteger RUNTIME_ID_ALLOCATOR = new AtomicInteger(100000); public static final float PLAYER_ENTITY_OFFSET = 1.62F; /** @@ -392,6 +419,165 @@ public static UUID uuidFromIntArray(int[] uuid) { return null; } + public static void callEntityEvents() { + // entities would be initialized before these events are called + List customEntities = new ArrayList<>(); + GeyserImpl.getInstance().getEventBus().fire(new GeyserDefineEntitiesEvent() { + + @Override + public Collection entities() { + return Collections.unmodifiableCollection(Registries.BEDROCK_ENTITY_DEFINITIONS.get().values()); + } + + @Override + public void register(@NonNull CustomEntityDefinition customEntityDefinition) { + Objects.requireNonNull(customEntityDefinition); + if (!(customEntityDefinition instanceof BedrockEntityDefinition definition)) { + throw new IllegalStateException("Unknown custom entity definition: " + customEntityDefinition); + } + if (Registries.BEDROCK_ENTITY_DEFINITIONS.get().containsKey(definition.identifier())) { + throw new IllegalStateException("Duplicate custom entity definition: " + customEntityDefinition); + } + Registries.BEDROCK_ENTITY_DEFINITIONS.register(definition.identifier(), definition); + customEntities.add(definition); + } + + @Override + public void registerEntityType(Consumer consumer) { + var builder = new GeyserEntityType.Builder(); + consumer.accept(builder); + + var type = GeyserEntityType.createCustomAndRegister(builder); + + Registries.JAVA_ENTITY_TYPES.register(type, null); + Registries.JAVA_ENTITY_IDENTIFIERS.register(type.identifier().toString(), null); + + var defaultBedrockDefinition = type.defaultBedrockDefinition(); + if (defaultBedrockDefinition != null && !isRegistered(defaultBedrockDefinition) + && defaultBedrockDefinition instanceof CustomEntityDefinition customEntityDefinition) { + register(customEntityDefinition); + } + } + + public boolean isRegistered(GeyserEntityDefinition definition) { + return Registries.BEDROCK_ENTITY_DEFINITIONS.get().containsKey(definition.identifier()); + } + }); + + if (!customEntities.isEmpty()) { + NbtMap nbt = Registries.BEDROCK_ENTITY_IDENTIFIERS.get(); + List idlist = new ArrayList<>(nbt.getList("idlist", NbtType.COMPOUND)); + + for (BedrockEntityDefinition definition : customEntities) { + idlist.add(NbtMap.builder() + .putBoolean("hasSpawnEgg", false) + .putString("id", definition.identifier().toString()) + .putBoolean("summonable", true) + .putString("bid", "") + .putInt("rid", RUNTIME_ID_ALLOCATOR.getAndIncrement()) + .putBoolean("experimental", false) + .build()); + GeyserImpl.getInstance().getLogger().debug("Registered custom entity " + definition.identifier()); + } + + NbtMap newIdentifiers = nbt.toBuilder() + .putList("idlist", NbtType.COMPOUND, idlist) + .build(); + + Registries.BEDROCK_ENTITY_IDENTIFIERS.set(newIdentifiers); + GeyserImpl.getInstance().getLogger().debug("Registered " + customEntities.size() + " custom entities"); + } + + GeyserImpl.getInstance().getEventBus().fire(new GeyserDefineEntityPropertiesEvent() { + @Override + public GeyserFloatEntityProperty registerFloatProperty(@NonNull Identifier identifier, @NonNull Identifier propertyId, float min, float max, @Nullable Float defaultValue) { + Objects.requireNonNull(identifier); + Objects.requireNonNull(propertyId); + if (propertyId.vanilla()) { + throw new IllegalArgumentException("Cannot register custom property in vanilla namespace! " + propertyId); + } + FloatProperty property = new FloatProperty(propertyId, max, min, defaultValue); + registerProperty(identifier, property); + return property; + } + + @Override + public IntProperty registerIntegerProperty(@NonNull Identifier identifier, @NonNull Identifier propertyId, int min, int max, @Nullable Integer defaultValue) { + Objects.requireNonNull(identifier); + Objects.requireNonNull(propertyId); + if (propertyId.vanilla()) { + throw new IllegalArgumentException("Cannot register custom property in vanilla namespace! " + propertyId); + } + IntProperty property = new IntProperty(propertyId, max, min, defaultValue); + registerProperty(identifier, property); + return property; + } + + @Override + public BooleanProperty registerBooleanProperty(@NonNull Identifier identifier, @NonNull Identifier propertyId, boolean defaultValue) { + Objects.requireNonNull(identifier); + Objects.requireNonNull(propertyId); + if (propertyId.vanilla()) { + throw new IllegalArgumentException("Cannot register custom property in vanilla namespace! " + propertyId); + } + BooleanProperty property = new BooleanProperty(propertyId, defaultValue); + registerProperty(identifier, property); + return property; + } + + @Override + public > EnumProperty registerEnumProperty(@NonNull Identifier identifier, @NonNull Identifier propertyId, @NonNull Class enumClass, @Nullable E defaultValue) { + Objects.requireNonNull(identifier); + Objects.requireNonNull(propertyId); + Objects.requireNonNull(enumClass); + if (propertyId.vanilla()) { + throw new IllegalArgumentException("Cannot register custom property in vanilla namespace! " + propertyId); + } + EnumProperty property = new EnumProperty<>(propertyId, enumClass, defaultValue == null ? enumClass.getEnumConstants()[0] : defaultValue); + registerProperty(identifier, property); + return property; + } + + @Override + public GeyserStringEnumProperty registerEnumProperty(@NonNull Identifier identifier, @NonNull Identifier propertyId, @NonNull List values, @Nullable String defaultValue) { + Objects.requireNonNull(identifier); + Objects.requireNonNull(propertyId); + Objects.requireNonNull(values); + if (propertyId.vanilla()) { + throw new IllegalArgumentException("Cannot register custom property in vanilla namespace! " + propertyId); + } + StringEnumProperty property = new StringEnumProperty(propertyId, values, defaultValue); + registerProperty(identifier, property); + return property; + } + + @Override + public Collection> properties(@NonNull Identifier identifier) { + Objects.requireNonNull(identifier); + var definition = Registries.BEDROCK_ENTITY_DEFINITIONS.get(identifier); + if (definition == null) { + throw new IllegalArgumentException("Unknown entity type: " + identifier); + } + return List.copyOf(definition.registeredProperties().getProperties()); + } + }); + + for (var definition : Registries.BEDROCK_ENTITY_DEFINITIONS.get().values()) { + if (definition.registeredProperties() != null) { + Registries.BEDROCK_ENTITY_PROPERTIES.get().add(definition.registeredProperties().toNbtMap(definition.identifier().toString())); + } + } + } + + private static void registerProperty(Identifier entityType, PropertyType property) { + var definition = Registries.BEDROCK_ENTITY_DEFINITIONS.get(entityType); + if (definition == null) { + throw new IllegalArgumentException("Unknown entity type: " + entityType); + } + + definition.registeredProperties().add(entityType.toString(), property); + } + private EntityUtils() { } } From 52b76f5b6f6c810a435054bb5513d620ec8163e6 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Wed, 26 Nov 2025 20:36:33 +0100 Subject: [PATCH 15/62] Fix startup --- .../geyser/entity/VanillaEntityType.java | 30 ++++++++++--------- .../org/geysermc/geyser/util/EntityUtils.java | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java index acd35c07c28..b9edb0d8d63 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java @@ -145,25 +145,27 @@ public VanillaEntityType build() { * set to false if we're not expecting this entity to spawn from the network. */ public VanillaEntityType build(boolean register) { - if (register && type == null) { - throw new IllegalStateException("Missing entity type!"); - } - - if (bedrockDefinition == null) { - Identifier identifier = bedrockIdentifier == null ? type.identifier() : IdentifierImpl.parse(bedrockIdentifier); - if (Registries.BEDROCK_ENTITY_DEFINITIONS.get().containsKey(identifier)) { - throw new IllegalStateException("Duplicate bedrock identifier: " + bedrockIdentifier); + if (register) { + if (type == null) { + throw new IllegalStateException("Missing entity type!"); } - bedrockDefinition = BedrockEntityDefinition.builder() - .properties(propertiesBuilder) - .identifier(identifier) - .build(); - Registries.BEDROCK_ENTITY_DEFINITIONS.get().put(identifier, bedrockDefinition); + if (bedrockDefinition == null) { + Identifier identifier = bedrockIdentifier == null ? type.identifier() : IdentifierImpl.parse(bedrockIdentifier); + if (Registries.BEDROCK_ENTITY_DEFINITIONS.get().containsKey(identifier)) { + throw new IllegalStateException("Duplicate bedrock identifier: " + bedrockIdentifier); + } + + bedrockDefinition = BedrockEntityDefinition.builder() + .properties(propertiesBuilder) + .identifier(identifier) + .build(); + Registries.BEDROCK_ENTITY_DEFINITIONS.get().put(identifier, bedrockDefinition); + } } VanillaEntityType definition = new VanillaEntityType<>(factory, type, width, height, offset, bedrockDefinition, translators); - if (register && definition.entityType() != null) { + if (register && type != null) { Registries.JAVA_ENTITY_TYPES.get().putIfAbsent(definition.entityType(), definition); Registries.JAVA_ENTITY_IDENTIFIERS.get().putIfAbsent(type.identifier().toString(), definition); } diff --git a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java index 13523d39eea..46a433fabd6 100644 --- a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java @@ -563,7 +563,7 @@ public Collection> properties(@NonNull Identifier identi }); for (var definition : Registries.BEDROCK_ENTITY_DEFINITIONS.get().values()) { - if (definition.registeredProperties() != null) { + if (!definition.registeredProperties().isEmpty()) { Registries.BEDROCK_ENTITY_PROPERTIES.get().add(definition.registeredProperties().toNbtMap(definition.identifier().toString())); } } From 8f8e3bea8c8764e6d3c319862f23c2f645d1a869 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Thu, 27 Nov 2025 18:43:49 +0100 Subject: [PATCH 16/62] Expose geyserId in API, add SessionAttachParrotsEvent --- .../geyser/api/entity/type/GeyserEntity.java | 33 ++++- .../bedrock/SessionAttachParrotsEvent.java | 55 ++++++++ .../bedrock/SessionSpawnEntityEvent.java | 69 ++++++++++ .../event/java/ServerSpawnEntityEvent.java | 42 ++---- .../geyser/entity/GeyserEntityData.java | 2 +- .../entity/spawn/EntitySpawnContext.java | 123 +++++++++++++++--- .../geyser/entity/type/BoatEntity.java | 10 -- .../geysermc/geyser/entity/type/Entity.java | 25 ++-- .../geyser/entity/type/FireworkEntity.java | 4 +- .../geyser/entity/type/FishingHookEntity.java | 4 +- .../geyser/entity/type/InteractionEntity.java | 2 +- .../geyser/entity/type/living/MobEntity.java | 3 +- .../entity/type/living/animal/FrogEntity.java | 2 +- .../type/living/animal/HoglinEntity.java | 2 +- .../living/animal/tameable/CatEntity.java | 4 +- .../living/animal/tameable/ParrotEntity.java | 4 +- .../animal/tameable/TameableEntity.java | 2 +- .../living/animal/tameable/WolfEntity.java | 6 +- .../type/living/monster/BasePiglinEntity.java | 2 +- .../living/monster/EnderDragonPartEntity.java | 4 +- .../type/living/monster/GuardianEntity.java | 2 +- .../entity/type/living/monster/VexEntity.java | 2 +- .../type/living/monster/WitherEntity.java | 2 +- .../type/living/monster/ZoglinEntity.java | 2 +- .../living/monster/raid/VindicatorEntity.java | 2 +- .../entity/type/player/PlayerEntity.java | 6 +- .../type/player/SessionPlayerEntity.java | 3 +- .../entity/vehicle/VehicleComponent.java | 2 +- .../level/physics/CollisionManager.java | 2 +- .../display/slot/BelownameDisplaySlot.java | 4 +- .../display/slot/PlayerlistDisplaySlot.java | 10 +- .../geyser/session/GeyserSession.java | 12 +- .../geyser/session/cache/EntityCache.java | 4 +- .../geyser/session/cache/PistonCache.java | 2 +- .../cache/waypoint/GeyserWaypoint.java | 2 +- .../session/cache/waypoint/WaypointCache.java | 4 +- .../org/geysermc/geyser/skin/SkinManager.java | 4 +- .../MerchantInventoryTranslator.java | 2 +- .../entity/VaultBlockEntityTranslator.java | 4 +- .../BedrockNetworkStackLatencyTranslator.java | 2 +- ...SetLocalPlayerAsInitializedTranslator.java | 2 +- .../entity/player/BedrockEmoteTranslator.java | 2 +- .../player/BedrockInteractTranslator.java | 8 +- .../player/BedrockPlayerActionTranslator.java | 6 +- .../BedrockPlayerAuthInputTranslator.java | 2 +- .../java/entity/JavaAddEntityTranslator.java | 2 +- .../java/entity/JavaAnimateTranslator.java | 8 +- .../entity/JavaDamageEventTranslator.java | 2 +- .../entity/JavaEntityEventTranslator.java | 8 +- .../entity/JavaRemoveMobEffectTranslator.java | 2 +- .../entity/JavaSetEntityLinkTranslator.java | 4 +- .../entity/JavaSetEntityMotionTranslator.java | 2 +- .../entity/JavaSetPassengersTranslator.java | 4 +- .../entity/JavaTakeItemEntityTranslator.java | 4 +- .../entity/JavaUpdateMobEffectTranslator.java | 4 +- .../player/JavaPlayerPositionTranslator.java | 4 +- .../player/JavaSetExperienceTranslator.java | 2 +- .../player/JavaSetHealthTranslator.java | 2 +- .../JavaHorseScreenOpenTranslator.java | 2 +- .../JavaMerchantOffersTranslator.java | 4 +- .../java/level/JavaExplodeTranslator.java | 2 +- .../java/level/JavaGameEventTranslator.java | 6 +- .../geysermc/geyser/util/DimensionUtils.java | 4 +- .../util/GeyserMockContextScoreboard.java | 2 +- 64 files changed, 381 insertions(+), 178 deletions(-) create mode 100644 api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionAttachParrotsEvent.java create mode 100644 api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionSpawnEntityEvent.java diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java b/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java index 86fa9d8faa0..17d7ac51f7a 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.api.entity.type; import org.checkerframework.checker.index.qual.NonNegative; +import org.checkerframework.checker.index.qual.Positive; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; @@ -44,21 +45,28 @@ */ public interface GeyserEntity { /** - * @return the entity ID that the server has assigned to this entity. + * @return the entity ID that the server has assigned to this entity, or null if none is present */ @NonNegative int javaId(); /** - * @return the entity uuid that the server has assigned to this entity + * @return the Geyser entity id that the Bedrock client sees */ - @NonNull + @Positive + long geyserId(); + + /** + * @return the entity uuid that the server has assigned to this entity, + * or null if none is assigned + */ + @Nullable UUID uuid(); /** * @return the Bedrock entity definition */ - GeyserEntityDefinition definition(); + @NonNull GeyserEntityDefinition definition(); /** * The position of this entity, without the Bedrock edition offset @@ -66,7 +74,22 @@ public interface GeyserEntity { * * @return the position of the entity, as it is known to the Java server. */ - Vector3f position(); + @NonNull Vector3f position(); + + /** + * @return the width of the entity + */ + float width(); + + /** + * @return the height of the entity + */ + float height(); + + /** + * @return the offset of the entity + */ + float offset(); /** * Updates an entity property with a new value. diff --git a/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionAttachParrotsEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionAttachParrotsEvent.java new file mode 100644 index 00000000000..e44e04cf909 --- /dev/null +++ b/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionAttachParrotsEvent.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.api.event.bedrock; + +import org.checkerframework.checker.nullness.qual.NonNull; +import org.geysermc.geyser.api.connection.GeyserConnection; +import org.geysermc.geyser.api.entity.type.player.GeyserPlayerEntity; + +/** + * Called when the Java server attaches parrots to a player. + */ +public abstract class SessionAttachParrotsEvent extends SessionSpawnEntityEvent { + + public SessionAttachParrotsEvent(@NonNull GeyserConnection connection) { + super(connection); + } + + /** + * @return the player with bird friends + */ + public abstract GeyserPlayerEntity player(); + + /** + * @return the parrot variant + */ + public abstract int variant(); + + /** + * @return true if parrot is on the right shoulder, left otherwise + */ + public abstract boolean right(); +} diff --git a/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionSpawnEntityEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionSpawnEntityEvent.java new file mode 100644 index 00000000000..24d76072447 --- /dev/null +++ b/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionSpawnEntityEvent.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.api.event.bedrock; + +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.geysermc.event.Cancellable; +import org.geysermc.geyser.api.connection.GeyserConnection; +import org.geysermc.geyser.api.entity.GeyserEntityDefinition; +import org.geysermc.geyser.api.entity.type.GeyserEntity; +import org.geysermc.geyser.api.event.connection.ConnectionEvent; +import org.geysermc.geyser.api.event.java.ServerSpawnEntityEvent; +import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; + +import java.util.concurrent.CompletableFuture; + +/** + * See {@link ServerSpawnEntityEvent} and {@link SessionAttachParrotsEvent} + */ +public abstract class SessionSpawnEntityEvent extends ConnectionEvent implements Cancellable { + + public SessionSpawnEntityEvent(@NonNull GeyserConnection connection) { + super(connection); + } + + /** + * Gets the entity definition sent to the connection when the entity is spawned. + * + * @return the entity definition sent to the connection when the entity is spawned + */ + public abstract @Nullable GeyserEntityDefinition entityDefinition(); + + /** + * Sets the entity definition sent to the connection when the entity is spawned. + * This entity definition MUST have been registered in the {@link GeyserDefineEntitiesEvent} before + * using it here! + * + * @param entityDefinition the entity definition sent to the connection when the entity is spawned + */ + public abstract void entityDefinition(@Nullable GeyserEntityDefinition entityDefinition); + + /** + * @return the GeyserEntity once it is created, or null if the spawn event is cancelled + */ + public abstract CompletableFuture<@Nullable GeyserEntity> futureEntity(); +} diff --git a/api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java index f0bb3b6d916..a0135e8bc15 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java @@ -27,19 +27,17 @@ import org.checkerframework.checker.index.qual.NonNegative; import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; +import org.geysermc.event.Cancellable; import org.geysermc.geyser.api.connection.GeyserConnection; -import org.geysermc.geyser.api.entity.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.JavaEntityType; -import org.geysermc.geyser.api.event.connection.ConnectionEvent; -import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; +import org.geysermc.geyser.api.event.bedrock.SessionSpawnEntityEvent; import java.util.UUID; /** - * Called when the downstream server spawns an entity. + * Called when the downstream server spawns a non-player entity. */ -public abstract class ServerSpawnEntityEvent extends ConnectionEvent { +public abstract class ServerSpawnEntityEvent extends SessionSpawnEntityEvent implements Cancellable { public ServerSpawnEntityEvent(@NonNull GeyserConnection connection) { super(connection); @@ -67,30 +65,24 @@ public ServerSpawnEntityEvent(@NonNull GeyserConnection connection) { public abstract @NonNull JavaEntityType entityType(); /** - * Gets the entity definition sent to the connection when the entity is spawned. - * - * @return the entity definition sent to the connection when the entity is spawned + * @return the width of the entity */ - public abstract @Nullable GeyserEntityDefinition entityDefinition(); + public abstract float width(); /** - * Sets the entity definition sent to the connection when the entity is spawned. - * This entity definition MUST have been registered in the {@link GeyserDefineEntitiesEvent} before - * using it here! - * - * @param entityDefinition the entity definition sent to the connection when the entity is spawned + * Sets the width of the entity. */ - public abstract void entityDefinition(@Nullable GeyserEntityDefinition entityDefinition); + public abstract void width(@NonNegative float width); /** - * @return the width of the entity + * @return the height of the entity */ - public abstract float width(); + public abstract float height(); /** - * @return the height of the entity + * Sets the height of the entity. */ - public abstract float height(); + public abstract void height(@NonNegative float height); /** * The vertical offset applied by Geyser to ensure the Bedrock entity doesn't clip @@ -100,16 +92,6 @@ public ServerSpawnEntityEvent(@NonNull GeyserConnection connection) { */ public abstract float offset(); - /** - * Sets the width of the entity. - */ - public abstract void width(@NonNegative float width); - - /** - * Sets the height of the entity. - */ - public abstract void height(@NonNegative float height); - /** * Sets the vertical offset applied by Geyser to avoid clipping */ diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java index 593bcbc7d0c..afdb0d13efb 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java @@ -74,7 +74,7 @@ public void showEmote(@NonNull GeyserPlayerEntity emoter, @NonNull String emoteI } EmotePacket packet = new EmotePacket(); - packet.setRuntimeEntityId(entity.getGeyserId()); + packet.setRuntimeEntityId(entity.geyserId()); packet.setXuid(""); packet.setPlatformId(""); // BDS sends empty packet.setEmoteId(emoteId); diff --git a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java index 0feb834b4e8..b9584deaa97 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java +++ b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java @@ -37,14 +37,19 @@ import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.entity.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.JavaEntityType; +import org.geysermc.geyser.api.entity.type.GeyserEntity; +import org.geysermc.geyser.api.entity.type.player.GeyserPlayerEntity; +import org.geysermc.geyser.api.event.bedrock.SessionAttachParrotsEvent; import org.geysermc.geyser.api.event.java.ServerSpawnEntityEvent; import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.type.Entity; +import org.geysermc.geyser.entity.type.player.PlayerEntity; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundAddEntityPacket; import java.util.UUID; +import java.util.concurrent.CompletableFuture; @Getter @Setter @@ -64,28 +69,47 @@ public class EntitySpawnContext { private float height; private float width; private float offset; - private long geyserId; + private @Nullable Long geyserId; + private CompletableFuture<@Nullable GeyserEntity> geyserEntityFuture; - public static final TriFunction, EntitySpawnContext> DUMMY_CONTEXT = ((session, uuid, definition) -> - new EntitySpawnContext(session, definition, 0, uuid, definition.defaultBedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, definition.height(), - definition.width(), definition.offset(), session.getEntityCache().getNextEntityId().incrementAndGet())); + public static final TriFunction, EntitySpawnContext> DUMMY_CONTEXT = ((session, uuid, definition) -> { + return new EntitySpawnContext(session, definition, 0, uuid); + }); + + public EntitySpawnContext(GeyserSession session, EntityTypeDefinition type, int javaId, UUID uuid) { + this(session, type, javaId, uuid, type.defaultBedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, + type.height(), type.width(), type.offset(), null, new CompletableFuture<>()); + } + + public EntitySpawnContext(GeyserSession session, EntityTypeDefinition type, int entityId, BedrockEntityDefinition definition, float height, float width, long geyserId) { + this(session, type, entityId, null, definition, Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, height, width, 0, geyserId, null); + } public static EntitySpawnContext fromPacket(GeyserSession session, EntityTypeDefinition definition, ClientboundAddEntityPacket packet) { Vector3f position = Vector3f.from(packet.getX(), packet.getY(), packet.getZ()); Vector3f motion = packet.getMovement().toFloat(); return new EntitySpawnContext(session, definition, packet.getEntityId(), packet.getUuid(), definition.defaultBedrockDefinition(), - position, motion, packet.getYaw(), packet.getPitch(), packet.getHeadYaw(), definition.height(), definition.width(), definition.offset(), 0); + position, motion, packet.getYaw(), packet.getPitch(), packet.getHeadYaw(), definition.height(), definition.width(), definition.offset(), null, new CompletableFuture<>()); } public static EntitySpawnContext inherited(GeyserSession session, EntityTypeDefinition definition, Entity base, Vector3f position) { - return new EntitySpawnContext(session, definition, 0, null, definition.defaultBedrockDefinition(), position, - base.getMotion(), base.getYaw(), base.getPitch(), base.getHeadYaw(), definition.height(), definition.width(), definition.offset(), - session.getEntityCache().getNextEntityId().incrementAndGet()); + return new EntitySpawnContext(session, definition, 0, null, definition.defaultBedrockDefinition(), position, base.getMotion(), base.getYaw(), + base.getPitch(), base.getHeadYaw(), definition.height(), definition.width(), definition.offset(), null, new CompletableFuture<>()); } - public void callEvent() { + public void callServerSpawnEvent() { GeyserImpl.getInstance().getEventBus().fire(new ServerSpawnEntityEvent(session) { + @Override + public boolean isCancelled() { + return bedrockEntityDefinition == null; + } + + @Override + public void setCancelled(boolean cancelled) { + bedrockEntityDefinition = null; + } + @Override public int entityId() { return javaId; @@ -101,6 +125,36 @@ public int entityId() { return entityTypeDefinition.type(); } + @Override + public float width() { + return width; + } + + @Override + public void width(@NonNegative float newWidth) { + width = newWidth; + } + + @Override + public float height() { + return height; + } + + @Override + public void height(@NonNegative float newHeight) { + height = newHeight; + } + + @Override + public float offset() { + return offset; + } + + @Override + public void offset(@NonNegative float newOffset) { + offset = newOffset; + } + @Override public @Nullable GeyserEntityDefinition entityDefinition() { return bedrockEntityDefinition; @@ -120,33 +174,60 @@ public void entityDefinition(@Nullable GeyserEntityDefinition entityDefinition) } @Override - public float width() { - return width; + public CompletableFuture<@Nullable GeyserEntity> futureEntity() { + return geyserEntityFuture; } + }); + } + public void callParrotEvent(PlayerEntity player, int variant, boolean right) { + GeyserImpl.getInstance().eventBus().fire(new SessionAttachParrotsEvent(session) { @Override - public float height() { - return height; + public GeyserPlayerEntity player() { + return player; } @Override - public float offset() { - return offset; + public int variant() { + return variant; } @Override - public void width(@NonNegative float newWidth) { - width = newWidth; + public boolean right() { + return right; } @Override - public void height(@NonNegative float newHeight) { - height = newHeight; + public @Nullable GeyserEntityDefinition entityDefinition() { + return bedrockEntityDefinition; } @Override - public void offset(@NonNegative float newOffset) { - offset = newOffset; + public void entityDefinition(@Nullable GeyserEntityDefinition entityDefinition) { + if (entityDefinition == null) { + bedrockEntityDefinition = null; + } else { + if (entityDefinition instanceof BedrockEntityDefinition bed) { + bedrockEntityDefinition = bed; + } else { + throw new IllegalStateException("Unknown implementation of GeyserEntityDefinition"); + } + } + } + + @Override + public CompletableFuture<@Nullable GeyserEntity> futureEntity() { + return geyserEntityFuture; + } + + @Override + public boolean isCancelled() { + return bedrockEntityDefinition == null; + } + + @Override + public void setCancelled(boolean cancelled) { + bedrockEntityDefinition = null; } }); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java index 0f289964ace..e34f0936a8e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java @@ -29,11 +29,9 @@ import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.cloudburstmc.protocol.bedrock.packet.AnimatePacket; import org.cloudburstmc.protocol.bedrock.packet.MoveEntityAbsolutePacket; import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.spawn.EntitySpawnContext; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; @@ -221,14 +219,6 @@ public long leashHolderBedrockId() { return leashHolderBedrockId; } - private void sendAnimationPacket(GeyserSession session, Entity rower, AnimatePacket.Action action, float rowTime) { - AnimatePacket packet = new AnimatePacket(); - packet.setRuntimeEntityId(rower.getGeyserId()); - packet.setAction(action); - packet.setRowingTime(rowTime); - session.sendUpstreamPacket(packet); - } - /** * Ordered by Bedrock ordinal */ diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index b35c563abbc..fe3354b5b96 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -45,6 +45,8 @@ import org.cloudburstmc.protocol.bedrock.packet.RemoveEntityPacket; import org.cloudburstmc.protocol.bedrock.packet.SetEntityDataPacket; import org.geysermc.geyser.api.entity.GeyserEntityDefinition; +import org.geysermc.geyser.api.entity.data.BatchEntityDataUpdater; +import org.geysermc.geyser.api.entity.data.GeyserEntityData; import org.geysermc.geyser.api.entity.property.BatchPropertyUpdater; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.entity.type.GeyserEntity; @@ -93,6 +95,7 @@ public class Entity implements GeyserEntity { protected EntityTypeDefinition javaTypeDefinition; protected int entityId; + @Accessors(fluent = true) protected final long geyserId; protected UUID uuid; /** @@ -170,7 +173,7 @@ public Entity(EntitySpawnContext context) { this.displayName = standardDisplayName(); this.entityId = context.javaId(); - this.geyserId = session.getEntityCache().getNextEntityId().incrementAndGet(); + this.geyserId = context.geyserId() == null ? session.getEntityCache().getNextEntityId().incrementAndGet() : context.geyserId(); this.uuid = context.uuid(); this.motion = context.motion(); this.yaw = context.yaw(); @@ -182,13 +185,15 @@ public Entity(EntitySpawnContext context) { this.offset = context.offset(); this.valid = false; - // TODO null or empty check this.propertyManager = bedrockDefinition.registeredProperties().isEmpty() ? null : new GeyserEntityPropertyManager(bedrockDefinition.registeredProperties()); - setPosition(position); + setPosition(context.position()); setAirSupply(getMaxAir()); initializeMetadata(); + + // Allow API users to do things pre-spawn + context.geyserEntityFuture().complete(this); } /** @@ -708,7 +713,7 @@ public final void updateInteractiveTag() { */ protected InteractiveTag testInteraction(Hand hand) { if (isAlive() && this instanceof Leashable leashable) { - if (leashable.leashHolderBedrockId() == session.getPlayerEntity().getGeyserId()) { + if (leashable.leashHolderBedrockId() == session.getPlayerEntity().geyserId()) { // Note this might be client side. Has yet to be an issue though, as of Java 1.21. return InteractiveTag.REMOVE_LEASH; } @@ -736,7 +741,7 @@ public InteractionResult interact(Hand hand) { return InteractionResult.SUCCESS; } } else if (isAlive() && this instanceof Leashable leashable) { - if (leashable.leashHolderBedrockId() == session.getPlayerEntity().getGeyserId()) { + if (leashable.leashHolderBedrockId() == session.getPlayerEntity().geyserId()) { // Note this might also update client side (a theoretical Geyser/client desync and Java parity issue). // Has yet to be an issue though, as of Java 1.21. return InteractionResult.SUCCESS; @@ -754,7 +759,7 @@ public InteractionResult interact(Hand hand) { public boolean hasLeashesToDrop() { BoundingBox searchBB = new BoundingBox(position.getX(), position.getY(), position.getZ(), 32, 32, 32); List leashedInRange = session.getEntityCache().getEntities().values().stream() - .filter(entity -> entity instanceof Leashable leashablex && leashablex.leashHolderBedrockId() == this.getGeyserId()) + .filter(entity -> entity instanceof Leashable leashablex && leashablex.leashHolderBedrockId() == this.geyserId()) .filter(entity -> { BoundingBox leashedBB = new BoundingBox(entity.position.toDouble(), entity.boundingBoxWidth, entity.boundingBoxHeight, entity.boundingBoxWidth); return searchBB.checkIntersection(leashedBB); @@ -824,7 +829,7 @@ public void update(@NonNull GeyserEntityProperty property, @Nullable T va if (propertyManager.hasProperties()) { SetEntityDataPacket packet = new SetEntityDataPacket(); - packet.setRuntimeEntityId(getGeyserId()); + packet.setRuntimeEntityId(geyserId()); propertyManager.applyFloatProperties(packet.getProperties().getFloatProperties()); propertyManager.applyIntProperties(packet.getProperties().getIntProperties()); if (immediate) { @@ -836,17 +841,17 @@ public void update(@NonNull GeyserEntityProperty property, @Nullable T va } @Override - public @NonNull UUID uuid() { + public @Nullable UUID uuid() { return uuid; } @Override - public GeyserEntityDefinition definition() { + public @NonNull GeyserEntityDefinition definition() { return bedrockDefinition; } @Override - public Vector3f position() { + public @NonNull Vector3f position() { return this.position.down(offset); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FireworkEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FireworkEntity.java index 438e43074e3..edc6ded0c06 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FireworkEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FireworkEntity.java @@ -80,7 +80,7 @@ public void setPlayerGliding(EntityMetadata entityMetadata) { this.attachedToSession = true; // We need to keep track of the fireworks rockets. - session.getAttachedFireworkRockets().add(this.getGeyserId()); + session.getAttachedFireworkRockets().add(this.geyserId()); } else { // Also ensure player stop boosting in cases like metadata changes. if (this.attachedToSession && session.getAttachedFireworkRockets().isEmpty()) { @@ -109,7 +109,7 @@ private void sendElytraBoost(int duration) { MovementEffectPacket movementEffect = new MovementEffectPacket(); movementEffect.setDuration(duration); movementEffect.setEffectType(MovementEffectType.GLIDE_BOOST); - movementEffect.setEntityRuntimeId(session.getPlayerEntity().getGeyserId()); + movementEffect.setEntityRuntimeId(session.getPlayerEntity().geyserId()); movementEffect.setTick(session.getClientTicks()); session.sendUpstreamPacket(movementEffect); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java index 7db12a1f6e0..622437a022e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java @@ -65,7 +65,7 @@ public FishingHookEntity(EntitySpawnContext context, PlayerEntity owner) { // so that it can be handled by moveAbsoluteImmediate. setBoundingBoxHeight(128); - this.bedrockOwnerId = owner.getGeyserId(); + this.bedrockOwnerId = owner.geyserId(); this.dirtyMetadata.put(EntityDataTypes.OWNER_EID, this.bedrockOwnerId); } @@ -73,7 +73,7 @@ public void setHookedEntity(IntEntityMetadata entityMetadata) { int hookedEntityId = entityMetadata.getPrimitiveValue() - 1; Entity entity = session.getEntityCache().getEntityByJavaId(hookedEntityId); if (entity != null) { - bedrockTargetId = entity.getGeyserId(); + bedrockTargetId = entity.geyserId(); dirtyMetadata.put(EntityDataTypes.TARGET_EID, bedrockTargetId); hooked = true; } else { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java index f1a69772d3c..447826bba72 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java @@ -92,7 +92,7 @@ public InteractionResult interact(Hand hand) { // but the bedrock client won't arm swing itself because of our armor stand workaround if (response) { AnimatePacket animatePacket = new AnimatePacket(); - animatePacket.setRuntimeEntityId(session.getPlayerEntity().getGeyserId()); + animatePacket.setRuntimeEntityId(session.getPlayerEntity().geyserId()); animatePacket.setAction(AnimatePacket.Action.SWING_ARM); session.sendUpstreamPacket(animatePacket); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java index c427c7649ad..d537f794bfa 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java @@ -35,7 +35,6 @@ import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.enchantment.EnchantmentComponent; import org.geysermc.geyser.item.type.SpawnEggItem; -import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.geyser.util.ItemUtils; @@ -78,7 +77,7 @@ protected final InteractiveTag testInteraction(Hand hand) { if (!isAlive()) { // dead lol return InteractiveTag.NONE; - } else if (leashHolderBedrockId == session.getPlayerEntity().getGeyserId()) { + } else if (leashHolderBedrockId == session.getPlayerEntity().geyserId()) { return InteractiveTag.REMOVE_LEASH; } else { GeyserItemStack itemStack = session.getPlayerInventory().getItemInHand(hand); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FrogEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FrogEntity.java index 8eca99dfc9e..142d1fe51b8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FrogEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/FrogEntity.java @@ -69,7 +69,7 @@ public void setTongueTarget(ObjectEntityMetadata entityMetadata) { if (entityId.isPresent()) { Entity entity = session.getEntityCache().getEntityByJavaId(entityId.getAsInt()); if (entity != null) { - dirtyMetadata.put(EntityDataTypes.TARGET_EID, entity.getGeyserId()); + dirtyMetadata.put(EntityDataTypes.TARGET_EID, entity.geyserId()); } } else { dirtyMetadata.put(EntityDataTypes.TARGET_EID, 0L); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HoglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HoglinEntity.java index 3d26b0551b6..d06bcf19fe7 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HoglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/HoglinEntity.java @@ -39,7 +39,7 @@ public class HoglinEntity extends AnimalEntity { public HoglinEntity(EntitySpawnContext context) { super(context); - dirtyMetadata.put(EntityDataTypes.TARGET_EID, session.getPlayerEntity().getGeyserId()); + dirtyMetadata.put(EntityDataTypes.TARGET_EID, session.getPlayerEntity().geyserId()); setFlag(EntityFlag.SHAKING, isShaking()); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java index 9719f212199..3c52cc492a8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java @@ -115,7 +115,7 @@ private void updateCollarColor() { @Override protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { boolean tamed = getFlag(EntityFlag.TAMED); - if (tamed && ownerBedrockId == session.getPlayerEntity().getGeyserId()) { + if (tamed && ownerBedrockId == session.getPlayerEntity().geyserId()) { // Toggle sitting return getFlag(EntityFlag.SITTING) ? InteractiveTag.STAND : InteractiveTag.SIT; } else { @@ -127,7 +127,7 @@ protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserI @Override protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { boolean tamed = getFlag(EntityFlag.TAMED); - if (tamed && ownerBedrockId == session.getPlayerEntity().getGeyserId()) { + if (tamed && ownerBedrockId == session.getPlayerEntity().geyserId()) { return InteractionResult.SUCCESS; } else { // Attempt to feed diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java index 5952b563ba2..37ae6a9106e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java @@ -64,7 +64,7 @@ protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserI return InteractiveTag.FEED; } else if (isPoisonousFood(itemInHand)) { return InteractiveTag.FEED; - } else if (onGround && tame && ownerBedrockId == session.getPlayerEntity().getGeyserId()) { + } else if (onGround && tame && ownerBedrockId == session.getPlayerEntity().geyserId()) { // Sitting/standing return getFlag(EntityFlag.SITTING) ? InteractiveTag.STAND : InteractiveTag.SIT; } @@ -79,7 +79,7 @@ protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemS return InteractionResult.SUCCESS; } else if (isPoisonousFood(itemInHand)) { return InteractionResult.SUCCESS; - } else if (onGround && tame && ownerBedrockId == session.getPlayerEntity().getGeyserId()) { + } else if (onGround && tame && ownerBedrockId == session.getPlayerEntity().geyserId()) { // Sitting/standing return InteractionResult.SUCCESS; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/TameableEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/TameableEntity.java index b13584078e5..0fbd8895a3e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/TameableEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/TameableEntity.java @@ -72,7 +72,7 @@ public void setOwner(EntityMetadata, ?> entityMetadata) { ownerBedrockId = Long.MAX_VALUE; } else { // Translate to entity ID - ownerBedrockId = entity.getGeyserId(); + ownerBedrockId = entity.geyserId(); } } else { // Reset diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java index 67b2521cd52..1acb231025a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java @@ -110,7 +110,7 @@ private void updateCollarColor() { if (ownerBedrockId == 0) { // If a color is set and there is no owner entity ID, set one. // Otherwise, the entire wolf is set to that color: https://user-images.githubusercontent.com/9083212/99209989-92691200-2792-11eb-911d-9a315c955be9.png - dirtyMetadata.put(EntityDataTypes.OWNER_EID, session.getPlayerEntity().getGeyserId()); + dirtyMetadata.put(EntityDataTypes.OWNER_EID, session.getPlayerEntity().geyserId()); } } @@ -159,7 +159,7 @@ protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserI // Bone and untamed - can tame return InteractiveTag.TAME; } - if (getFlag(EntityFlag.TAMED) && ownerBedrockId == session.getPlayerEntity().getGeyserId()) { + if (getFlag(EntityFlag.TAMED) && ownerBedrockId == session.getPlayerEntity().geyserId()) { if (itemInHand.asItem() instanceof DyeItem dyeItem) { // If this fails, as of Java Edition 1.18.1, you cannot toggle sit/stand if (dyeItem.dyeColor() != this.collarColor) { @@ -188,7 +188,7 @@ protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserI @NonNull @Override protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { - if (ownerBedrockId == session.getPlayerEntity().getGeyserId() || getFlag(EntityFlag.TAMED) + if (ownerBedrockId == session.getPlayerEntity().geyserId() || getFlag(EntityFlag.TAMED) || itemInHand.is(Items.BONE) && !getFlag(EntityFlag.ANGRY)) { // Sitting toggle or feeding; not angry return InteractionResult.CONSUME; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BasePiglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BasePiglinEntity.java index fff876e5877..b68a7a2fa3f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BasePiglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/BasePiglinEntity.java @@ -45,7 +45,7 @@ public BasePiglinEntity(EntitySpawnContext context) { public void setMobFlags(ByteEntityMetadata entityMetadata) { super.setMobFlags(entityMetadata); byte xd = entityMetadata.getPrimitiveValue(); - dirtyMetadata.put(EntityDataTypes.TARGET_EID, (xd & 4) == 4 ? session.getPlayerEntity().getGeyserId() : 0); + dirtyMetadata.put(EntityDataTypes.TARGET_EID, (xd & 4) == 4 ? session.getPlayerEntity().geyserId() : 0); } public void setImmuneToZombification(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java index 07ace32dd62..5d72f2c17ff 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java @@ -25,7 +25,6 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinitions; @@ -46,7 +45,6 @@ public EnderDragonPartEntity(GeyserSession session, int entityId, long geyserId, } public static EntitySpawnContext dragonPartSpawnContext(GeyserSession session, int entityId, long geyserId, float width, float height) { - return new EntitySpawnContext(session, VanillaEntities.ENDER_DRAGON_PART, entityId, null, - BedrockEntityDefinitions.ARMOR_STAND, Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, height, width, 0, geyserId); + return new EntitySpawnContext(session, VanillaEntities.ENDER_DRAGON_PART, entityId, BedrockEntityDefinitions.ARMOR_STAND, height, width, geyserId); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GuardianEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GuardianEntity.java index 551c83c4822..3ca35610f14 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GuardianEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/GuardianEntity.java @@ -40,7 +40,7 @@ public void setGuardianTarget(IntEntityMetadata entityMetadata) { int entityId = entityMetadata.getPrimitiveValue(); Entity entity = session.getEntityCache().getEntityByJavaId(entityId); if (entity != null) { - dirtyMetadata.put(EntityDataTypes.TARGET_EID, entity.getGeyserId()); + dirtyMetadata.put(EntityDataTypes.TARGET_EID, entity.geyserId()); } else { dirtyMetadata.put(EntityDataTypes.TARGET_EID, (long) 0); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/VexEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/VexEntity.java index 8e39263aeef..06c140e1e74 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/VexEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/VexEntity.java @@ -39,6 +39,6 @@ public void setVexFlags(ByteEntityMetadata entityMetadata) { byte xd = entityMetadata.getPrimitiveValue(); // Set the target to the player to force the attack animation // even if the player isn't the target as we dont get the target on Java - dirtyMetadata.put(EntityDataTypes.TARGET_EID, (xd & 0x01) == 0x01 ? session.getPlayerEntity().getGeyserId() : 0); + dirtyMetadata.put(EntityDataTypes.TARGET_EID, (xd & 0x01) == 0x01 ? session.getPlayerEntity().geyserId() : 0); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WitherEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WitherEntity.java index 4145f097682..a98bebf061f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WitherEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WitherEntity.java @@ -59,7 +59,7 @@ private void setTargetId(EntityDataType entityData, IntEntityMetadata enti int entityId = entityMetadata.getPrimitiveValue(); Entity entity = session.getEntityCache().getEntityByJavaId(entityId); if (entity != null) { - dirtyMetadata.put(entityData, entity.getGeyserId()); + dirtyMetadata.put(entityData, entity.geyserId()); } else { dirtyMetadata.put(entityData, (long) 0); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java index c87c7b499f9..bf5cca23eec 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java @@ -34,7 +34,7 @@ public class ZoglinEntity extends MonsterEntity { public ZoglinEntity(EntitySpawnContext context) { super(context); - dirtyMetadata.put(EntityDataTypes.TARGET_EID, session.getPlayerEntity().getGeyserId()); + dirtyMetadata.put(EntityDataTypes.TARGET_EID, session.getPlayerEntity().geyserId()); } public void setBaby(BooleanEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/VindicatorEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/VindicatorEntity.java index dc26d55a6d8..a15611716c4 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/VindicatorEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/raid/VindicatorEntity.java @@ -34,7 +34,7 @@ public class VindicatorEntity extends AbstractIllagerEntity { public VindicatorEntity(EntitySpawnContext context) { super(context); - dirtyMetadata.put(EntityDataTypes.TARGET_EID, session.getPlayerEntity().getGeyserId()); + dirtyMetadata.put(EntityDataTypes.TARGET_EID, session.getPlayerEntity().geyserId()); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java index 6b2e5cd9d7f..03f49e91a5d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java @@ -160,7 +160,9 @@ protected void setParrot(OptionalInt variant, boolean isLeft) { return; } // The parrot is a separate entity in Bedrock, but part of the player entity in Java - ParrotEntity parrot = new ParrotEntity(EntitySpawnContext.inherited(session, VanillaEntities.PARROT, this, position)); + EntitySpawnContext context = EntitySpawnContext.inherited(session, VanillaEntities.PARROT, this, position); + context.callParrotEvent(this, variant.getAsInt(), !isLeft); + ParrotEntity parrot = new ParrotEntity(context); parrot.spawnEntity(); parrot.getDirtyMetadata().put(EntityDataTypes.VARIANT, variant.getAsInt()); // Different position whether the parrot is left or right @@ -170,7 +172,7 @@ protected void setParrot(OptionalInt variant, boolean isLeft) { parrot.updateBedrockMetadata(); SetEntityLinkPacket linkPacket = new SetEntityLinkPacket(); EntityLinkData.Type type = isLeft ? EntityLinkData.Type.RIDER : EntityLinkData.Type.PASSENGER; - linkPacket.setEntityLink(new EntityLinkData(geyserId, parrot.getGeyserId(), type, false, false, 0f)); + linkPacket.setEntityLink(new EntityLinkData(geyserId, parrot.geyserId(), type, false, false, 0f)); // Delay, or else spawned-in players won't get the link // TODO: Find a better solution. session.scheduleInEventLoop(() -> session.sendUpstreamPacket(linkPacket), 500, TimeUnit.MILLISECONDS); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java index 343142c1893..80280f9aefb 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java @@ -132,8 +132,7 @@ public class SessionPlayerEntity extends PlayerEntity { private float javaYaw; public SessionPlayerEntity(GeyserSession session) { - super(new EntitySpawnContext(session, VanillaEntities.PLAYER, -1, null, VanillaEntities.PLAYER.defaultBedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, - 0, 0, 0, VanillaEntities.PLAYER.height(), VanillaEntities.PLAYER.width(), VanillaEntities.PLAYER.offset(), 1), null, null); + super(new EntitySpawnContext(session, VanillaEntities.PLAYER, -1, null), null, null); valid = true; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java index 5b24e718ce3..2b290095318 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java +++ b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java @@ -736,7 +736,7 @@ protected void moveVehicle(Vector3d javaPos, Vector3f lastRotation) { Vector3f bedrockPos = javaPos.toFloat(); MoveEntityDeltaPacket moveEntityDeltaPacket = new MoveEntityDeltaPacket(); - moveEntityDeltaPacket.setRuntimeEntityId(vehicle.getGeyserId()); + moveEntityDeltaPacket.setRuntimeEntityId(vehicle.geyserId()); if (vehicle.isOnGround()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.ON_GROUND); diff --git a/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java b/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java index 3be41ed0c47..4b30b7cdd32 100644 --- a/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java +++ b/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java @@ -221,7 +221,7 @@ public BoundingBox getActiveBoundingBox() { public void recalculatePosition() { PlayerEntity entity = session.getPlayerEntity(); MovePlayerPacket movePlayerPacket = new MovePlayerPacket(); - movePlayerPacket.setRuntimeEntityId(entity.getGeyserId()); + movePlayerPacket.setRuntimeEntityId(entity.geyserId()); movePlayerPacket.setPosition(entity.getPosition()); movePlayerPacket.setRotation(entity.getBedrockRotation()); movePlayerPacket.setMode(MovePlayerPacket.Mode.NORMAL); diff --git a/core/src/main/java/org/geysermc/geyser/scoreboard/display/slot/BelownameDisplaySlot.java b/core/src/main/java/org/geysermc/geyser/scoreboard/display/slot/BelownameDisplaySlot.java index 825fd447e0e..0077283d85f 100644 --- a/core/src/main/java/org/geysermc/geyser/scoreboard/display/slot/BelownameDisplaySlot.java +++ b/core/src/main/java/org/geysermc/geyser/scoreboard/display/slot/BelownameDisplaySlot.java @@ -118,7 +118,7 @@ public void playerRegistered(PlayerEntity player) { @Override public void playerRemoved(PlayerEntity player) { synchronized (displayScores) { - displayScores.remove(player.getGeyserId()); + displayScores.remove(player.geyserId()); } } @@ -132,7 +132,7 @@ private void addDisplayScore(ScoreReference reference) { private BelownameDisplayScore addDisplayScore(PlayerEntity player, ScoreReference reference) { var score = new BelownameDisplayScore(this, objective.getScoreboard().nextId(), reference, player); synchronized (displayScores) { - displayScores.put(player.getGeyserId(), score); + displayScores.put(player.geyserId(), score); } return score; } diff --git a/core/src/main/java/org/geysermc/geyser/scoreboard/display/slot/PlayerlistDisplaySlot.java b/core/src/main/java/org/geysermc/geyser/scoreboard/display/slot/PlayerlistDisplaySlot.java index 4660ddad2d6..2f94ce3ba1e 100644 --- a/core/src/main/java/org/geysermc/geyser/scoreboard/display/slot/PlayerlistDisplaySlot.java +++ b/core/src/main/java/org/geysermc/geyser/scoreboard/display/slot/PlayerlistDisplaySlot.java @@ -126,8 +126,8 @@ public void addScore(ScoreReference reference) { synchronized (displayScores) { for (PlayerEntity player : players) { - var score = new PlayerlistDisplayScore(this, objective.getScoreboard().nextId(), reference, player.getGeyserId()); - displayScores.put(player.getGeyserId(), score); + var score = new PlayerlistDisplayScore(this, objective.getScoreboard().nextId(), reference, player.geyserId()); + displayScores.put(player.geyserId(), score); } } } @@ -144,9 +144,9 @@ public void playerRegistered(PlayerEntity player) { return; } - var score = new PlayerlistDisplayScore(this, objective.getScoreboard().nextId(), reference, player.getGeyserId()); + var score = new PlayerlistDisplayScore(this, objective.getScoreboard().nextId(), reference, player.geyserId()); synchronized (displayScores) { - displayScores.put(player.getGeyserId(), score); + displayScores.put(player.geyserId(), score); } } @@ -154,7 +154,7 @@ public void playerRegistered(PlayerEntity player) { public void playerRemoved(PlayerEntity player) { PlayerlistDisplayScore score; synchronized (displayScores) { - score = displayScores.remove(player.getGeyserId()); + score = displayScores.remove(player.geyserId()); } if (score == null) { diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index ca11bb5c865..8c29870f658 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -870,7 +870,7 @@ public void connect() { upstream.sendPacket(setCommandsEnabledPacket); UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket(); - attributesPacket.setRuntimeEntityId(getPlayerEntity().getGeyserId()); + attributesPacket.setRuntimeEntityId(getPlayerEntity().geyserId()); // Default move speed // Bedrock clients move very fast by default until they get an attribute packet correcting the speed attributesPacket.setAttributes(Collections.singletonList( @@ -1724,8 +1724,8 @@ private void startGame() { this.upstream.getCodecHelper().setCameraPresetDefinitions(CameraDefinitions.CAMERA_DEFINITIONS); StartGamePacket startGamePacket = new StartGamePacket(); - startGamePacket.setUniqueEntityId(playerEntity.getGeyserId()); - startGamePacket.setRuntimeEntityId(playerEntity.getGeyserId()); + startGamePacket.setUniqueEntityId(playerEntity.geyserId()); + startGamePacket.setRuntimeEntityId(playerEntity.geyserId()); startGamePacket.setPlayerGameType(EntityUtils.toBedrockGamemode(gameMode)); startGamePacket.setPlayerPosition(Vector3f.from(0, 69, 0)); startGamePacket.setRotation(Vector2f.from(1, 1)); @@ -1854,7 +1854,7 @@ public void confirmTeleport(Vector3f position) { if (unconfirmedTeleport.getTeleportType() == TeleportCache.TeleportType.KEEP_VELOCITY) { SetEntityMotionPacket entityMotionPacket = new SetEntityMotionPacket(); - entityMotionPacket.setRuntimeEntityId(playerEntity.getGeyserId()); + entityMotionPacket.setRuntimeEntityId(playerEntity.geyserId()); entityMotionPacket.setMotion(unconfirmedTeleport.getVelocity()); this.sendUpstreamPacket(entityMotionPacket); } @@ -2002,7 +2002,7 @@ public void sendGameRule(String gameRule, Object value) { * Send an AdventureSettingsPacket to the client with the latest flags */ public void sendAdventureSettings() { - long bedrockId = playerEntity.getGeyserId(); + long bedrockId = playerEntity.geyserId(); // Set command permission if OP permission level is high enough // This allows mobile players access to a GUI for doing commands. The commands there do not change above OPERATOR // and all commands there are accessible with OP permission level 2 @@ -2153,7 +2153,7 @@ public void refreshEmotes(List emotes) { player.getEmotes().add(piece); } EmoteListPacket emoteList = new EmoteListPacket(); - emoteList.setRuntimeEntityId(player.getPlayerEntity().getGeyserId()); + emoteList.setRuntimeEntityId(player.getPlayerEntity().geyserId()); emoteList.getPieceIds().addAll(pieces); player.sendUpstreamPacket(emoteList); } diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java index a0e5db79cae..5effa9f0d9c 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java @@ -86,8 +86,8 @@ public void spawnEntity(Entity entity) { public boolean cacheEntity(Entity entity) { // Check to see if the entity exists, otherwise we can end up with duplicated mobs if (!entityIdTranslations.containsKey(entity.getEntityId())) { - entityIdTranslations.put(entity.getEntityId(), entity.getGeyserId()); - entities.put(entity.getGeyserId(), entity); + entityIdTranslations.put(entity.getEntityId(), entity.geyserId()); + entities.put(entity.geyserId(), entity); return true; } return false; diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/PistonCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/PistonCache.java index dee4aa7cf50..61672d4c4da 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/PistonCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/PistonCache.java @@ -146,7 +146,7 @@ private void sendPlayerMotion() { playerEntity.setMotion(playerMotion); SetEntityMotionPacket setEntityMotionPacket = new SetEntityMotionPacket(); - setEntityMotionPacket.setRuntimeEntityId(playerEntity.getGeyserId()); + setEntityMotionPacket.setRuntimeEntityId(playerEntity.geyserId()); setEntityMotionPacket.setMotion(playerMotion); session.sendUpstreamPacket(setEntityMotionPacket); } diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/waypoint/GeyserWaypoint.java b/core/src/main/java/org/geysermc/geyser/session/cache/waypoint/GeyserWaypoint.java index 09d2480b294..1072b1f6fcf 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/waypoint/GeyserWaypoint.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/waypoint/GeyserWaypoint.java @@ -84,7 +84,7 @@ public void untrack() { public void setPlayer(PlayerEntity entity) { if (sendListPackets) { untrack(); - entityId = entity.getGeyserId(); + entityId = entity.geyserId(); sendListPackets = false; sendLocationPacket(true); } else if (entity == null) { // Previously had an attached player, and now that player is gone diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/waypoint/WaypointCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/waypoint/WaypointCache.java index 1a0c0723066..2242b164eb7 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/waypoint/WaypointCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/waypoint/WaypointCache.java @@ -81,7 +81,7 @@ public void listPlayer(PlayerEntity player) { // distance PlayerLocationPacket locationPacket = new PlayerLocationPacket(); locationPacket.setType(PlayerLocationPacket.Type.HIDE); - locationPacket.setTargetEntityId(player.getGeyserId()); + locationPacket.setTargetEntityId(player.geyserId()); session.sendUpstreamPacket(locationPacket); } } @@ -114,7 +114,7 @@ private void track(TrackedWaypoint waypoint) { Optional uuid = Optional.ofNullable(waypoint.uuid()); Optional player = uuid.flatMap(id -> Optional.ofNullable(session.getEntityCache().getPlayerEntity(id))); - OptionalLong playerId = player.stream().mapToLong(PlayerEntity::getGeyserId).findFirst(); + OptionalLong playerId = player.stream().mapToLong(PlayerEntity::geyserId).findFirst(); GeyserWaypoint tracked = GeyserWaypoint.create(session, uuid, playerId, waypoint); if (tracked != null) { diff --git a/core/src/main/java/org/geysermc/geyser/skin/SkinManager.java b/core/src/main/java/org/geysermc/geyser/skin/SkinManager.java index 48246c4e84e..a6ed32eb8af 100644 --- a/core/src/main/java/org/geysermc/geyser/skin/SkinManager.java +++ b/core/src/main/java/org/geysermc/geyser/skin/SkinManager.java @@ -113,7 +113,7 @@ public static PlayerListPacket.Entry buildCachedEntry(GeyserSession session, Ava session, playerEntity.getUuid(), playerEntity.getUsername(), - playerEntity.getGeyserId(), + playerEntity.geyserId(), skin, cape, geometry, @@ -173,7 +173,7 @@ public static void sendSkinPacket(GeyserSession session, AvatarEntity entity, Sk session, entity.getUuid(), entity.getUsername(), - entity.getGeyserId(), + entity.geyserId(), skin, cape, geometry, diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java index a59b22c387f..33f8dcc4876 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java @@ -113,7 +113,7 @@ protected void initializeMetadata() { SetEntityLinkPacket linkPacket = new SetEntityLinkPacket(); EntityLinkData.Type type = EntityLinkData.Type.PASSENGER; - linkPacket.setEntityLink(new EntityLinkData(session.getPlayerEntity().getGeyserId(), context.geyserId(), type, true, false, 0f)); + linkPacket.setEntityLink(new EntityLinkData(session.getPlayerEntity().geyserId(), context.geyserId(), type, true, false, 0f)); session.sendUpstreamPacket(linkPacket); container.setVillager(villager); diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/VaultBlockEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/VaultBlockEntityTranslator.java index b1eb8fa71b4..c250f94a428 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/VaultBlockEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/VaultBlockEntityTranslator.java @@ -64,11 +64,11 @@ public void translateTag(GeyserSession session, NbtMapBuilder bedrockNbt, NbtMap for (int[] player : connectedPlayers) { UUID uuid = EntityUtils.uuidFromIntArray(player); if (uuid.equals(session.getPlayerEntity().getUuid())) { - bedrockPlayers.add(session.getPlayerEntity().getGeyserId()); + bedrockPlayers.add(session.getPlayerEntity().geyserId()); } else { PlayerEntity playerEntity = session.getEntityCache().getPlayerEntity(uuid); if (playerEntity != null) { - bedrockPlayers.add(playerEntity.getGeyserId()); + bedrockPlayers.add(playerEntity.geyserId()); } } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockNetworkStackLatencyTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockNetworkStackLatencyTranslator.java index 91c5e9a45bc..679b657dda3 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockNetworkStackLatencyTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockNetworkStackLatencyTranslator.java @@ -71,7 +71,7 @@ public void translate(GeyserSession session, NetworkStackLatencyPacket packet) { session.scheduleInEventLoop(() -> { // Hack to fix the url image loading bug UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket(); - attributesPacket.setRuntimeEntityId(session.getPlayerEntity().getGeyserId()); + attributesPacket.setRuntimeEntityId(session.getPlayerEntity().geyserId()); AttributeData attribute = session.getPlayerEntity().getAttributes().get(GeyserAttributeType.EXPERIENCE_LEVEL); if (attribute != null) { diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockSetLocalPlayerAsInitializedTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockSetLocalPlayerAsInitializedTranslator.java index 01388ed414b..6d42d37132c 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockSetLocalPlayerAsInitializedTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockSetLocalPlayerAsInitializedTranslator.java @@ -40,7 +40,7 @@ public class BedrockSetLocalPlayerAsInitializedTranslator extends PacketTranslator { @Override public void translate(GeyserSession session, SetLocalPlayerAsInitializedPacket packet) { - if (session.getPlayerEntity().getGeyserId() == packet.getRuntimeEntityId()) { + if (session.getPlayerEntity().geyserId() == packet.getRuntimeEntityId()) { if (!session.getUpstream().isInitialized()) { session.getUpstream().setInitialized(true); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockEmoteTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockEmoteTranslator.java index 04007bfd6ee..184a401df5e 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockEmoteTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockEmoteTranslator.java @@ -75,7 +75,7 @@ private static void playEmote(GeyserSession session, int emoterJavaId, String em Entity emoter = session.getEntityCache().getEntityByJavaId(emoterJavaId); // Must be ran on same thread if (emoter instanceof PlayerEntity) { EmotePacket packet = new EmotePacket(); - packet.setRuntimeEntityId(emoter.getGeyserId()); + packet.setRuntimeEntityId(emoter.geyserId()); packet.setXuid(emoterXuid); packet.setPlatformId(""); // BDS sends empty packet.setEmoteId(emoteId); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockInteractTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockInteractTranslator.java index dab08d090cb..e21ac89c71f 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockInteractTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockInteractTranslator.java @@ -51,7 +51,7 @@ public class BedrockInteractTranslator extends PacketTranslator @Override public void translate(GeyserSession session, InteractPacket packet) { Entity entity; - if (packet.getRuntimeEntityId() == session.getPlayerEntity().getGeyserId()) { + if (packet.getRuntimeEntityId() == session.getPlayerEntity().geyserId()) { //Player is not in entity cache entity = session.getPlayerEntity(); } else { @@ -88,13 +88,13 @@ public void translate(GeyserSession session, InteractPacket packet) { return; } - long vehicleBedrockId = currentVehicle.getGeyserId(); - if (session.getPlayerEntity().getVehicle().getGeyserId() == vehicleBedrockId) { + long vehicleBedrockId = currentVehicle.geyserId(); + if (session.getPlayerEntity().getVehicle().geyserId() == vehicleBedrockId) { // The Bedrock client, as of 1.19.51, dismounts on its end. The server may not agree with this. // If the server doesn't agree with our dismount (sends a packet saying we dismounted), // then remount the player. SetEntityLinkPacket linkPacket = new SetEntityLinkPacket(); - linkPacket.setEntityLink(new EntityLinkData(vehicleBedrockId, session.getPlayerEntity().getGeyserId(), EntityLinkData.Type.PASSENGER, true, false, 0f)); + linkPacket.setEntityLink(new EntityLinkData(vehicleBedrockId, session.getPlayerEntity().geyserId(), EntityLinkData.Type.PASSENGER, true, false, 0f)); session.sendUpstreamPacket(linkPacket); } }, 1, TimeUnit.SECONDS)); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockPlayerActionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockPlayerActionTranslator.java index 797505e9914..e2679012d56 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockPlayerActionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockPlayerActionTranslator.java @@ -58,13 +58,13 @@ public void translate(GeyserSession session, PlayerActionPacket packet) { SessionPlayerEntity entity = session.getPlayerEntity(); // Respawn process is finished and the server and client are both OK with respawning. EntityEventPacket eventPacket = new EntityEventPacket(); - eventPacket.setRuntimeEntityId(entity.getGeyserId()); + eventPacket.setRuntimeEntityId(entity.geyserId()); eventPacket.setType(EntityEventType.RESPAWN); eventPacket.setData(0); session.sendUpstreamPacket(eventPacket); // Resend attributes or else in rare cases the user can think they're not dead when they are, upon joining the server UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket(); - attributesPacket.setRuntimeEntityId(entity.getGeyserId()); + attributesPacket.setRuntimeEntityId(entity.geyserId()); attributesPacket.getAttributes().addAll(entity.getAttributes().values()); session.sendUpstreamPacket(attributesPacket); @@ -112,7 +112,7 @@ public void translate(GeyserSession session, PlayerActionPacket packet) { session.sendUpstreamPacket(spawnPacket); UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket(); - attributesPacket.setRuntimeEntityId(entity.getGeyserId()); + attributesPacket.setRuntimeEntityId(entity.geyserId()); attributesPacket.getAttributes().addAll(entity.getAttributes().values()); session.sendUpstreamPacket(attributesPacket); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java index 8e98c2b6c42..aaae7a56a69 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java @@ -174,7 +174,7 @@ public void translate(GeyserSession session, PlayerAuthInputPacket packet) { if (packet.getInputMode().equals(InputMode.TOUCH)) { AnimatePacket animatePacket = new AnimatePacket(); animatePacket.setAction(AnimatePacket.Action.SWING_ARM); - animatePacket.setRuntimeEntityId(session.getPlayerEntity().getGeyserId()); + animatePacket.setRuntimeEntityId(session.getPlayerEntity().geyserId()); session.sendUpstreamPacket(animatePacket); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java index 0d97af97b71..b5dd8572434 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java @@ -101,7 +101,7 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) return; } - context.callEvent(); + context.callServerSpawnEvent(); if (context.bedrockEntityDefinition() == null) { // TODO log warn return; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAnimateTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAnimateTranslator.java index a917a3c298b..d2aa1328eec 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAnimateTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAnimateTranslator.java @@ -57,12 +57,12 @@ public void translate(GeyserSession session, ClientboundAnimatePacket packet) { } AnimatePacket animatePacket = new AnimatePacket(); - animatePacket.setRuntimeEntityId(entity.getGeyserId()); + animatePacket.setRuntimeEntityId(entity.geyserId()); switch (animation) { case SWING_ARM -> { if (entity instanceof LivingEntity livingEntity && livingEntity.useArmSwingAttack()) { EntityEventPacket entityEventPacket = new EntityEventPacket(); - entityEventPacket.setRuntimeEntityId(entity.getGeyserId()); + entityEventPacket.setRuntimeEntityId(entity.geyserId()); entityEventPacket.setType(EntityEventType.ATTACK_START); session.sendUpstreamPacket(entityEventPacket); return; @@ -81,7 +81,7 @@ public void translate(GeyserSession session, ClientboundAnimatePacket packet) { offHandPacket.setBlendOutTime(0.0f); offHandPacket.setStopExpression("query.any_animation_finished"); offHandPacket.setController("__runtime_controller"); - offHandPacket.getRuntimeEntityIds().add(entity.getGeyserId()); + offHandPacket.getRuntimeEntityIds().add(entity.geyserId()); session.sendUpstreamPacket(offHandPacket); return; } @@ -98,7 +98,7 @@ public void translate(GeyserSession session, ClientboundAnimatePacket packet) { stringPacket.setIdentifier("geyseropt:enchanted_hit_multiple"); stringPacket.setDimensionId(DimensionUtils.javaToBedrock(session)); stringPacket.setPosition(Vector3f.ZERO); - stringPacket.setUniqueEntityId(entity.getGeyserId()); + stringPacket.setUniqueEntityId(entity.geyserId()); stringPacket.setMolangVariablesJson(Optional.empty()); session.sendUpstreamPacket(stringPacket); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaDamageEventTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaDamageEventTranslator.java index 9d491f92cf7..185ad1f522c 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaDamageEventTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaDamageEventTranslator.java @@ -45,7 +45,7 @@ public void translate(GeyserSession session, ClientboundDamageEventPacket packet // We can probably actually map damage types. EntityEventPacket entityEventPacket = new EntityEventPacket(); - entityEventPacket.setRuntimeEntityId(entity.getGeyserId()); + entityEventPacket.setRuntimeEntityId(entity.geyserId()); entityEventPacket.setType(EntityEventType.HURT); session.sendUpstreamPacket(entityEventPacket); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java index 9f8b8bd65fe..e5fdd34ca8c 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java @@ -70,7 +70,7 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet return; EntityEventPacket entityEventPacket = new EntityEventPacket(); - entityEventPacket.setRuntimeEntityId(entity.getGeyserId()); + entityEventPacket.setRuntimeEntityId(entity.geyserId()); switch (packet.getEvent()) { case PLAYER_ENABLE_REDUCED_DEBUG: session.setReducedDebugInfo(true); @@ -132,12 +132,12 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet // Player is pulled from a fishing rod // The physics of this are clientside on Java FishingHookEntity fishingHook = (FishingHookEntity) entity; - if (fishingHook.getBedrockTargetId() == session.getPlayerEntity().getGeyserId()) { + if (fishingHook.getBedrockTargetId() == session.getPlayerEntity().geyserId()) { Entity hookOwner = session.getEntityCache().getEntityByGeyserId(fishingHook.getBedrockOwnerId()); if (hookOwner != null) { // https://minecraft.wiki/w/Fishing_Rod#Hooking_mobs_and_other_entities SetEntityMotionPacket motionPacket = new SetEntityMotionPacket(); - motionPacket.setRuntimeEntityId(session.getPlayerEntity().getGeyserId()); + motionPacket.setRuntimeEntityId(session.getPlayerEntity().geyserId()); motionPacket.setMotion(hookOwner.getPosition().sub(session.getPlayerEntity().getPosition()).mul(0.1f)); session.sendUpstreamPacket(motionPacket); } @@ -237,7 +237,7 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet // I assume part of the problem is that Bedrock uses a duration and Java just says the rabbit is jumping SetEntityDataPacket dataPacket = new SetEntityDataPacket(); dataPacket.getMetadata().put(EntityDataTypes.JUMP_DURATION, (byte) 3); - dataPacket.setRuntimeEntityId(entity.getGeyserId()); + dataPacket.setRuntimeEntityId(entity.geyserId()); session.sendUpstreamPacket(dataPacket); return; } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaRemoveMobEffectTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaRemoveMobEffectTranslator.java index 0230d8c235d..dfc7deb9528 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaRemoveMobEffectTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaRemoveMobEffectTranslator.java @@ -52,7 +52,7 @@ public void translate(GeyserSession session, ClientboundRemoveMobEffectPacket pa MobEffectPacket mobEffectPacket = new MobEffectPacket(); mobEffectPacket.setEvent(MobEffectPacket.Event.REMOVE); - mobEffectPacket.setRuntimeEntityId(entity.getGeyserId()); + mobEffectPacket.setRuntimeEntityId(entity.geyserId()); mobEffectPacket.setEffectId(EntityUtils.toBedrockEffectId(packet.getEffect())); session.sendUpstreamPacket(mobEffectPacket); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityLinkTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityLinkTranslator.java index 15d47a28598..9d6550d6617 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityLinkTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityLinkTranslator.java @@ -55,7 +55,7 @@ public void translate(GeyserSession session, ClientboundSetEntityLinkPacket pack asLeashable.setLeashHolderBedrockId(-1L); holderId.updateBedrockMetadata(); EntityEventPacket eventPacket = new EntityEventPacket(); - eventPacket.setRuntimeEntityId(holderId.getGeyserId()); + eventPacket.setRuntimeEntityId(holderId.geyserId()); eventPacket.setType(EntityEventType.REMOVE_LEASH); eventPacket.setData(0); session.sendUpstreamPacket(eventPacket); @@ -63,7 +63,7 @@ public void translate(GeyserSession session, ClientboundSetEntityLinkPacket pack } holderId.setFlag(EntityFlag.LEASHED, true); - asLeashable.setLeashHolderBedrockId(attachedToId.getGeyserId()); + asLeashable.setLeashHolderBedrockId(attachedToId.geyserId()); holderId.updateBedrockMetadata(); } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityMotionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityMotionTranslator.java index a59ce57aaf3..716770bbe8e 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityMotionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetEntityMotionTranslator.java @@ -57,7 +57,7 @@ public void translate(GeyserSession session, ClientboundSetEntityMotionPacket pa } SetEntityMotionPacket entityMotionPacket = new SetEntityMotionPacket(); - entityMotionPacket.setRuntimeEntityId(entity.getGeyserId()); + entityMotionPacket.setRuntimeEntityId(entity.geyserId()); entityMotionPacket.setMotion(entity.getMotion()); session.sendUpstreamPacket(entityMotionPacket); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java index 5b166c7464e..27d3c231dd9 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java @@ -74,7 +74,7 @@ public void translate(GeyserSession session, ClientboundSetPassengersPacket pack boolean rider = packet.getPassengerIds()[0] == passengerId; EntityLinkData.Type type = rider ? EntityLinkData.Type.RIDER : EntityLinkData.Type.PASSENGER; SetEntityLinkPacket linkPacket = new SetEntityLinkPacket(); - linkPacket.setEntityLink(new EntityLinkData(entity.getGeyserId(), passenger.getGeyserId(), type, false, false, 0f)); + linkPacket.setEntityLink(new EntityLinkData(entity.geyserId(), passenger.geyserId(), type, false, false, 0f)); session.sendUpstreamPacket(linkPacket); newPassengers.add(passenger); @@ -94,7 +94,7 @@ public void translate(GeyserSession session, ClientboundSetPassengersPacket pack } if (!newPassengers.contains(passenger)) { SetEntityLinkPacket linkPacket = new SetEntityLinkPacket(); - linkPacket.setEntityLink(new EntityLinkData(entity.getGeyserId(), passenger.getGeyserId(), EntityLinkData.Type.REMOVE, false, false, 0f)); + linkPacket.setEntityLink(new EntityLinkData(entity.geyserId(), passenger.geyserId(), EntityLinkData.Type.REMOVE, false, false, 0f)); session.sendUpstreamPacket(linkPacket); passenger.setVehicle(null); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaTakeItemEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaTakeItemEntityTranslator.java index 7722459d4db..4f3c6579b3a 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaTakeItemEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaTakeItemEntityTranslator.java @@ -61,8 +61,8 @@ public void translate(GeyserSession session, ClientboundTakeItemEntityPacket pac } else { // Item is being picked up (visual only) TakeItemEntityPacket takeItemEntityPacket = new TakeItemEntityPacket(); - takeItemEntityPacket.setRuntimeEntityId(collectorEntity.getGeyserId()); - takeItemEntityPacket.setItemRuntimeEntityId(collectedEntity.getGeyserId()); + takeItemEntityPacket.setRuntimeEntityId(collectorEntity.geyserId()); + takeItemEntityPacket.setItemRuntimeEntityId(collectedEntity.geyserId()); session.sendUpstreamPacket(takeItemEntityPacket); } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaUpdateMobEffectTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaUpdateMobEffectTranslator.java index 572a309a759..c8d7b818ec3 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaUpdateMobEffectTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaUpdateMobEffectTranslator.java @@ -68,7 +68,7 @@ public void translate(GeyserSession session, ClientboundUpdateMobEffectPacket pa mobEffectPacket.setAmplifier(packet.getAmplifier()); mobEffectPacket.setDuration(packet.getDuration()); mobEffectPacket.setEvent(event); - mobEffectPacket.setRuntimeEntityId(entity.getGeyserId()); + mobEffectPacket.setRuntimeEntityId(entity.geyserId()); mobEffectPacket.setParticles(packet.isShowParticles()); mobEffectPacket.setEffectId(EntityUtils.toBedrockEffectId(packet.getEffect())); session.sendUpstreamPacket(mobEffectPacket); @@ -88,7 +88,7 @@ public void translate(GeyserSession session, ClientboundUpdateMobEffectPacket pa } UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket(); - attributesPacket.setRuntimeEntityId(entity.getGeyserId()); + attributesPacket.setRuntimeEntityId(entity.geyserId()); attributesPacket.setAttributes(Collections.singletonList(attribute)); session.sendUpstreamPacket(attributesPacket); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java index 3b5de520bca..ab16171395f 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java @@ -83,7 +83,7 @@ public void translate(GeyserSession session, ClientboundPlayerPositionPacket pac entity.updateBedrockMetadata(); MovePlayerPacket movePlayerPacket = new MovePlayerPacket(); - movePlayerPacket.setRuntimeEntityId(entity.getGeyserId()); + movePlayerPacket.setRuntimeEntityId(entity.geyserId()); movePlayerPacket.setPosition(entity.getPosition()); movePlayerPacket.setRotation(entity.getBedrockRotation()); movePlayerPacket.setMode(MovePlayerPacket.Mode.RESPAWN); @@ -141,7 +141,7 @@ public void translate(GeyserSession session, ClientboundPlayerPositionPacket pac // Our motion got reset by the teleport but the deltaMovement is not 0 so send a motion packet to fix that. SetEntityMotionPacket entityMotionPacket = new SetEntityMotionPacket(); - entityMotionPacket.setRuntimeEntityId(entity.getGeyserId()); + entityMotionPacket.setRuntimeEntityId(entity.geyserId()); entityMotionPacket.setMotion(entity.getMotion()); session.sendUpstreamPacket(entityMotionPacket); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaSetExperienceTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaSetExperienceTranslator.java index 3e355041598..2cbc77cb819 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaSetExperienceTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaSetExperienceTranslator.java @@ -49,7 +49,7 @@ public void translate(GeyserSession session, ClientboundSetExperiencePacket pack entity.getAttributes().put(GeyserAttributeType.EXPERIENCE_LEVEL, experienceLevel); UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket(); - attributesPacket.setRuntimeEntityId(session.getPlayerEntity().getGeyserId()); + attributesPacket.setRuntimeEntityId(session.getPlayerEntity().geyserId()); attributesPacket.setAttributes(Arrays.asList(experience, experienceLevel)); session.sendUpstreamPacket(attributesPacket); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaSetHealthTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaSetHealthTranslator.java index 1f8992e54f2..412a325561d 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaSetHealthTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaSetHealthTranslator.java @@ -73,7 +73,7 @@ public void translate(GeyserSession session, ClientboundSetHealthPacket packet) entity.getAttributes().put(GeyserAttributeType.SATURATION, saturationAttribute); attributes.add(saturationAttribute); - attributesPacket.setRuntimeEntityId(entity.getGeyserId()); + attributesPacket.setRuntimeEntityId(entity.geyserId()); session.sendUpstreamPacket(attributesPacket); } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaHorseScreenOpenTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaHorseScreenOpenTranslator.java index 28b29d0d44e..8a32a6bc05f 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaHorseScreenOpenTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaHorseScreenOpenTranslator.java @@ -111,7 +111,7 @@ public void translate(GeyserSession session, ClientboundHorseScreenOpenPacket pa UpdateEquipPacket updateEquipPacket = new UpdateEquipPacket(); updateEquipPacket.setWindowId((short) packet.getContainerId()); updateEquipPacket.setWindowType((short) ContainerType.HORSE.getId()); - updateEquipPacket.setUniqueEntityId(entity.getGeyserId()); + updateEquipPacket.setUniqueEntityId(entity.geyserId()); NbtMapBuilder builder = NbtMap.builder(); List slots = new ArrayList<>(); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaMerchantOffersTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaMerchantOffersTranslator.java index ebc62602cea..c1e6bb6aeb2 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaMerchantOffersTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/inventory/JavaMerchantOffersTranslator.java @@ -104,8 +104,8 @@ public static void openMerchant(GeyserSession session, ClientboundMerchantOffers updateTradePacket.setSize(0); updateTradePacket.setNewTradingUi(true); updateTradePacket.setUsingEconomyTrade(true); - updateTradePacket.setPlayerUniqueEntityId(session.getPlayerEntity().getGeyserId()); - updateTradePacket.setTraderUniqueEntityId(villager.getGeyserId()); + updateTradePacket.setPlayerUniqueEntityId(session.getPlayerEntity().geyserId()); + updateTradePacket.setTraderUniqueEntityId(villager.geyserId()); NbtMapBuilder builder = NbtMap.builder(); boolean addExtraTrade = packet.isShowProgress() && packet.getVillagerLevel() < 5; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaExplodeTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaExplodeTranslator.java index 816842eba85..9eb0ff802c6 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaExplodeTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaExplodeTranslator.java @@ -73,7 +73,7 @@ public void translate(GeyserSession session, ClientboundExplodePacket packet) { entity.setMotion(entity.getMotion().add(packet.getPlayerKnockback().toFloat())); SetEntityMotionPacket motionPacket = new SetEntityMotionPacket(); - motionPacket.setRuntimeEntityId(entity.getGeyserId()); + motionPacket.setRuntimeEntityId(entity.geyserId()); motionPacket.setMotion(entity.getMotion()); session.sendUpstreamPacket(motionPacket); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaGameEventTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaGameEventTranslator.java index 96ebd7d607c..0ddf6e67bf2 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaGameEventTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaGameEventTranslator.java @@ -88,7 +88,7 @@ public void translate(GeyserSession session, ClientboundGameEventPacket packet) if (session.getPlayerEntity().isOnGround() && gameMode == GameMode.SPECTATOR) { // Fix a bug where the player has glitched movement and thinks they are still on the ground MovePlayerPacket movePlayerPacket = new MovePlayerPacket(); - movePlayerPacket.setRuntimeEntityId(entity.getGeyserId()); + movePlayerPacket.setRuntimeEntityId(entity.geyserId()); movePlayerPacket.setPosition(entity.getPosition()); movePlayerPacket.setRotation(entity.getBedrockRotation()); movePlayerPacket.setOnGround(false); @@ -109,7 +109,7 @@ public void translate(GeyserSession session, ClientboundGameEventPacket packet) case FIRST_TIME -> { ShowCreditsPacket showCreditsPacket = new ShowCreditsPacket(); showCreditsPacket.setStatus(ShowCreditsPacket.Status.START_CREDITS); - showCreditsPacket.setRuntimeEntityId(entity.getGeyserId()); + showCreditsPacket.setRuntimeEntityId(entity.geyserId()); session.sendUpstreamPacket(showCreditsPacket); } } @@ -120,7 +120,7 @@ public void translate(GeyserSession session, ClientboundGameEventPacket packet) EntityEventPacket eventPacket = new EntityEventPacket(); eventPacket.setType(EntityEventType.ELDER_GUARDIAN_CURSE); eventPacket.setData(0); - eventPacket.setRuntimeEntityId(entity.getGeyserId()); + eventPacket.setRuntimeEntityId(entity.geyserId()); session.sendUpstreamPacket(eventPacket); break; case IMMEDIATE_RESPAWN: diff --git a/core/src/main/java/org/geysermc/geyser/util/DimensionUtils.java b/core/src/main/java/org/geysermc/geyser/util/DimensionUtils.java index d4464938d13..9dfc2309a89 100644 --- a/core/src/main/java/org/geysermc/geyser/util/DimensionUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/DimensionUtils.java @@ -71,7 +71,7 @@ public static void switchDimension(GeyserSession session, JavaDimension javaDime for (Effect effect : entityEffects) { MobEffectPacket mobEffectPacket = new MobEffectPacket(); mobEffectPacket.setEvent(MobEffectPacket.Event.REMOVE); - mobEffectPacket.setRuntimeEntityId(player.getGeyserId()); + mobEffectPacket.setRuntimeEntityId(player.geyserId()); mobEffectPacket.setEffectId(EntityUtils.toBedrockEffectId(effect)); session.sendUpstreamPacket(mobEffectPacket); } @@ -146,7 +146,7 @@ private static void finalizeDimensionSwitch(GeyserSession session, Entity player // initial chunks are sent, prior to the client acknowledgement // Note: send this before chunks are sent. Fixed https://github.com/GeyserMC/Geyser/issues/3421 PlayerActionPacket ackPacket = new PlayerActionPacket(); - ackPacket.setRuntimeEntityId(player.getGeyserId()); + ackPacket.setRuntimeEntityId(player.geyserId()); ackPacket.setAction(PlayerActionType.DIMENSION_CHANGE_SUCCESS); ackPacket.setBlockPosition(Vector3i.ZERO); ackPacket.setResultPosition(Vector3i.ZERO); diff --git a/core/src/test/java/org/geysermc/geyser/scoreboard/network/util/GeyserMockContextScoreboard.java b/core/src/test/java/org/geysermc/geyser/scoreboard/network/util/GeyserMockContextScoreboard.java index 54702a853e4..aebcd76cf43 100644 --- a/core/src/test/java/org/geysermc/geyser/scoreboard/network/util/GeyserMockContextScoreboard.java +++ b/core/src/test/java/org/geysermc/geyser/scoreboard/network/util/GeyserMockContextScoreboard.java @@ -74,7 +74,7 @@ private static void createSessionSpy(GeyserMockContext context) { // SessionPlayerEntity loads stuff in like blocks, which is not what we want var playerEntity = context.mock(SessionPlayerEntity.class); - when(playerEntity.getGeyserId()).thenReturn(1L); + when(playerEntity.geyserId()).thenReturn(1L); when(playerEntity.getUsername()).thenReturn("Tim203"); when(session.getPlayerEntity()).thenReturn(playerEntity); From 9e6b1333b33ae99bfa3b2112255891339f8137b4 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Thu, 27 Nov 2025 22:13:22 +0100 Subject: [PATCH 17/62] Rename SessionAttachParrotsEvent -> ServerAttachParrotsEvent, fill in API Javadocs --- .../geyser/api/entity/EntityData.java | 11 +++++- .../geyser/api/entity/JavaEntityType.java | 13 +++++++ .../entity/custom/CustomEntityDefinition.java | 16 +------- .../entity/custom/CustomJavaEntityType.java | 39 ++++++++++++++++++- .../bedrock/SessionSpawnEntityEvent.java | 3 +- .../ServerAttachParrotsEvent.java} | 7 ++-- .../lifecycle/GeyserDefineEntitiesEvent.java | 8 ---- .../GeyserDefineEntityPropertiesEvent.java | 3 +- .../entity/BedrockEntityDefinition.java | 9 +++++ .../geyser/entity/GeyserEntityData.java | 11 +++++- .../entity/spawn/EntitySpawnContext.java | 4 +- .../loader/ProviderRegistryLoader.java | 12 ++++-- .../geyser/session/cache/EntityCache.java | 27 ++++++++++--- .../org/geysermc/geyser/util/EntityUtils.java | 1 + gradle/libs.versions.toml | 3 +- 15 files changed, 123 insertions(+), 44 deletions(-) rename api/src/main/java/org/geysermc/geyser/api/event/{bedrock/SessionAttachParrotsEvent.java => java/ServerAttachParrotsEvent.java} (87%) diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java b/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java index 30f2335ff18..00fbf871ec4 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java @@ -52,7 +52,12 @@ public interface EntityData { /** * Returns a {@link GeyserEntity} to e.g. update entity properties. */ - @NonNull CompletableFuture<@Nullable GeyserEntity> entityByJavaUuid(@NonNegative UUID javaUuid); + @NonNull CompletableFuture<@Nullable GeyserEntity> entityByUuid(@NonNegative UUID javaUuid); + + /** + * Returns a {@link GeyserEntity} based on a Geyser entity id + */ + @NonNull CompletableFuture<@Nullable GeyserEntity> entityByGeyserId(@NonNegative long geyserId); /** * Displays a player entity as emoting to this client. @@ -65,6 +70,7 @@ public interface EntityData { /** * @deprecated use {@link GeyserConnection#playerEntity()} */ + @Deprecated @NonNull GeyserPlayerEntity playerEntity(); /** @@ -86,7 +92,8 @@ public interface EntityData { boolean isMovementLocked(); /** - * @deprecated use {@link GeyserConnection#requestHandSwap()} ()} + * @deprecated use {@link GeyserConnection#requestHandSwap()} */ + @Deprecated void switchHands(); } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java index b2c120c0880..b87b5918c36 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java @@ -69,8 +69,21 @@ default boolean is(Identifier javaIdentifier) { return identifier().equals(javaIdentifier); } + /** + * Gets the default Bedrock entity definition, if available, + * that is associated with this Minecraft: Java Edition entity type. + * + * @return the default Bedrock entity definition + */ @Nullable GeyserEntityDefinition defaultBedrockDefinition(); + /** + * Returns the JavaEntityType representation of a built-in vanilla Java entity type. + * + * @param identifier the Java Edition entity type identifier + * @throws IllegalArgumentException if such an entity does not exist + * @return the Java Edition entity type for the vanilla entity type + */ static JavaEntityType ofVanilla(Identifier identifier) { return GeyserApi.api().provider(JavaEntityType.class, identifier); } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java index e32c257fb86..6589c2a99ff 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java @@ -46,19 +46,7 @@ default boolean vanilla() { * @param bedrockIdentifier the Bedrock entity identifier * @return a new builder */ - static Builder builder(@NonNull Identifier bedrockIdentifier) { - return GeyserApi.api().provider(Builder.class, bedrockIdentifier); - } - - interface Builder { - - // TODO needed? - - /** - * Builds the entity definition. - * - * @return the entity definition - */ - CustomEntityDefinition build(); + static CustomEntityDefinition create(@NonNull Identifier bedrockIdentifier) { + return GeyserApi.api().provider(CustomEntityDefinition.class, bedrockIdentifier); } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java index f9144ac9a2e..2707730c7f0 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java @@ -29,25 +29,62 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.api.entity.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.JavaEntityType; +import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; import org.geysermc.geyser.api.util.Identifier; +/** + * Represents a custom Minecraft: Java Edition entity type. + * This can only be used with modded servers! + */ public interface CustomJavaEntityType extends JavaEntityType { @Override default boolean vanilla() { return false; - }; + } interface Builder { + /** + * The entity type's identifier. It cannot be in the Minecraft namespace + * for custom entities! + * + * @param entityType the identifier + * @return this builder + */ Builder type(Identifier entityType); + /** + * The entity type's numeric network id. + * @param javaId the java id + * @return this builder + */ Builder javaId(int javaId); + /** + * The width of this entity. + * @param width the width of this entity + * @return this builder + */ Builder width(@NonNegative float width); + /** + * The height of this entity + * @param height the height + * @return this builder + */ Builder height(@NonNegative float height); + /** + * The default Bedrock edition entity definition. + * You can define custom Bedrock entities, or use vanilla definitions + * obtainable via the {@link GeyserDefineEntitiesEvent#entities()} collection. + * Calling this method with a non-registered {@link CustomEntityDefinition} will + * register it too. + * + * @param defaultBedrockDefinition the default Bedrock definition + * @return this builder + */ Builder defaultBedrockDefinition(@Nullable GeyserEntityDefinition defaultBedrockDefinition); } } diff --git a/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionSpawnEntityEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionSpawnEntityEvent.java index 24d76072447..4fe11980472 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionSpawnEntityEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionSpawnEntityEvent.java @@ -33,12 +33,13 @@ import org.geysermc.geyser.api.entity.type.GeyserEntity; import org.geysermc.geyser.api.event.connection.ConnectionEvent; import org.geysermc.geyser.api.event.java.ServerSpawnEntityEvent; +import org.geysermc.geyser.api.event.java.ServerAttachParrotsEvent; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; import java.util.concurrent.CompletableFuture; /** - * See {@link ServerSpawnEntityEvent} and {@link SessionAttachParrotsEvent} + * See {@link ServerSpawnEntityEvent} and {@link ServerAttachParrotsEvent} */ public abstract class SessionSpawnEntityEvent extends ConnectionEvent implements Cancellable { diff --git a/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionAttachParrotsEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerAttachParrotsEvent.java similarity index 87% rename from api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionAttachParrotsEvent.java rename to api/src/main/java/org/geysermc/geyser/api/event/java/ServerAttachParrotsEvent.java index e44e04cf909..04475808327 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionAttachParrotsEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerAttachParrotsEvent.java @@ -23,18 +23,19 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.geyser.api.event.bedrock; +package org.geysermc.geyser.api.event.java; import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.api.connection.GeyserConnection; import org.geysermc.geyser.api.entity.type.player.GeyserPlayerEntity; +import org.geysermc.geyser.api.event.bedrock.SessionSpawnEntityEvent; /** * Called when the Java server attaches parrots to a player. */ -public abstract class SessionAttachParrotsEvent extends SessionSpawnEntityEvent { +public abstract class ServerAttachParrotsEvent extends SessionSpawnEntityEvent { - public SessionAttachParrotsEvent(@NonNull GeyserConnection connection) { + public ServerAttachParrotsEvent(@NonNull GeyserConnection connection) { super(connection); } diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java index 156d0dd7bd9..6e1f4f4b1c5 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java @@ -48,14 +48,6 @@ public interface GeyserDefineEntitiesEvent extends Event { */ Collection entities(); - /** - * Registers a custom entity definition from its builder - * @param builder the custom entity definition builder - */ - default void register(CustomEntityDefinition.Builder builder) { - register(builder.build()); - } - /** * Registers a custom entity definition * @param customEntityDefinition the custom entity definition to register diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntityPropertiesEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntityPropertiesEvent.java index 763c98e2fb0..94091d3be6e 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntityPropertiesEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntityPropertiesEvent.java @@ -28,6 +28,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.event.Event; +import org.geysermc.geyser.api.connection.GeyserConnection; import org.geysermc.geyser.api.entity.EntityData; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.entity.property.type.GeyserBooleanEntityProperty; @@ -63,7 +64,7 @@ * } * * Retrieving entity instances is possible with the {@link EntityData#entityByJavaId(int)} method, or - * {@link EntityData#playerEntity()} for the connection player entity. + * {@link GeyserConnection#playerEntity()} for the connection player entity. * To update the value of a property on a specific entity, use {@link GeyserEntity#updateProperty(GeyserEntityProperty, Object)}, * or {@link GeyserEntity#updatePropertiesBatched(Consumer)} to update multiple properties efficiently at once. * diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java index 95ce91092c4..7f5b0983eba 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java @@ -37,6 +37,7 @@ import org.geysermc.geyser.entity.properties.GeyserEntityProperties; import java.util.List; +import java.util.Objects; @Getter @Accessors(fluent = true) @@ -57,6 +58,14 @@ public static BedrockEntityDefinition of(Identifier identifier) { return builder().identifier(identifier).build(); } + public static BedrockEntityDefinition ofCustom(@NonNull Identifier identifier) { + Objects.requireNonNull(identifier, "identifier"); + if (identifier.vanilla()) { + throw new IllegalArgumentException("Cannot register custom entity in vanilla namespace! " + identifier); + } + return builder().identifier(identifier).build(); + } + @Override public List> properties() { if (registeredProperties.isEmpty()) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java index afdb0d13efb..43e0ca36615 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java @@ -59,9 +59,16 @@ public GeyserEntityData(GeyserSession session) { } @Override - public @NonNull CompletableFuture<@Nullable GeyserEntity> entityByJavaUuid(@NonNegative UUID javaUuid) { + public @NonNull CompletableFuture<@Nullable GeyserEntity> entityByUuid(@NonNegative UUID javaUuid) { CompletableFuture future = new CompletableFuture<>(); - session.ensureInEventLoop(() -> future.complete(null)); // TODO CE + session.ensureInEventLoop(() -> future.complete(session.getEntityCache().getEntityByUuid(javaUuid))); + return future; + } + + @Override + public @NonNull CompletableFuture<@Nullable GeyserEntity> entityByGeyserId(@NonNegative long geyserId) { + CompletableFuture future = new CompletableFuture<>(); + session.ensureInEventLoop(() -> future.complete(session.getEntityCache().getEntityByGeyserId(geyserId))); return future; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java index b9584deaa97..5c870f28fe0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java +++ b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java @@ -39,7 +39,7 @@ import org.geysermc.geyser.api.entity.JavaEntityType; import org.geysermc.geyser.api.entity.type.GeyserEntity; import org.geysermc.geyser.api.entity.type.player.GeyserPlayerEntity; -import org.geysermc.geyser.api.event.bedrock.SessionAttachParrotsEvent; +import org.geysermc.geyser.api.event.java.ServerAttachParrotsEvent; import org.geysermc.geyser.api.event.java.ServerSpawnEntityEvent; import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityTypeDefinition; @@ -181,7 +181,7 @@ public void entityDefinition(@Nullable GeyserEntityDefinition entityDefinition) } public void callParrotEvent(PlayerEntity player, int variant, boolean right) { - GeyserImpl.getInstance().eventBus().fire(new SessionAttachParrotsEvent(session) { + GeyserImpl.getInstance().eventBus().fire(new ServerAttachParrotsEvent(session) { @Override public GeyserPlayerEntity player() { return player; diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java index 812665f1431..8146476f9e5 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java @@ -34,8 +34,8 @@ import org.geysermc.geyser.api.block.custom.component.MaterialInstance; import org.geysermc.geyser.api.block.custom.nonvanilla.JavaBlockState; import org.geysermc.geyser.api.command.Command; -import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; import org.geysermc.geyser.api.entity.JavaEntityType; +import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; import org.geysermc.geyser.api.event.EventRegistrar; import org.geysermc.geyser.api.extension.Extension; import org.geysermc.geyser.api.item.custom.CustomItemData; @@ -47,6 +47,8 @@ import org.geysermc.geyser.api.pack.option.SubpackOption; import org.geysermc.geyser.api.pack.option.UrlFallbackOption; import org.geysermc.geyser.api.util.Identifier; +import org.geysermc.geyser.entity.BedrockEntityDefinition; +import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.event.GeyserEventRegistrar; import org.geysermc.geyser.extension.command.GeyserExtensionCommand; import org.geysermc.geyser.impl.IdentifierImpl; @@ -111,9 +113,11 @@ public Map, ProviderSupplier> load(Map, ProviderSupplier> prov providers.put(CameraFade.Builder.class, args -> new GeyserCameraFade.Builder()); providers.put(CameraPosition.Builder.class, args -> new GeyserCameraPosition.Builder()); - // entities TODO CE - //providers.put(JavaEntityType.class, args -> args.length == 1 ? GeyserEntityType.ofVanilla((Identifier) args[0]) : GeyserEntityType.createCustomAndRegister((Identifier) args[0], (int) args[1])); - //providers.put(CustomEntityDefinition.class, args -> GeyserCustomEntityDefinition.inherited((String) args[0], (JavaEntityType) args[1])); + // entities + providers.put(CustomEntityDefinition.class, args -> BedrockEntityDefinition.ofCustom((Identifier) args[0])); + providers.put(JavaEntityType.class, args -> GeyserEntityType.ofVanilla((Identifier) args[0])); + + // TODO GeyserEntityData... return providers; } diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java index 5effa9f0d9c..45fc536adf6 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java @@ -29,19 +29,22 @@ import it.unimi.dsi.fastutil.ints.Int2LongOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2LongMap; +import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import lombok.Getter; +import org.geysermc.geyser.entity.type.Entity; +import org.geysermc.geyser.entity.type.Tickable; +import org.geysermc.geyser.entity.type.player.PlayerEntity; +import org.geysermc.geyser.session.GeyserSession; + import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Consumer; -import lombok.Getter; -import org.geysermc.geyser.entity.type.Entity; -import org.geysermc.geyser.entity.type.Tickable; -import org.geysermc.geyser.entity.type.player.PlayerEntity; -import org.geysermc.geyser.session.GeyserSession; /** * Each session has its own EntityCache in the occasion that an entity packet is sent specifically @@ -57,6 +60,7 @@ public class EntityCache { */ private final List tickableEntities = new ObjectArrayList<>(); private final Int2LongMap entityIdTranslations = new Int2LongOpenHashMap(); + private final Object2LongMap entityUuidTranslations = new Object2LongOpenHashMap<>(); private final Map playerEntities = new Object2ObjectOpenHashMap<>(); private final Map bossBars = new Object2ObjectOpenHashMap<>(); @@ -88,6 +92,9 @@ public boolean cacheEntity(Entity entity) { if (!entityIdTranslations.containsKey(entity.getEntityId())) { entityIdTranslations.put(entity.getEntityId(), entity.geyserId()); entities.put(entity.geyserId(), entity); + if (entity.getUuid() != null) { + entityUuidTranslations.put(entity.getUuid(), entity.getEntityId()); + } return true; } return false; @@ -106,6 +113,9 @@ public void removeEntity(Entity entity) { entity.despawnEntity(); } entities.remove(entityIdTranslations.remove(entity.getEntityId())); + if (entity.getUuid() != null) { + entityUuidTranslations.removeLong(entity.getUuid()); + } // don't track the entity anymore, now that it's removed session.getWorldCache().getScoreboard().entityRemoved(entity); @@ -135,6 +145,13 @@ public Entity getEntityByJavaId(int javaId) { return entities.get(entityIdTranslations.get(javaId)); } + public Entity getEntityByUuid(UUID uuid) { + if (uuid == session.getPlayerEntity().getUuid()) { + return session.getPlayerEntity(); + } + return entities.get(entityUuidTranslations.getLong(uuid)); + } + public void addPlayerEntity(PlayerEntity entity) { synchronized (playerEntities) { // putIfAbsent matches the behavior of playerInfoMap in Java as of 1.19.3 diff --git a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java index 46a433fabd6..d3ac2f5e8fe 100644 --- a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java @@ -449,6 +449,7 @@ public void registerEntityType(Consumer consumer) var type = GeyserEntityType.createCustomAndRegister(builder); + // TODO register non-vanilla properly! Registries.JAVA_ENTITY_TYPES.register(type, null); Registries.JAVA_ENTITY_IDENTIFIERS.register(type.identifier().toString(), null); diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9db8682ef28..d8c369e05fa 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -80,6 +80,7 @@ fastutil-int-byte-maps = { group = "org.cloudburstmc.fastutil.maps", name = "int fastutil-int-boolean-maps = { group = "org.cloudburstmc.fastutil.maps", name = "int-boolean-maps", version.ref = "fastutil" } fastutil-object-int-maps = { group = "org.cloudburstmc.fastutil.maps", name = "object-int-maps", version.ref = "fastutil" } fastutil-object-object-maps = { group = "org.cloudburstmc.fastutil.maps", name = "object-object-maps", version.ref = "fastutil" } +fastutil-object-long-maps = { group = "org.cloudburstmc.fastutil.maps", name = "object-long-maps", version.ref = "fastutil" } fastutil-long-object-maps = { group = "org.cloudburstmc.fastutil.maps", name = "long-object-maps", version.ref = "fastutil" } fastutil-reference-object-maps = { group = "org.cloudburstmc.fastutil.maps", name = "reference-object-maps", version.ref = "fastutil" } @@ -171,7 +172,7 @@ runvelocity = { id = "xyz.jpenilla.run-velocity", version.ref = "runtask" } runpaper = { id = "xyz.jpenilla.run-paper", version.ref = "runtask" } [bundles] -fastutil = [ "fastutil-int-int-maps", "fastutil-int-long-maps", "fastutil-long-object-maps", "fastutil-int-byte-maps", "fastutil-int-boolean-maps", "fastutil-object-int-maps", "fastutil-object-object-maps", "fastutil-reference-object-maps" ] +fastutil = [ "fastutil-int-int-maps", "fastutil-int-long-maps", "fastutil-long-object-maps", "fastutil-object-long-maps","fastutil-int-byte-maps", "fastutil-int-boolean-maps", "fastutil-object-int-maps", "fastutil-object-object-maps", "fastutil-reference-object-maps" ] adventure = [ "adventure-text-serializer-gson", "adventure-text-serializer-legacy", "adventure-text-serializer-plain" ] log4j = [ "log4j-api", "log4j-core", "log4j-slf4j2-impl", "log4j-iostreams", "log4j-jul" ] jline = [ "jline-terminal", "jline-terminal-jna", "jline-reader" ] From 75d5f07170bec2292c74878c13ac64ee5b151490 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Thu, 27 Nov 2025 22:18:12 +0100 Subject: [PATCH 18/62] Apply some suggestions --- .../org/geysermc/geyser/entity/BedrockEntityDefinition.java | 3 ++- .../bedrock/entity/player/input/BedrockMovePlayer.java | 4 ++-- core/src/main/java/org/geysermc/geyser/util/EntityUtils.java | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java index 7f5b0983eba..1498b3b8e40 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java @@ -28,6 +28,7 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; +import lombok.ToString; import lombok.experimental.Accessors; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; @@ -41,6 +42,7 @@ @Getter @Accessors(fluent = true) +@ToString public class BedrockEntityDefinition implements GeyserEntityDefinition { private final @NonNull Identifier identifier; private final @NonNull GeyserEntityProperties registeredProperties; @@ -101,5 +103,4 @@ BedrockEntityDefinition build() { return new BedrockEntityDefinition(identifier, propertiesBuilder != null ? propertiesBuilder.build() : new GeyserEntityProperties()); } } - } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java index 4800d256de1..f007a8fbc82 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java @@ -60,7 +60,7 @@ static void translate(GeyserSession session, PlayerAuthInputPacket packet) { // Ignore movement packets until Bedrock's position matches the teleported position if (session.getUnconfirmedTeleport() != null) { - session.confirmTeleport(packet.getPosition().sub(0, VanillaEntities.PLAYER_ENTITY_OFFSET, 0)); + session.confirmTeleport(packet.getPosition().down(VanillaEntities.PLAYER_ENTITY_OFFSET)); return; } @@ -125,7 +125,7 @@ static void translate(GeyserSession session, PlayerAuthInputPacket packet) { // Therefore, we're fixing this by allowing player to no clip to clip through the floor, not only this fixed the issue but // player y velocity should match java perfectly, much better than teleport player right down :) // Shouldn't mess with anything because beyond this point there is nothing to collide and not even entities since they're prob dead. - if (packet.getPosition().getY() - VanillaEntities.PLAYER_ENTITY_OFFSET< session.getBedrockDimension().minY() - 5) { + if (packet.getPosition().getY() - VanillaEntities.PLAYER_ENTITY_OFFSET < session.getBedrockDimension().minY() - 5) { // Ensuring that we still can collide with collidable entity that are also in the void (eg: boat, shulker) boolean possibleOnGround = false; diff --git a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java index d3ac2f5e8fe..bd1e982c5a3 100644 --- a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java @@ -271,7 +271,7 @@ public static void updateMountOffset(Entity passenger, Entity mount, boolean rid } } } else if (mountDefinition.is(BuiltinEntityType.HAPPY_GHAST)) { - int seatingIndex = Math.min(index, 4); + int seatingIndex = Math.min(index, 3); xOffset = HappyGhastEntity.X_OFFSETS[seatingIndex]; yOffset = 3.4f; zOffset = HappyGhastEntity.Z_OFFSETS[seatingIndex]; From 5a16517d3c22a7788cd5aba8f39257b82f625a64 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Thu, 27 Nov 2025 22:52:47 +0100 Subject: [PATCH 19/62] Another couple changes, start designing an entity data system to set scale/variant/height/width and so forth --- .../entity/custom/CustomEntityDefinition.java | 14 +---- .../entity/custom/CustomJavaEntityType.java | 3 +- .../entity/data/BatchEntityDataUpdater.java | 32 +++++++++++ .../api/entity/data/GeyserEntityData.java | 54 +++++++++++++++++++ .../entity/data/GeyserEntityDataTypes.java | 34 ++++++++++++ .../geyser/api/entity/type/GeyserEntity.java | 9 ++++ .../lifecycle/GeyserDefineEntitiesEvent.java | 5 +- .../geyser/command/CommandRegistry.java | 33 ++++++++++++ .../entity/BedrockEntityDefinition.java | 10 +++- .../geysermc/geyser/entity/type/Entity.java | 13 +++++ .../loader/ProviderRegistryLoader.java | 3 -- .../org/geysermc/geyser/util/EntityUtils.java | 28 +++++----- 12 files changed, 203 insertions(+), 35 deletions(-) create mode 100644 api/src/main/java/org/geysermc/geyser/api/entity/data/BatchEntityDataUpdater.java create mode 100644 api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityData.java create mode 100644 api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java index 6589c2a99ff..67120ba7628 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java @@ -25,13 +25,13 @@ package org.geysermc.geyser.api.entity.custom; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.geysermc.geyser.api.GeyserApi; import org.geysermc.geyser.api.entity.GeyserEntityDefinition; +import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; import org.geysermc.geyser.api.util.Identifier; /** * Represents a custom entity definition. + * To register, use {@link GeyserDefineEntitiesEvent#register(Identifier)} */ public interface CustomEntityDefinition extends GeyserEntityDefinition { @@ -39,14 +39,4 @@ public interface CustomEntityDefinition extends GeyserEntityDefinition { default boolean vanilla() { return false; } - - /** - * Creates a builder for a custom entity definition. - * - * @param bedrockIdentifier the Bedrock entity identifier - * @return a new builder - */ - static CustomEntityDefinition create(@NonNull Identifier bedrockIdentifier) { - return GeyserApi.api().provider(CustomEntityDefinition.class, bedrockIdentifier); - } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java index 2707730c7f0..1acfb7b8f40 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java @@ -79,8 +79,7 @@ interface Builder { * The default Bedrock edition entity definition. * You can define custom Bedrock entities, or use vanilla definitions * obtainable via the {@link GeyserDefineEntitiesEvent#entities()} collection. - * Calling this method with a non-registered {@link CustomEntityDefinition} will - * register it too. + * This entity has to be registered before calling this method! * * @param defaultBedrockDefinition the default Bedrock definition * @return this builder diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/BatchEntityDataUpdater.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/BatchEntityDataUpdater.java new file mode 100644 index 00000000000..7f6b6910986 --- /dev/null +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/BatchEntityDataUpdater.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.api.entity.data; + +@FunctionalInterface +public interface BatchEntityDataUpdater { + + void updateMetadata(GeyserEntityData type, T value); +} diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityData.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityData.java new file mode 100644 index 00000000000..3b7d75d9aa3 --- /dev/null +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityData.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.api.entity.data; + +import org.geysermc.geyser.api.GeyserApi; + +public interface GeyserEntityData { + + /** + * @return the type class + */ + Class typeClass(); + + /** + * @return the name of this entity data type + */ + String name(); + + /** + * Creates a new Geyser entity data type. + * + * @param typeClass the class of the value type + * @param name the name of the entity data type + * @throws IllegalArgumentException if such a type does not exist + * @return this instance + * @param the value type + */ + static GeyserEntityData of(Class typeClass, String name) { + return GeyserApi.api().provider(GeyserEntityData.class, typeClass, name); + } +} diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java new file mode 100644 index 00000000000..b6b3cdf5f00 --- /dev/null +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.api.entity.data; + +public final class GeyserEntityDataTypes { + public static final GeyserEntityData COLOR = GeyserEntityData.of(Byte.class, "COLOR"); + public static final GeyserEntityData VARIANT = GeyserEntityData.of(Integer.class, "VARIANT"); + public static final GeyserEntityData WIDTH = GeyserEntityData.of(Float.class, "WIDTH"); + public static final GeyserEntityData HEIGHT = GeyserEntityData.of(Float.class, "HEIGHT"); + public static final GeyserEntityData SCALE = GeyserEntityData.of(Float.class, "SCALE"); +} diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java b/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java index 17d7ac51f7a..98b33cf0a50 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java @@ -32,6 +32,7 @@ import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.api.connection.GeyserConnection; import org.geysermc.geyser.api.entity.GeyserEntityDefinition; +import org.geysermc.geyser.api.entity.data.BatchEntityDataUpdater; import org.geysermc.geyser.api.entity.property.BatchPropertyUpdater; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntityPropertiesEvent; @@ -115,6 +116,14 @@ default void updatePropertiesBatched(Consumer consumer) { this.updatePropertiesBatched(consumer, false); } + /** + * Updates Bedrock metadata, like scale, height, width and other entity metadata + * @see BatchEntityDataUpdater + * + * @param consumer a batch updater + */ + void updateEntityDataBatched(Consumer consumer); + /** * Updates multiple properties with just one update packet, which can be sent immediately to the client. * Usually, sending updates immediately is not required except for specific situations where packet batching diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java index 6e1f4f4b1c5..198242ffc4c 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java @@ -30,6 +30,7 @@ import org.geysermc.geyser.api.entity.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; import org.geysermc.geyser.api.entity.custom.CustomJavaEntityType; +import org.geysermc.geyser.api.util.Identifier; import java.util.Collection; import java.util.function.Consumer; @@ -50,9 +51,9 @@ public interface GeyserDefineEntitiesEvent extends Event { /** * Registers a custom entity definition - * @param customEntityDefinition the custom entity definition to register + * @param identifier the identifier of the custom entity to register */ - void register(@NonNull CustomEntityDefinition customEntityDefinition); + CustomEntityDefinition register(@NonNull Identifier identifier); /** * Registers a non-vanilla Java entity type. diff --git a/core/src/main/java/org/geysermc/geyser/command/CommandRegistry.java b/core/src/main/java/org/geysermc/geyser/command/CommandRegistry.java index 70bd21bc538..dbd6602b48f 100644 --- a/core/src/main/java/org/geysermc/geyser/command/CommandRegistry.java +++ b/core/src/main/java/org/geysermc/geyser/command/CommandRegistry.java @@ -34,12 +34,18 @@ import org.cloudburstmc.protocol.bedrock.data.command.CommandParam; import org.cloudburstmc.protocol.bedrock.data.command.CommandParamData; import org.cloudburstmc.protocol.bedrock.data.command.CommandPermission; +import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.command.Command; +import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; import org.geysermc.geyser.api.event.EventRegistrar; +import org.geysermc.geyser.api.event.java.ServerAttachParrotsEvent; +import org.geysermc.geyser.api.event.java.ServerSpawnEntityEvent; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineCommandsEvent; +import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; import org.geysermc.geyser.api.event.lifecycle.GeyserRegisterPermissionsEvent; import org.geysermc.geyser.api.extension.Extension; +import org.geysermc.geyser.api.util.Identifier; import org.geysermc.geyser.api.util.PlatformType; import org.geysermc.geyser.api.util.TriState; import org.geysermc.geyser.command.defaults.AdvancedTooltipsCommand; @@ -58,6 +64,8 @@ import org.geysermc.geyser.command.defaults.StatisticsCommand; import org.geysermc.geyser.command.defaults.StopCommand; import org.geysermc.geyser.command.defaults.VersionCommand; +import org.geysermc.geyser.entity.BedrockEntityDefinitions; +import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.event.type.GeyserDefineCommandsEventImpl; import org.geysermc.geyser.extension.command.GeyserExtensionCommand; import org.geysermc.geyser.session.GeyserSession; @@ -83,6 +91,7 @@ import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; import static org.geysermc.geyser.command.GeyserCommand.DEFAULT_ROOT_COMMAND; @@ -214,6 +223,30 @@ public void register(@NonNull Command command) { // Wait for the right moment (depends on the platform) to register permissions. geyser.eventBus().subscribe(this, GeyserRegisterPermissionsEvent.class, this::onRegisterPermissions); + + AtomicReference definition = new AtomicReference<>(); + + geyser.eventBus().subscribe(this, GeyserDefineEntitiesEvent.class, event -> { + definition.set(event.register(Identifier.of("sample", "robot"))); + }); + + geyser.eventBus().subscribe(this, ServerSpawnEntityEvent.class, event -> { + if (event.entityType().is(Identifier.of("armor_stand"))) { + event.entityDefinition(definition.get()); + + event.futureEntity().whenComplete((entity, throwable) -> { + if (entity != null) { + var a = (Entity) entity; + a.getDirtyMetadata().put(EntityDataTypes.SCALE, 0.5F); + a.updateBedrockMetadata(); + } + }); + } + }); + + geyser.eventBus().subscribe(this, ServerAttachParrotsEvent.class, event -> { + event.entityDefinition(BedrockEntityDefinitions.CHEST_BOAT); + }); } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java index 1498b3b8e40..d39d0bc94a8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java @@ -33,9 +33,11 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.api.entity.GeyserEntityDefinition; +import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.util.Identifier; import org.geysermc.geyser.entity.properties.GeyserEntityProperties; +import org.geysermc.geyser.registry.Registries; import java.util.List; import java.util.Objects; @@ -43,7 +45,7 @@ @Getter @Accessors(fluent = true) @ToString -public class BedrockEntityDefinition implements GeyserEntityDefinition { +public class BedrockEntityDefinition implements CustomEntityDefinition, GeyserEntityDefinition { private final @NonNull Identifier identifier; private final @NonNull GeyserEntityProperties registeredProperties; @@ -60,7 +62,11 @@ public static BedrockEntityDefinition of(Identifier identifier) { return builder().identifier(identifier).build(); } - public static BedrockEntityDefinition ofCustom(@NonNull Identifier identifier) { + public static BedrockEntityDefinition api(@NonNull Identifier identifier) { + if (Registries.BEDROCK_ENTITY_DEFINITIONS.get().containsKey(identifier)) { + return Registries.BEDROCK_ENTITY_DEFINITIONS.get().get(identifier); + } + Objects.requireNonNull(identifier, "identifier"); if (identifier.vanilla()) { throw new IllegalArgumentException("Cannot register custom entity in vanilla namespace! " + identifier); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index fe3354b5b96..962ebd661ad 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -854,4 +854,17 @@ public void update(@NonNull GeyserEntityProperty property, @Nullable T va public @NonNull Vector3f position() { return this.position.down(offset); } + + @Override + public void updateEntityDataBatched(Consumer consumer) { + Objects.requireNonNull(consumer); + consumer.accept(new BatchEntityDataUpdater() { + + @Override + public void updateMetadata(GeyserEntityData type, T value) { + // TODO + // ideally we just support any type cloudburst lib supports + } + }); + } } diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java index 8146476f9e5..414c17126d1 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java @@ -35,7 +35,6 @@ import org.geysermc.geyser.api.block.custom.nonvanilla.JavaBlockState; import org.geysermc.geyser.api.command.Command; import org.geysermc.geyser.api.entity.JavaEntityType; -import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; import org.geysermc.geyser.api.event.EventRegistrar; import org.geysermc.geyser.api.extension.Extension; import org.geysermc.geyser.api.item.custom.CustomItemData; @@ -47,7 +46,6 @@ import org.geysermc.geyser.api.pack.option.SubpackOption; import org.geysermc.geyser.api.pack.option.UrlFallbackOption; import org.geysermc.geyser.api.util.Identifier; -import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.event.GeyserEventRegistrar; import org.geysermc.geyser.extension.command.GeyserExtensionCommand; @@ -114,7 +112,6 @@ public Map, ProviderSupplier> load(Map, ProviderSupplier> prov providers.put(CameraPosition.Builder.class, args -> new GeyserCameraPosition.Builder()); // entities - providers.put(CustomEntityDefinition.class, args -> BedrockEntityDefinition.ofCustom((Identifier) args[0])); providers.put(JavaEntityType.class, args -> GeyserEntityType.ofVanilla((Identifier) args[0])); // TODO GeyserEntityData... diff --git a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java index bd1e982c5a3..48fe7332ec1 100644 --- a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java @@ -430,16 +430,18 @@ public Collection entities() { } @Override - public void register(@NonNull CustomEntityDefinition customEntityDefinition) { - Objects.requireNonNull(customEntityDefinition); - if (!(customEntityDefinition instanceof BedrockEntityDefinition definition)) { - throw new IllegalStateException("Unknown custom entity definition: " + customEntityDefinition); + public CustomEntityDefinition register(@NonNull Identifier identifier) { + Objects.requireNonNull(identifier); + if (Registries.BEDROCK_ENTITY_DEFINITIONS.get().containsKey(identifier)) { + throw new IllegalStateException("Duplicate custom entity definition: " + identifier); } - if (Registries.BEDROCK_ENTITY_DEFINITIONS.get().containsKey(definition.identifier())) { - throw new IllegalStateException("Duplicate custom entity definition: " + customEntityDefinition); + if (identifier.vanilla()) { + throw new IllegalStateException("Cannot register custom entity in vanilla namespace! " + identifier); } - Registries.BEDROCK_ENTITY_DEFINITIONS.register(definition.identifier(), definition); + BedrockEntityDefinition definition = BedrockEntityDefinition.api(identifier); + Registries.BEDROCK_ENTITY_DEFINITIONS.register(identifier, definition); customEntities.add(definition); + return definition; } @Override @@ -449,15 +451,13 @@ public void registerEntityType(Consumer consumer) var type = GeyserEntityType.createCustomAndRegister(builder); + var defaultBedrockDefinition = type.defaultBedrockDefinition(); + if (defaultBedrockDefinition != null && !isRegistered(defaultBedrockDefinition)) { + throw new IllegalStateException("Default bedrock entity definition has not been registered!"); + } // TODO register non-vanilla properly! Registries.JAVA_ENTITY_TYPES.register(type, null); Registries.JAVA_ENTITY_IDENTIFIERS.register(type.identifier().toString(), null); - - var defaultBedrockDefinition = type.defaultBedrockDefinition(); - if (defaultBedrockDefinition != null && !isRegistered(defaultBedrockDefinition) - && defaultBedrockDefinition instanceof CustomEntityDefinition customEntityDefinition) { - register(customEntityDefinition); - } } public boolean isRegistered(GeyserEntityDefinition definition) { @@ -486,7 +486,7 @@ public boolean isRegistered(GeyserEntityDefinition definition) { .build(); Registries.BEDROCK_ENTITY_IDENTIFIERS.set(newIdentifiers); - GeyserImpl.getInstance().getLogger().debug("Registered " + customEntities.size() + " custom entities"); + GeyserImpl.getInstance().getLogger().info("Registered " + customEntities.size() + " custom entities"); } GeyserImpl.getInstance().getEventBus().fire(new GeyserDefineEntityPropertiesEvent() { From 460305a515adb3e7a205fa88315641f4659125b5 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sun, 30 Nov 2025 02:13:20 +0100 Subject: [PATCH 20/62] Api design goes brrr --- .../geyser/api/entity/EntityData.java | 12 +- .../entity/custom/CustomEntityDefinition.java | 18 ++- .../entity/custom/CustomJavaEntityType.java | 4 +- .../entity/data/BatchEntityDataUpdater.java | 32 ----- ...ityData.java => GeyserEntityDataType.java} | 35 ++++-- .../entity/data/GeyserEntityDataTypes.java | 80 +++++++----- .../GeyserEntityDefinition.java | 22 +++- .../{ => definition}/JavaEntityType.java | 14 +-- .../geyser/api/entity/type/GeyserEntity.java | 42 +++---- .../bedrock/SessionSpawnEntityEvent.java | 18 +-- .../event/java/ServerSpawnEntityEvent.java | 36 +----- .../lifecycle/GeyserDefineEntitiesEvent.java | 8 +- .../geyser/command/CommandRegistry.java | 33 ----- .../entity/BedrockEntityDefinition.java | 16 ++- .../entity/BedrockEntityDefinitions.java | 18 +-- .../geyser/entity/GeyserDirtyMetadata.java | 5 + .../geyser/entity/GeyserEntityData.java | 18 +-- .../geyser/entity/GeyserEntityType.java | 27 ++-- .../NonVanillaEntityTypeDefinition.java | 17 +-- .../entity/spawn/EntitySpawnContext.java | 75 ++++------- .../geyser/entity/type/BoatEntity.java | 4 +- .../geysermc/geyser/entity/type/Entity.java | 51 +++++--- .../geyser/entity/type/ItemEntity.java | 6 +- .../geyser/entity/type/MinecartEntity.java | 2 +- .../geyser/entity/type/TNTEntity.java | 7 +- .../geyser/entity/type/TextDisplayEntity.java | 2 +- .../entity/type/player/AvatarEntity.java | 2 +- .../impl/entity/GeyserEntityDataImpl.java | 116 ++++++++++++++++++ .../loader/ProviderRegistryLoader.java | 10 +- .../TrialSpawnerBlockEntityTranslator.java | 2 +- .../player/input/BedrockMovePlayer.java | 2 +- .../BedrockPlayerAuthInputTranslator.java | 4 +- .../org/geysermc/geyser/util/EntityUtils.java | 33 ++--- 33 files changed, 432 insertions(+), 339 deletions(-) delete mode 100644 api/src/main/java/org/geysermc/geyser/api/entity/data/BatchEntityDataUpdater.java rename api/src/main/java/org/geysermc/geyser/api/entity/data/{GeyserEntityData.java => GeyserEntityDataType.java} (54%) rename api/src/main/java/org/geysermc/geyser/api/entity/{ => definition}/GeyserEntityDefinition.java (68%) rename api/src/main/java/org/geysermc/geyser/api/entity/{ => definition}/JavaEntityType.java (81%) create mode 100644 core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java b/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java index 00fbf871ec4..0dfc6b01518 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java @@ -41,23 +41,29 @@ */ public interface EntityData { + /** + * @deprecated use {@link #byGeyserId(long)} + */ + @Deprecated + @NonNull CompletableFuture<@Nullable GeyserEntity> entityByJavaId(@NonNegative int javaId); + /** * Returns a {@link GeyserEntity} to e.g. make them play an emote. * * @param javaId the Java entity ID to look up * @return a {@link GeyserEntity} if present in this connection's entity tracker */ - @NonNull CompletableFuture<@Nullable GeyserEntity> entityByJavaId(@NonNegative int javaId); + @Nullable GeyserEntity byJavaId(@NonNegative int javaId); /** * Returns a {@link GeyserEntity} to e.g. update entity properties. */ - @NonNull CompletableFuture<@Nullable GeyserEntity> entityByUuid(@NonNegative UUID javaUuid); + @Nullable GeyserEntity byUuid(@NonNull UUID javaUuid); /** * Returns a {@link GeyserEntity} based on a Geyser entity id */ - @NonNull CompletableFuture<@Nullable GeyserEntity> entityByGeyserId(@NonNegative long geyserId); + @Nullable GeyserEntity byGeyserId(@NonNegative long geyserId); /** * Displays a player entity as emoting to this client. diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java index 67120ba7628..f9a50de8708 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java @@ -25,13 +25,13 @@ package org.geysermc.geyser.api.entity.custom; -import org.geysermc.geyser.api.entity.GeyserEntityDefinition; -import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.geysermc.geyser.api.GeyserApi; +import org.geysermc.geyser.api.entity.definition.GeyserEntityDefinition; import org.geysermc.geyser.api.util.Identifier; /** - * Represents a custom entity definition. - * To register, use {@link GeyserDefineEntitiesEvent#register(Identifier)} + * Represents a custom entity definition for a non-vanilla, custom Bedrock entity. */ public interface CustomEntityDefinition extends GeyserEntityDefinition { @@ -39,4 +39,14 @@ public interface CustomEntityDefinition extends GeyserEntityDefinition { default boolean vanilla() { return false; } + + /** + * Creates or retrieves a GeyserEntityDefinition by the Bedrock entity type identifier. + * + * @param identifier the Bedrock entity identifier + * @return the GeyserEntityDefinition + */ + static @NonNull CustomEntityDefinition of(@NonNull Identifier identifier) { + return GeyserApi.api().provider(GeyserEntityDefinition.class, identifier); + } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java index 1acfb7b8f40..17bf6b51c8f 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java @@ -27,8 +27,8 @@ import org.checkerframework.checker.index.qual.NonNegative; import org.checkerframework.checker.nullness.qual.Nullable; -import org.geysermc.geyser.api.entity.GeyserEntityDefinition; -import org.geysermc.geyser.api.entity.JavaEntityType; +import org.geysermc.geyser.api.entity.definition.GeyserEntityDefinition; +import org.geysermc.geyser.api.entity.definition.JavaEntityType; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; import org.geysermc.geyser.api.util.Identifier; diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/BatchEntityDataUpdater.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/BatchEntityDataUpdater.java deleted file mode 100644 index 7f6b6910986..00000000000 --- a/api/src/main/java/org/geysermc/geyser/api/entity/data/BatchEntityDataUpdater.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2025 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.geyser.api.entity.data; - -@FunctionalInterface -public interface BatchEntityDataUpdater { - - void updateMetadata(GeyserEntityData type, T value); -} diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityData.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataType.java similarity index 54% rename from api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityData.java rename to api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataType.java index 3b7d75d9aa3..3484f217bf4 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityData.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataType.java @@ -26,29 +26,42 @@ package org.geysermc.geyser.api.entity.data; import org.geysermc.geyser.api.GeyserApi; +import org.geysermc.geyser.api.entity.type.GeyserEntity; -public interface GeyserEntityData { +/** + * Represents a type of entity data that can be sent for an entity. + *

+ * Entity data types define the kind of value stored for a particular piece of metadata, + * such as a {@code Byte}, {@code Integer}, {@code Float}; and the name associated with them. + *

+ * Unlike custom items or blocks, it is possible to update entity metadata at runtime, + * which can be done using {@link GeyserEntity#update(GeyserEntityDataType, Object)}. + * + * @param the value type associated with this entity data type + */ +public interface GeyserEntityDataType { /** - * @return the type class + * Gets the Java class representing the value type associated with this data type. + * + * @return the class of the value used by this entity data type */ Class typeClass(); /** + * Gets the unique name of this data type. + *

+ * The name is used internally to identify and register the data type so it can be + * referenced when reading or writing entity metadata. + * * @return the name of this entity data type */ String name(); /** - * Creates a new Geyser entity data type. - * - * @param typeClass the class of the value type - * @param name the name of the entity data type - * @throws IllegalArgumentException if such a type does not exist - * @return this instance - * @param the value type + * For API usage only; use the types defined in {@link GeyserEntityDataTypes} */ - static GeyserEntityData of(Class typeClass, String name) { - return GeyserApi.api().provider(GeyserEntityData.class, typeClass, name); + static GeyserEntityDataType of(Class typeClass, String name) { + return GeyserApi.api().provider(GeyserEntityDataType.class, typeClass, name); } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java index b6b3cdf5f00..ca280e1f119 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java @@ -1,34 +1,54 @@ -/* - * Copyright (c) 2025 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - package org.geysermc.geyser.api.entity.data; +/** + * Contains commonly used {@link GeyserEntityDataType} constants for built-in entity + * metadata fields. + *

+ * These data types define the structure of certain primitive or numeric metadata + * values that can be used for Bedrock entities. Each constant is backed by a + * pre-registered entity data type that can be used when reading or writing metadata + * through the Geyser API. + */ public final class GeyserEntityDataTypes { - public static final GeyserEntityData COLOR = GeyserEntityData.of(Byte.class, "COLOR"); - public static final GeyserEntityData VARIANT = GeyserEntityData.of(Integer.class, "VARIANT"); - public static final GeyserEntityData WIDTH = GeyserEntityData.of(Float.class, "WIDTH"); - public static final GeyserEntityData HEIGHT = GeyserEntityData.of(Float.class, "HEIGHT"); - public static final GeyserEntityData SCALE = GeyserEntityData.of(Float.class, "SCALE"); + + /** + * Represents a single-byte value used for color types + * (e.g., sheep wool color). + */ + public static final GeyserEntityDataType COLOR = + GeyserEntityDataType.of(Byte.class, "color"); + + /** + * Represents a numeric variant index that can be queried in resource packs. + */ + public static final GeyserEntityDataType VARIANT = + GeyserEntityDataType.of(Integer.class, "variant"); + + /** + * Represents the entity's width. + */ + public static final GeyserEntityDataType WIDTH = + GeyserEntityDataType.of(Float.class, "width"); + + /** + * Represents the entity's height. + */ + public static final GeyserEntityDataType HEIGHT = + GeyserEntityDataType.of(Float.class, "height"); + + /** + * Represents the entity's vertical offset. + */ + public static final GeyserEntityDataType VERTICAL_OFFSET = + GeyserEntityDataType.of(Float.class, "vertical_offset"); + + /** + * Represents the scale multiplier. + */ + public static final GeyserEntityDataType SCALE = + GeyserEntityDataType.of(Float.class, "scale"); + + private GeyserEntityDataTypes() { + // no-op + } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/GeyserEntityDefinition.java b/api/src/main/java/org/geysermc/geyser/api/entity/definition/GeyserEntityDefinition.java similarity index 68% rename from api/src/main/java/org/geysermc/geyser/api/entity/GeyserEntityDefinition.java rename to api/src/main/java/org/geysermc/geyser/api/entity/definition/GeyserEntityDefinition.java index 0090f26e5fa..6e720e2bc8f 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/GeyserEntityDefinition.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/definition/GeyserEntityDefinition.java @@ -23,15 +23,20 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.geyser.api.entity; +package org.geysermc.geyser.api.entity.definition; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.geysermc.geyser.api.GeyserApi; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; +import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; import org.geysermc.geyser.api.util.Identifier; import java.util.List; /** * Represents a Bedrock entity definition. + * Custom Bedrock entity definitions must be registered in the + * {@link GeyserDefineEntitiesEvent} before usage! */ public interface GeyserEntityDefinition { @@ -49,4 +54,19 @@ public interface GeyserEntityDefinition { * @return whether this entity is a vanilla entity */ boolean vanilla(); + + /** + * @return whether this definition has been registered + */ + boolean registered(); + + /** + * Creates or retrieves a GeyserEntityDefinition by the Bedrock entity type identifier. + * + * @param identifier the Bedrock entity identifier + * @return the GeyserEntityDefinition + */ + static @NonNull GeyserEntityDefinition of(@NonNull Identifier identifier) { + return GeyserApi.api().provider(GeyserEntityDefinition.class, identifier); + } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/definition/JavaEntityType.java similarity index 81% rename from api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java rename to api/src/main/java/org/geysermc/geyser/api/entity/definition/JavaEntityType.java index b87b5918c36..c7b7f865c78 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/JavaEntityType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/definition/JavaEntityType.java @@ -23,10 +23,9 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.geyser.api.entity; +package org.geysermc.geyser.api.entity.definition; import org.checkerframework.checker.nullness.qual.Nullable; -import org.geysermc.geyser.api.GeyserApi; import org.geysermc.geyser.api.util.Identifier; /** @@ -76,15 +75,4 @@ default boolean is(Identifier javaIdentifier) { * @return the default Bedrock entity definition */ @Nullable GeyserEntityDefinition defaultBedrockDefinition(); - - /** - * Returns the JavaEntityType representation of a built-in vanilla Java entity type. - * - * @param identifier the Java Edition entity type identifier - * @throws IllegalArgumentException if such an entity does not exist - * @return the Java Edition entity type for the vanilla entity type - */ - static JavaEntityType ofVanilla(Identifier identifier) { - return GeyserApi.api().provider(JavaEntityType.class, identifier); - } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java b/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java index 98b33cf0a50..dea35a5e0ff 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java @@ -31,8 +31,9 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.api.connection.GeyserConnection; -import org.geysermc.geyser.api.entity.GeyserEntityDefinition; -import org.geysermc.geyser.api.entity.data.BatchEntityDataUpdater; +import org.geysermc.geyser.api.entity.data.GeyserEntityDataType; +import org.geysermc.geyser.api.entity.data.GeyserEntityDataTypes; +import org.geysermc.geyser.api.entity.definition.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.property.BatchPropertyUpdater; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntityPropertiesEvent; @@ -59,7 +60,7 @@ public interface GeyserEntity { /** * @return the entity uuid that the server has assigned to this entity, - * or null if none is assigned + * or null if none is assigned */ @Nullable UUID uuid(); @@ -78,19 +79,24 @@ public interface GeyserEntity { @NonNull Vector3f position(); /** - * @return the width of the entity - */ - float width(); - - /** - * @return the height of the entity + * Queries the current value of a given {@link GeyserEntityDataType}. + * + * @see GeyserEntityDataTypes + * @param dataType the entity data type to query + * @return the value, or null if not set + * @param the type of the value */ - float height(); + @Nullable T value(@NonNull GeyserEntityDataType dataType); /** - * @return the offset of the entity + * Updates an entity property with a new value. + * If the new value is null, the property is reset to the default value. + * + * @param dataType an entity data type, such as from {@link GeyserEntityDataTypes} + * @param value the new property value + * @param the type of the value */ - float offset(); + void update(@NonNull GeyserEntityDataType dataType, @Nullable T value); /** * Updates an entity property with a new value. @@ -107,31 +113,23 @@ default void updateProperty(@NonNull GeyserEntityProperty property, @Null /** * Updates multiple properties with just one update packet. - * @see BatchPropertyUpdater * * @param consumer a batch updater + * @see BatchPropertyUpdater * @since 2.9.0 */ default void updatePropertiesBatched(Consumer consumer) { this.updatePropertiesBatched(consumer, false); } - /** - * Updates Bedrock metadata, like scale, height, width and other entity metadata - * @see BatchEntityDataUpdater - * - * @param consumer a batch updater - */ - void updateEntityDataBatched(Consumer consumer); - /** * Updates multiple properties with just one update packet, which can be sent immediately to the client. * Usually, sending updates immediately is not required except for specific situations where packet batching * would result in update order issues. - * @see BatchPropertyUpdater * * @param consumer a batch updater * @param immediate whether this update should be sent immediately + * @see BatchPropertyUpdater * @since 2.9.1 */ void updatePropertiesBatched(Consumer consumer, boolean immediate); diff --git a/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionSpawnEntityEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionSpawnEntityEvent.java index 4fe11980472..176e84792ed 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionSpawnEntityEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionSpawnEntityEvent.java @@ -29,14 +29,14 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.event.Cancellable; import org.geysermc.geyser.api.connection.GeyserConnection; -import org.geysermc.geyser.api.entity.GeyserEntityDefinition; +import org.geysermc.geyser.api.entity.definition.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.type.GeyserEntity; import org.geysermc.geyser.api.event.connection.ConnectionEvent; -import org.geysermc.geyser.api.event.java.ServerSpawnEntityEvent; import org.geysermc.geyser.api.event.java.ServerAttachParrotsEvent; +import org.geysermc.geyser.api.event.java.ServerSpawnEntityEvent; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; -import java.util.concurrent.CompletableFuture; +import java.util.function.Consumer; /** * See {@link ServerSpawnEntityEvent} and {@link ServerAttachParrotsEvent} @@ -52,7 +52,7 @@ public SessionSpawnEntityEvent(@NonNull GeyserConnection connection) { * * @return the entity definition sent to the connection when the entity is spawned */ - public abstract @Nullable GeyserEntityDefinition entityDefinition(); + public abstract @Nullable GeyserEntityDefinition definition(); /** * Sets the entity definition sent to the connection when the entity is spawned. @@ -61,10 +61,14 @@ public SessionSpawnEntityEvent(@NonNull GeyserConnection connection) { * * @param entityDefinition the entity definition sent to the connection when the entity is spawned */ - public abstract void entityDefinition(@Nullable GeyserEntityDefinition entityDefinition); + public abstract void definition(@Nullable GeyserEntityDefinition entityDefinition); /** - * @return the GeyserEntity once it is created, or null if the spawn event is cancelled + * Adds a consumer for the {@link GeyserEntity} that will be called once the entity is created, + * assuming that it hasn't been cancelled. + * Using this method, you can modify the entities' entity properties, scale, with, and other entity data. + * + * @param consumer the consumer for the new GeyserEntity */ - public abstract CompletableFuture<@Nullable GeyserEntity> futureEntity(); + public abstract void preSpawnConsumer(Consumer<@NonNull GeyserEntity> consumer); } diff --git a/api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java index a0135e8bc15..cb292d9a3d3 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java @@ -25,11 +25,10 @@ package org.geysermc.geyser.api.event.java; -import org.checkerframework.checker.index.qual.NonNegative; import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.event.Cancellable; import org.geysermc.geyser.api.connection.GeyserConnection; -import org.geysermc.geyser.api.entity.JavaEntityType; +import org.geysermc.geyser.api.entity.definition.JavaEntityType; import org.geysermc.geyser.api.event.bedrock.SessionSpawnEntityEvent; import java.util.UUID; @@ -63,37 +62,4 @@ public ServerSpawnEntityEvent(@NonNull GeyserConnection connection) { * @return the Java edition entity type of the entity being spawned */ public abstract @NonNull JavaEntityType entityType(); - - /** - * @return the width of the entity - */ - public abstract float width(); - - /** - * Sets the width of the entity. - */ - public abstract void width(@NonNegative float width); - - /** - * @return the height of the entity - */ - public abstract float height(); - - /** - * Sets the height of the entity. - */ - public abstract void height(@NonNegative float height); - - /** - * The vertical offset applied by Geyser to ensure the Bedrock entity doesn't clip - * into the ground due to Java vs Bedrock differences. - * - * @return the offset of the entity - */ - public abstract float offset(); - - /** - * Sets the vertical offset applied by Geyser to avoid clipping - */ - public abstract void offset(@NonNegative float offset); } diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java index 198242ffc4c..81e87a8031d 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java @@ -27,10 +27,8 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.event.Event; -import org.geysermc.geyser.api.entity.GeyserEntityDefinition; -import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; import org.geysermc.geyser.api.entity.custom.CustomJavaEntityType; -import org.geysermc.geyser.api.util.Identifier; +import org.geysermc.geyser.api.entity.definition.GeyserEntityDefinition; import java.util.Collection; import java.util.function.Consumer; @@ -51,9 +49,9 @@ public interface GeyserDefineEntitiesEvent extends Event { /** * Registers a custom entity definition - * @param identifier the identifier of the custom entity to register + * @param definition the custom entity definition to register */ - CustomEntityDefinition register(@NonNull Identifier identifier); + void register(@NonNull GeyserEntityDefinition definition); /** * Registers a non-vanilla Java entity type. diff --git a/core/src/main/java/org/geysermc/geyser/command/CommandRegistry.java b/core/src/main/java/org/geysermc/geyser/command/CommandRegistry.java index dbd6602b48f..70bd21bc538 100644 --- a/core/src/main/java/org/geysermc/geyser/command/CommandRegistry.java +++ b/core/src/main/java/org/geysermc/geyser/command/CommandRegistry.java @@ -34,18 +34,12 @@ import org.cloudburstmc.protocol.bedrock.data.command.CommandParam; import org.cloudburstmc.protocol.bedrock.data.command.CommandParamData; import org.cloudburstmc.protocol.bedrock.data.command.CommandPermission; -import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.command.Command; -import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; import org.geysermc.geyser.api.event.EventRegistrar; -import org.geysermc.geyser.api.event.java.ServerAttachParrotsEvent; -import org.geysermc.geyser.api.event.java.ServerSpawnEntityEvent; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineCommandsEvent; -import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; import org.geysermc.geyser.api.event.lifecycle.GeyserRegisterPermissionsEvent; import org.geysermc.geyser.api.extension.Extension; -import org.geysermc.geyser.api.util.Identifier; import org.geysermc.geyser.api.util.PlatformType; import org.geysermc.geyser.api.util.TriState; import org.geysermc.geyser.command.defaults.AdvancedTooltipsCommand; @@ -64,8 +58,6 @@ import org.geysermc.geyser.command.defaults.StatisticsCommand; import org.geysermc.geyser.command.defaults.StopCommand; import org.geysermc.geyser.command.defaults.VersionCommand; -import org.geysermc.geyser.entity.BedrockEntityDefinitions; -import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.event.type.GeyserDefineCommandsEventImpl; import org.geysermc.geyser.extension.command.GeyserExtensionCommand; import org.geysermc.geyser.session.GeyserSession; @@ -91,7 +83,6 @@ import java.util.Locale; import java.util.Map; import java.util.Set; -import java.util.concurrent.atomic.AtomicReference; import static org.geysermc.geyser.command.GeyserCommand.DEFAULT_ROOT_COMMAND; @@ -223,30 +214,6 @@ public void register(@NonNull Command command) { // Wait for the right moment (depends on the platform) to register permissions. geyser.eventBus().subscribe(this, GeyserRegisterPermissionsEvent.class, this::onRegisterPermissions); - - AtomicReference definition = new AtomicReference<>(); - - geyser.eventBus().subscribe(this, GeyserDefineEntitiesEvent.class, event -> { - definition.set(event.register(Identifier.of("sample", "robot"))); - }); - - geyser.eventBus().subscribe(this, ServerSpawnEntityEvent.class, event -> { - if (event.entityType().is(Identifier.of("armor_stand"))) { - event.entityDefinition(definition.get()); - - event.futureEntity().whenComplete((entity, throwable) -> { - if (entity != null) { - var a = (Entity) entity; - a.getDirtyMetadata().put(EntityDataTypes.SCALE, 0.5F); - a.updateBedrockMetadata(); - } - }); - } - }); - - geyser.eventBus().subscribe(this, ServerAttachParrotsEvent.class, event -> { - event.entityDefinition(BedrockEntityDefinitions.CHEST_BOAT); - }); } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java index d39d0bc94a8..a17ca1f156d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java @@ -32,8 +32,8 @@ import lombok.experimental.Accessors; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -import org.geysermc.geyser.api.entity.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; +import org.geysermc.geyser.api.entity.definition.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.util.Identifier; import org.geysermc.geyser.entity.properties.GeyserEntityProperties; @@ -45,7 +45,7 @@ @Getter @Accessors(fluent = true) @ToString -public class BedrockEntityDefinition implements CustomEntityDefinition, GeyserEntityDefinition { +public class BedrockEntityDefinition implements GeyserEntityDefinition, CustomEntityDefinition { private final @NonNull Identifier identifier; private final @NonNull GeyserEntityProperties registeredProperties; @@ -58,18 +58,19 @@ public static Builder builder() { return new Builder(); } - public static BedrockEntityDefinition of(Identifier identifier) { + public static BedrockEntityDefinition ofVanilla(Identifier identifier) { return builder().identifier(identifier).build(); } - public static BedrockEntityDefinition api(@NonNull Identifier identifier) { + public static BedrockEntityDefinition getOrCreate(@NonNull Identifier identifier) { + Objects.requireNonNull(identifier, "identifier"); if (Registries.BEDROCK_ENTITY_DEFINITIONS.get().containsKey(identifier)) { return Registries.BEDROCK_ENTITY_DEFINITIONS.get().get(identifier); } Objects.requireNonNull(identifier, "identifier"); if (identifier.vanilla()) { - throw new IllegalArgumentException("Cannot register custom entity in vanilla namespace! " + identifier); + throw new IllegalArgumentException("Cannot create custom entity in vanilla namespace! " + identifier); } return builder().identifier(identifier).build(); } @@ -87,6 +88,11 @@ public boolean vanilla() { return identifier.vanilla(); } + @Override + public boolean registered() { + return Registries.BEDROCK_ENTITY_DEFINITIONS.get().containsKey(identifier); + } + public static class Builder { private Identifier identifier; @Setter(AccessLevel.NONE) diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java index 0bfcdd0a70b..aabc7766626 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java @@ -43,15 +43,15 @@ public class BedrockEntityDefinitions { public static final BedrockEntityDefinition ZOMBIE; static { - ARMOR_STAND = BedrockEntityDefinition.of(IdentifierImpl.of("armor_stand")); - ARROW = BedrockEntityDefinition.of(IdentifierImpl.of("arrow")); - BOAT = BedrockEntityDefinition.of(IdentifierImpl.of("boat")); - CHEST_BOAT = BedrockEntityDefinition.of(IdentifierImpl.of("chest_boat")); - EVOCATION_ILLAGER = BedrockEntityDefinition.of(IdentifierImpl.of("evocation_illager")); - LLAMA = BedrockEntityDefinition.of(IdentifierImpl.of("llama")); - MINECART = BedrockEntityDefinition.of(IdentifierImpl.of("minecraft")); - SPLASH_POTION = BedrockEntityDefinition.of(IdentifierImpl.of("splash_position")); - ZOMBIE = BedrockEntityDefinition.of(IdentifierImpl.of("zombie")); + ARMOR_STAND = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("armor_stand")); + ARROW = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("arrow")); + BOAT = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("boat")); + CHEST_BOAT = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("chest_boat")); + EVOCATION_ILLAGER = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("evocation_illager")); + LLAMA = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("llama")); + MINECART = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("minecraft")); + SPLASH_POTION = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("splash_position")); + ZOMBIE = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("zombie")); } public static void init() { diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserDirtyMetadata.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserDirtyMetadata.java index 1ee84f4b5ef..0aa15691fb4 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserDirtyMetadata.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserDirtyMetadata.java @@ -26,19 +26,24 @@ package org.geysermc.geyser.entity; import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; +import lombok.AllArgsConstructor; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataMap; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataType; +import org.geysermc.geyser.entity.type.Entity; import java.util.Map; /** * A wrapper for temporarily storing entity metadata that will be sent to Bedrock. */ +@AllArgsConstructor public final class GeyserDirtyMetadata { + private final Entity entity; private final Map, Object> metadata = new Object2ObjectLinkedOpenHashMap<>(); public void put(EntityDataType entityData, T value) { metadata.put(entityData, value); + entity.getMetadata().put(entityData, value); } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java index 43e0ca36615..06a3b311a57 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java @@ -59,17 +59,19 @@ public GeyserEntityData(GeyserSession session) { } @Override - public @NonNull CompletableFuture<@Nullable GeyserEntity> entityByUuid(@NonNegative UUID javaUuid) { - CompletableFuture future = new CompletableFuture<>(); - session.ensureInEventLoop(() -> future.complete(session.getEntityCache().getEntityByUuid(javaUuid))); - return future; + public @Nullable GeyserEntity byJavaId(@NonNegative int javaId) { + return session.getEntityCache().getEntityByJavaId(javaId); } @Override - public @NonNull CompletableFuture<@Nullable GeyserEntity> entityByGeyserId(@NonNegative long geyserId) { - CompletableFuture future = new CompletableFuture<>(); - session.ensureInEventLoop(() -> future.complete(session.getEntityCache().getEntityByGeyserId(geyserId))); - return future; + public @Nullable GeyserEntity byUuid(@NonNull UUID javaUuid) { + Objects.requireNonNull(javaUuid, "javaUuid"); + return session.getEntityCache().getEntityByUuid(javaUuid); + } + + @Override + public @Nullable GeyserEntity byGeyserId(@NonNegative long geyserId) { + return session.getEntityCache().getEntityByGeyserId(geyserId); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java index 1b3d2e2571f..0a8a811c353 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java @@ -35,9 +35,9 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.Constants; -import org.geysermc.geyser.api.entity.GeyserEntityDefinition; -import org.geysermc.geyser.api.entity.JavaEntityType; import org.geysermc.geyser.api.entity.custom.CustomJavaEntityType; +import org.geysermc.geyser.api.entity.definition.GeyserEntityDefinition; +import org.geysermc.geyser.api.entity.definition.JavaEntityType; import org.geysermc.geyser.api.util.Identifier; import org.geysermc.geyser.impl.IdentifierImpl; import org.geysermc.geyser.registry.Registries; @@ -50,7 +50,7 @@ import java.util.Map; import java.util.Objects; -public record GeyserEntityType(Identifier identifier, int javaId) implements CustomJavaEntityType, JavaEntityType { +public record GeyserEntityType(Identifier identifier, int javaId) implements JavaEntityType, CustomJavaEntityType { private static final Identifier UNREGISTERED = IdentifierImpl.of(Constants.GEYSER_CUSTOM_NAMESPACE, "unregistered_sadface"); private static final Map VANILLA = new EnumMap<>(BuiltinEntityType.class); @@ -141,7 +141,6 @@ public static GeyserEntityType of(EntityType type) { return type instanceof BuiltinEntityType builtin ? ofVanilla(builtin) : of(type.id()); } - @SuppressWarnings("ConstantValue") public static GeyserEntityType createCustomAndRegister(Builder builder) { Identifier javaIdentifier = Objects.requireNonNull(builder.identifier, "javaIdentifier may not be null"); int javaId = builder.javaId; @@ -167,10 +166,10 @@ public static class Builder implements CustomJavaEntityType.Builder { private int javaId; private float width; private float height; - private GeyserEntityDefinition defaultBedrockDefinition; + private BedrockEntityDefinition defaultBedrockDefinition; @Override - public CustomJavaEntityType.Builder type(@NonNull Identifier entityType) { + public Builder type(@NonNull Identifier entityType) { Objects.requireNonNull(entityType, "entityType may not be null"); if (entityType.vanilla()) { throw new IllegalArgumentException("Cannot register custom entity type in vanilla namespace!" + entityType); @@ -183,7 +182,7 @@ public CustomJavaEntityType.Builder type(@NonNull Identifier entityType) { } @Override - public CustomJavaEntityType.Builder javaId(int javaId) { + public Builder javaId(int javaId) { if (javaId < 0) { throw new IllegalArgumentException("Invalid custom entity type id (may not be negative): " + javaId); } @@ -198,7 +197,7 @@ public CustomJavaEntityType.Builder javaId(int javaId) { } @Override - public CustomJavaEntityType.Builder width(@NonNegative float width) { + public Builder width(@NonNegative float width) { if (width < 0) { throw new IllegalArgumentException("Invalid custom entity type width (may not be negative): " + width); } @@ -207,7 +206,7 @@ public CustomJavaEntityType.Builder width(@NonNegative float width) { } @Override - public CustomJavaEntityType.Builder height(@NonNegative float height) { + public Builder height(@NonNegative float height) { if (height < 0) { throw new IllegalArgumentException("Invalid custom entity type height (may not be negative): " + height); } @@ -216,8 +215,14 @@ public CustomJavaEntityType.Builder height(@NonNegative float height) { } @Override - public CustomJavaEntityType.Builder defaultBedrockDefinition(@Nullable GeyserEntityDefinition defaultBedrockDefinition) { - this.defaultBedrockDefinition = defaultBedrockDefinition; + public Builder defaultBedrockDefinition(@Nullable GeyserEntityDefinition defaultBedrockDefinition) { + if (defaultBedrockDefinition == null) { + this.defaultBedrockDefinition = null; + } else if (defaultBedrockDefinition instanceof BedrockEntityDefinition bedrockEntityDefinition) { + this.defaultBedrockDefinition = bedrockEntityDefinition; + } else { + throw new IllegalArgumentException("Invalid default geyser definition: " + defaultBedrockDefinition); + } return this; } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/NonVanillaEntityTypeDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/NonVanillaEntityTypeDefinition.java index 3365848733b..c4a66f572d4 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/NonVanillaEntityTypeDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/NonVanillaEntityTypeDefinition.java @@ -29,22 +29,23 @@ import lombok.Getter; import lombok.ToString; import lombok.experimental.Accessors; -import org.geysermc.geyser.entity.factory.EntityFactory; import org.geysermc.geyser.entity.type.Entity; -import org.geysermc.geyser.translator.entity.EntityMetadataTranslator; import org.geysermc.mcprotocollib.protocol.data.game.entity.type.BuiltinEntityType; -import java.util.List; - @Getter @Accessors(fluent = true) @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -// TODO -public class NonVanillaEntityTypeDefinition extends EntityTypeDefinition { +public class NonVanillaEntityTypeDefinition extends EntityTypeDefinition { + + /* + Soooooooooooooo this is fun. + - How should we expose entity metadata translators? + - Extending "vanilla" classes / entities??? Geyser uses instanceof checks... + */ - public NonVanillaEntityTypeDefinition(EntityFactory factory, GeyserEntityType type, BedrockEntityDefinition definition, List> translators) { - super(factory, type, 0, 0,0, definition, translators); + public NonVanillaEntityTypeDefinition(GeyserEntityType.Builder builder, GeyserEntityType entityType) { + super(Entity::new, entityType, builder.getWidth(), builder.getHeight(), 0f, builder.getDefaultBedrockDefinition(), VanillaEntityBases.ENTITY.translators); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java index 5c870f28fe0..6513d00041d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java +++ b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java @@ -29,14 +29,13 @@ import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; -import org.checkerframework.checker.index.qual.NonNegative; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.common.util.TriFunction; import org.geysermc.geyser.GeyserImpl; -import org.geysermc.geyser.api.entity.GeyserEntityDefinition; -import org.geysermc.geyser.api.entity.JavaEntityType; +import org.geysermc.geyser.api.entity.definition.GeyserEntityDefinition; +import org.geysermc.geyser.api.entity.definition.JavaEntityType; import org.geysermc.geyser.api.entity.type.GeyserEntity; import org.geysermc.geyser.api.entity.type.player.GeyserPlayerEntity; import org.geysermc.geyser.api.event.java.ServerAttachParrotsEvent; @@ -48,8 +47,10 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundAddEntityPacket; +import java.util.Collection; +import java.util.HashSet; import java.util.UUID; -import java.util.concurrent.CompletableFuture; +import java.util.function.Consumer; @Getter @Setter @@ -70,7 +71,7 @@ public class EntitySpawnContext { private float width; private float offset; private @Nullable Long geyserId; - private CompletableFuture<@Nullable GeyserEntity> geyserEntityFuture; + private @Nullable Collection> consumers; public static final TriFunction, EntitySpawnContext> DUMMY_CONTEXT = ((session, uuid, definition) -> { return new EntitySpawnContext(session, definition, 0, uuid); @@ -78,7 +79,7 @@ public class EntitySpawnContext { public EntitySpawnContext(GeyserSession session, EntityTypeDefinition type, int javaId, UUID uuid) { this(session, type, javaId, uuid, type.defaultBedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, - type.height(), type.width(), type.offset(), null, new CompletableFuture<>()); + type.height(), type.width(), type.offset(), null, null); } public EntitySpawnContext(GeyserSession session, EntityTypeDefinition type, int entityId, BedrockEntityDefinition definition, float height, float width, long geyserId) { @@ -89,12 +90,12 @@ public static EntitySpawnContext fromPacket(GeyserSession session, EntityTypeDef Vector3f position = Vector3f.from(packet.getX(), packet.getY(), packet.getZ()); Vector3f motion = packet.getMovement().toFloat(); return new EntitySpawnContext(session, definition, packet.getEntityId(), packet.getUuid(), definition.defaultBedrockDefinition(), - position, motion, packet.getYaw(), packet.getPitch(), packet.getHeadYaw(), definition.height(), definition.width(), definition.offset(), null, new CompletableFuture<>()); + position, motion, packet.getYaw(), packet.getPitch(), packet.getHeadYaw(), definition.height(), definition.width(), definition.offset(), null, null); } public static EntitySpawnContext inherited(GeyserSession session, EntityTypeDefinition definition, Entity base, Vector3f position) { return new EntitySpawnContext(session, definition, 0, null, definition.defaultBedrockDefinition(), position, base.getMotion(), base.getYaw(), - base.getPitch(), base.getHeadYaw(), definition.height(), definition.width(), definition.offset(), null, new CompletableFuture<>()); + base.getPitch(), base.getHeadYaw(), definition.height(), definition.width(), definition.offset(), null, null); } public void callServerSpawnEvent() { @@ -126,42 +127,12 @@ public int entityId() { } @Override - public float width() { - return width; - } - - @Override - public void width(@NonNegative float newWidth) { - width = newWidth; - } - - @Override - public float height() { - return height; - } - - @Override - public void height(@NonNegative float newHeight) { - height = newHeight; - } - - @Override - public float offset() { - return offset; - } - - @Override - public void offset(@NonNegative float newOffset) { - offset = newOffset; - } - - @Override - public @Nullable GeyserEntityDefinition entityDefinition() { + public @Nullable GeyserEntityDefinition definition() { return bedrockEntityDefinition; } @Override - public void entityDefinition(@Nullable GeyserEntityDefinition entityDefinition) { + public void definition(@Nullable GeyserEntityDefinition entityDefinition) { if (entityDefinition == null) { bedrockEntityDefinition = null; } else { @@ -174,8 +145,11 @@ public void entityDefinition(@Nullable GeyserEntityDefinition entityDefinition) } @Override - public CompletableFuture<@Nullable GeyserEntity> futureEntity() { - return geyserEntityFuture; + public void preSpawnConsumer(Consumer<@NonNull GeyserEntity> consumer) { + if (consumers == null) { + consumers = new HashSet<>(); + } + consumers.add(consumer); } }); } @@ -198,12 +172,12 @@ public boolean right() { } @Override - public @Nullable GeyserEntityDefinition entityDefinition() { + public @Nullable GeyserEntityDefinition definition() { return bedrockEntityDefinition; } @Override - public void entityDefinition(@Nullable GeyserEntityDefinition entityDefinition) { + public void definition(@Nullable GeyserEntityDefinition entityDefinition) { if (entityDefinition == null) { bedrockEntityDefinition = null; } else { @@ -215,11 +189,6 @@ public void entityDefinition(@Nullable GeyserEntityDefinition entityDefinition) } } - @Override - public CompletableFuture<@Nullable GeyserEntity> futureEntity() { - return geyserEntityFuture; - } - @Override public boolean isCancelled() { return bedrockEntityDefinition == null; @@ -229,6 +198,14 @@ public boolean isCancelled() { public void setCancelled(boolean cancelled) { bedrockEntityDefinition = null; } + + @Override + public void preSpawnConsumer(Consumer<@NonNull GeyserEntity> consumer) { + if (consumers == null) { + consumers = new HashSet<>(); + } + consumers.add(consumer); + } }); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java index e34f0936a8e..7dda5092414 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java @@ -92,7 +92,7 @@ protected void initializeMetadata() { @Override public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { // We don't include the rotation (y) as it causes the boat to appear sideways - setPosition(position.add(0d, offset(), 0d)); + setPosition(position.add(0d, offset, 0d)); setYaw(yaw + 90); setHeadYaw(yaw + 90); setOnGround(isOnGround); @@ -101,7 +101,7 @@ public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYa moveEntityPacket.setRuntimeEntityId(geyserId); if (session.getPlayerEntity().getVehicle() == this && session.getPlayerEntity().isRidingInFront()) { // Minimal glitching when ClientboundMoveVehiclePacket is sent - moveEntityPacket.setPosition(position.up(VanillaEntities.PLAYER_ENTITY_OFFSET - offset())); + moveEntityPacket.setPosition(position.up(VanillaEntities.PLAYER_ENTITY_OFFSET - offset)); } else { moveEntityPacket.setPosition(this.position); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index 962ebd661ad..8bdd9d547be 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.entity.type; +import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; @@ -34,6 +35,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector2f; import org.cloudburstmc.math.vector.Vector3f; +import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; @@ -44,9 +46,8 @@ import org.cloudburstmc.protocol.bedrock.packet.MoveEntityDeltaPacket; import org.cloudburstmc.protocol.bedrock.packet.RemoveEntityPacket; import org.cloudburstmc.protocol.bedrock.packet.SetEntityDataPacket; -import org.geysermc.geyser.api.entity.GeyserEntityDefinition; -import org.geysermc.geyser.api.entity.data.BatchEntityDataUpdater; -import org.geysermc.geyser.api.entity.data.GeyserEntityData; +import org.geysermc.geyser.api.entity.data.GeyserEntityDataType; +import org.geysermc.geyser.api.entity.definition.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.property.BatchPropertyUpdater; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.entity.type.GeyserEntity; @@ -59,6 +60,7 @@ import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.geyser.entity.type.living.MobEntity; import org.geysermc.geyser.entity.type.player.PlayerEntity; +import org.geysermc.geyser.impl.entity.GeyserEntityDataImpl; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.level.physics.BoundingBox; @@ -79,6 +81,7 @@ import java.util.Collections; import java.util.EnumMap; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -142,7 +145,12 @@ public class Entity implements GeyserEntity { /** * A container to store temporary metadata before it's sent to Bedrock. */ - protected final GeyserDirtyMetadata dirtyMetadata = new GeyserDirtyMetadata(); + protected final GeyserDirtyMetadata dirtyMetadata = new GeyserDirtyMetadata(this); + /** + * A container storing all current metadata for an entity. + */ + protected final Map, Object> metadata = new Object2ObjectLinkedOpenHashMap<>(); + /** * The entity flags for the Bedrock entity. * These must always be saved - if flags are updated and the other values aren't present, the Bedrock client will @@ -161,7 +169,6 @@ public class Entity implements GeyserEntity { protected float width; @Accessors(fluent = true) protected float height; - @Accessors(fluent = true) protected float offset; protected final @Nullable GeyserEntityPropertyManager propertyManager; @@ -193,7 +200,9 @@ public Entity(EntitySpawnContext context) { initializeMetadata(); // Allow API users to do things pre-spawn - context.geyserEntityFuture().complete(this); + if (context.consumers() != null) { + context.consumers().forEach(consumer -> consumer.accept(this)); + } } /** @@ -840,6 +849,13 @@ public void update(@NonNull GeyserEntityProperty property, @Nullable T va } } + public void offset(float offset) { + // TODO queue!! + if (isValid()) { + this.moveRelative(0, offset, 0, 0, 0, isOnGround()); + } + } + @Override public @Nullable UUID uuid() { return uuid; @@ -856,15 +872,20 @@ public void update(@NonNull GeyserEntityProperty property, @Nullable T va } @Override - public void updateEntityDataBatched(Consumer consumer) { - Objects.requireNonNull(consumer); - consumer.accept(new BatchEntityDataUpdater() { + public void update(@NonNull GeyserEntityDataType dataType, @Nullable T value) { + if (dataType instanceof GeyserEntityDataImpl geyserEntityDataImpl) { + geyserEntityDataImpl.update(this, value); + } else { + throw new IllegalArgumentException("Invalid data type: " + dataType.getClass().getSimpleName()); + } + } - @Override - public void updateMetadata(GeyserEntityData type, T value) { - // TODO - // ideally we just support any type cloudburst lib supports - } - }); + @Override + public T value(@NonNull GeyserEntityDataType dataType) { + if (dataType instanceof GeyserEntityDataImpl geyserEntityDataImpl) { + return geyserEntityDataImpl.value(this); + } else { + throw new IllegalArgumentException("Invalid data type: " + dataType.getClass().getSimpleName()); + } } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java index 5b5cb7b2827..171d7956764 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java @@ -59,7 +59,7 @@ public void spawnEntity() { AddItemEntityPacket itemPacket = new AddItemEntityPacket(); itemPacket.setRuntimeEntityId(geyserId); itemPacket.setUniqueEntityId(geyserId); - itemPacket.setPosition(position.add(0d, offset(), 0d)); + itemPacket.setPosition(position.add(0d, offset, 0d)); itemPacket.setMotion(motion); itemPacket.setFromFishing(false); itemPacket.setItemInHand(item); @@ -110,10 +110,10 @@ public void setItem(EntityMetadata entityMetadata) { @Override protected void moveAbsoluteImmediate(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - float offset = offset(); + float offset = super.offset; if (waterLevel.join() == 0) { // Item is in a full block of water // Move the item entity down so it doesn't float above the water - offset = -offset(); + offset = -offset; } super.moveAbsoluteImmediate(position.add(0, offset, 0), 0, 0, 0, isOnGround, teleported); this.position = position; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java index 1f69e21718f..0cd37e2fa18 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java @@ -112,7 +112,7 @@ public void tick() { moveEntityPacket.setRuntimeEntityId(geyserId); moveEntityPacket.setX(position.getX()); - moveEntityPacket.setY(position.getY() + offset()); + moveEntityPacket.setY(position.getY() + offset); moveEntityPacket.setZ(position.getZ()); moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_X); moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Y); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java index 9d88967e37b..c1624d64434 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java @@ -40,14 +40,9 @@ public TNTEntity(EntitySpawnContext context) { setPosition(position.up(offset)); } - @Override - public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, boolean isOnGround) { - super.moveRelative(relX, relY + offset(), relZ, yaw, pitch, isOnGround); - } - @Override public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - super.moveAbsolute(position.add(Vector3f.from(0, offset(), 0)), yaw, pitch, headYaw, isOnGround, teleported); + super.moveAbsolute(position.add(Vector3f.from(0, offset, 0)), yaw, pitch, headYaw, isOnGround, teleported); } public void setFuseLength(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java index 303b2f7461e..62a175a10bd 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java @@ -59,7 +59,7 @@ public TextDisplayEntity(EntitySpawnContext context) { @Override public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, boolean isOnGround) { - super.moveRelative(relX, relY + offset(), relZ, yaw, pitch, isOnGround); + super.moveRelative(relX, relY + offset, relZ, yaw, pitch, isOnGround); } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java index bb241798a94..f9eeeae8ff7 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java @@ -111,7 +111,7 @@ public void spawnEntity() { addPlayerPacket.setUsername(username); addPlayerPacket.setRuntimeEntityId(geyserId); addPlayerPacket.setUniqueEntityId(geyserId); - addPlayerPacket.setPosition(position.sub(0, offset(), 0)); + addPlayerPacket.setPosition(position()); addPlayerPacket.setRotation(getBedrockRotation()); addPlayerPacket.setMotion(motion); addPlayerPacket.setHand(ItemTranslator.translateToBedrock(session, getMainHandItem())); diff --git a/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java b/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java new file mode 100644 index 00000000000..5fec98b0a1a --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.impl.entity; + +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import lombok.AllArgsConstructor; +import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataType; +import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; +import org.geysermc.geyser.api.entity.data.GeyserEntityDataType; +import org.geysermc.geyser.entity.type.Entity; + +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Function; + +@AllArgsConstructor +public class GeyserEntityDataImpl implements GeyserEntityDataType { + + public static Map> TYPES; + static { + TYPES = new Object2ObjectOpenHashMap<>(); + TYPES.put("color", new GeyserEntityDataImpl<>(Byte.class, "color", EntityDataTypes.COLOR)); + TYPES.put("variant", new GeyserEntityDataImpl<>(Integer.class, "variant", EntityDataTypes.VARIANT)); + TYPES.put("width", new GeyserEntityDataImpl<>(Float.class, "width", EntityDataTypes.WIDTH)); + TYPES.put("height", new GeyserEntityDataImpl<>(Float.class, "height", EntityDataTypes.HEIGHT)); + TYPES.put("scale", new GeyserEntityDataImpl<>(Float.class, "scale", EntityDataTypes.SCALE)); + + // "custom" + TYPES.put("vertical_offset", new GeyserEntityDataImpl<>(Float.class, "offset", Entity::offset, Entity::getOffset)); + } + + public static GeyserEntityDataImpl lookup(Class clazz, String name) { + var type = TYPES.get(name); + if (type == null) { + throw new IllegalArgumentException("Unknown entity data type: " + name); + } + if (type.typeClass == clazz) { + return TYPES.get(name); + } + throw new IllegalArgumentException("Unknown entity data type: " + name); + } + + private final Class typeClass; + private final String name; + private final BiConsumer consumer; + private final Function getter; + + public GeyserEntityDataImpl(Class typeClass, String name, EntityDataType type) { + this.typeClass = typeClass; + this.name = name; + this.consumer = (entity, data) -> entity.getDirtyMetadata().put(type, data); + this.getter = entity -> { + var value = entity.getMetadata().get(type); + // Always the case! + if (typeClass.isInstance(value)) { + return typeClass.cast(value); + } else { + return null; + } + }; + } + + public GeyserEntityDataImpl(Class typeClass, String name, EntityFlag flag) { + this.typeClass = typeClass; + this.name = name; + this.consumer = (entity, data) -> { + if (!(data instanceof Boolean bool)) { + throw new RuntimeException("Invalid data type: " + data.getClass().getName()); + } + entity.setFlag(flag, bool); + }; + this.getter = entity -> typeClass.cast(entity.getFlag(flag)); + } + + @Override + public Class typeClass() { + return typeClass; + } + + @Override + public String name() { + return name; + } + + public void update(Entity entity, T value) { + consumer.accept(entity, value); + } + + public T value(Entity entity) { + return getter.apply(entity); + } +} diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java index 414c17126d1..67d4b873b5b 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java @@ -34,7 +34,9 @@ import org.geysermc.geyser.api.block.custom.component.MaterialInstance; import org.geysermc.geyser.api.block.custom.nonvanilla.JavaBlockState; import org.geysermc.geyser.api.command.Command; -import org.geysermc.geyser.api.entity.JavaEntityType; +import org.geysermc.geyser.api.entity.data.GeyserEntityDataType; +import org.geysermc.geyser.api.entity.definition.GeyserEntityDefinition; +import org.geysermc.geyser.api.entity.definition.JavaEntityType; import org.geysermc.geyser.api.event.EventRegistrar; import org.geysermc.geyser.api.extension.Extension; import org.geysermc.geyser.api.item.custom.CustomItemData; @@ -46,12 +48,14 @@ import org.geysermc.geyser.api.pack.option.SubpackOption; import org.geysermc.geyser.api.pack.option.UrlFallbackOption; import org.geysermc.geyser.api.util.Identifier; +import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.GeyserEntityType; import org.geysermc.geyser.event.GeyserEventRegistrar; import org.geysermc.geyser.extension.command.GeyserExtensionCommand; import org.geysermc.geyser.impl.IdentifierImpl; import org.geysermc.geyser.impl.camera.GeyserCameraFade; import org.geysermc.geyser.impl.camera.GeyserCameraPosition; +import org.geysermc.geyser.impl.entity.GeyserEntityDataImpl; import org.geysermc.geyser.item.GeyserCustomItemData; import org.geysermc.geyser.item.GeyserCustomItemOptions; import org.geysermc.geyser.item.GeyserNonVanillaCustomItemData; @@ -112,9 +116,9 @@ public Map, ProviderSupplier> load(Map, ProviderSupplier> prov providers.put(CameraPosition.Builder.class, args -> new GeyserCameraPosition.Builder()); // entities + providers.put(GeyserEntityDefinition.class, args -> BedrockEntityDefinition.getOrCreate((Identifier) args[0])); providers.put(JavaEntityType.class, args -> GeyserEntityType.ofVanilla((Identifier) args[0])); - - // TODO GeyserEntityData... + providers.put(GeyserEntityDataType.class, args -> GeyserEntityDataImpl.lookup((Class) args[0], (String) args[1])); return providers; } diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java index fbfd1c268f0..ba820c949dc 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/TrialSpawnerBlockEntityTranslator.java @@ -48,7 +48,7 @@ public void translateTag(GeyserSession session, NbtMapBuilder bedrockNbt, NbtMap } NbtMapBuilder spawnData = NbtMap.builder(); EntityTypeDefinition definition = Registries.JAVA_ENTITY_IDENTIFIERS.get(entityData.getString("id")); - if (definition != null) { + if (definition != null && definition.defaultBedrockDefinition() != null) { spawnData.putString("TypeId", definition.defaultBedrockDefinition().identifier().toString()); } spawnData.putInt("Weight", entityData.getInt("Size", 1)); // ??? presumably since these are the only other two extra attributes diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java index f007a8fbc82..c10bd562df6 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java @@ -146,7 +146,7 @@ static void translate(GeyserSession session, PlayerAuthInputPacket packet) { final BoundingBox entityBoundingBox = new BoundingBox(0, 0, 0, other.getBoundingBoxWidth(), other.getBoundingBoxHeight(), other.getBoundingBoxWidth()); // Also offset the position down for boat as their position is offset. - entityBoundingBox.translate(other.getPosition().down(other instanceof BoatEntity ? other.offset() : 0).toDouble()); + entityBoundingBox.translate(other.getPosition().down(other instanceof BoatEntity ? other.getOffset() : 0).toDouble()); if (entityBoundingBox.checkIntersection(boundingBox)) { possibleOnGround = true; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java index aaae7a56a69..e27de87c4c8 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java @@ -290,7 +290,7 @@ private static void processVehicleInput(GeyserSession session, PlayerAuthInputPa Vector3f position = vehicle.getPosition(); if (vehicle instanceof BoatEntity) { - position = position.down(vehicle.offset()); + position = position.down(vehicle.getOffset()); } final BoundingBox box = new BoundingBox( @@ -327,7 +327,7 @@ private static void processVehicleInput(GeyserSession session, PlayerAuthInputPa if (vehicle instanceof BoatEntity) { // Remove some Y position to prevents boats flying up - vehiclePosition = vehiclePosition.down(vehicle.offset()); + vehiclePosition = vehiclePosition.down(vehicle.getOffset()); } vehicle.setPosition(vehiclePosition); diff --git a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java index 48fe7332ec1..698c98a8c3c 100644 --- a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java @@ -35,9 +35,8 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.GeyserImpl; -import org.geysermc.geyser.api.entity.GeyserEntityDefinition; -import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; import org.geysermc.geyser.api.entity.custom.CustomJavaEntityType; +import org.geysermc.geyser.api.entity.definition.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.entity.property.type.GeyserFloatEntityProperty; import org.geysermc.geyser.api.entity.property.type.GeyserStringEnumProperty; @@ -47,6 +46,7 @@ import org.geysermc.geyser.entity.BedrockEntityDefinition; import org.geysermc.geyser.entity.EntityTypeDefinition; import org.geysermc.geyser.entity.GeyserEntityType; +import org.geysermc.geyser.entity.NonVanillaEntityTypeDefinition; import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.properties.type.BooleanProperty; import org.geysermc.geyser.entity.properties.type.EnumProperty; @@ -430,18 +430,20 @@ public Collection entities() { } @Override - public CustomEntityDefinition register(@NonNull Identifier identifier) { - Objects.requireNonNull(identifier); - if (Registries.BEDROCK_ENTITY_DEFINITIONS.get().containsKey(identifier)) { - throw new IllegalStateException("Duplicate custom entity definition: " + identifier); + public void register(@NonNull GeyserEntityDefinition entityDefinition) { + Objects.requireNonNull(entityDefinition); + if (!(entityDefinition instanceof BedrockEntityDefinition bedrockEntityDefinition)) { + throw new IllegalArgumentException("EntityDefinition must not be a custom implementation of BedrockEntityDefinition! Found " + entityDefinition.getClass().getSimpleName()); + } + + if (Registries.BEDROCK_ENTITY_DEFINITIONS.get().containsValue(bedrockEntityDefinition)) { + throw new IllegalStateException("Duplicate custom entity definition: " + entityDefinition); } - if (identifier.vanilla()) { - throw new IllegalStateException("Cannot register custom entity in vanilla namespace! " + identifier); + if (bedrockEntityDefinition.vanilla()) { + throw new IllegalStateException("Cannot register entity in vanilla namespace! " + bedrockEntityDefinition.identifier()); } - BedrockEntityDefinition definition = BedrockEntityDefinition.api(identifier); - Registries.BEDROCK_ENTITY_DEFINITIONS.register(identifier, definition); - customEntities.add(definition); - return definition; + Registries.BEDROCK_ENTITY_DEFINITIONS.register(bedrockEntityDefinition.identifier(), bedrockEntityDefinition); + customEntities.add(bedrockEntityDefinition); } @Override @@ -455,9 +457,10 @@ public void registerEntityType(Consumer consumer) if (defaultBedrockDefinition != null && !isRegistered(defaultBedrockDefinition)) { throw new IllegalStateException("Default bedrock entity definition has not been registered!"); } - // TODO register non-vanilla properly! - Registries.JAVA_ENTITY_TYPES.register(type, null); - Registries.JAVA_ENTITY_IDENTIFIERS.register(type.identifier().toString(), null); + + NonVanillaEntityTypeDefinition definition = new NonVanillaEntityTypeDefinition(builder, type); + Registries.JAVA_ENTITY_TYPES.register(type, definition); + Registries.JAVA_ENTITY_IDENTIFIERS.register(type.identifier().toString(), definition); } public boolean isRegistered(GeyserEntityDefinition definition) { From b26b9d17fbedbddef192e88a9a4fb39e3594396b Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sun, 30 Nov 2025 02:25:43 +0100 Subject: [PATCH 21/62] Implement dirty entities to send updates once a tick --- .../geyser/entity/GeyserDirtyMetadata.java | 5 ----- .../org/geysermc/geyser/entity/type/Entity.java | 17 +++++++++-------- .../geysermc/geyser/session/GeyserSession.java | 8 +++++++- .../geyser/session/cache/EntityCache.java | 9 +++++++++ 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserDirtyMetadata.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserDirtyMetadata.java index 0aa15691fb4..1ee84f4b5ef 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserDirtyMetadata.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserDirtyMetadata.java @@ -26,24 +26,19 @@ package org.geysermc.geyser.entity; import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; -import lombok.AllArgsConstructor; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataMap; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataType; -import org.geysermc.geyser.entity.type.Entity; import java.util.Map; /** * A wrapper for temporarily storing entity metadata that will be sent to Bedrock. */ -@AllArgsConstructor public final class GeyserDirtyMetadata { - private final Entity entity; private final Map, Object> metadata = new Object2ObjectLinkedOpenHashMap<>(); public void put(EntityDataType entityData, T value) { metadata.put(entityData, value); - entity.getMetadata().put(entityData, value); } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index 8bdd9d547be..1a33012e319 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -145,7 +145,7 @@ public class Entity implements GeyserEntity { /** * A container to store temporary metadata before it's sent to Bedrock. */ - protected final GeyserDirtyMetadata dirtyMetadata = new GeyserDirtyMetadata(this); + protected final GeyserDirtyMetadata dirtyMetadata = new GeyserDirtyMetadata(); /** * A container storing all current metadata for an entity. */ @@ -413,7 +413,7 @@ public void updateBedrockMetadata() { return; } - if (dirtyMetadata.hasEntries() || flagsDirty) { + if (dirtyMetadata.hasEntries() || flagsDirty || (propertyManager != null && propertyManager.hasProperties())) { SetEntityDataPacket entityDataPacket = new SetEntityDataPacket(); entityDataPacket.setRuntimeEntityId(geyserId); if (flagsDirty) { @@ -837,20 +837,20 @@ public void update(@NonNull GeyserEntityProperty property, @Nullable T va }); if (propertyManager.hasProperties()) { - SetEntityDataPacket packet = new SetEntityDataPacket(); - packet.setRuntimeEntityId(geyserId()); - propertyManager.applyFloatProperties(packet.getProperties().getFloatProperties()); - propertyManager.applyIntProperties(packet.getProperties().getIntProperties()); if (immediate) { + SetEntityDataPacket packet = new SetEntityDataPacket(); + packet.setRuntimeEntityId(geyserId()); + propertyManager.applyFloatProperties(packet.getProperties().getFloatProperties()); + propertyManager.applyIntProperties(packet.getProperties().getIntProperties()); session.sendUpstreamPacketImmediately(packet); } else { - session.sendUpstreamPacket(packet); + session.getEntityCache().markDirty(this); } } } public void offset(float offset) { - // TODO queue!! + // TODO queue? if (isValid()) { this.moveRelative(0, offset, 0, 0, 0, isOnGround()); } @@ -875,6 +875,7 @@ public void offset(float offset) { public void update(@NonNull GeyserEntityDataType dataType, @Nullable T value) { if (dataType instanceof GeyserEntityDataImpl geyserEntityDataImpl) { geyserEntityDataImpl.update(this, value); + session.getEntityCache().markDirty(this); } else { throw new IllegalArgumentException("Invalid data type: " + dataType.getClass().getSimpleName()); } diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index 8c29870f658..fed487cddc3 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -125,8 +125,8 @@ import org.geysermc.geyser.command.CommandRegistry; import org.geysermc.geyser.command.GeyserCommandSource; import org.geysermc.geyser.configuration.GeyserConfig; -import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.GeyserEntityData; +import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.attribute.GeyserAttributeType; import org.geysermc.geyser.entity.type.BoatEntity; import org.geysermc.geyser.entity.type.Entity; @@ -235,6 +235,7 @@ import java.util.Collections; import java.util.EnumSet; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -1262,6 +1263,11 @@ protected void tick() { clientVehicle.getVehicleComponent().tickVehicle(); } + for (Iterator it = entityCache.getDirtyEntities().iterator(); it.hasNext(); ) { + it.next().updateBedrockMetadata(); + it.remove(); + } + for (Tickable entity : entityCache.getTickableEntities()) { entity.drawTick(); if (gameShouldUpdate) { diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java index 45fc536adf6..83d0f68eed4 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java @@ -33,6 +33,7 @@ import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import lombok.Getter; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.Tickable; @@ -42,6 +43,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.UUID; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Consumer; @@ -63,6 +65,8 @@ public class EntityCache { private final Object2LongMap entityUuidTranslations = new Object2LongOpenHashMap<>(); private final Map playerEntities = new Object2ObjectOpenHashMap<>(); private final Map bossBars = new Object2ObjectOpenHashMap<>(); + @Getter + private final Set dirtyEntities = new ObjectOpenHashSet<>(); @Getter private final AtomicLong nextEntityId = new AtomicLong(2L); @@ -123,6 +127,11 @@ public void removeEntity(Entity entity) { if (entity instanceof Tickable) { tickableEntities.remove(entity); } + dirtyEntities.remove(entity); + } + + public void markDirty(Entity entity) { + dirtyEntities.add(entity); } public void removeAllEntities() { From 37f1285fbdb10faa7f01cbfdf3061af0ee8d82c9 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sun, 30 Nov 2025 02:30:16 +0100 Subject: [PATCH 22/62] Fix NPE in test --- .../geysermc/geyser/entity/spawn/EntitySpawnContext.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java index 6513d00041d..617d8e22bb5 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java +++ b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java @@ -45,6 +45,7 @@ import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.player.PlayerEntity; import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.util.EnvironmentUtils; import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundAddEntityPacket; import java.util.Collection; @@ -99,6 +100,11 @@ public static EntitySpawnContext inherited(GeyserSession session, EntityTypeDefi } public void callServerSpawnEvent() { + // TODO we should actually test this? + if (EnvironmentUtils.IS_UNIT_TESTING) { + return; + } + GeyserImpl.getInstance().getEventBus().fire(new ServerSpawnEntityEvent(session) { @Override From a64865024af30e6390278cb22c2109d83c0d5801 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sun, 30 Nov 2025 13:11:21 +0100 Subject: [PATCH 23/62] Attempt to add feature branch publishing --- build-logic/src/main/kotlin/extensions.kt | 12 ++++++++++++ .../kotlin/geyser.publish-conventions.gradle.kts | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/build-logic/src/main/kotlin/extensions.kt b/build-logic/src/main/kotlin/extensions.kt index d785259960b..47b104719cb 100644 --- a/build-logic/src/main/kotlin/extensions.kt +++ b/build-logic/src/main/kotlin/extensions.kt @@ -24,6 +24,7 @@ */ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import net.kyori.indra.git.IndraGitExtension import org.gradle.api.DefaultTask import org.gradle.api.Project import org.gradle.api.artifacts.MinimalExternalModuleDependency @@ -33,6 +34,7 @@ import org.gradle.api.tasks.Input import org.gradle.api.tasks.options.Option import org.gradle.api.tasks.TaskAction import org.gradle.kotlin.dsl.named +import org.gradle.kotlin.dsl.the import java.io.File import java.net.URL @@ -114,6 +116,16 @@ open class DownloadFilesTask : DefaultTask() { } } +fun Project.branchName(): String = + the().branchName() ?: System.getenv("BRANCH_NAME") ?: "local/dev" + +fun Project.shouldAddBranchName(): Boolean { + return branchName() !in arrayOf("master", "local/dev") +} + +fun Project.versionWithBranchName(): String = + branchName().replace(Regex("[^0-9A-Za-z-_]"), "-") + '-' + version + private fun calcExclusion(section: String, bit: Int, excludedOn: Int): String = if (excludedOn and bit > 0) section else "" diff --git a/build-logic/src/main/kotlin/geyser.publish-conventions.gradle.kts b/build-logic/src/main/kotlin/geyser.publish-conventions.gradle.kts index eca5877216d..753b245319e 100644 --- a/build-logic/src/main/kotlin/geyser.publish-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/geyser.publish-conventions.gradle.kts @@ -4,6 +4,12 @@ plugins { } indra { + configurePublications { + if (shouldAddBranchName()) { + version = versionWithBranchName() + } + } + publishSnapshotsTo("geysermc", "https://repo.opencollab.dev/maven-snapshots") publishReleasesTo("geysermc", "https://repo.opencollab.dev/maven-releases") } @@ -12,4 +18,4 @@ publishing { // skip shadow jar from publishing. Workaround for https://github.com/johnrengelman/shadow/issues/651 val javaComponent = project.components["java"] as AdhocComponentWithVariants javaComponent.withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) { skip() } -} \ No newline at end of file +} From a497d3d84cd6cec9e3c3d59cd88a68b437d48ba5 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sun, 30 Nov 2025 15:28:47 +0100 Subject: [PATCH 24/62] API polishing; properly initialize height/width --- .../api/connection/GeyserConnection.java | 4 +- .../geyser/api/entity/EntityData.java | 3 +- .../entity/custom/CustomJavaEntityType.java | 2 +- .../geyser/api/entity/type/GeyserEntity.java | 7 +-- .../lifecycle/GeyserDefineEntitiesEvent.java | 10 +++-- .../GeyserDefineEntityPropertiesEvent.java | 6 +-- .../entity/BedrockEntityDefinition.java | 18 ++------ .../geyser/entity/GeyserEntityType.java | 2 +- .../NonVanillaEntityTypeDefinition.java | 6 --- .../entity/spawn/EntitySpawnContext.java | 44 ++++++++++++++----- .../geyser/entity/type/DisplayBaseEntity.java | 2 +- .../geysermc/geyser/entity/type/Entity.java | 14 +++--- .../living/monster/EnderDragonPartEntity.java | 7 +-- .../entity/type/player/PlayerEntity.java | 11 ++++- .../geyser/session/GeyserSession.java | 2 +- .../java/entity/JavaAddEntityTranslator.java | 8 +++- .../org/geysermc/geyser/util/EntityUtils.java | 11 +++-- 17 files changed, 89 insertions(+), 68 deletions(-) diff --git a/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java b/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java index 648ede4d2a5..9e96709038a 100644 --- a/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java +++ b/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java @@ -180,9 +180,7 @@ public interface GeyserConnection extends Connection, CommandSource { * * @param emoter the player entity emoting. * @param emoteId the emote ID to send to this client. - * @deprecated use {@link EntityData#showEmote(GeyserPlayerEntity, String)} instead */ - @Deprecated void showEmote(@NonNull GeyserPlayerEntity emoter, @NonNull String emoteId); /** @@ -250,5 +248,5 @@ public interface GeyserConnection extends Connection, CommandSource { * Sends a request to the Java server to switch the items in the main and offhand. * There is no guarantee of the server accepting the request. */ - void requestHandSwap(); + void switchHands(); } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java b/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java index 0dfc6b01518..191c037f0ea 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java @@ -71,6 +71,7 @@ public interface EntityData { * @param emoter the player entity emoting * @param emoteId the emote ID to send to this client */ + @Deprecated void showEmote(@NonNull GeyserPlayerEntity emoter, @NonNull String emoteId); /** @@ -98,7 +99,7 @@ public interface EntityData { boolean isMovementLocked(); /** - * @deprecated use {@link GeyserConnection#requestHandSwap()} + * @deprecated use {@link GeyserConnection#switchHands()} */ @Deprecated void switchHands(); diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java index 17bf6b51c8f..2181dd2ba5f 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java @@ -84,6 +84,6 @@ interface Builder { * @param defaultBedrockDefinition the default Bedrock definition * @return this builder */ - Builder defaultBedrockDefinition(@Nullable GeyserEntityDefinition defaultBedrockDefinition); + Builder definition(@Nullable GeyserEntityDefinition defaultBedrockDefinition); } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java b/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java index dea35a5e0ff..29fb2cd6f66 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java @@ -112,12 +112,9 @@ default void updateProperty(@NonNull GeyserEntityProperty property, @Null } /** - * Updates multiple properties with just one update packet. - * - * @param consumer a batch updater - * @see BatchPropertyUpdater - * @since 2.9.0 + * @deprecated - use {@link #updateProperty(GeyserEntityProperty, Object)} instead */ + @Deprecated default void updatePropertiesBatched(Consumer consumer) { this.updatePropertiesBatched(consumer, false); } diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java index 81e87a8031d..9bfeb78a27e 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java @@ -27,6 +27,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.event.Event; +import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; import org.geysermc.geyser.api.entity.custom.CustomJavaEntityType; import org.geysermc.geyser.api.entity.definition.GeyserEntityDefinition; @@ -37,8 +38,6 @@ * Called when entities are defined within Geyser. *

* This event can be used to add custom entities to Geyser. - * Entity definitions can be created using the builder provided - * inside of {@link GeyserEntityDefinition}. */ public interface GeyserDefineEntitiesEvent extends Event { @@ -47,11 +46,16 @@ public interface GeyserDefineEntitiesEvent extends Event { */ Collection entities(); + /** + * @return an immutable collection of all registered custom entity definitions + */ + Collection customEntities(); + /** * Registers a custom entity definition * @param definition the custom entity definition to register */ - void register(@NonNull GeyserEntityDefinition definition); + void register(@NonNull CustomEntityDefinition definition); /** * Registers a non-vanilla Java entity type. diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntityPropertiesEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntityPropertiesEvent.java index 94091d3be6e..55ffa4112d1 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntityPropertiesEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntityPropertiesEvent.java @@ -41,7 +41,6 @@ import java.util.Collection; import java.util.List; -import java.util.function.Consumer; /** * Lifecycle event fired during Geyser's startup to allow custom entity properties @@ -63,10 +62,9 @@ * } * } * - * Retrieving entity instances is possible with the {@link EntityData#entityByJavaId(int)} method, or + * Retrieving entity instances is possible with, for example, the {@link EntityData#byJavaId(int)} method, or * {@link GeyserConnection#playerEntity()} for the connection player entity. - * To update the value of a property on a specific entity, use {@link GeyserEntity#updateProperty(GeyserEntityProperty, Object)}, - * or {@link GeyserEntity#updatePropertiesBatched(Consumer)} to update multiple properties efficiently at once. + * To update the value of a property on a specific entity, use {@link GeyserEntity#updateProperty(GeyserEntityProperty, Object)}. * *

Notes: *

    diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java index a17ca1f156d..72530bea926 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java @@ -26,10 +26,7 @@ package org.geysermc.geyser.entity; import lombok.AccessLevel; -import lombok.Getter; import lombok.Setter; -import lombok.ToString; -import lombok.experimental.Accessors; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; @@ -42,17 +39,10 @@ import java.util.List; import java.util.Objects; -@Getter -@Accessors(fluent = true) -@ToString -public class BedrockEntityDefinition implements GeyserEntityDefinition, CustomEntityDefinition { - private final @NonNull Identifier identifier; - private final @NonNull GeyserEntityProperties registeredProperties; - - public BedrockEntityDefinition(@NonNull Identifier identifier, @NonNull GeyserEntityProperties registeredProperties) { - this.identifier = identifier; - this.registeredProperties = registeredProperties; - } +public record BedrockEntityDefinition( + @NonNull Identifier identifier, + @NonNull GeyserEntityProperties registeredProperties +) implements GeyserEntityDefinition, CustomEntityDefinition { public static Builder builder() { return new Builder(); diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java index 0a8a811c353..c46b71043ca 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java @@ -215,7 +215,7 @@ public Builder height(@NonNegative float height) { } @Override - public Builder defaultBedrockDefinition(@Nullable GeyserEntityDefinition defaultBedrockDefinition) { + public Builder definition(@Nullable GeyserEntityDefinition defaultBedrockDefinition) { if (defaultBedrockDefinition == null) { this.defaultBedrockDefinition = null; } else if (defaultBedrockDefinition instanceof BedrockEntityDefinition bedrockEntityDefinition) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/NonVanillaEntityTypeDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/NonVanillaEntityTypeDefinition.java index c4a66f572d4..07f45d0dc82 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/NonVanillaEntityTypeDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/NonVanillaEntityTypeDefinition.java @@ -38,12 +38,6 @@ @ToString(callSuper = true) public class NonVanillaEntityTypeDefinition extends EntityTypeDefinition { - /* - Soooooooooooooo this is fun. - - How should we expose entity metadata translators? - - Extending "vanilla" classes / entities??? Geyser uses instanceof checks... - */ - public NonVanillaEntityTypeDefinition(GeyserEntityType.Builder builder, GeyserEntityType entityType) { super(Entity::new, entityType, builder.getWidth(), builder.getHeight(), 0f, builder.getDefaultBedrockDefinition(), VanillaEntityBases.ENTITY.translators); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java index 617d8e22bb5..29655c74894 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java +++ b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java @@ -25,7 +25,6 @@ package org.geysermc.geyser.entity.spawn; -import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; @@ -56,7 +55,6 @@ @Getter @Setter @Accessors(fluent = true) -@AllArgsConstructor public class EntitySpawnContext { private final GeyserSession session; private final EntityTypeDefinition entityTypeDefinition; @@ -80,29 +78,51 @@ public class EntitySpawnContext { public EntitySpawnContext(GeyserSession session, EntityTypeDefinition type, int javaId, UUID uuid) { this(session, type, javaId, uuid, type.defaultBedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, - type.height(), type.width(), type.offset(), null, null); + type.height(), type.width(), type.offset(), null); } public EntitySpawnContext(GeyserSession session, EntityTypeDefinition type, int entityId, BedrockEntityDefinition definition, float height, float width, long geyserId) { - this(session, type, entityId, null, definition, Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, height, width, 0, geyserId, null); + this(session, type, entityId, null, definition, Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, height, width, 0, geyserId); } public static EntitySpawnContext fromPacket(GeyserSession session, EntityTypeDefinition definition, ClientboundAddEntityPacket packet) { Vector3f position = Vector3f.from(packet.getX(), packet.getY(), packet.getZ()); Vector3f motion = packet.getMovement().toFloat(); return new EntitySpawnContext(session, definition, packet.getEntityId(), packet.getUuid(), definition.defaultBedrockDefinition(), - position, motion, packet.getYaw(), packet.getPitch(), packet.getHeadYaw(), definition.height(), definition.width(), definition.offset(), null, null); + position, motion, packet.getYaw(), packet.getPitch(), packet.getHeadYaw(), definition.height(), definition.width(), definition.offset(), null); } public static EntitySpawnContext inherited(GeyserSession session, EntityTypeDefinition definition, Entity base, Vector3f position) { return new EntitySpawnContext(session, definition, 0, null, definition.defaultBedrockDefinition(), position, base.getMotion(), base.getYaw(), - base.getPitch(), base.getHeadYaw(), definition.height(), definition.width(), definition.offset(), null, null); + base.getPitch(), base.getHeadYaw(), definition.height(), definition.width(), definition.offset(), null); } - public void callServerSpawnEvent() { - // TODO we should actually test this? + public EntitySpawnContext(GeyserSession session, EntityTypeDefinition definition, int javaId, UUID uuid, BedrockEntityDefinition bedrockEntityDefinition, Vector3f position, + Vector3f motion, float yaw, float pitch, float headYaw, float height, float width, float offset, @Nullable Long geyserId) { + this.session = session; + this.entityTypeDefinition = definition; + this.javaId = javaId; + this.uuid = uuid; + this.bedrockEntityDefinition = bedrockEntityDefinition; + this.position = position; + this.motion = motion; + this.yaw = yaw; + this.pitch = pitch; + this.headYaw = headYaw; + this.height = height; + this.width = width; + this.offset = offset; + this.geyserId = geyserId; + this.consumers = null; + } + + /** + * @return true if an entity should be spawned + */ + public boolean callServerSpawnEvent() { + // TODO add tests if (EnvironmentUtils.IS_UNIT_TESTING) { - return; + return true; } GeyserImpl.getInstance().getEventBus().fire(new ServerSpawnEntityEvent(session) { @@ -158,9 +178,11 @@ public void preSpawnConsumer(Consumer<@NonNull GeyserEntity> consumer) { consumers.add(consumer); } }); + + return bedrockEntityDefinition != null; } - public void callParrotEvent(PlayerEntity player, int variant, boolean right) { + public boolean callParrotEvent(PlayerEntity player, int variant, boolean right) { GeyserImpl.getInstance().eventBus().fire(new ServerAttachParrotsEvent(session) { @Override public GeyserPlayerEntity player() { @@ -213,5 +235,7 @@ public void preSpawnConsumer(Consumer<@NonNull GeyserEntity> consumer) { consumers.add(consumer); } }); + + return bedrockEntityDefinition != null; } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/DisplayBaseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/DisplayBaseEntity.java index cb7d29e728a..b338f965827 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/DisplayBaseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/DisplayBaseEntity.java @@ -55,7 +55,7 @@ public void setDisplayName(EntityMetadata, ?> entityMetadata // On JE: custom name does not override text display. } - public void setTranslation(EntityMetadata translationMeta){ + public void setTranslation(EntityMetadata translationMeta) { this.baseTranslation = translationMeta.getValue(); if (this.baseTranslation == null) { return; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index 1a33012e319..f6c21792f03 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -108,6 +108,9 @@ public class Entity implements GeyserEntity { @Setter(AccessLevel.NONE) protected String nametag = ""; + /** + * The entity position, WITH vertical offset + */ protected Vector3f position; protected Vector3f motion; @@ -194,21 +197,18 @@ public Entity(EntitySpawnContext context) { this.valid = false; this.propertyManager = bedrockDefinition.registeredProperties().isEmpty() ? null : new GeyserEntityPropertyManager(bedrockDefinition.registeredProperties()); - setPosition(context.position()); + setPosition(context.position().up(offset)); setAirSupply(getMaxAir()); initializeMetadata(); - - // Allow API users to do things pre-spawn - if (context.consumers() != null) { - context.consumers().forEach(consumer -> consumer.accept(this)); - } } /** * Called on entity spawn. Used to populate the entity metadata and flags with default values. */ protected void initializeMetadata() { + dirtyMetadata.put(EntityDataTypes.WIDTH, width); + dirtyMetadata.put(EntityDataTypes.HEIGHT, height); dirtyMetadata.put(EntityDataTypes.SCALE, 1f); dirtyMetadata.put(EntityDataTypes.COLOR, (byte) 0); dirtyMetadata.put(EntityDataTypes.AIR_SUPPLY_MAX, getMaxAir()); @@ -699,8 +699,6 @@ public boolean isAlive() { return this.valid; } - - /** * Update the suggestion that the client currently has on their screen for this entity (for example, "Feed" or "Ride") */ diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java index 5d72f2c17ff..d23412c6670 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java @@ -25,7 +25,6 @@ package org.geysermc.geyser.entity.type.living.monster; -import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.BedrockEntityDefinitions; import org.geysermc.geyser.entity.VanillaEntities; @@ -37,11 +36,13 @@ public class EnderDragonPartEntity extends Entity { public EnderDragonPartEntity(GeyserSession session, int entityId, long geyserId, float width, float height) { super(dragonPartSpawnContext(session, entityId, geyserId, width, height)); + } - dirtyMetadata.put(EntityDataTypes.WIDTH, width); - dirtyMetadata.put(EntityDataTypes.HEIGHT, height); + @Override + protected void initializeMetadata() { setFlag(EntityFlag.INVISIBLE, true); setFlag(EntityFlag.FIRE_IMMUNE, true); + super.initializeMetadata(); } public static EntitySpawnContext dragonPartSpawnContext(GeyserSession session, int entityId, long geyserId, float width, float height) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java index 03f49e91a5d..215460e2b1a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java @@ -34,6 +34,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityLinkData; import org.cloudburstmc.protocol.bedrock.packet.SetEntityLinkPacket; import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket; +import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.entity.type.player.GeyserPlayerEntity; import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.attribute.GeyserAttributeType; @@ -161,10 +162,16 @@ protected void setParrot(OptionalInt variant, boolean isLeft) { } // The parrot is a separate entity in Bedrock, but part of the player entity in Java EntitySpawnContext context = EntitySpawnContext.inherited(session, VanillaEntities.PARROT, this, position); - context.callParrotEvent(this, variant.getAsInt(), !isLeft); + if (context.callParrotEvent(this, variant.getAsInt(), !isLeft)) { + GeyserImpl.getInstance().getLogger().debug("TODO"); + return; + } ParrotEntity parrot = new ParrotEntity(context); - parrot.spawnEntity(); parrot.getDirtyMetadata().put(EntityDataTypes.VARIANT, variant.getAsInt()); + if (context.consumers() != null) { + context.consumers().forEach(consumer -> consumer.accept(parrot)); + } + parrot.spawnEntity(); // Different position whether the parrot is left or right float offset = isLeft ? 0.4f : -0.4f; parrot.getDirtyMetadata().put(EntityDataTypes.SEAT_OFFSET, Vector3f.from(offset, -0.22, -0.1)); diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index fed487cddc3..4bc084a150d 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -2403,7 +2403,7 @@ public void removeFog(String... fogNameSpaces) { } @Override - public void requestHandSwap() { + public void switchHands() { requestOffhandSwap(); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java index b5dd8572434..21dc0facb24 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java @@ -101,8 +101,7 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) return; } - context.callServerSpawnEvent(); - if (context.bedrockEntityDefinition() == null) { + if (!context.callServerSpawnEvent()) { // TODO log warn return; } @@ -136,6 +135,11 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) } } + // Call pre-spawn consumer + if (context.consumers() != null) { + context.consumers().forEach(consumer -> consumer.accept(entity)); + } + session.getEntityCache().spawnEntity(entity); } } diff --git a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java index 698c98a8c3c..784c030f55e 100644 --- a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java @@ -35,6 +35,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; import org.geysermc.geyser.api.entity.custom.CustomJavaEntityType; import org.geysermc.geyser.api.entity.definition.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; @@ -430,13 +431,17 @@ public Collection entities() { } @Override - public void register(@NonNull GeyserEntityDefinition entityDefinition) { + public Collection customEntities() { + return Collections.unmodifiableCollection(customEntities); + } + + @Override + public void register(@NonNull CustomEntityDefinition entityDefinition) { Objects.requireNonNull(entityDefinition); if (!(entityDefinition instanceof BedrockEntityDefinition bedrockEntityDefinition)) { throw new IllegalArgumentException("EntityDefinition must not be a custom implementation of BedrockEntityDefinition! Found " + entityDefinition.getClass().getSimpleName()); } - - if (Registries.BEDROCK_ENTITY_DEFINITIONS.get().containsValue(bedrockEntityDefinition)) { + if (entityDefinition.registered()) { throw new IllegalStateException("Duplicate custom entity definition: " + entityDefinition); } if (bedrockEntityDefinition.vanilla()) { From a3b3c7212463be1eff9863646fbae9fbcf6848e1 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Mon, 1 Dec 2025 01:19:37 +0100 Subject: [PATCH 25/62] Refactor: unify offset handling, always store Java entity position --- .../entity/BedrockEntityDefinitions.java | 2 +- .../geyser/entity/EntityTypeBase.java | 9 ++++++ .../entity/spawn/EntitySpawnContext.java | 2 +- .../geyser/entity/type/BoatEntity.java | 12 +++---- .../geysermc/geyser/entity/type/Entity.java | 32 +++++++++---------- .../geyser/entity/type/EvokerFangsEntity.java | 2 +- .../geyser/entity/type/FireballEntity.java | 6 ++-- .../geyser/entity/type/FishingHookEntity.java | 14 ++++---- .../geyser/entity/type/InteractionEntity.java | 6 ++-- .../geyser/entity/type/ItemEntity.java | 18 ++++++----- .../geyser/entity/type/LeashKnotEntity.java | 3 +- .../geyser/entity/type/LightningEntity.java | 4 +-- .../geyser/entity/type/MinecartEntity.java | 7 ++-- .../geyser/entity/type/TNTEntity.java | 7 ---- .../geyser/entity/type/TextDisplayEntity.java | 15 ++------- .../geyser/entity/type/ThrowableEntity.java | 25 ++++++++------- .../entity/type/ThrowableItemEntity.java | 5 +-- .../entity/type/living/ArmorStandEntity.java | 8 ++--- .../entity/type/living/MagmaCubeEntity.java | 4 +-- .../entity/type/living/SquidEntity.java | 4 +-- .../entity/type/living/animal/GoatEntity.java | 2 +- .../type/living/animal/OcelotEntity.java | 4 +-- .../type/living/animal/SnifferEntity.java | 2 +- .../type/living/animal/farm/CowEntity.java | 2 +- .../type/living/merchant/VillagerEntity.java | 2 +- .../type/living/monster/CreakingEntity.java | 6 ++-- .../type/living/monster/CreeperEntity.java | 2 +- .../living/monster/EnderDragonEntity.java | 22 ++++++------- .../type/living/monster/EndermanEntity.java | 2 +- .../type/living/monster/WardenEntity.java | 2 +- .../entity/type/player/AvatarEntity.java | 21 ++++++------ .../entity/type/player/PlayerEntity.java | 8 ++--- .../type/player/SessionPlayerEntity.java | 29 +++++++---------- .../entity/vehicle/VehicleComponent.java | 14 ++++---- .../holder/BlockInventoryHolder.java | 2 +- .../level/physics/CollisionManager.java | 4 +-- .../geyser/session/GeyserSession.java | 6 ++-- .../session/cache/BlockBreakHandler.java | 5 ++- .../geyser/session/cache/BossBar.java | 2 +- .../geyser/session/cache/SkullCache.java | 4 +-- .../geyser/session/cache/TeleportCache.java | 2 ++ .../geyser/session/cache/WorldBorder.java | 21 ++++++------ .../MerchantInventoryTranslator.java | 2 +- .../inventory/PlayerInventoryTranslator.java | 4 +-- .../chest/DoubleChestInventoryTranslator.java | 2 +- .../level/event/PlaySoundEventTranslator.java | 2 +- ...BedrockInventoryTransactionTranslator.java | 13 +++----- .../player/input/BedrockMovePlayer.java | 15 ++++----- .../BedrockPlayerAuthInputTranslator.java | 18 +++-------- .../java/entity/JavaAddEntityTranslator.java | 4 +-- .../entity/JavaEntityEventTranslator.java | 14 ++++---- .../entity/JavaSetPassengersTranslator.java | 3 +- .../entity/JavaSoundEntityTranslator.java | 2 +- .../entity/JavaTakeItemEntityTranslator.java | 2 +- .../player/JavaPlayerLookAtTranslator.java | 6 ++-- .../player/JavaPlayerPositionTranslator.java | 29 +++++++++-------- .../player/JavaSetHealthTranslator.java | 2 +- .../java/level/JavaGameEventTranslator.java | 4 +-- .../JavaLevelChunkWithLightTranslator.java | 2 +- .../level/JavaLevelParticlesTranslator.java | 2 +- .../geysermc/geyser/util/DimensionUtils.java | 4 +-- .../geysermc/geyser/util/InventoryUtils.java | 4 +-- 62 files changed, 229 insertions(+), 254 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java index aabc7766626..7e9af4b0ddd 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java @@ -49,7 +49,7 @@ public class BedrockEntityDefinitions { CHEST_BOAT = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("chest_boat")); EVOCATION_ILLAGER = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("evocation_illager")); LLAMA = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("llama")); - MINECART = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("minecraft")); + MINECART = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("minecart")); SPLASH_POTION = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("splash_position")); ZOMBIE = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("zombie")); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityTypeBase.java b/core/src/main/java/org/geysermc/geyser/entity/EntityTypeBase.java index 6c583307df2..0c50fc24e4f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityTypeBase.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityTypeBase.java @@ -45,8 +45,17 @@ @Getter @Accessors(fluent = true) public class EntityTypeBase { + /** + * The width of the Java entity type. + */ protected final float width; + /** + * The height of the Java entity type + */ protected final float height; + /** + * The vertical offset for the default Bedrock entity. + */ protected final float offset; protected final List> translators; diff --git a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java index 29655c74894..ce29e4ee83c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java +++ b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java @@ -236,6 +236,6 @@ public void preSpawnConsumer(Consumer<@NonNull GeyserEntity> consumer) { } }); - return bedrockEntityDefinition != null; + return bedrockEntityDefinition == null; } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java index 7dda5092414..4c6f0bd5462 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java @@ -68,9 +68,8 @@ public class BoatEntity extends Entity implements Leashable, Tickable { private final float ROWING_SPEED = 0.1f; public BoatEntity(EntitySpawnContext context, BoatVariant variant) { - // Initial rotation is incorrect super(context); - setPosition(position.up(offset)); + // Initial rotation is incorrect setYaw(yaw + 90); setHeadYaw(yaw + 90); this.variant = variant; @@ -90,9 +89,8 @@ protected void initializeMetadata() { } @Override - public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + public void moveAbsolute(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { // We don't include the rotation (y) as it causes the boat to appear sideways - setPosition(position.add(0d, offset, 0d)); setYaw(yaw + 90); setHeadYaw(yaw + 90); setOnGround(isOnGround); @@ -101,9 +99,10 @@ public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYa moveEntityPacket.setRuntimeEntityId(geyserId); if (session.getPlayerEntity().getVehicle() == this && session.getPlayerEntity().isRidingInFront()) { // Minimal glitching when ClientboundMoveVehiclePacket is sent - moveEntityPacket.setPosition(position.up(VanillaEntities.PLAYER_ENTITY_OFFSET - offset)); + // TODO OFFSET + moveEntityPacket.setPosition(javaPosition.up(VanillaEntities.PLAYER_ENTITY_OFFSET - offset)); } else { - moveEntityPacket.setPosition(this.position); + moveEntityPacket.setPosition(bedrockPosition()); } moveEntityPacket.setRotation(getBedrockRotation()); moveEntityPacket.setOnGround(isOnGround); @@ -115,6 +114,7 @@ public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYa /** * Move the boat without making the adjustments needed to translate from Java */ + // TODO offset public void moveAbsoluteWithoutAdjustments(Vector3f position, float yaw, boolean isOnGround, boolean teleported) { super.moveAbsolute(position, yaw, 0, yaw, isOnGround, teleported); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index f6c21792f03..06c0183f04e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -109,8 +109,9 @@ public class Entity implements GeyserEntity { protected String nametag = ""; /** - * The entity position, WITH vertical offset + * The entity position as it is known to the Java server */ + @Accessors(fluent = true) protected Vector3f position; protected Vector3f motion; @@ -197,7 +198,7 @@ public Entity(EntitySpawnContext context) { this.valid = false; this.propertyManager = bedrockDefinition.registeredProperties().isEmpty() ? null : new GeyserEntityPropertyManager(bedrockDefinition.registeredProperties()); - setPosition(context.position().up(offset)); + position(context.position()); setAirSupply(getMaxAir()); initializeMetadata(); @@ -231,7 +232,7 @@ public void spawnEntity() { addEntityPacket.setIdentifier(bedrockDefinition.identifier().toString()); addEntityPacket.setRuntimeEntityId(geyserId); addEntityPacket.setUniqueEntityId(geyserId); - addEntityPacket.setPosition(position); + addEntityPacket.setPosition(bedrockPosition()); addEntityPacket.setMotion(motion); addEntityPacket.setRotation(Vector2f.from(pitch, yaw)); addEntityPacket.setHeadRotation(headYaw); @@ -291,15 +292,15 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float MoveEntityDeltaPacket moveEntityPacket = new MoveEntityDeltaPacket(); moveEntityPacket.setRuntimeEntityId(geyserId); if (relX != 0.0) { - moveEntityPacket.setX(position.getX()); + moveEntityPacket.setX(bedrockPosition().getX()); moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_X); } if (relY != 0.0) { - moveEntityPacket.setY(position.getY()); + moveEntityPacket.setY(bedrockPosition().getY()); moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Y); } if (relZ != 0.0) { - moveEntityPacket.setZ(position.getZ()); + moveEntityPacket.setZ(bedrockPosition().getZ()); moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Z); } if (pitch != this.pitch) { @@ -324,12 +325,12 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float session.sendUpstreamPacket(moveEntityPacket); } - public void moveAbsolute(Vector3f position, float yaw, float pitch, boolean isOnGround, boolean teleported) { - moveAbsolute(position, yaw, pitch, getHeadYaw(), isOnGround, teleported); + public void moveAbsolute(Vector3f javaPosition, float yaw, float pitch, boolean isOnGround, boolean teleported) { + moveAbsolute(javaPosition, yaw, pitch, getHeadYaw(), isOnGround, teleported); } - public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - setPosition(position); + public void moveAbsolute(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + position(javaPosition); // Setters are intentional so it can be overridden in places like AbstractArrowEntity setYaw(yaw); setPitch(pitch); @@ -338,7 +339,7 @@ public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYa MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket(); moveEntityPacket.setRuntimeEntityId(geyserId); - moveEntityPacket.setPosition(position); + moveEntityPacket.setPosition(bedrockPosition()); moveEntityPacket.setRotation(getBedrockRotation()); moveEntityPacket.setOnGround(isOnGround); moveEntityPacket.setTeleported(teleported); @@ -699,6 +700,10 @@ public boolean isAlive() { return this.valid; } + public Vector3f bedrockPosition() { + return position.up(offset); + } + /** * Update the suggestion that the client currently has on their screen for this entity (for example, "Feed" or "Ride") */ @@ -864,11 +869,6 @@ public void offset(float offset) { return bedrockDefinition; } - @Override - public @NonNull Vector3f position() { - return this.position.down(offset); - } - @Override public void update(@NonNull GeyserEntityDataType dataType, @Nullable T value) { if (dataType instanceof GeyserEntityDataImpl geyserEntityDataImpl) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java index ed8f1fe4f15..4cce8ea0217 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java @@ -57,7 +57,7 @@ public void setAttackStarted() { if (!silent) { // Play the chomp sound PlaySoundPacket packet = new PlaySoundPacket(); - packet.setPosition(this.position); + packet.setPosition(bedrockPosition()); packet.setSound("mob.evocation_fangs.attack"); packet.setVolume(1.0f); packet.setPitch(ThreadLocalRandom.current().nextFloat() * 0.2f + 0.85f); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java index ed2cec25611..9155ab948ad 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java @@ -56,15 +56,15 @@ private Vector3f tickMovement(Vector3f position) { } @Override - protected void moveAbsoluteImmediate(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + protected void moveAbsoluteImmediate(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { // Advance the position by a few ticks before sending it to Bedrock Vector3f lastMotion = motion; - Vector3f newPosition = position; + Vector3f newPosition = javaPosition; for (int i = 0; i < futureTicks; i++) { newPosition = tickMovement(newPosition); } super.moveAbsoluteImmediate(newPosition, yaw, pitch, headYaw, isOnGround, teleported); - this.position = position; + this.position = javaPosition; this.motion = lastMotion; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java index 622437a022e..06ecfaa17c1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java @@ -82,10 +82,10 @@ public void setHookedEntity(IntEntityMetadata entityMetadata) { } @Override - protected void moveAbsoluteImmediate(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - boundingBox.setMiddleX(position.getX()); - boundingBox.setMiddleY(position.getY() + boundingBox.getSizeY() / 2); - boundingBox.setMiddleZ(position.getZ()); + protected void moveAbsoluteImmediate(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + boundingBox.setMiddleX(javaPosition.getX()); + boundingBox.setMiddleY(javaPosition.getY() + boundingBox.getSizeY() / 2); + boundingBox.setMiddleZ(javaPosition.getZ()); boolean touchingWater = false; boolean collided = false; @@ -100,7 +100,7 @@ protected void moveAbsoluteImmediate(Vector3f position, float yaw, float pitch, } double waterHeight = BlockStateValues.getWaterHeight(blockID); - if (waterHeight != -1 && position.getY() <= (iter.getY() + waterHeight)) { + if (waterHeight != -1 && javaPosition.getY() <= (iter.getY() + waterHeight)) { touchingWater = true; } } @@ -111,7 +111,7 @@ protected void moveAbsoluteImmediate(Vector3f position, float yaw, float pitch, inWater = touchingWater; if (!collided) { - super.moveAbsoluteImmediate(position, yaw, pitch, headYaw, isOnGround, teleported); + super.moveAbsoluteImmediate(javaPosition, yaw, pitch, headYaw, isOnGround, teleported); } else { super.moveAbsoluteImmediate(this.position, yaw, pitch, headYaw, true, true); } @@ -125,7 +125,7 @@ private void sendSplashSound(GeyserSession session) { } PlaySoundPacket playSoundPacket = new PlaySoundPacket(); playSoundPacket.setSound("random.splash"); - playSoundPacket.setPosition(position); + playSoundPacket.setPosition(bedrockPosition()); playSoundPacket.setVolume(volume); playSoundPacket.setPitch(1f + ThreadLocalRandom.current().nextFloat() * 0.3f); session.sendUpstreamPacket(playSoundPacket); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java index 447826bba72..80d6e6eb7f3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java @@ -123,11 +123,11 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float } @Override - public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + public void moveAbsolute(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { if (secondEntity != null) { - secondEntity.moveAbsolute(position.up(getBoundingBoxHeight()), yaw, pitch, headYaw, isOnGround, teleported); + secondEntity.moveAbsolute(javaPosition.up(getBoundingBoxHeight()), yaw, pitch, headYaw, isOnGround, teleported); } - super.moveAbsolute(position, yaw, pitch, headYaw, isOnGround, teleported); + super.moveAbsolute(javaPosition, yaw, pitch, headYaw, isOnGround, teleported); } public void setWidth(FloatEntityMetadata width) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java index 171d7956764..5311c470316 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java @@ -59,7 +59,7 @@ public void spawnEntity() { AddItemEntityPacket itemPacket = new AddItemEntityPacket(); itemPacket.setRuntimeEntityId(geyserId); itemPacket.setUniqueEntityId(geyserId); - itemPacket.setPosition(position.add(0d, offset, 0d)); + itemPacket.setPosition(bedrockPosition()); itemPacket.setMotion(motion); itemPacket.setFromFishing(false); itemPacket.setItemInHand(item); @@ -109,16 +109,18 @@ public void setItem(EntityMetadata entityMetadata) { } @Override - protected void moveAbsoluteImmediate(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - float offset = super.offset; + protected void moveAbsoluteImmediate(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + // TODO offset - how handled on java??? if (waterLevel.join() == 0) { // Item is in a full block of water // Move the item entity down so it doesn't float above the water - offset = -offset; + this.offset = -Math.abs(offset); + } else { + this.offset = Math.abs(offset); } - super.moveAbsoluteImmediate(position.add(0, offset, 0), 0, 0, 0, isOnGround, teleported); - this.position = position; + super.moveAbsoluteImmediate(javaPosition, 0, 0, 0, isOnGround, teleported); + this.position = javaPosition; - waterLevel = session.getGeyser().getWorldManager().getBlockAtAsync(session, position.getFloorX(), position.getFloorY(), position.getFloorZ()) + waterLevel = session.getGeyser().getWorldManager().getBlockAtAsync(session, javaPosition.getFloorX(), javaPosition.getFloorY(), javaPosition.getFloorZ()) .thenApply(BlockStateValues::getWaterLevel); } @@ -135,7 +137,7 @@ protected float getGravity() { @Override protected float getDrag() { if (isOnGround()) { - Vector3i groundBlockPos = position.toInt().down(1); + Vector3i groundBlockPos = position.toInt().down(); BlockState blockState = session.getGeyser().getWorldManager().blockAt(session, groundBlockPos); return BlockStateValues.getSlipperiness(blockState) * 0.98f; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java index 52a699a7e52..ef8210717f7 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java @@ -34,7 +34,8 @@ public class LeashKnotEntity extends Entity { public LeashKnotEntity(EntitySpawnContext context) { super(context); // Position is incorrect by default - setPosition(position.add(0.5f, 0.25f, 0.5f)); + // TODO offset + position(position.add(0.5f, 0.25f, 0.5f)); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LightningEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LightningEntity.java index 981c237b48f..64293a91b15 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LightningEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LightningEntity.java @@ -44,14 +44,14 @@ public void spawnEntity() { ThreadLocalRandom random = ThreadLocalRandom.current(); PlaySoundPacket thunderPacket = new PlaySoundPacket(); - thunderPacket.setPosition(this.position); + thunderPacket.setPosition(this.bedrockPosition()); thunderPacket.setSound("ambient.weather.thunder"); thunderPacket.setPitch(0.8f + random.nextFloat() * 0.2f); thunderPacket.setVolume(10000f); // Really. session.sendUpstreamPacket(thunderPacket); PlaySoundPacket impactPacket = new PlaySoundPacket(); - impactPacket.setPosition(this.position); + impactPacket.setPosition(this.bedrockPosition()); impactPacket.setSound("ambient.weather.lightning.impact"); impactPacket.setPitch(0.5f + random.nextFloat() * 0.2f); impactPacket.setVolume(2.0f); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java index 0cd37e2fa18..e5f7709dba6 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java @@ -59,7 +59,6 @@ public class MinecartEntity extends Entity implements Tickable { public MinecartEntity(EntitySpawnContext context) { super(context); - setPosition(position.up(offset)); } public void setCustomBlock(IntEntityMetadata entityMetadata) { @@ -102,7 +101,7 @@ public void tick() { Vector3f position = getCurrentLerpPosition(delta).toFloat(); Vector3f movement = getCurrentLerpMovement(delta).toFloat(); - setPosition(position); + position(position); setMotion(movement); setYaw(180.0F - getCurrentLerpYaw(delta)); @@ -199,8 +198,8 @@ private void updateCompletedStep() { } @Override - public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - super.moveAbsolute(position.up(offset), yaw, pitch, headYaw, isOnGround, teleported); + public void moveAbsolute(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + super.moveAbsolute(javaPosition, yaw, pitch, headYaw, isOnGround, teleported); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java index c1624d64434..6bb8124ea0f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/TNTEntity.java @@ -25,7 +25,6 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.SetEntityDataPacket; @@ -37,12 +36,6 @@ public class TNTEntity extends Entity implements Tickable { public TNTEntity(EntitySpawnContext context) { super(context); - setPosition(position.up(offset)); - } - - @Override - public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - super.moveAbsolute(position.add(Vector3f.from(0, offset, 0)), yaw, pitch, headYaw, isOnGround, teleported); } public void setFuseLength(IntEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java index 62a175a10bd..1f36736d7ed 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java @@ -28,7 +28,6 @@ import lombok.Getter; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.spawn.EntitySpawnContext; @@ -54,12 +53,6 @@ public class TextDisplayEntity extends DisplayBaseEntity { public TextDisplayEntity(EntitySpawnContext context) { super(context); - setPosition(position.up(offset)); - } - - @Override - public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, boolean isOnGround) { - super.moveRelative(relX, relY + offset, relZ, yaw, pitch, isOnGround); } /** @@ -76,15 +69,10 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float private float calculateLineOffset() { if (lineCount == 0) { return 0; - } + } return LINE_HEIGHT_OFFSET * lineCount; } - @Override - public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - super.moveAbsolute(position.add(0, calculateLineOffset(), 0), yaw, pitch, headYaw, isOnGround, teleported); - } - @Override protected void initializeMetadata() { super.initializeMetadata(); @@ -112,5 +100,6 @@ private void calculateLineCount(@Nullable Component text) { return; } lineCount = PlainTextComponentSerializer.plainText().serialize(text).split("\n").length; + setOffset(calculateLineOffset()); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java index 38545807473..28358ca44b1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java @@ -61,7 +61,8 @@ public void tick() { motion = motion.mul(drag).down(gravity); } - protected void moveAbsoluteImmediate(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + // TODO offsets!!! + protected void moveAbsoluteImmediate(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { MoveEntityDeltaPacket moveEntityDeltaPacket = new MoveEntityDeltaPacket(); moveEntityDeltaPacket.setRuntimeEntityId(geyserId); @@ -74,19 +75,19 @@ protected void moveAbsoluteImmediate(Vector3f position, float yaw, float pitch, moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.TELEPORTING); } - if (this.position.getX() != position.getX()) { + if (this.position.getX() != javaPosition.getX()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_X); - moveEntityDeltaPacket.setX(position.getX()); + moveEntityDeltaPacket.setX(javaPosition.getX()); } - if (this.position.getY() != position.getY()) { + if (this.position.getY() != javaPosition.getY()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Y); - moveEntityDeltaPacket.setY(position.getY()); + moveEntityDeltaPacket.setY(javaPosition.getY() + offset); } - if (this.position.getZ() != position.getZ()) { + if (this.position.getZ() != javaPosition.getZ()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Z); - moveEntityDeltaPacket.setZ(position.getZ()); + moveEntityDeltaPacket.setZ(javaPosition.getZ()); } - setPosition(position); + position(javaPosition); if (getYaw() != yaw) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_YAW); @@ -163,7 +164,7 @@ public void despawnEntity() { if (javaTypeDefinition.is(BuiltinEntityType.ENDER_PEARL)) { LevelEventPacket particlePacket = new LevelEventPacket(); particlePacket.setType(LevelEvent.PARTICLE_TELEPORT); - particlePacket.setPosition(position); + particlePacket.setPosition(bedrockPosition()); session.sendUpstreamPacket(particlePacket); } super.despawnEntity(); @@ -176,9 +177,9 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float } @Override - public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - moveAbsoluteImmediate(position, yaw, pitch, headYaw, isOnGround, teleported); - lastJavaPosition = position; + public void moveAbsolute(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + moveAbsoluteImmediate(javaPosition, yaw, pitch, headYaw, isOnGround, teleported); + lastJavaPosition = javaPosition; } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java index 8b273176f0d..b5720bdc91d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableItemEntity.java @@ -25,10 +25,8 @@ package org.geysermc.geyser.entity.type; -import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; -import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.spawn.EntitySpawnContext; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; @@ -63,8 +61,7 @@ private void checkVisibility() { // Prevent projectiles from blocking the player's screen if (session.isTickingFrozen()) { // This may seem odd, but it matches java edition - Vector3f playerPos = session.getPlayerEntity().getPosition().down(VanillaEntities.PLAYER_ENTITY_OFFSET); - setInvisible(playerPos.distanceSquared(position.add(0, offset, 0)) < 12.25); + setInvisible(session.getPlayerEntity().bedrockPosition().distanceSquared(bedrockPosition()) < 12.25); } else { setInvisible(age < 2); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java index 60c21386cf8..9857eebd5c4 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java @@ -113,14 +113,14 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float } @Override - public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + public void moveAbsolute(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { if (secondEntity != null) { - secondEntity.moveAbsolute(position, yaw, pitch, headYaw, isOnGround, teleported); + secondEntity.moveAbsolute(javaPosition, yaw, pitch, headYaw, isOnGround, teleported); } // Fake the height to be above where it is so the nametag appears in the right location float yOffset = getYOffset(); - super.moveAbsolute(yOffset != 0 ? position.up(yOffset) : position , yaw, yaw, yaw, isOnGround, teleported); - this.position = position; + super.moveAbsolute(yOffset != 0 ? javaPosition.up(yOffset) : javaPosition, yaw, yaw, yaw, isOnGround, teleported); + this.position = javaPosition; } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java index a19f06cd0cb..d4339f1f5ca 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java @@ -42,9 +42,9 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float } @Override - public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + public void moveAbsolute(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { updateJump(isOnGround); - super.moveAbsolute(position, yaw, pitch, headYaw, isOnGround, teleported); + super.moveAbsolute(javaPosition, yaw, pitch, headYaw, isOnGround, teleported); } public void updateJump(boolean newOnGround) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java index 93442ed76b7..2f55233c97d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java @@ -84,8 +84,8 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float } @Override - public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - super.moveAbsolute(position, yaw, pitch, headYaw, isOnGround, teleported); + public void moveAbsolute(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + super.moveAbsolute(javaPosition, yaw, pitch, headYaw, isOnGround, teleported); checkInWater(); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java index 6800fb617e3..346772147e2 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java @@ -74,7 +74,7 @@ protected void setDimensionsFromPose(Pose pose) { @Override protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (!getFlag(EntityFlag.BABY) && itemInHand.is(Items.BUCKET)) { - session.playSoundEvent(isScreamer ? SoundEvent.MILK_SCREAMER : SoundEvent.MILK, position); + session.playSoundEvent(isScreamer ? SoundEvent.MILK_SCREAMER : SoundEvent.MILK, bedrockPosition()); return InteractionResult.SUCCESS; } else { return super.mobInteract(hand, itemInHand); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java index b3deed39289..f43717f4cda 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java @@ -52,7 +52,7 @@ protected Tag getFoodTag() { @NonNull @Override protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { - if (!getFlag(EntityFlag.TRUSTING) && canEat(itemInHand) && session.getPlayerEntity().getPosition().distanceSquared(position) < 9f) { + if (!getFlag(EntityFlag.TRUSTING) && canEat(itemInHand) && session.getPlayerEntity().position().distanceSquared(position) < 9f) { // Attempt to feed return InteractiveTag.FEED; } else { @@ -63,7 +63,7 @@ protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserI @NonNull @Override protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { - if (!getFlag(EntityFlag.TRUSTING) && canEat(itemInHand) && session.getPlayerEntity().getPosition().distanceSquared(position) < 9f) { + if (!getFlag(EntityFlag.TRUSTING) && canEat(itemInHand) && session.getPlayerEntity().position().distanceSquared(position) < 9f) { // Attempt to feed return InteractionResult.SUCCESS; } else { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java index a6abd5fa2a6..7cb4749b6d7 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java @@ -102,7 +102,7 @@ public void tick() { // The java client renders digging particles on its own, but bedrock does not if (digTicks > 0 && --digTicks < DIG_START && digTicks % 5 == 0) { Vector3f rot = Vector3f.createDirectionDeg(0, -getYaw()).mul(2.25f); - Vector3f pos = getPosition().add(rot).up(0.2f).floor(); // Handle non-full blocks + Vector3f pos = position.add(rot).up(0.2f).floor(); // Handle non-full blocks int blockId = session.getBlockMappings().getBedrockBlockId(session.getGeyser().getWorldManager().getBlockAt(session, pos.toInt().down())); LevelEventPacket levelEventPacket = new LevelEventPacket(); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/CowEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/CowEntity.java index 76ffdde24de..0799f9d3a99 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/CowEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/CowEntity.java @@ -64,7 +64,7 @@ protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemS return super.mobInteract(hand, itemInHand); } - session.playSoundEvent(SoundEvent.MILK, position); + session.playSoundEvent(SoundEvent.MILK, bedrockPosition()); return InteractionResult.SUCCESS; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java index 70898292b32..e61e9fa3597 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java @@ -154,7 +154,7 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket(); moveEntityPacket.setRuntimeEntityId(geyserId); moveEntityPacket.setRotation(Vector3f.from(0, 0, bedRotation)); - moveEntityPacket.setPosition(Vector3f.from(position.getX() + xOffset, position.getY(), position.getZ() + zOffset)); + moveEntityPacket.setPosition(Vector3f.from(position.getX() + xOffset, position.getY() + offset, position.getZ() + zOffset)); moveEntityPacket.setOnGround(isOnGround); moveEntityPacket.setTeleported(false); session.sendUpstreamPacket(moveEntityPacket); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java index 5ca0af19a6f..38a0b46db72 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreakingEntity.java @@ -104,9 +104,9 @@ public void createParticleBeam() { levelEventGenericPacket.setTag( NbtMap.builder() .putInt("CreakingAmount", 20) - .putFloat("CreakingX", position.getX()) - .putFloat("CreakingY", position.getY()) - .putFloat("CreakingZ", position.getZ()) + .putFloat("CreakingX", bedrockPosition().getX()) + .putFloat("CreakingY", bedrockPosition().getY()) + .putFloat("CreakingZ", bedrockPosition().getZ()) .putInt("HeartAmount", 20) .putFloat("HeartX", homePosition.getX()) .putFloat("HeartY", homePosition.getY()) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java index d6214d35c9a..389c06cf5fc 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java @@ -74,7 +74,7 @@ protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserI protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (itemInHand.is(session, ItemTag.CREEPER_IGNITERS)) { // Ignite creeper - as of 1.19.3 - session.playSoundEvent(SoundEvent.IGNITE, position); + session.playSoundEvent(SoundEvent.IGNITE, bedrockPosition()); return InteractionResult.SUCCESS; } else { return super.mobInteract(hand, itemInHand); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java index 3921e5a9e4e..b2a4b36dbb1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java @@ -186,13 +186,13 @@ private void updateBoundingBoxes() { headDuck = baseSegment.y - getSegment(0).y; } - head.setPosition(facingDir.up(pitchY).mul(pitchXZ, 1, -pitchXZ).mul(6.5f).up(headDuck)); - neck.setPosition(facingDir.up(pitchY).mul(pitchXZ, 1, -pitchXZ).mul(5.5f).up(headDuck)); - body.setPosition(facingDir.mul(0.5f, 0f, -0.5f)); + head.position(facingDir.up(pitchY).mul(pitchXZ, 1, -pitchXZ).mul(6.5f).up(headDuck)); + neck.position(facingDir.up(pitchY).mul(pitchXZ, 1, -pitchXZ).mul(5.5f).up(headDuck)); + body.position(facingDir.mul(0.5f, 0f, -0.5f)); Vector3f wingPos = Vector3f.createDirectionDeg(0, 90f - getHeadYaw()).mul(4.5f).up(2f); - rightWing.setPosition(wingPos); - leftWing.setPosition(wingPos.mul(-1, 1, -1)); // Mirror horizontally + rightWing.position(wingPos); + leftWing.position(wingPos.mul(-1, 1, -1)); // Mirror horizontally Vector3f tailBase = facingDir.mul(1.5f); for (int i = 0; i < tail.length; i++) { @@ -202,11 +202,11 @@ private void updateBoundingBoxes() { float angle = getHeadYaw() + targetSegment.yaw - baseSegment.yaw; float tailYOffset = targetSegment.y - baseSegment.y - (distance + 1.5f) * pitchY + 1.5f; - tail[i].setPosition(Vector3f.createDirectionDeg(0, angle).mul(distance).add(tailBase).mul(-pitchXZ, 1, pitchXZ).up(tailYOffset)); + tail[i].position(Vector3f.createDirectionDeg(0, angle).mul(distance).add(tailBase).mul(-pitchXZ, 1, pitchXZ).up(tailYOffset)); } // Send updated positions for (EnderDragonPartEntity part : allParts) { - part.moveAbsolute(part.getPosition().add(position), 0, 0, 0, false, false); + part.moveAbsolute(part.position().add(position), 0, 0, 0, false, false); } } @@ -219,7 +219,7 @@ private void effectTick() { if (Math.cos(wingPosition * 2f * Math.PI) <= -0.3f && Math.cos(lastWingPosition * 2f * Math.PI) >= -0.3f) { PlaySoundPacket playSoundPacket = new PlaySoundPacket(); playSoundPacket.setSound("mob.enderdragon.flap"); - playSoundPacket.setPosition(position); + playSoundPacket.setPosition(bedrockPosition()); playSoundPacket.setVolume(5f); playSoundPacket.setPitch(0.8f + random.nextFloat() * 0.3f); session.sendUpstreamPacket(playSoundPacket); @@ -245,7 +245,7 @@ private void effectTick() { phaseTicks++; if (phase == 3) { // Landing Phase float headHeight = head.getBoundingBoxHeight(); - Vector3f headCenter = head.getPosition().up(headHeight * 0.5f); + Vector3f headCenter = head.position().up(headHeight * 0.5f); for (int i = 0; i < 8; i++) { Vector3f particlePos = headCenter.add(random.nextGaussian() / 2f, random.nextGaussian() / 2f, random.nextGaussian() / 2f); @@ -263,7 +263,7 @@ private void effectTick() { for (int i = 0; i < 8; i++) { SpawnParticleEffectPacket spawnParticleEffectPacket = new SpawnParticleEffectPacket(); spawnParticleEffectPacket.setDimensionId(DimensionUtils.javaToBedrock(session)); - spawnParticleEffectPacket.setPosition(head.getPosition().add(random.nextGaussian() / 2f, random.nextGaussian() / 2f, random.nextGaussian() / 2f)); + spawnParticleEffectPacket.setPosition(head.position().add(random.nextGaussian() / 2f, random.nextGaussian() / 2f, random.nextGaussian() / 2f)); spawnParticleEffectPacket.setIdentifier("minecraft:dragon_breath_fire"); spawnParticleEffectPacket.setMolangVariablesJson(Optional.empty()); session.sendUpstreamPacket(spawnParticleEffectPacket); @@ -291,7 +291,7 @@ private void playGrowlSound() { Random random = ThreadLocalRandom.current(); PlaySoundPacket playSoundPacket = new PlaySoundPacket(); playSoundPacket.setSound("mob.enderdragon.growl"); - playSoundPacket.setPosition(position); + playSoundPacket.setPosition(bedrockPosition()); playSoundPacket.setVolume(2.5f); playSoundPacket.setPitch(0.8f + random.nextFloat() * 0.3f); session.sendUpstreamPacket(playSoundPacket); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EndermanEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EndermanEntity.java index 6dbd904db4b..7068ea8f4b1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EndermanEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EndermanEntity.java @@ -55,7 +55,7 @@ public void setScreaming(BooleanEntityMetadata entityMetadata) { if (entityMetadata.getPrimitiveValue()) { LevelSoundEventPacket packet = new LevelSoundEventPacket(); packet.setSound(SoundEvent.STARE); - packet.setPosition(this.position); + packet.setPosition(this.bedrockPosition()); packet.setExtraData(-1); packet.setIdentifier("minecraft:enderman"); session.sendUpstreamPacket(packet); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WardenEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WardenEntity.java index 8f3c2ff71f4..8f560caf19e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WardenEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/WardenEntity.java @@ -77,7 +77,7 @@ public void tick() { PlaySoundPacket packet = new PlaySoundPacket(); packet.setSound("mob.warden.heartbeat"); - packet.setPosition(position); + packet.setPosition(bedrockPosition()); packet.setPitch((random.nextFloat() - random.nextFloat()) * 0.2f + 1.0f); packet.setVolume(1.0f); session.sendUpstreamPacket(packet); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java index f9eeeae8ff7..e16c5f4a4cc 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java @@ -40,8 +40,8 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.AddPlayerPacket; import org.cloudburstmc.protocol.bedrock.packet.MovePlayerPacket; -import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.spawn.EntitySpawnContext; +import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.LivingEntity; import org.geysermc.geyser.level.block.Blocks; import org.geysermc.geyser.skin.SkinManager; @@ -131,8 +131,8 @@ public void spawnEntity() { } @Override - public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - setPosition(position); + public void moveAbsolute(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + position(javaPosition); setYaw(yaw); setPitch(pitch); setHeadYaw(headYaw); @@ -141,7 +141,7 @@ public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYa MovePlayerPacket movePlayerPacket = new MovePlayerPacket(); movePlayerPacket.setRuntimeEntityId(geyserId); - movePlayerPacket.setPosition(this.position); + movePlayerPacket.setPosition(bedrockPosition()); movePlayerPacket.setRotation(getBedrockRotation()); movePlayerPacket.setOnGround(isOnGround); movePlayerPacket.setMode(this instanceof SessionPlayerEntity || teleported ? MovePlayerPacket.Mode.TELEPORT : MovePlayerPacket.Mode.NORMAL); @@ -168,7 +168,7 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float MovePlayerPacket movePlayerPacket = new MovePlayerPacket(); movePlayerPacket.setRuntimeEntityId(geyserId); - movePlayerPacket.setPosition(position); + movePlayerPacket.setPosition(bedrockPosition()); movePlayerPacket.setRotation(getBedrockRotation()); movePlayerPacket.setOnGround(isOnGround); movePlayerPacket.setMode(this instanceof SessionPlayerEntity ? MovePlayerPacket.Mode.TELEPORT : MovePlayerPacket.Mode.NORMAL); @@ -190,14 +190,15 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float } @Override - public void setPosition(Vector3f position) { + public Entity position(Vector3f position) { if (this.bedPosition != null) { // As of Bedrock 1.21.22 and Fabric 1.21.1 // Messes with Bedrock if we send this to the client itself, though. - super.setPosition(position.up(0.2f)); + super.position(position.up(0.2f)); } else { - super.setPosition(position.add(0, offset, 0)); + super.position(position); } + return this; } @Override @@ -206,7 +207,7 @@ public void setPosition(Vector3f position) { if (bedPosition != null) { // Required to sync position of entity to bed // Fixes https://github.com/GeyserMC/Geyser/issues/3595 on vanilla 1.19.3 servers - did not happen on Paper - this.setPosition(bedPosition.toFloat()); + this.position(bedPosition.toFloat()); // TODO evaluate if needed int bed = session.getGeyser().getWorldManager().getBlockAt(session, bedPosition); @@ -315,7 +316,7 @@ public void setPose(Pose pose) { if (pose == Pose.SWIMMING) { // This is just for, so we know if player is swimming or crawling. - if (session.getGeyser().getWorldManager().blockAt(session, position.down(VanillaEntities.PLAYER_ENTITY_OFFSET).toInt()).is(Blocks.WATER)) { + if (session.getGeyser().getWorldManager().blockAt(session, position.toInt()).is(Blocks.WATER)) { setFlag(EntityFlag.SWIMMING, true); } else { setFlag(EntityFlag.CRAWLING, true); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java index 215460e2b1a..fc340923f6e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java @@ -111,13 +111,13 @@ public void sendPlayer() { } @Override - public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - super.moveAbsolute(position, yaw, pitch, headYaw, isOnGround, teleported); + public void moveAbsolute(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + super.moveAbsolute(javaPosition, yaw, pitch, headYaw, isOnGround, teleported); if (leftParrot != null) { - leftParrot.moveAbsolute(position, yaw, pitch, headYaw, true, teleported); + leftParrot.moveAbsolute(javaPosition, yaw, pitch, headYaw, true, teleported); } if (rightParrot != null) { - rightParrot.moveAbsolute(position, yaw, pitch, headYaw, true, teleported); + rightParrot.moveAbsolute(javaPosition, yaw, pitch, headYaw, true, teleported); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java index 80280f9aefb..44f552dabb9 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java @@ -31,7 +31,6 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector2f; import org.cloudburstmc.math.vector.Vector3f; -import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.protocol.bedrock.data.AttributeData; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; @@ -164,11 +163,11 @@ public void setYaw(float yaw) { @Override public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, float headYaw, boolean isOnGround) { super.moveRelative(relX, relY, relZ, yaw, pitch, headYaw, isOnGround); - session.getCollisionManager().updatePlayerBoundingBox(this.position.down(offset)); + session.getCollisionManager().updatePlayerBoundingBox(this.position); } @Override - public void setPosition(Vector3f position) { + public Entity position(Vector3f position) { if (valid) { // Don't update during session init session.getCollisionManager().updatePlayerBoundingBox(position); @@ -176,7 +175,8 @@ public void setPosition(Vector3f position) { session.setNoClip(false); } } - this.position = position.add(0, offset, 0); + this.position = position; + return this; } /** @@ -193,7 +193,7 @@ public void updateOwnRotation(float yaw, float pitch, float headYaw) { MovePlayerPacket movePlayerPacket = new MovePlayerPacket(); movePlayerPacket.setRuntimeEntityId(geyserId); - movePlayerPacket.setPosition(position); + movePlayerPacket.setPosition(bedrockPosition()); movePlayerPacket.setRotation(getBedrockRotation()); movePlayerPacket.setOnGround(isOnGround()); movePlayerPacket.setMode(MovePlayerPacket.Mode.TELEPORT); @@ -209,17 +209,13 @@ public void updateOwnRotation(float yaw, float pitch, float headYaw) { } /** - * Set the player's position without applying an offset or moving the bounding box - * This is used in BedrockMovePlayer which receives the player's position - * with the offset pre-applied - * - * @param position the new position of the Bedrock player + * Set the player's position from a position sent in a Bedrock packet */ - public void setPositionManual(Vector3f position) { - this.position = position; + public void setPositionFromBedrock(Vector3f position) { + this.position = position.down(offset); // Player is "above" the void so they're not supposed to no clip. - if (session.isNoClip() && position.getY() - VanillaEntities.PLAYER_ENTITY_OFFSET >= session.getBedrockDimension().minY() - 5) { + if (session.isNoClip() && this.position.getY() >= session.getBedrockDimension().minY() - 5) { session.setNoClip(false); } } @@ -490,7 +486,7 @@ public void setVehicle(Entity entity) { public float getJumpVelocity() { float velocity = 0.42F; - if (session.getGeyser().getWorldManager().blockAt(session, this.getPosition().sub(0, VanillaEntities.PLAYER_ENTITY_OFFSET + 0.1F, 0).toInt()).is(Blocks.HONEY_BLOCK)) { + if (session.getGeyser().getWorldManager().blockAt(session, this.position().down(0.1F).toInt()).is(Blocks.HONEY_BLOCK)) { velocity *= 0.6F; } @@ -501,8 +497,7 @@ public boolean isOnClimbableBlock() { if (session.getGameMode() == GameMode.SPECTATOR) { return false; } - Vector3i pos = getPosition().down(VanillaEntities.PLAYER_ENTITY_OFFSET).toInt(); - BlockState state = session.getGeyser().getWorldManager().blockAt(session, pos); + BlockState state = session.getGeyser().getWorldManager().blockAt(session, position.toInt()); if (state.block().is(session, BlockTag.CLIMBABLE)) { return true; } @@ -511,7 +506,7 @@ public boolean isOnClimbableBlock() { if (!state.getValue(Properties.OPEN)) { return false; } else { - BlockState belowState = session.getGeyser().getWorldManager().blockAt(session, pos.down()); + BlockState belowState = session.getGeyser().getWorldManager().blockAt(session, position.toInt().down()); return belowState.is(Blocks.LADDER) && belowState.getValue(Properties.HORIZONTAL_FACING) == state.getValue(Properties.HORIZONTAL_FACING); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java index 2b290095318..a823dbe6b7c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java +++ b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java @@ -89,9 +89,9 @@ public VehicleComponent(T vehicle, float stepHeight) { double width = vehicle.getBoundingBoxWidth(); double height = vehicle.getBoundingBoxHeight(); this.boundingBox = new BoundingBox( - vehicle.getPosition().getX(), - vehicle.getPosition().getY() + height / 2, - vehicle.getPosition().getZ(), + vehicle.position().getX(), + vehicle.position().getY() + height / 2, + vehicle.position().getZ(), width, height, width ); } @@ -742,19 +742,19 @@ protected void moveVehicle(Vector3d javaPos, Vector3f lastRotation) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.ON_GROUND); } - if (vehicle.getPosition().getX() != bedrockPos.getX()) { + if (vehicle.position().getX() != bedrockPos.getX()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_X); moveEntityDeltaPacket.setX(bedrockPos.getX()); } - if (vehicle.getPosition().getY() != bedrockPos.getY()) { + if (vehicle.position().getY() != bedrockPos.getY()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Y); moveEntityDeltaPacket.setY(bedrockPos.getY()); } - if (vehicle.getPosition().getZ() != bedrockPos.getZ()) { + if (vehicle.position().getZ() != bedrockPos.getZ()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Z); moveEntityDeltaPacket.setZ(bedrockPos.getZ()); } - vehicle.setPosition(bedrockPos); + vehicle.position(bedrockPos); if (vehicle.getPitch() != lastRotation.getX()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_PITCH); diff --git a/core/src/main/java/org/geysermc/geyser/inventory/holder/BlockInventoryHolder.java b/core/src/main/java/org/geysermc/geyser/inventory/holder/BlockInventoryHolder.java index fa385224fd3..8c9ec65ea97 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/holder/BlockInventoryHolder.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/holder/BlockInventoryHolder.java @@ -162,7 +162,7 @@ protected boolean canUseRealBlock(GeyserSession session, Container container) { * a block to hold the inventory that's wildly out of range. */ protected boolean checkInteractionPosition(GeyserSession session) { - return session.getLastInteractionPlayerPosition().distance(session.getPlayerEntity().getPosition()) < 2; + return session.getLastInteractionPlayerPosition().distance(session.getPlayerEntity().bedrockPosition()) < 2; } /** diff --git a/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java b/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java index 4b30b7cdd32..d5f44d739d8 100644 --- a/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java +++ b/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java @@ -222,7 +222,7 @@ public void recalculatePosition() { PlayerEntity entity = session.getPlayerEntity(); MovePlayerPacket movePlayerPacket = new MovePlayerPacket(); movePlayerPacket.setRuntimeEntityId(entity.geyserId()); - movePlayerPacket.setPosition(entity.getPosition()); + movePlayerPacket.setPosition(entity.bedrockPosition()); movePlayerPacket.setRotation(entity.getBedrockRotation()); movePlayerPacket.setMode(MovePlayerPacket.Mode.NORMAL); session.sendUpstreamPacket(movePlayerPacket); @@ -425,7 +425,7 @@ public BlockCollision getCollisionLavaWalking(int blockId, int blockY, BoundingB * @return if the player is currently in a water block */ public boolean isPlayerInWater() { - BlockState state = session.getGeyser().getWorldManager().blockAt(session, session.getPlayerEntity().getPosition().toInt()); + BlockState state = session.getGeyser().getWorldManager().blockAt(session, session.getPlayerEntity().position().toInt()); return state.is(Blocks.WATER) && state.getValue(Properties.LEVEL) == 0; } diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index 4bc084a150d..0f6e3c9aa05 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -789,7 +789,7 @@ public GeyserSession(GeyserImpl geyser, BedrockServerSession bedrockServerSessio this.blockBreakHandler = new BlockBreakHandler(this); this.playerEntity = new SessionPlayerEntity(this); - collisionManager.updatePlayerBoundingBox(this.playerEntity.getPosition()); + collisionManager.updatePlayerBoundingBox(this.playerEntity.position()); this.playerInventoryHolder = new InventoryHolder<>(this, new PlayerInventory(this), InventoryTranslator.PLAYER_INVENTORY_TRANSLATOR); this.inventoryHolder = null; @@ -843,7 +843,7 @@ public void connect() { componentPacket.getItems().addAll(itemMappings.getItemDefinitions().values()); upstream.sendPacket(componentPacket); - ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false); + ChunkUtils.sendEmptyChunks(this, playerEntity.position().toInt(), 0, false); BiomeDefinitionListPacket biomeDefinitionListPacket = new BiomeDefinitionListPacket(); biomeDefinitionListPacket.setBiomes(Registries.BIOMES.get()); @@ -2353,7 +2353,7 @@ public void updateInputLocks() { } packet.setLockComponentData(result); - packet.setServerPosition(this.playerEntity.getPosition()); + packet.setServerPosition(this.playerEntity.bedrockPosition()); sendUpstreamPacket(packet); } diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/BlockBreakHandler.java b/core/src/main/java/org/geysermc/geyser/session/cache/BlockBreakHandler.java index dc383d40188..ef5a97a5cab 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/BlockBreakHandler.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/BlockBreakHandler.java @@ -43,7 +43,6 @@ import org.cloudburstmc.protocol.bedrock.packet.PlayerAuthInputPacket; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.block.custom.CustomBlockState; -import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.ItemFrameEntity; import org.geysermc.geyser.inventory.GeyserItemStack; @@ -490,8 +489,8 @@ protected boolean canBreak(Vector3i vector, BlockState state, PlayerActionType a } } - Vector3f playerPosition = session.getPlayerEntity().getPosition(); - playerPosition = playerPosition.down(VanillaEntities.PLAYER_ENTITY_OFFSET - session.getEyeHeight()); + Vector3f playerPosition = session.getPlayerEntity().position(); + playerPosition = playerPosition.down(session.getEyeHeight()); return BedrockInventoryTransactionTranslator.canInteractWithBlock(session, playerPosition, vector); } diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/BossBar.java b/core/src/main/java/org/geysermc/geyser/session/cache/BossBar.java index 7c0891a5c95..a559806a97e 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/BossBar.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/BossBar.java @@ -117,7 +117,7 @@ private void addBossEntity() { addEntityPacket.setRuntimeEntityId(entityId); addEntityPacket.setIdentifier("minecraft:creeper"); addEntityPacket.setEntityType(33); - addEntityPacket.setPosition(session.getPlayerEntity().getPosition().sub(0D, -10D, 0D)); + addEntityPacket.setPosition(session.getPlayerEntity().position().sub(0D, -10D, 0D)); addEntityPacket.setRotation(Vector2f.ZERO); addEntityPacket.setMotion(Vector3f.ZERO); EntityDataMap metadata = addEntityPacket.getMetadata(); diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/SkullCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/SkullCache.java index 671437b2c52..0a3bbfecc0b 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/SkullCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/SkullCache.java @@ -168,10 +168,10 @@ public Skull updateSkull(Vector3i position, BlockState blockState) { public void updateVisibleSkulls() { if (cullingEnabled) { // No need to recheck skull visibility for small movements - if (lastPlayerPosition != null && session.getPlayerEntity().getPosition().distanceSquared(lastPlayerPosition) < 4) { + if (lastPlayerPosition != null && session.getPlayerEntity().position().distanceSquared(lastPlayerPosition) < 4) { return; } - lastPlayerPosition = session.getPlayerEntity().getPosition(); + lastPlayerPosition = session.getPlayerEntity().position(); inRangeSkulls.clear(); for (Skull skull : skulls.values()) { diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/TeleportCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/TeleportCache.java index d672338f71d..e7f044ab91c 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/TeleportCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/TeleportCache.java @@ -28,6 +28,7 @@ import lombok.Data; import lombok.RequiredArgsConstructor; import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.GeyserImpl; /** * Represents a teleport ID and corresponding coordinates that need to be confirmed.
    @@ -68,6 +69,7 @@ public TeleportCache(Vector3f position, float pitch, float yaw, int teleportConf private int unconfirmedFor = 0; public boolean canConfirm(Vector3f position) { + GeyserImpl.getInstance().getLogger().info("TeleportCache_canConfirm " + position + " " + this.position); final float distanceX = Math.abs(this.position.getX() - position.getX()); final float distanceY = Math.abs(this.position.getY() - position.getY()); final float distanceZ = Math.abs(this.position.getZ() - position.getZ()); diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java b/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java index 0bc8810bc5b..7cb86614222 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java @@ -25,6 +25,8 @@ package org.geysermc.geyser.session.cache; +import lombok.Getter; +import lombok.Setter; import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.GenericMath; import org.cloudburstmc.math.vector.Vector2d; @@ -33,9 +35,6 @@ import org.cloudburstmc.protocol.bedrock.data.LevelEvent; import org.cloudburstmc.protocol.bedrock.data.LevelEventType; import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; -import lombok.Getter; -import lombok.Setter; -import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.player.PlayerEntity; import org.geysermc.geyser.level.physics.Axis; import org.geysermc.geyser.level.physics.BoundingBox; @@ -137,7 +136,7 @@ public void setWorldCoordinateScale(double worldCoordinateScale) { * @return true as long as the player entity is within the world limits. */ public boolean isInsideBorderBoundaries() { - return isInsideBorderBoundaries(session.getPlayerEntity().getPosition()); + return isInsideBorderBoundaries(session.getPlayerEntity().position()); } public boolean isInsideBorderBoundaries(Vector3f position) { @@ -151,7 +150,7 @@ public boolean isInsideBorderBoundaries(Vector3f position) { * warning blocks set. */ public boolean isCloseToBorderBoundaries() { - Vector3f position = session.getPlayerEntity().getPosition(); + Vector3f position = session.getPlayerEntity().position(); return !(position.getX() > minX + CLOSE_TO_BORDER && position.getX() < maxX - CLOSE_TO_BORDER && position.getZ() > minZ + CLOSE_TO_BORDER && position.getZ() < maxZ - CLOSE_TO_BORDER); } @@ -160,6 +159,7 @@ public boolean isCloseToBorderBoundaries() { * Confirms that the entity is within world border boundaries when they move. * Otherwise, if {@code adjustPosition} is true, this function will push the player back. * + * @param newPosition the position as known to Java Edition - no offset * @return if this player was indeed against the world border. Will return false if no world border was defined for us. */ public boolean isPassingIntoBorderBoundaries(Vector3f newPosition, boolean adjustPosition) { @@ -168,8 +168,7 @@ public boolean isPassingIntoBorderBoundaries(Vector3f newPosition, boolean adjus PlayerEntity playerEntity = session.getPlayerEntity(); // Move the player back, but allow gravity to take place // Teleported = true makes going back better, but disconnects the player from their mounted entity - playerEntity.moveAbsolute(Vector3f.from(playerEntity.getPosition().getX(), (newPosition.getY() - VanillaEntities.PLAYER_ENTITY_OFFSET), playerEntity.getPosition().getZ()), - playerEntity.getYaw(), playerEntity.getPitch(), playerEntity.getHeadYaw(), playerEntity.isOnGround(), playerEntity.getVehicle() == null); + playerEntity.moveAbsolute(Vector3f.from(playerEntity.position()), playerEntity.getYaw(), playerEntity.getPitch(), playerEntity.getHeadYaw(), playerEntity.isOnGround(), playerEntity.getVehicle() == null); } return isInWorldBorder; } @@ -177,7 +176,7 @@ public boolean isPassingIntoBorderBoundaries(Vector3f newPosition, boolean adjus public boolean isPassingIntoBorderBoundaries(Vector3f newEntityPosition) { int entityX = GenericMath.floor(newEntityPosition.getX()); int entityZ = GenericMath.floor(newEntityPosition.getZ()); - Vector3f currentEntityPosition = session.getPlayerEntity().getPosition(); + Vector3f currentEntityPosition = session.getPlayerEntity().bedrockPosition(); // Make sure we can't move out of the world border, but if we're out of the world border, we can move in return (entityX == (int) minX && currentEntityPosition.getX() > newEntityPosition.getX()) || (entityX == (int) maxX && currentEntityPosition.getX() < newEntityPosition.getX()) || @@ -191,7 +190,7 @@ public boolean isPassingIntoBorderBoundaries(Vector3f newEntityPosition) { * @return true as long the entity is within the world limits and not in the warning zone at the edge to the border. */ public boolean isWithinWarningBoundaries() { - Vector3f entityPosition = session.getPlayerEntity().getPosition(); + Vector3f entityPosition = session.getPlayerEntity().position(); return entityPosition.getX() > warningMinX && entityPosition.getX() < warningMaxX && entityPosition.getZ() > warningMinZ && entityPosition.getZ() < warningMaxZ; } @@ -305,7 +304,7 @@ public void drawWall() { return; } currentWallTick = 0; - Vector3f entityPosition = session.getPlayerEntity().getPosition(); + Vector3f entityPosition = session.getPlayerEntity().bedrockPosition(); float particlePosX = entityPosition.getX(); float particlePosY = entityPosition.getY(); float particlePosZ = entityPosition.getZ(); @@ -325,7 +324,7 @@ public void drawWall() { } private void drawWall(Vector3f position, boolean drawWallX) { - int initialY = (int) (position.getY() - VanillaEntities.PLAYER_ENTITY_OFFSET - 1); + int initialY = (int) (position.getY() - 1); for (int y = initialY; y < (initialY + 5); y++) { if (drawWallX) { float x = position.getX(); diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java index 33f8dcc4876..560cb138ec6 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java @@ -99,7 +99,7 @@ public SlotType getSlotType(int javaSlot) { public boolean prepareInventory(GeyserSession session, MerchantContainer container) { if (container.getVillager() == null) { var context = EntitySpawnContext.DUMMY_CONTEXT.apply(session, null, VanillaEntities.VILLAGER); - context.position(session.getPlayerEntity().getPosition().sub(0, 3, 0)); + context.position(session.getPlayerEntity().position().sub(0, 3, 0)); Entity villager = new Entity(context) { @Override diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/PlayerInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/PlayerInventoryTranslator.java index fb2880fb44c..451d4eca1ab 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/PlayerInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/PlayerInventoryTranslator.java @@ -586,14 +586,14 @@ public void openInventory(GeyserSession session, PlayerInventory inventory) { containerOpenPacket.setId((byte) 0); containerOpenPacket.setType(org.cloudburstmc.protocol.bedrock.data.inventory.ContainerType.INVENTORY); containerOpenPacket.setUniqueEntityId(-1); - containerOpenPacket.setBlockPosition(session.getPlayerEntity().getPosition().toInt()); + containerOpenPacket.setBlockPosition(session.getPlayerEntity().bedrockPosition().toInt()); session.sendUpstreamPacket(containerOpenPacket); } @Override public void closeInventory(GeyserSession session, PlayerInventory inventory, boolean force) { if (force) { - Vector3i pos = session.getPlayerEntity().getPosition().toInt(); + Vector3i pos = session.getPlayerEntity().bedrockPosition().toInt(); UpdateBlockPacket packet = new UpdateBlockPacket(); packet.setBlockPosition(pos); diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/chest/DoubleChestInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/chest/DoubleChestInventoryTranslator.java index 0b8f13b1cc2..1691d2a07a1 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/chest/DoubleChestInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/chest/DoubleChestInventoryTranslator.java @@ -202,7 +202,7 @@ public void closeInventory(GeyserSession session, Container container, boolean f private boolean canUseRealBlock(GeyserSession session, Container container) { // See BlockInventoryHolder - same concept there except we're also dealing with a specific block state - if (session.getLastInteractionPlayerPosition().equals(session.getPlayerEntity().getPosition())) { + if (session.getLastInteractionPlayerPosition().equals(session.getPlayerEntity().bedrockPosition())) { BlockState state = session.getGeyser().getWorldManager().blockAt(session, session.getLastInteractionBlockPosition()); if (!BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.get().containsKey(state.javaId())) { if (state.block() instanceof ChestBlock && state.getValue(Properties.CHEST_TYPE) != ChestType.SINGLE) { diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/event/PlaySoundEventTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/level/event/PlaySoundEventTranslator.java index 774060a4c27..3a08ae24568 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/level/event/PlaySoundEventTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/level/event/PlaySoundEventTranslator.java @@ -40,7 +40,7 @@ public void translate(GeyserSession session, ClientboundLevelEventPacket packet) Random rand = ThreadLocalRandom.current(); PlaySoundPacket playSoundPacket = new PlaySoundPacket(); playSoundPacket.setSound(name); - playSoundPacket.setPosition(!relative ? session.getPlayerEntity().getPosition() : Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()).add(0.5f, 0.5f, 0.5f)); + playSoundPacket.setPosition(!relative ? session.getPlayerEntity().bedrockPosition() : Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ()).add(0.5f, 0.5f, 0.5f)); playSoundPacket.setVolume(volume); playSoundPacket.setPitch((pitchSub ? (rand.nextFloat() - rand.nextFloat()) : rand.nextFloat()) * pitchMul + pitchAdd); //replicates java client randomness session.sendUpstreamPacket(playSoundPacket); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java index d4fd6ad1929..c4cc9e1ea70 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java @@ -43,7 +43,6 @@ import org.cloudburstmc.protocol.bedrock.packet.InventoryTransactionPacket; import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket; import org.cloudburstmc.protocol.bedrock.packet.PlaySoundPacket; -import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.ItemFrameEntity; import org.geysermc.geyser.inventory.GeyserItemStack; @@ -215,7 +214,7 @@ public void translate(GeyserSession session, InventoryTransactionPacket packet) boolean hasAlreadyClicked = System.currentTimeMillis() - session.getLastInteractionTime() < 110.0 && packetBlockPosition.distanceSquared(session.getLastInteractionBlockPosition()) < 0.00001; session.setLastInteractionBlockPosition(packetBlockPosition); - session.setLastInteractionPlayerPosition(session.getPlayerEntity().getPosition()); + session.setLastInteractionPlayerPosition(session.getPlayerEntity().bedrockPosition()); if (hasAlreadyClicked) { break; } else { @@ -249,9 +248,7 @@ public void translate(GeyserSession session, InventoryTransactionPacket packet) } // As of 1.21, Paper does not have any additional range checks that would inconvenience normal players. - Vector3f playerPosition = session.getPlayerEntity().getPosition(); - playerPosition = playerPosition.down(VanillaEntities.PLAYER_ENTITY_OFFSET - session.getEyeHeight()); - + Vector3f playerPosition = session.getPlayerEntity().position().down(session.getEyeHeight()); if (!canInteractWithBlock(session, playerPosition, packetBlockPosition)) { BlockUtils.restoreCorrectBlock(session, blockPos); return; @@ -411,13 +408,13 @@ public void translate(GeyserSession session, InventoryTransactionPacket packet) // BDS uses a LevelSoundEvent2Packet, but that doesn't work here... (as of 1.21.20) LevelSoundEventPacket soundPacket = new LevelSoundEventPacket(); soundPacket.setSound(SoundEvent.valueOf("GOAT_CALL_" + instrument.bedrockInstrument().ordinal())); - soundPacket.setPosition(session.getPlayerEntity().getPosition()); + soundPacket.setPosition(session.getPlayerEntity().bedrockPosition()); soundPacket.setIdentifier("minecraft:player"); soundPacket.setExtraData(-1); session.sendUpstreamPacket(soundPacket); } else { PlaySoundPacket playSoundPacket = new PlaySoundPacket(); - playSoundPacket.setPosition(session.getPlayerEntity().position()); + playSoundPacket.setPosition(session.getPlayerEntity().bedrockPosition()); playSoundPacket.setSound(SoundUtils.translatePlaySound(instrument.soundEvent())); playSoundPacket.setPitch(1.0F); playSoundPacket.setVolume(instrument.range() / 16.0F); @@ -505,7 +502,7 @@ public void translate(GeyserSession session, InventoryTransactionPacket packet) } private void processEntityInteraction(GeyserSession session, InventoryTransactionPacket packet, Entity entity) { - Vector3f entityPosition = entity.getPosition(); + Vector3f entityPosition = entity.position(); if (!session.getWorldBorder().isInsideBorderBoundaries(entityPosition)) { // No transaction is able to go through (as of Java Edition 1.18.1) return; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java index c10bd562df6..5d2db10205b 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockMovePlayer.java @@ -31,7 +31,6 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.PlayerAuthInputPacket; import org.geysermc.geyser.entity.VanillaEntities; -import org.geysermc.geyser.entity.type.BoatEntity; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; import org.geysermc.geyser.level.physics.BoundingBox; @@ -65,7 +64,7 @@ static void translate(GeyserSession session, PlayerAuthInputPacket packet) { } // This is vanilla behaviour, LocalPlayer#sendPosition 1.21.8. - boolean actualPositionChanged = entity.getPosition().distanceSquared(packet.getPosition()) > 4e-8; + boolean actualPositionChanged = entity.bedrockPosition().distanceSquared(packet.getPosition()) > 4e-8; if (actualPositionChanged) { // Send book update before the player moves @@ -146,7 +145,7 @@ static void translate(GeyserSession session, PlayerAuthInputPacket packet) { final BoundingBox entityBoundingBox = new BoundingBox(0, 0, 0, other.getBoundingBoxWidth(), other.getBoundingBoxHeight(), other.getBoundingBoxWidth()); // Also offset the position down for boat as their position is offset. - entityBoundingBox.translate(other.getPosition().down(other instanceof BoatEntity ? other.getOffset() : 0).toDouble()); + entityBoundingBox.translate(other.position().toDouble()); if (entityBoundingBox.checkIntersection(boundingBox)) { possibleOnGround = true; @@ -180,11 +179,11 @@ static void translate(GeyserSession session, PlayerAuthInputPacket packet) { // Player position MUST be updated on our end, otherwise e.g. chunk loading breaks if (hasVehicle) { - entity.setPositionManual(packet.getPosition()); + entity.setPositionFromBedrock(packet.getPosition()); session.getSkullCache().updateVisibleSkulls(); } } else if (positionChangedAndShouldUpdate) { - if (isValidMove(session, entity.getPosition(), packet.getPosition())) { + if (isValidMove(session, entity.bedrockPosition(), packet.getPosition())) { CollisionResult result = session.getCollisionManager().adjustBedrockPosition(packet.getPosition(), isOnGround, packet.getInputData().contains(PlayerAuthInputData.HANDLE_TELEPORT)); if (result != null) { // A null return value cancels the packet Vector3d position = result.correctedMovement(); @@ -208,7 +207,7 @@ static void translate(GeyserSession session, PlayerAuthInputPacket packet) { movePacket = new ServerboundMovePlayerPosPacket(isOnGround, horizontalCollision, position.getX(), position.getY(), position.getZ()); } - entity.setPositionManual(packet.getPosition()); + entity.setPositionFromBedrock(packet.getPosition()); // Send final movement changes session.sendDownstreamGamePacket(movePacket); @@ -233,10 +232,10 @@ static void translate(GeyserSession session, PlayerAuthInputPacket packet) { // Move parrots to match if applicable if (entity.getLeftParrot() != null) { - entity.getLeftParrot().moveAbsolute(entity.getPosition(), entity.getYaw(), entity.getPitch(), entity.getHeadYaw(), true, false); + entity.getLeftParrot().moveAbsolute(entity.position(), entity.getYaw(), entity.getPitch(), entity.getHeadYaw(), true, false); } if (entity.getRightParrot() != null) { - entity.getRightParrot().moveAbsolute(entity.getPosition(), entity.getYaw(), entity.getPitch(), entity.getHeadYaw(), true, false); + entity.getRightParrot().moveAbsolute(entity.position(), entity.getYaw(), entity.getPitch(), entity.getHeadYaw(), true, false); } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java index e27de87c4c8..0e61840fcb7 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java @@ -287,11 +287,7 @@ private static void processVehicleInput(GeyserSession session, PlayerAuthInputPa // We only need to determine onGround status this way for client predicted vehicles. // For other vehicle, Geyser already handle it in VehicleComponent or the Java server handle it. if (packet.getInputData().contains(PlayerAuthInputData.IN_CLIENT_PREDICTED_IN_VEHICLE)) { - Vector3f position = vehicle.getPosition(); - - if (vehicle instanceof BoatEntity) { - position = position.down(vehicle.getOffset()); - } + Vector3f position = vehicle.position(); final BoundingBox box = new BoundingBox( position.up(vehicle.getBoundingBoxHeight() / 2f).toDouble(), @@ -305,14 +301,15 @@ private static void processVehicleInput(GeyserSession session, PlayerAuthInputPa vehicle.setOnGround(correctedMovement.getY() != movement.getY() && session.getPlayerEntity().getLastTickEndVelocity().getY() < 0); } - Vector3f vehiclePosition = packet.getPosition(); + Vector3f vehiclePosition = packet.getPosition().down(vehicle.getOffset()); Vector2f vehicleRotation = packet.getVehicleRotation(); if (vehicleRotation == null) { return; // If the client just got in or out of a vehicle for example. Or if this vehicle isn't client predicted. } if (session.getWorldBorder().isPassingIntoBorderBoundaries(vehiclePosition, false)) { - Vector3f position = vehicle.getPosition(); + Vector3f position = vehicle.position(); + // TODO offset if (vehicle instanceof BoatEntity boat) { // Undo the changes usually applied to the boat boat.moveAbsoluteWithoutAdjustments(position, vehicle.getYaw(), vehicle.isOnGround(), true); @@ -325,12 +322,7 @@ private static void processVehicleInput(GeyserSession session, PlayerAuthInputPa return; } - if (vehicle instanceof BoatEntity) { - // Remove some Y position to prevents boats flying up - vehiclePosition = vehiclePosition.down(vehicle.getOffset()); - } - - vehicle.setPosition(vehiclePosition); + vehicle.position(vehiclePosition); ServerboundMoveVehiclePacket moveVehiclePacket = new ServerboundMoveVehiclePacket( vehiclePosition.toDouble(), vehicleRotation.getY() - 90, vehiclePosition.getX(), // TODO I wonder if this is related to the horse spinning bugs... diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java index 21dc0facb24..838991ba106 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java @@ -85,7 +85,7 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) } entity.setEntityId(packet.getEntityId()); - entity.setPosition(Vector3f.from(packet.getX(), packet.getY(), packet.getZ())); + entity.position(Vector3f.from(packet.getX(), packet.getY(), packet.getZ())); entity.setYaw(packet.getYaw()); entity.setPitch(packet.getPitch()); entity.setHeadYaw(packet.getHeadYaw()); @@ -102,7 +102,7 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) } if (!context.callServerSpawnEvent()) { - // TODO log warn + GeyserImpl.getInstance().getLogger().debug(session, "Cancelled entity spawn (%s) at (%s)".formatted(type.identifier(), context.position())); return; } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java index e5fdd34ca8c..930ca1cca67 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java @@ -105,14 +105,14 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet LevelEventPacket particlePacket = new LevelEventPacket(); particlePacket.setType(ParticleType.ICON_CRACK); particlePacket.setData(ItemTranslator.getBedrockItemDefinition(session, egg.getItemStack()).getRuntimeId() << 16); - particlePacket.setPosition(entity.getPosition()); + particlePacket.setPosition(entity.bedrockPosition()); for (int i = 0; i < 6; i++) { session.sendUpstreamPacket(particlePacket); } } else if (entity.getJavaTypeDefinition().is(BuiltinEntityType.SNOWBALL)) { LevelEventPacket particlePacket = new LevelEventPacket(); particlePacket.setType(ParticleType.SNOWBALL_POOF); - particlePacket.setPosition(entity.getPosition()); + particlePacket.setPosition(entity.bedrockPosition()); for (int i = 0; i < 8; i++) { session.sendUpstreamPacket(particlePacket); } @@ -138,7 +138,7 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet // https://minecraft.wiki/w/Fishing_Rod#Hooking_mobs_and_other_entities SetEntityMotionPacket motionPacket = new SetEntityMotionPacket(); motionPacket.setRuntimeEntityId(session.getPlayerEntity().geyserId()); - motionPacket.setMotion(hookOwner.getPosition().sub(session.getPlayerEntity().getPosition()).mul(0.1f)); + motionPacket.setMotion(hookOwner.bedrockPosition().sub(session.getPlayerEntity().bedrockPosition()).mul(0.1f)); session.sendUpstreamPacket(motionPacket); } } @@ -152,7 +152,7 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet case ZOMBIE_VILLAGER_CURE: // Played when a zombie bites the golden apple LevelSoundEventPacket soundPacket = new LevelSoundEventPacket(); soundPacket.setSound(SoundEvent.REMEDY); - soundPacket.setPosition(entity.getPosition()); + soundPacket.setPosition(entity.bedrockPosition()); soundPacket.setExtraData(-1); soundPacket.setIdentifier(""); soundPacket.setRelativeVolumeDisabled(false); @@ -183,7 +183,7 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet PlaySoundPacket playSoundPacket = new PlaySoundPacket(); playSoundPacket.setSound("random.totem"); - playSoundPacket.setPosition(entity.getPosition()); + playSoundPacket.setPosition(entity.bedrockPosition()); playSoundPacket.setVolume(1.0F); playSoundPacket.setPitch(1.0F + (ThreadLocalRandom.current().nextFloat() * 0.1F) - 0.05F); session.sendUpstreamPacket(playSoundPacket); @@ -216,7 +216,7 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet case VILLAGER_SWEAT: LevelEventPacket levelEventPacket = new LevelEventPacket(); levelEventPacket.setType(ParticleType.WATER_SPLASH); - levelEventPacket.setPosition(entity.getPosition().up(entity.height())); + levelEventPacket.setPosition(entity.bedrockPosition().up(entity.height())); session.sendUpstreamPacket(levelEventPacket); return; case IRON_GOLEM_EMPTY_HAND: @@ -250,7 +250,7 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet case LIVING_EQUIPMENT_BREAK_OFF_HAND: LevelSoundEventPacket equipmentBreakPacket = new LevelSoundEventPacket(); equipmentBreakPacket.setSound(SoundEvent.BREAK); - equipmentBreakPacket.setPosition(entity.getPosition()); + equipmentBreakPacket.setPosition(entity.bedrockPosition()); equipmentBreakPacket.setExtraData(-1); equipmentBreakPacket.setIdentifier(""); session.sendUpstreamPacket(equipmentBreakPacket); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java index 27d3c231dd9..209924eeea1 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java @@ -29,7 +29,6 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityLinkData; import org.cloudburstmc.protocol.bedrock.packet.SetEntityLinkPacket; -import org.geysermc.geyser.entity.VanillaEntities; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.vehicle.ClientVehicle; import org.geysermc.geyser.session.GeyserSession; @@ -59,7 +58,7 @@ public void translate(GeyserSession session, ClientboundSetPassengersPacket pack if (passenger == session.getPlayerEntity()) { session.getPlayerEntity().setVehicle(entity); // We need to confirm teleports before entering a vehicle, or else we will likely exit right out - session.confirmTeleport(passenger.getPosition().down(VanillaEntities.PLAYER_ENTITY_OFFSET)); + session.confirmTeleport(passenger.position()); if (entity instanceof ClientVehicle clientVehicle) { clientVehicle.getVehicleComponent().onMount(); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSoundEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSoundEntityTranslator.java index d6e70b3f3dd..a7ff5e44770 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSoundEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSoundEntityTranslator.java @@ -40,6 +40,6 @@ public void translate(GeyserSession session, ClientboundSoundEntityPacket packet if (entity == null) { return; } - SoundUtils.playSound(session, packet.getSound(), entity.getPosition(), packet.getVolume(), packet.getPitch()); + SoundUtils.playSound(session, packet.getSound(), entity.bedrockPosition(), packet.getVolume(), packet.getPitch()); } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaTakeItemEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaTakeItemEntityTranslator.java index 4f3c6579b3a..26188a31e7c 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaTakeItemEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaTakeItemEntityTranslator.java @@ -55,7 +55,7 @@ public void translate(GeyserSession session, ClientboundTakeItemEntityPacket pac // Player just picked up an experience orb LevelEventPacket xpPacket = new LevelEventPacket(); xpPacket.setType(LevelEvent.SOUND_EXPERIENCE_ORB_PICKUP); - xpPacket.setPosition(collectedEntity.getPosition()); + xpPacket.setPosition(collectedEntity.bedrockPosition()); xpPacket.setData(0); session.sendUpstreamPacket(xpPacket); } else { diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerLookAtTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerLookAtTranslator.java index 954c636145f..0ec79b55225 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerLookAtTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerLookAtTranslator.java @@ -37,7 +37,7 @@ public class JavaPlayerLookAtTranslator extends PacketTranslator target.getPosition(); - case EYES -> target.getPosition().add(0, target.getBoundingBoxHeight(), 0); + case FEET -> target.position(); + case EYES -> target.position().add(0, target.getBoundingBoxHeight(), 0); }; } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java index ab16171395f..fdcd5273439 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java @@ -31,7 +31,7 @@ import org.cloudburstmc.protocol.bedrock.packet.MovePlayerPacket; import org.cloudburstmc.protocol.bedrock.packet.RespawnPacket; import org.cloudburstmc.protocol.bedrock.packet.SetEntityMotionPacket; -import org.geysermc.geyser.entity.VanillaEntities; +import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.TeleportCache; @@ -54,29 +54,31 @@ public void translate(GeyserSession session, ClientboundPlayerPositionPacket pac } final SessionPlayerEntity entity = session.getPlayerEntity(); - Vector3d position = packet.getPosition(); - - position = position.add( - packet.getRelatives().contains(PositionElement.X) ? entity.getPosition().getX() : 0, - packet.getRelatives().contains(PositionElement.Y) ? entity.getPosition().getY() - VanillaEntities.PLAYER_ENTITY_OFFSET : 0, - packet.getRelatives().contains(PositionElement.Z) ? entity.getPosition().getZ() : 0); + Vector3d position = packet.getPosition().add( + packet.getRelatives().contains(PositionElement.X) ? entity.position().getX() : 0, + packet.getRelatives().contains(PositionElement.Y) ? entity.position().getY() : 0, + packet.getRelatives().contains(PositionElement.Z) ? entity.position().getZ() : 0); float newPitch = MathUtils.clamp(packet.getXRot() + (packet.getRelatives().contains(PositionElement.X_ROT) ? entity.getPitch() : 0), -90, 90); float newYaw = packet.getYRot() + (packet.getRelatives().contains(PositionElement.Y_ROT) ? entity.getYaw() : 0); final int teleportId = packet.getId(); + GeyserImpl.getInstance().getLogger().info("teleport to " + position); + acceptTeleport(session, position, newYaw, newPitch, teleportId); if (!session.isSpawned()) { - entity.setPosition(position.toFloat()); + entity.position(position.toFloat()); entity.setYaw(packet.getYRot()); entity.setPitch(packet.getXRot()); entity.setHeadYaw(packet.getYRot()); + GeyserImpl.getInstance().getLogger().info("BEDROCK POS: " + entity.bedrockPosition()); + RespawnPacket respawnPacket = new RespawnPacket(); respawnPacket.setRuntimeEntityId(0); // Bedrock server behavior - respawnPacket.setPosition(entity.getPosition()); + respawnPacket.setPosition(entity.bedrockPosition()); respawnPacket.setState(RespawnPacket.State.SERVER_READY); session.sendUpstreamPacket(respawnPacket); @@ -84,7 +86,7 @@ public void translate(GeyserSession session, ClientboundPlayerPositionPacket pac MovePlayerPacket movePlayerPacket = new MovePlayerPacket(); movePlayerPacket.setRuntimeEntityId(entity.geyserId()); - movePlayerPacket.setPosition(entity.getPosition()); + movePlayerPacket.setPosition(entity.bedrockPosition()); movePlayerPacket.setRotation(entity.getBedrockRotation()); movePlayerPacket.setMode(MovePlayerPacket.Mode.RESPAWN); session.sendUpstreamPacket(movePlayerPacket); @@ -116,9 +118,8 @@ public void translate(GeyserSession session, ClientboundPlayerPositionPacket pac return; } - session.getGeyser().getLogger().debug("Teleport (" + teleportId + ") from " + entity.getPosition().getX() + " " + (entity.getPosition().getY() - VanillaEntities.PLAYER_ENTITY_OFFSET) + " " + entity.getPosition().getZ()); - - Vector3f lastPlayerPosition = entity.getPosition().down(VanillaEntities.PLAYER_ENTITY_OFFSET); + Vector3f lastPlayerPosition = entity.position(); + session.getGeyser().getLogger().debug("Teleport (" + teleportId + ") from " + lastPlayerPosition); float lastPlayerPitch = entity.getPitch(); float lastPlayerYaw = entity.getYaw(); Vector3f teleportDestination = position.toFloat(); @@ -155,7 +156,7 @@ public void translate(GeyserSession session, ClientboundPlayerPositionPacket pac session.setUnconfirmedTeleport(new TeleportCache(teleportDestination, deltaMovement, newPitch, newYaw, teleportId, type)); } - session.getGeyser().getLogger().debug("to " + entity.getPosition().getX() + " " + (entity.getPosition().getY() - VanillaEntities.PLAYER_ENTITY_OFFSET) + " " + entity.getPosition().getZ()); + session.getGeyser().getLogger().debug("to " + entity.position()); } private void acceptTeleport(GeyserSession session, Vector3d position, float yaw, float pitch, int id) { diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaSetHealthTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaSetHealthTranslator.java index 412a325561d..80fead39511 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaSetHealthTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaSetHealthTranslator.java @@ -51,7 +51,7 @@ public void translate(GeyserSession session, ClientboundSetHealthPacket packet) // https://github.com/GeyserMC/Geyser/issues/2957 RespawnPacket respawnPacket = new RespawnPacket(); respawnPacket.setRuntimeEntityId(0); - respawnPacket.setPosition(entity.getPosition()); + respawnPacket.setPosition(entity.bedrockPosition()); respawnPacket.setState(RespawnPacket.State.SERVER_READY); session.sendUpstreamPacket(respawnPacket); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaGameEventTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaGameEventTranslator.java index 0ddf6e67bf2..f6be90bff1c 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaGameEventTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaGameEventTranslator.java @@ -89,7 +89,7 @@ public void translate(GeyserSession session, ClientboundGameEventPacket packet) // Fix a bug where the player has glitched movement and thinks they are still on the ground MovePlayerPacket movePlayerPacket = new MovePlayerPacket(); movePlayerPacket.setRuntimeEntityId(entity.geyserId()); - movePlayerPacket.setPosition(entity.getPosition()); + movePlayerPacket.setPosition(entity.bedrockPosition()); movePlayerPacket.setRotation(entity.getBedrockRotation()); movePlayerPacket.setOnGround(false); movePlayerPacket.setMode(MovePlayerPacket.Mode.TELEPORT); @@ -139,7 +139,7 @@ public void translate(GeyserSession session, ClientboundGameEventPacket packet) arrowSoundPacket.setSound("random.orb"); arrowSoundPacket.setPitch(0.5f); arrowSoundPacket.setVolume(0.5f); - arrowSoundPacket.setPosition(entity.getPosition()); + arrowSoundPacket.setPosition(entity.bedrockPosition()); session.sendUpstreamPacket(arrowSoundPacket); break; default: diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelChunkWithLightTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelChunkWithLightTranslator.java index 46278e3c533..ada5af30036 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelChunkWithLightTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelChunkWithLightTranslator.java @@ -89,7 +89,7 @@ public void translate(GeyserSession session, ClientboundLevelChunkWithLightPacke final boolean useExtendedCollisions = !session.getBlockMappings().getExtendedCollisionBoxes().isEmpty(); if (session.isSpawned()) { - ChunkUtils.updateChunkPosition(session, session.getPlayerEntity().getPosition().toInt()); + ChunkUtils.updateChunkPosition(session, session.getPlayerEntity().position().toInt()); } // Ensure that, if the player is using lower world heights, the position is not offset diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelParticlesTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelParticlesTranslator.java index d2ffbef2646..6b6f2b6aed7 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelParticlesTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelParticlesTranslator.java @@ -151,7 +151,7 @@ public void translate(GeyserSession session, ClientboundLevelParticlesPacket pac } else if (data.getPositionSource() instanceof EntityPositionSource entityPositionSource) { Entity entity = session.getEntityCache().getEntityByJavaId(entityPositionSource.getEntityId()); if (entity != null) { - target = entity.getPosition().up(entityPositionSource.getYOffset()); + target = entity.position().up(entityPositionSource.getYOffset()); } else { session.getGeyser().getLogger().debug("Unable to find entity with Java Id: " + entityPositionSource.getEntityId() + " for vibration particle."); return null; diff --git a/core/src/main/java/org/geysermc/geyser/util/DimensionUtils.java b/core/src/main/java/org/geysermc/geyser/util/DimensionUtils.java index 9dfc2309a89..754fa04167f 100644 --- a/core/src/main/java/org/geysermc/geyser/util/DimensionUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/DimensionUtils.java @@ -130,7 +130,7 @@ private static void changeDimension(GeyserSession session, int bedrockDimension) setBedrockDimension(session, bedrockDimension); - session.getPlayerEntity().setPosition(pos); + session.getPlayerEntity().position(pos); session.setSpawned(false); session.setLastChunkPosition(null); } @@ -155,7 +155,7 @@ private static void finalizeDimensionSwitch(GeyserSession session, Entity player // TODO - fix this hack of a fix by sending the final dimension switching logic after sections have been sent. // The client wants sections sent to it before it can successfully respawn. - ChunkUtils.sendEmptyChunks(session, player.getPosition().toInt(), 3, true); + ChunkUtils.sendEmptyChunks(session, player.position().toInt(), 3, true); } public static void setBedrockDimension(GeyserSession session, int bedrockDimension) { diff --git a/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java b/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java index 17040a9ce7a..08488a7eb23 100644 --- a/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java @@ -238,8 +238,8 @@ public static Vector3i findAvailableWorldSpace(GeyserSession session) { // Check if a fake block can be placed, either above the player or beneath. BedrockDimension dimension = session.getBedrockDimension(); int minY = dimension.minY(), maxY = minY + dimension.height(); - Vector3i flatPlayerPosition = session.getPlayerEntity().getPosition().toInt(); - Vector3i position = flatPlayerPosition.add(Vector3i.UP); + Vector3i flatPlayerPosition = session.getPlayerEntity().position().toInt(); + Vector3i position = flatPlayerPosition.up(2); if (position.getY() < minY) { return null; } From f3070f7509822744a98a324c0f508367f157fb48 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Mon, 1 Dec 2025 01:38:01 +0100 Subject: [PATCH 26/62] Remove unused offsets --- .../geyser/entity/BedrockEntityDefinitions.java | 2 +- .../geysermc/geyser/entity/VanillaEntities.java | 14 -------------- .../player/JavaPlayerPositionTranslator.java | 5 ----- 3 files changed, 1 insertion(+), 20 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java index 7e9af4b0ddd..b780b9bc24a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinitions.java @@ -50,7 +50,7 @@ public class BedrockEntityDefinitions { EVOCATION_ILLAGER = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("evocation_illager")); LLAMA = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("llama")); MINECART = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("minecart")); - SPLASH_POTION = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("splash_position")); + SPLASH_POTION = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("splash_potion")); ZOMBIE = BedrockEntityDefinition.ofVanilla(IdentifierImpl.of("zombie")); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntities.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntities.java index 7042aa2d1a5..3de8a499edb 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntities.java +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntities.java @@ -740,7 +740,6 @@ public final class VanillaEntities { CREEPER = VanillaEntityType.inherited(CreeperEntity::new, mobEntityBase) .type(BuiltinEntityType.CREEPER) .height(1.7f).width(0.6f) - .offset(1.62f) .addTranslator(MetadataTypes.INT, CreeperEntity::setSwelling) .addTranslator(MetadataTypes.BOOLEAN, (entity, entityMetadata) -> entity.setFlag(EntityFlag.POWERED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue())) .addTranslator(MetadataTypes.BOOLEAN, CreeperEntity::setIgnited) @@ -768,7 +767,6 @@ public final class VanillaEntities { GIANT = VanillaEntityType.inherited(GiantEntity::new, mobEntityBase) .type(BuiltinEntityType.GIANT) .height(1.8f).width(1.6f) - .offset(1.62f) .bedrockDefinition(BedrockEntityDefinitions.ZOMBIE) .build(); IRON_GOLEM = VanillaEntityType.inherited(IronGolemEntity::new, mobEntityBase) @@ -779,7 +777,6 @@ public final class VanillaEntities { PHANTOM = VanillaEntityType.inherited(PhantomEntity::new, mobEntityBase) .type(BuiltinEntityType.PHANTOM) .height(0.5f).width(0.9f) - .offset(0.6f) .addTranslator(MetadataTypes.INT, PhantomEntity::setPhantomScale) .build(); SILVERFISH = VanillaEntityType.inherited(MonsterEntity::new, mobEntityBase) @@ -796,7 +793,6 @@ public final class VanillaEntities { SKELETON = VanillaEntityType.inherited(SkeletonEntity::new, mobEntityBase) .type(BuiltinEntityType.SKELETON) .height(1.8f).width(0.6f) - .offset(1.62f) .addTranslator(MetadataTypes.BOOLEAN, SkeletonEntity::setConvertingToStray) .build(); SNOW_GOLEM = VanillaEntityType.inherited(SnowGolemEntity::new, mobEntityBase) @@ -807,7 +803,6 @@ public final class VanillaEntities { SPIDER = VanillaEntityType.inherited(SpiderEntity::new, mobEntityBase) .type(BuiltinEntityType.SPIDER) .height(0.9f).width(1.4f) - .offset(1f) .addTranslator(MetadataTypes.BYTE, SpiderEntity::setSpiderFlags) .build(); CAVE_SPIDER = VanillaEntityType.inherited(SpiderEntity::new, SPIDER) @@ -817,7 +812,6 @@ public final class VanillaEntities { STRAY = VanillaEntityType.inherited(AbstractSkeletonEntity::new, mobEntityBase) .type(BuiltinEntityType.STRAY) .height(1.8f).width(0.6f) - .offset(1.62f) .build(); VEX = VanillaEntityType.inherited(VexEntity::new, mobEntityBase) .type(BuiltinEntityType.VEX) @@ -849,7 +843,6 @@ public final class VanillaEntities { ZOMBIE = VanillaEntityType.inherited(ZombieEntity::new, mobEntityBase) .type(BuiltinEntityType.ZOMBIE) .height(1.8f).width(0.6f) - .offset(1.62f) .bedrockDefinition(BedrockEntityDefinitions.ZOMBIE) .addTranslator(MetadataTypes.BOOLEAN, ZombieEntity::setZombieBaby) .addTranslator(null) // "set special type", doesn't do anything @@ -858,7 +851,6 @@ public final class VanillaEntities { ZOMBIE_VILLAGER = VanillaEntityType.inherited(ZombieVillagerEntity::new, ZOMBIE) .type(BuiltinEntityType.ZOMBIE_VILLAGER) .height(1.8f).width(0.6f) - .offset(1.62f) .bedrockIdentifier("minecraft:zombie_villager_v2") .addTranslator(MetadataTypes.BOOLEAN, ZombieVillagerEntity::setTransforming) .addTranslator(MetadataTypes.VILLAGER_DATA, ZombieVillagerEntity::setZombieVillagerData) @@ -866,7 +858,6 @@ public final class VanillaEntities { ZOMBIFIED_PIGLIN = VanillaEntityType.inherited(ZombifiedPiglinEntity::new, ZOMBIE) //TODO test how zombie entity metadata is handled? .type(BuiltinEntityType.ZOMBIFIED_PIGLIN) .height(1.95f).width(0.6f) - .offset(1.62f) .bedrockIdentifier("minecraft:zombie_pigman") .build(); @@ -960,7 +951,6 @@ public final class VanillaEntities { PILLAGER = VanillaEntityType.inherited(PillagerEntity::new, raidParticipantEntityBase) .type(BuiltinEntityType.PILLAGER) .height(1.8f).width(0.6f) - .offset(1.62f) .addTranslator(MetadataTypes.BOOLEAN, PillagerEntity::setChargingCrossbow) .build(); RAVAGER = VanillaEntityType.inherited(RavagerEntity::new, raidParticipantEntityBase) @@ -970,12 +960,10 @@ public final class VanillaEntities { VINDICATOR = VanillaEntityType.inherited(VindicatorEntity::new, raidParticipantEntityBase) .type(BuiltinEntityType.VINDICATOR) .height(1.8f).width(0.6f) - .offset(1.62f) .build(); WITCH = VanillaEntityType.inherited(RaidParticipantEntity::new, raidParticipantEntityBase) .type(BuiltinEntityType.WITCH) .height(1.8f).width(0.6f) - .offset(1.62f) .addTranslator(null) // Using item .build(); } @@ -1122,14 +1110,12 @@ public final class VanillaEntities { VILLAGER = VanillaEntityType.inherited(VillagerEntity::new, abstractVillagerEntityBase) .type(BuiltinEntityType.VILLAGER) .height(1.8f).width(0.6f) - .offset(1.62f) .bedrockIdentifier("minecraft:villager_v2") .addTranslator(MetadataTypes.VILLAGER_DATA, VillagerEntity::setVillagerData) .build(); WANDERING_TRADER = VanillaEntityType.inherited(abstractVillagerEntityBase.factory(), abstractVillagerEntityBase) .type(BuiltinEntityType.WANDERING_TRADER) .height(1.8f).width(0.6f) - .offset(1.62f) .build(); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java index fdcd5273439..9fed5c59897 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java @@ -31,7 +31,6 @@ import org.cloudburstmc.protocol.bedrock.packet.MovePlayerPacket; import org.cloudburstmc.protocol.bedrock.packet.RespawnPacket; import org.cloudburstmc.protocol.bedrock.packet.SetEntityMotionPacket; -import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.entity.type.player.SessionPlayerEntity; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.cache.TeleportCache; @@ -64,8 +63,6 @@ public void translate(GeyserSession session, ClientboundPlayerPositionPacket pac final int teleportId = packet.getId(); - GeyserImpl.getInstance().getLogger().info("teleport to " + position); - acceptTeleport(session, position, newYaw, newPitch, teleportId); if (!session.isSpawned()) { @@ -74,8 +71,6 @@ public void translate(GeyserSession session, ClientboundPlayerPositionPacket pac entity.setPitch(packet.getXRot()); entity.setHeadYaw(packet.getYRot()); - GeyserImpl.getInstance().getLogger().info("BEDROCK POS: " + entity.bedrockPosition()); - RespawnPacket respawnPacket = new RespawnPacket(); respawnPacket.setRuntimeEntityId(0); // Bedrock server behavior respawnPacket.setPosition(entity.bedrockPosition()); From 8a79001b4b20e9839b330c7632b75802fd4f98bc Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Mon, 1 Dec 2025 15:53:48 +0100 Subject: [PATCH 27/62] Remove debug print, validate that entity definitions have been registered, setup publishing --- .github/workflows/build.yml | 11 ++++++- .../entity/spawn/EntitySpawnContext.java | 32 ++++++++++++------- .../entity/type/player/PlayerEntity.java | 2 +- .../geyser/session/cache/TeleportCache.java | 2 -- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 59aa890869e..31344ffaf64 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -51,7 +51,16 @@ jobs: bootstrap/viaproxy/build/libs/Geyser-ViaProxy.jar - name: Publish to Maven Repository - if: ${{ success() && github.repository == 'GeyserMC/Geyser' && github.ref_name == 'master' }} + if: >- + ${{ + success() && + github.repository == 'GeyserMC/Geyser' && + ( + github.ref_name == 'master' || + (github.event.pull_request && + contains(github.event.pull_request.labels.*.name, 'PR: Needs Testing')) + ) + }} run: ./gradlew publish env: BUILD_NUMBER: ${{ steps.release-info.outputs.curentRelease }} diff --git a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java index ce29e4ee83c..618af0c8e2a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java +++ b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java @@ -161,13 +161,17 @@ public int entityId() { public void definition(@Nullable GeyserEntityDefinition entityDefinition) { if (entityDefinition == null) { bedrockEntityDefinition = null; - } else { - if (entityDefinition instanceof BedrockEntityDefinition bed) { - bedrockEntityDefinition = bed; - } else { - throw new IllegalStateException("Unknown implementation of GeyserEntityDefinition"); - } } + + if (!(entityDefinition instanceof BedrockEntityDefinition definition)) { + throw new IllegalStateException("Unknown implementation of GeyserEntityDefinition"); + } + + if (!entityDefinition.registered()) { + throw new IllegalStateException("%s is not registered!".formatted(entityDefinition.identifier())); + } + + bedrockEntityDefinition = definition; } @Override @@ -208,13 +212,17 @@ public boolean right() { public void definition(@Nullable GeyserEntityDefinition entityDefinition) { if (entityDefinition == null) { bedrockEntityDefinition = null; - } else { - if (entityDefinition instanceof BedrockEntityDefinition bed) { - bedrockEntityDefinition = bed; - } else { - throw new IllegalStateException("Unknown implementation of GeyserEntityDefinition"); - } } + + if (!(entityDefinition instanceof BedrockEntityDefinition definition)) { + throw new IllegalStateException("Unknown implementation of GeyserEntityDefinition"); + } + + if (!entityDefinition.registered()) { + throw new IllegalStateException("%s is not registered!".formatted(entityDefinition.identifier())); + } + + bedrockEntityDefinition = definition; } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java index fc340923f6e..2ec0c0a4a25 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java @@ -163,7 +163,7 @@ protected void setParrot(OptionalInt variant, boolean isLeft) { // The parrot is a separate entity in Bedrock, but part of the player entity in Java EntitySpawnContext context = EntitySpawnContext.inherited(session, VanillaEntities.PARROT, this, position); if (context.callParrotEvent(this, variant.getAsInt(), !isLeft)) { - GeyserImpl.getInstance().getLogger().debug("TODO"); + GeyserImpl.getInstance().getLogger().debug(session, "Cancelled parrot spawn as definition is null!"); return; } ParrotEntity parrot = new ParrotEntity(context); diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/TeleportCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/TeleportCache.java index e7f044ab91c..d672338f71d 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/TeleportCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/TeleportCache.java @@ -28,7 +28,6 @@ import lombok.Data; import lombok.RequiredArgsConstructor; import org.cloudburstmc.math.vector.Vector3f; -import org.geysermc.geyser.GeyserImpl; /** * Represents a teleport ID and corresponding coordinates that need to be confirmed.
    @@ -69,7 +68,6 @@ public TeleportCache(Vector3f position, float pitch, float yaw, int teleportConf private int unconfirmedFor = 0; public boolean canConfirm(Vector3f position) { - GeyserImpl.getInstance().getLogger().info("TeleportCache_canConfirm " + position + " " + this.position); final float distanceX = Math.abs(this.position.getX() - position.getX()); final float distanceY = Math.abs(this.position.getY() - position.getY()); final float distanceZ = Math.abs(this.position.getZ() - position.getZ()); From d4f07135f4ca3dc401d7684d87612c2fc676ee89 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Mon, 1 Dec 2025 16:35:30 +0100 Subject: [PATCH 28/62] Set up feature branch publishing and vertical offset applying --- .github/workflows/build.yml | 11 +---------- .../org/geysermc/geyser/api/entity/EntityData.java | 5 +---- .../api/entity/custom/CustomEntityDefinition.java | 12 +++++++++++- .../geyser/entity/BedrockEntityDefinition.java | 1 - .../java/org/geysermc/geyser/entity/type/Entity.java | 3 ++- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 31344ffaf64..ce948ac2c13 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -51,16 +51,7 @@ jobs: bootstrap/viaproxy/build/libs/Geyser-ViaProxy.jar - name: Publish to Maven Repository - if: >- - ${{ - success() && - github.repository == 'GeyserMC/Geyser' && - ( - github.ref_name == 'master' || - (github.event.pull_request && - contains(github.event.pull_request.labels.*.name, 'PR: Needs Testing')) - ) - }} + if: ${{ success() && github.repository == 'GeyserMC/Geyser' && (github.ref_name == 'master' || startsWith(github.ref_name, 'feature/')) }} run: ./gradlew publish env: BUILD_NUMBER: ${{ steps.release-info.outputs.curentRelease }} diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java b/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java index 191c037f0ea..c252aac6c89 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java @@ -66,10 +66,7 @@ public interface EntityData { @Nullable GeyserEntity byGeyserId(@NonNegative long geyserId); /** - * Displays a player entity as emoting to this client. - * - * @param emoter the player entity emoting - * @param emoteId the emote ID to send to this client + * @deprecated use {@link GeyserConnection#showEmote(GeyserPlayerEntity, String)} instead */ @Deprecated void showEmote(@NonNull GeyserPlayerEntity emoter, @NonNull String emoteId); diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java index f9a50de8708..034739628c6 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java @@ -44,9 +44,19 @@ default boolean vanilla() { * Creates or retrieves a GeyserEntityDefinition by the Bedrock entity type identifier. * * @param identifier the Bedrock entity identifier - * @return the GeyserEntityDefinition + * @return the CustomEntityDefinition */ static @NonNull CustomEntityDefinition of(@NonNull Identifier identifier) { return GeyserApi.api().provider(GeyserEntityDefinition.class, identifier); } + + /** + * Creates or retrieves a GeyserEntityDefinition by the Bedrock entity type identifier. + * + * @param identifier the Bedrock entity identifier, in string format + * @return the CustomEntityDefinition + */ + static @NonNull CustomEntityDefinition of(@NonNull String identifier) { + return of(Identifier.of(identifier)); + } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java index 72530bea926..55ef704ad85 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java @@ -58,7 +58,6 @@ public static BedrockEntityDefinition getOrCreate(@NonNull Identifier identifier return Registries.BEDROCK_ENTITY_DEFINITIONS.get().get(identifier); } - Objects.requireNonNull(identifier, "identifier"); if (identifier.vanilla()) { throw new IllegalArgumentException("Cannot create custom entity in vanilla namespace! " + identifier); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index 06c0183f04e..1deac5fbc3f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -853,9 +853,10 @@ public void update(@NonNull GeyserEntityProperty property, @Nullable T va } public void offset(float offset) { + this.offset = offset; // TODO queue? if (isValid()) { - this.moveRelative(0, offset, 0, 0, 0, isOnGround()); + this.moveRelative(0, 0, 0, 0, 0, isOnGround()); } } From 899bd29af7c0f788be031407a4e60d355f3c4f32 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Tue, 2 Dec 2025 00:51:55 +0100 Subject: [PATCH 29/62] correct javadoc --- .../java/org/geysermc/geyser/api/entity/type/GeyserEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java b/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java index 29fb2cd6f66..808403da120 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java @@ -47,7 +47,7 @@ */ public interface GeyserEntity { /** - * @return the entity ID that the server has assigned to this entity, or null if none is present + * @return the entity ID that the server has assigned to this entity, or 0 if none is present */ @NonNegative int javaId(); From a1d4f3e89780cf1b97ecbeb8b21d56724056f213 Mon Sep 17 00:00:00 2001 From: Pierpaolo Coletta Date: Fri, 12 Dec 2025 22:14:48 +0100 Subject: [PATCH 30/62] Change entity definition log level to debug for missing definitions (#6042) --- .../protocol/java/entity/JavaAddEntityTranslator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java index 838991ba106..41bb9f9a50c 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java @@ -65,7 +65,7 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) EntityTypeDefinition definition = Registries.JAVA_ENTITY_TYPES.get(type); if (definition == null) { - session.getGeyser().getLogger().warning("Could not find an entity definition for add entity packet " + packet); + session.getGeyser().getLogger().debug("Could not find an entity definition for add entity packet " + packet); return; } From 494420ece86f0fabf8783598f9440a1817b77ad8 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sat, 13 Dec 2025 23:47:34 +0100 Subject: [PATCH 31/62] Fix villager inventories not showing up --- .../translator/inventory/MerchantInventoryTranslator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java index 560cb138ec6..f67828c1a5e 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java @@ -113,7 +113,7 @@ protected void initializeMetadata() { SetEntityLinkPacket linkPacket = new SetEntityLinkPacket(); EntityLinkData.Type type = EntityLinkData.Type.PASSENGER; - linkPacket.setEntityLink(new EntityLinkData(session.getPlayerEntity().geyserId(), context.geyserId(), type, true, false, 0f)); + linkPacket.setEntityLink(new EntityLinkData(session.getPlayerEntity().geyserId(), villager.geyserId(), type, true, false, 0f)); session.sendUpstreamPacket(linkPacket); container.setVillager(villager); From ec2359327d2d06f1b172bb0d8836a331638d9876 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Tue, 16 Dec 2025 15:08:01 +0100 Subject: [PATCH 32/62] Fix interaction range check --- .../session/cache/BlockBreakHandler.java | 5 ++--- ...BedrockInventoryTransactionTranslator.java | 22 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/BlockBreakHandler.java b/core/src/main/java/org/geysermc/geyser/session/cache/BlockBreakHandler.java index ef5a97a5cab..eb5ed461f72 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/BlockBreakHandler.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/BlockBreakHandler.java @@ -489,9 +489,8 @@ protected boolean canBreak(Vector3i vector, BlockState state, PlayerActionType a } } - Vector3f playerPosition = session.getPlayerEntity().position(); - playerPosition = playerPosition.down(session.getEyeHeight()); - return BedrockInventoryTransactionTranslator.canInteractWithBlock(session, playerPosition, vector); + Vector3f playerEyeHeight = session.getPlayerEntity().position().up(session.getEyeHeight()); + return BedrockInventoryTransactionTranslator.canInteractWithBlock(session, playerEyeHeight, vector); } protected boolean canDestroyBlock(BlockState state) { diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java index 304ff0e2caf..acf273b863f 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java @@ -249,8 +249,8 @@ public void translate(GeyserSession session, InventoryTransactionPacket packet) } // As of 1.21, Paper does not have any additional range checks that would inconvenience normal players. - Vector3f playerPosition = session.getPlayerEntity().position().down(session.getEyeHeight()); - if (!canInteractWithBlock(session, playerPosition, packetBlockPosition)) { + Vector3f playerEyeHeight = session.getPlayerEntity().position().up(session.getEyeHeight()); + if (!canInteractWithBlock(session, playerEyeHeight, packetBlockPosition)) { BlockUtils.restoreCorrectBlock(session, blockPos); return; } @@ -555,17 +555,17 @@ public static boolean canInteractWithBlock(GeyserSession session, Vector3f playe double additionalRangeCheck = blockInteractionRange + 1.0d; // AABB.(BlockPos) - float minX = packetBlockPosition.getX(); - float minY = packetBlockPosition.getY(); - float minZ = packetBlockPosition.getZ(); - float maxX = packetBlockPosition.getX() + 1; - float maxY = packetBlockPosition.getY() + 1; - float maxZ = packetBlockPosition.getZ() + 1; + double minX = packetBlockPosition.getX(); + double minY = packetBlockPosition.getY(); + double minZ = packetBlockPosition.getZ(); + double maxX = packetBlockPosition.getX() + 1; + double maxY = packetBlockPosition.getY() + 1; + double maxZ = packetBlockPosition.getZ() + 1; // AABB#distanceToSqr - float diffX = Math.max(Math.max(minX - playerPosition.getX(), playerPosition.getX() - maxX), 0); - float diffY = Math.max(Math.max(minY - playerPosition.getY(), playerPosition.getY() - maxY), 0); - float diffZ = Math.max(Math.max(minZ - playerPosition.getZ(), playerPosition.getZ() - maxZ), 0); + double diffX = Math.max(Math.max(minX - playerPosition.getX(), playerPosition.getX() - maxX), 0); + double diffY = Math.max(Math.max(minY - playerPosition.getY(), playerPosition.getY() - maxY), 0); + double diffZ = Math.max(Math.max(minZ - playerPosition.getZ(), playerPosition.getZ() - maxZ), 0); return ((diffX * diffX) + (diffY * diffY) + (diffZ * diffZ)) < (additionalRangeCheck * additionalRangeCheck); } From 199737d1efbce71be528153cf69aae19af845503 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Tue, 16 Dec 2025 23:00:59 +0100 Subject: [PATCH 33/62] Expose entity hitboxes in API, store bedrock position to avoid re-calculation --- .../entity/data/GeyserEntityDataTypes.java | 8 ++ .../entity/data/GeyserListEntityDataType.java | 48 ++++++++ .../geyser/api/entity/data/types/Hitbox.java | 71 +++++++++++ .../geysermc/geyser/entity/type/Entity.java | 15 ++- .../geyser/entity/type/FireballEntity.java | 4 +- .../geyser/entity/type/FishingHookEntity.java | 6 +- .../geyser/entity/type/InteractionEntity.java | 6 +- .../geyser/entity/type/ItemEntity.java | 6 +- .../geyser/entity/type/ItemFrameEntity.java | 2 +- .../geyser/entity/type/LeashKnotEntity.java | 2 +- .../geyser/entity/type/MinecartEntity.java | 2 +- .../geyser/entity/type/PaintingEntity.java | 4 +- .../geyser/entity/type/TextDisplayEntity.java | 2 +- .../geyser/entity/type/ThrowableEntity.java | 16 +-- .../entity/type/living/ArmorStandEntity.java | 16 +-- .../entity/type/living/SquidEntity.java | 2 +- .../type/living/animal/OcelotEntity.java | 4 +- .../type/living/animal/SnifferEntity.java | 2 +- .../type/living/merchant/VillagerEntity.java | 4 +- .../living/monster/EnderDragonEntity.java | 8 +- .../entity/type/player/AvatarEntity.java | 12 +- .../entity/type/player/PlayerEntity.java | 2 +- .../type/player/SessionPlayerEntity.java | 15 ++- .../entity/vehicle/BoatVehicleComponent.java | 20 +-- .../entity/vehicle/VehicleComponent.java | 16 +-- .../impl/entity/GeyserEntityDataImpl.java | 2 +- .../impl/entity/GeyserListEntityDataImpl.java | 82 +++++++++++++ .../geyser/impl/entity/HitboxImpl.java | 116 ++++++++++++++++++ .../loader/ProviderRegistryLoader.java | 7 ++ .../org/geysermc/geyser/util/EntityUtils.java | 1 - 30 files changed, 416 insertions(+), 85 deletions(-) create mode 100644 api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserListEntityDataType.java create mode 100644 api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java create mode 100644 core/src/main/java/org/geysermc/geyser/impl/entity/GeyserListEntityDataImpl.java create mode 100644 core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java index ca280e1f119..d312bbda78b 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java @@ -1,5 +1,7 @@ package org.geysermc.geyser.api.entity.data; +import org.geysermc.geyser.api.entity.data.types.Hitbox; + /** * Contains commonly used {@link GeyserEntityDataType} constants for built-in entity * metadata fields. @@ -48,6 +50,12 @@ public final class GeyserEntityDataTypes { public static final GeyserEntityDataType SCALE = GeyserEntityDataType.of(Float.class, "scale"); + /** + * Represents custom hitboxes for entities + */ + public static final GeyserListEntityDataType HITBOXES = + GeyserListEntityDataType.of(Hitbox.class, "hitboxes"); + private GeyserEntityDataTypes() { // no-op } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserListEntityDataType.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserListEntityDataType.java new file mode 100644 index 00000000000..655a8776059 --- /dev/null +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserListEntityDataType.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.api.entity.data; + +import org.geysermc.geyser.api.GeyserApi; + +import java.util.List; + +/** + * Represents a list of objects for an entity data types + * For example, there can be multiple hitboxes on an entity + * + * @param + */ +public interface GeyserListEntityDataType extends GeyserEntityDataType> { + + Class listTypeClass(); + + /** + * API usage only, use the types defined in {@link GeyserEntityDataTypes} + */ + static GeyserListEntityDataType of(Class typeClass, String name) { + return GeyserApi.api().provider(GeyserListEntityDataType.class, List.class, typeClass, name); + } +} diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java new file mode 100644 index 00000000000..46d284512f8 --- /dev/null +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.api.entity.data.types; + +import org.cloudburstmc.math.vector.Vector3f; +import org.geysermc.geyser.api.GeyserApi; + +/** + * Represents an entity hitbox. + */ +public interface Hitbox { + + /** + * The min "corner" of the hitbox + * @return the vector of the corner + */ + Vector3f min(); + + /** + * The max "corner" of the hitbox + * @return the vector of the corner + */ + Vector3f max(); + + /** + * The pivot of the hitbox + * @return + */ + Vector3f pivot(); + + static Builder builder() { + return GeyserApi.api().provider(Builder.class); + } + + /** + * The builder for the hitbox + */ + interface Builder { + + Builder min(Vector3f min); + + Builder max(Vector3f max); + + Builder origin(Vector3f pivot); + + Hitbox build(); + } +} diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index 0dcc81034e3..2079e093851 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -113,7 +113,9 @@ public class Entity implements GeyserEntity { * The entity position as it is known to the Java server */ @Accessors(fluent = true) - protected Vector3f position; + private Vector3f position; + @Setter(AccessLevel.NONE) + private Vector3f bedrockPosition; protected Vector3f motion; /** @@ -708,8 +710,13 @@ public boolean isAlive() { return this.valid; } + public void position(Vector3f position) { + this.position = position; + this.bedrockPosition = position.up(offset); + } + public Vector3f bedrockPosition() { - return position.up(offset); + return bedrockPosition; } /** @@ -860,10 +867,10 @@ public void update(@NonNull GeyserEntityProperty property, @Nullable T va } } - public void offset(float offset) { + public void offset(float offset, boolean teleport) { this.offset = offset; // TODO queue? - if (isValid()) { + if (isValid() && teleport) { this.moveRelative(0, 0, 0, 0, 0, isOnGround()); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java index 9155ab948ad..1cec6961352 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java @@ -64,7 +64,7 @@ protected void moveAbsoluteImmediate(Vector3f javaPosition, float yaw, float pit newPosition = tickMovement(newPosition); } super.moveAbsoluteImmediate(newPosition, yaw, pitch, headYaw, isOnGround, teleported); - this.position = javaPosition; + position(javaPosition); this.motion = lastMotion; } @@ -73,6 +73,6 @@ public void tick() { if (removedInVoid()) { return; } - moveAbsoluteImmediate(tickMovement(position), getYaw(), getPitch(), getHeadYaw(), false, false); + moveAbsoluteImmediate(tickMovement(position()), getYaw(), getPitch(), getHeadYaw(), false, false); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java index 06ecfaa17c1..a86b1231b9b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java @@ -113,7 +113,7 @@ protected void moveAbsoluteImmediate(Vector3f javaPosition, float yaw, float pit if (!collided) { super.moveAbsoluteImmediate(javaPosition, yaw, pitch, headYaw, isOnGround, teleported); } else { - super.moveAbsoluteImmediate(this.position, yaw, pitch, headYaw, true, true); + super.moveAbsoluteImmediate(this.position(), yaw, pitch, headYaw, true, true); } } @@ -144,7 +144,7 @@ public void tick() { float gravity = getGravity(); motion = motion.down(gravity); - moveAbsoluteImmediate(position.add(motion), getYaw(), getPitch(), getHeadYaw(), isOnGround(), false); + moveAbsoluteImmediate(position().add(motion), getYaw(), getPitch(), getHeadYaw(), isOnGround(), false); float drag = getDrag(); motion = motion.mul(drag); @@ -162,7 +162,7 @@ protected float getGravity() { * @return true if this entity is currently in air. */ protected boolean isInAir() { - int block = session.getGeyser().getWorldManager().getBlockAt(session, position.toInt()); + int block = session.getGeyser().getWorldManager().getBlockAt(session, position().toInt()); return block == Block.JAVA_AIR_ID; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java index 80d6e6eb7f3..09359fb09e0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java @@ -119,7 +119,7 @@ public void setDisplayName(EntityMetadata, ?> entityMetadata @Override public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, float headYaw, boolean isOnGround) { - moveAbsolute(position.add(relX, relY, relZ), yaw, pitch, headYaw, isOnGround, false); + moveAbsolute(position().add(relX, relY, relZ), yaw, pitch, headYaw, isOnGround, false); } @Override @@ -141,7 +141,7 @@ public void setHeight(FloatEntityMetadata height) { setBoundingBoxHeight(Math.min(height.getPrimitiveValue(), 64f)); if (secondEntity != null) { - secondEntity.moveAbsolute(position.up(getBoundingBoxHeight()), yaw, pitch, onGround, true); + secondEntity.moveAbsolute(position().up(getBoundingBoxHeight()), yaw, pitch, onGround, true); } } @@ -159,7 +159,7 @@ public void updateNameTag() { } if (this.secondEntity == null) { - secondEntity = new ArmorStandEntity(EntitySpawnContext.inherited(session, VanillaEntities.ARMOR_STAND, this, position.up(getBoundingBoxHeight()))); + secondEntity = new ArmorStandEntity(EntitySpawnContext.inherited(session, VanillaEntities.ARMOR_STAND, this, position().up(getBoundingBoxHeight()))); } secondEntity.getDirtyMetadata().put(EntityDataTypes.NAME, nametag); secondEntity.getDirtyMetadata().put(EntityDataTypes.NAMETAG_ALWAYS_SHOW, isNameTagVisible ? (byte) 1 : (byte) 0); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java index 5311c470316..30a4400e106 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java @@ -79,7 +79,7 @@ public void tick() { if (!isOnGround() || (motion.getX() * motion.getX() + motion.getZ() * motion.getZ()) > 0.00001) { float gravity = getGravity(); motion = motion.down(gravity); - moveAbsoluteImmediate(position.add(motion), getYaw(), getPitch(), getHeadYaw(), isOnGround(), false); + moveAbsoluteImmediate(position().add(motion), getYaw(), getPitch(), getHeadYaw(), isOnGround(), false); float drag = getDrag(); motion = motion.mul(drag, 0.98f, drag); } @@ -118,7 +118,7 @@ protected void moveAbsoluteImmediate(Vector3f javaPosition, float yaw, float pit this.offset = Math.abs(offset); } super.moveAbsoluteImmediate(javaPosition, 0, 0, 0, isOnGround, teleported); - this.position = javaPosition; + position(javaPosition); waterLevel = session.getGeyser().getWorldManager().getBlockAtAsync(session, javaPosition.getFloorX(), javaPosition.getFloorY(), javaPosition.getFloorZ()) .thenApply(BlockStateValues::getWaterLevel); @@ -137,7 +137,7 @@ protected float getGravity() { @Override protected float getDrag() { if (isOnGround()) { - Vector3i groundBlockPos = position.toInt().down(); + Vector3i groundBlockPos = position().toInt().down(); BlockState blockState = session.getGeyser().getWorldManager().blockAt(session, groundBlockPos); return BlockStateValues.getSlipperiness(blockState) * 0.98f; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java index 3093af41d8d..2bdd65b0d4b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ItemFrameEntity.java @@ -80,7 +80,7 @@ public ItemFrameEntity(EntitySpawnContext context) { super(context); blockDefinition = buildBlockDefinition(Direction.SOUTH); // Default to SOUTH direction, like on Java - entity metadata should correct this when necessary - bedrockPosition = Vector3i.from(position.getFloorX(), position.getFloorY(), position.getFloorZ()); + bedrockPosition = position().floor().toInt(); session.getItemFrameCache().put(bedrockPosition, this); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java index ef8210717f7..66f212f169f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LeashKnotEntity.java @@ -35,7 +35,7 @@ public LeashKnotEntity(EntitySpawnContext context) { super(context); // Position is incorrect by default // TODO offset - position(position.add(0.5f, 0.25f, 0.5f)); + position(position().add(0.5f, 0.25f, 0.5f)); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java index e5f7709dba6..3b1611061aa 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java @@ -194,7 +194,7 @@ private PartialStep getCurrentLerpStep(float delta) { } private void updateCompletedStep() { - lastCompletedStep = new MinecartStep(position.toDouble(), motion.toDouble(), yaw, pitch, 0.0F); + lastCompletedStep = new MinecartStep(position().toDouble(), motion.toDouble(), yaw, pitch, 0.0F); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java index f3e9e5fd744..15c3bf7fc64 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java @@ -92,7 +92,7 @@ private void updatePainting() { valid = true; - session.getGeyser().getLogger().debug("Spawned painting on " + position); + session.getGeyser().getLogger().debug("Spawned painting on " + position()); } @Override @@ -101,7 +101,7 @@ public void updateHeadLookRotation(float headYaw) { } private Vector3f fixOffset(PaintingType paintingName) { - Vector3f position = super.position; + Vector3f position = position(); // ViaVersion already adds the offset for us on older versions, // so no need to do it then otherwise it will be spaced if (session.isEmulatePost1_18Logic()) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java index 1f36736d7ed..899d80cf7b7 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java @@ -90,7 +90,7 @@ public void setText(EntityMetadata entityMetadata) { // If the line count changed, update the position to account for the new offset if (previousLineCount != lineCount) { - moveAbsolute(position, yaw, pitch, headYaw, onGround, false); + moveAbsolute(position(), yaw, pitch, headYaw, onGround, false); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java index 28358ca44b1..2b31a6d3124 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java @@ -43,7 +43,7 @@ public class ThrowableEntity extends Entity implements Tickable { public ThrowableEntity(EntitySpawnContext context) { super(context); - this.lastJavaPosition = position; + this.lastJavaPosition = position(); } /** @@ -55,7 +55,7 @@ public void tick() { if (removedInVoid()) { return; } - moveAbsoluteImmediate(position.add(motion), getYaw(), getPitch(), getHeadYaw(), isOnGround(), false); + moveAbsoluteImmediate(position().add(motion), getYaw(), getPitch(), getHeadYaw(), isOnGround(), false); float drag = getDrag(); float gravity = getGravity(); motion = motion.mul(drag).down(gravity); @@ -75,15 +75,15 @@ protected void moveAbsoluteImmediate(Vector3f javaPosition, float yaw, float pit moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.TELEPORTING); } - if (this.position.getX() != javaPosition.getX()) { + if (this.position().getX() != javaPosition.getX()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_X); moveEntityDeltaPacket.setX(javaPosition.getX()); } - if (this.position.getY() != javaPosition.getY()) { + if (this.position().getY() != javaPosition.getY()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Y); moveEntityDeltaPacket.setY(javaPosition.getY() + offset); } - if (this.position.getZ() != javaPosition.getZ()) { + if (this.position().getZ() != javaPosition.getZ()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Z); moveEntityDeltaPacket.setZ(javaPosition.getZ()); } @@ -155,7 +155,7 @@ protected float getDrag() { * @return true if this entity is currently in water. */ protected boolean isInWater() { - int block = session.getGeyser().getWorldManager().getBlockAt(session, position.toInt()); + int block = session.getGeyser().getWorldManager().getBlockAt(session, position().toInt()); return BlockStateValues.getWaterLevel(block) != -1; } @@ -173,7 +173,7 @@ public void despawnEntity() { @Override public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, float headYaw, boolean isOnGround) { moveAbsoluteImmediate(lastJavaPosition.add(relX, relY, relZ), yaw, pitch, headYaw, isOnGround, false); - lastJavaPosition = position; + lastJavaPosition = position(); } @Override @@ -188,7 +188,7 @@ public void moveAbsolute(Vector3f javaPosition, float yaw, float pitch, float he * @return true if the entity was removed */ public boolean removedInVoid() { - if (position.getY() < session.getDimensionType().minY() - 64) { + if (position().getY() < session.getDimensionType().minY() - 64) { session.getEntityCache().removeEntity(this); return true; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java index 9857eebd5c4..c8d598d40e8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java @@ -92,11 +92,9 @@ public ArmorStandEntity(EntitySpawnContext context) { @Override public void spawnEntity() { - Vector3f javaPosition = position; // Apply the offset if we're the second entity - position = position.up(getYOffset()); + offset(getYOffset(), false); super.spawnEntity(); - position = javaPosition; } @Override @@ -109,7 +107,7 @@ public void despawnEntity() { @Override public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, float headYaw, boolean isOnGround) { - moveAbsolute(position.add(relX, relY, relZ), yaw, pitch, headYaw, onGround, false); + moveAbsolute(position().add(relX, relY, relZ), yaw, pitch, headYaw, onGround, false); } @Override @@ -118,9 +116,8 @@ public void moveAbsolute(Vector3f javaPosition, float yaw, float pitch, float he secondEntity.moveAbsolute(javaPosition, yaw, pitch, headYaw, isOnGround, teleported); } // Fake the height to be above where it is so the nametag appears in the right location - float yOffset = getYOffset(); - super.moveAbsolute(yOffset != 0 ? javaPosition.up(yOffset) : javaPosition, yaw, yaw, yaw, isOnGround, teleported); - this.position = javaPosition; + offset(getYOffset(), false); + super.moveAbsolute(javaPosition, yaw, yaw, yaw, isOnGround, teleported); } @Override @@ -240,7 +237,7 @@ public void updateBedrockMetadata() { super.updateBedrockMetadata(); if (positionUpdateRequired) { positionUpdateRequired = false; - moveAbsolute(position, yaw, pitch, headYaw, onGround, true); + moveAbsolute(position(), yaw, pitch, headYaw, onGround, true); } } @@ -341,8 +338,7 @@ private void updateSecondEntityStatus(boolean sendMetadata) { if (secondEntity == null) { // Create the second entity. It doesn't need to worry about the items, but it does need to worry about // the metadata as it will hold the name tag. - // TODO - secondEntity = new ArmorStandEntity(EntitySpawnContext.inherited(session, VanillaEntities.ARMOR_STAND, this, position)); + secondEntity = new ArmorStandEntity(EntitySpawnContext.inherited(session, VanillaEntities.ARMOR_STAND, this, position())); secondEntity.primaryEntity = false; } // Copy metadata diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java index 2f55233c97d..8ce1ce2dc08 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java @@ -128,7 +128,7 @@ private void checkInWater() { if (getFlag(EntityFlag.RIDING)) { inWater = CompletableFuture.completedFuture(false); } else { - inWater = session.getGeyser().getWorldManager().getBlockAtAsync(session, position.toInt()) + inWater = session.getGeyser().getWorldManager().getBlockAtAsync(session, position().toInt()) .thenApply(block -> BlockStateValues.getWaterLevel(block) != -1); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java index f43717f4cda..62db9465817 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java @@ -52,7 +52,7 @@ protected Tag getFoodTag() { @NonNull @Override protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { - if (!getFlag(EntityFlag.TRUSTING) && canEat(itemInHand) && session.getPlayerEntity().position().distanceSquared(position) < 9f) { + if (!getFlag(EntityFlag.TRUSTING) && canEat(itemInHand) && session.getPlayerEntity().position().distanceSquared(position()) < 9f) { // Attempt to feed return InteractiveTag.FEED; } else { @@ -63,7 +63,7 @@ protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserI @NonNull @Override protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { - if (!getFlag(EntityFlag.TRUSTING) && canEat(itemInHand) && session.getPlayerEntity().position().distanceSquared(position) < 9f) { + if (!getFlag(EntityFlag.TRUSTING) && canEat(itemInHand) && session.getPlayerEntity().position().distanceSquared(position()) < 9f) { // Attempt to feed return InteractionResult.SUCCESS; } else { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java index 7cb4749b6d7..9feb713091b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java @@ -102,7 +102,7 @@ public void tick() { // The java client renders digging particles on its own, but bedrock does not if (digTicks > 0 && --digTicks < DIG_START && digTicks % 5 == 0) { Vector3f rot = Vector3f.createDirectionDeg(0, -getYaw()).mul(2.25f); - Vector3f pos = position.add(rot).up(0.2f).floor(); // Handle non-full blocks + Vector3f pos = position().add(rot).up(0.2f).floor(); // Handle non-full blocks int blockId = session.getBlockMappings().getBedrockBlockId(session.getGeyser().getWorldManager().getBlockAt(session, pos.toInt().down())); LevelEventPacket levelEventPacket = new LevelEventPacket(); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java index e61e9fa3597..e9f6a43c85e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java @@ -149,12 +149,12 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float setPitch(pitch); setHeadYaw(headYaw); setOnGround(isOnGround); - this.position = Vector3f.from(position.getX() + relX, position.getY() + relY, position.getZ() + relZ); + position(Vector3f.from(position().getX() + relX, position().getY() + relY, position().getZ() + relZ)); MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket(); moveEntityPacket.setRuntimeEntityId(geyserId); moveEntityPacket.setRotation(Vector3f.from(0, 0, bedRotation)); - moveEntityPacket.setPosition(Vector3f.from(position.getX() + xOffset, position.getY() + offset, position.getZ() + zOffset)); + moveEntityPacket.setPosition(position().add(xOffset, offset, zOffset)); moveEntityPacket.setOnGround(isOnGround); moveEntityPacket.setTeleported(false); session.sendUpstreamPacket(moveEntityPacket); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java index b2a4b36dbb1..62d44575e84 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java @@ -134,7 +134,7 @@ public void spawnEntity() { for (int i = 0; i < segmentHistory.length; i++) { segmentHistory[i] = new Segment(); segmentHistory[i].yaw = getHeadYaw(); - segmentHistory[i].y = position.getY(); + segmentHistory[i].y = position().getY(); } } @@ -206,7 +206,7 @@ private void updateBoundingBoxes() { } // Send updated positions for (EnderDragonPartEntity part : allParts) { - part.moveAbsolute(part.position().add(position), 0, 0, 0, false, false); + part.moveAbsolute(part.position().add(position()), 0, 0, 0, false, false); } } @@ -277,7 +277,7 @@ private void effectTick() { float xOffset = 8f * (random.nextFloat() - 0.5f); float yOffset = 4f * (random.nextFloat() - 0.5f) + 2f; float zOffset = 8f * (random.nextFloat() - 0.5f); - Vector3f particlePos = position.add(xOffset, yOffset, zOffset); + Vector3f particlePos = position().add(xOffset, yOffset, zOffset); LevelEventPacket particlePacket = new LevelEventPacket(); particlePacket.setType(ParticleType.EXPLODE); particlePacket.setPosition(particlePos); @@ -311,7 +311,7 @@ private boolean isSitting() { private void pushSegment() { latestSegment = (latestSegment + 1) % segmentHistory.length; segmentHistory[latestSegment].yaw = getHeadYaw(); - segmentHistory[latestSegment].y = position.getY(); + segmentHistory[latestSegment].y = position().getY(); } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java index e16c5f4a4cc..4da65c898a7 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java @@ -41,7 +41,6 @@ import org.cloudburstmc.protocol.bedrock.packet.AddPlayerPacket; import org.cloudburstmc.protocol.bedrock.packet.MovePlayerPacket; import org.geysermc.geyser.entity.spawn.EntitySpawnContext; -import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.type.LivingEntity; import org.geysermc.geyser.level.block.Blocks; import org.geysermc.geyser.skin.SkinManager; @@ -162,7 +161,7 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float setYaw(yaw); setPitch(pitch); setHeadYaw(headYaw); - this.position = Vector3f.from(position.getX() + relX, position.getY() + relY, position.getZ() + relZ); + position(Vector3f.from(position().getX() + relX, position().getY() + relY, position().getZ() + relZ)); setOnGround(isOnGround); @@ -175,9 +174,9 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float // If the player is moved while sleeping, we have to adjust their y, so it appears // correctly on Bedrock. This fixes GSit's lay. if (getFlag(EntityFlag.SLEEPING)) { - if (bedPosition != null && (bedPosition.getY() == 0 || bedPosition.distanceSquared(position.toInt()) > 4)) { + if (bedPosition != null && (bedPosition.getY() == 0 || bedPosition.distanceSquared(position().toInt()) > 4)) { // Force the player movement by using a teleport - movePlayerPacket.setPosition(Vector3f.from(position.getX(), position.getY() - offset + 0.2f, position.getZ())); + movePlayerPacket.setPosition(Vector3f.from(position().getX(), position().getY() - offset + 0.2f, position().getZ())); movePlayerPacket.setMode(MovePlayerPacket.Mode.TELEPORT); } } @@ -190,7 +189,7 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float } @Override - public Entity position(Vector3f position) { + public void position(Vector3f position) { if (this.bedPosition != null) { // As of Bedrock 1.21.22 and Fabric 1.21.1 // Messes with Bedrock if we send this to the client itself, though. @@ -198,7 +197,6 @@ public Entity position(Vector3f position) { } else { super.position(position); } - return this; } @Override @@ -316,7 +314,7 @@ public void setPose(Pose pose) { if (pose == Pose.SWIMMING) { // This is just for, so we know if player is swimming or crawling. - if (session.getGeyser().getWorldManager().blockAt(session, position.toInt()).is(Blocks.WATER)) { + if (session.getGeyser().getWorldManager().blockAt(session, position().toInt()).is(Blocks.WATER)) { setFlag(EntityFlag.SWIMMING, true); } else { setFlag(EntityFlag.CRAWLING, true); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java index 2ec0c0a4a25..95c798d1c38 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java @@ -161,7 +161,7 @@ protected void setParrot(OptionalInt variant, boolean isLeft) { return; } // The parrot is a separate entity in Bedrock, but part of the player entity in Java - EntitySpawnContext context = EntitySpawnContext.inherited(session, VanillaEntities.PARROT, this, position); + EntitySpawnContext context = EntitySpawnContext.inherited(session, VanillaEntities.PARROT, this, position()); if (context.callParrotEvent(this, variant.getAsInt(), !isLeft)) { GeyserImpl.getInstance().getLogger().debug(session, "Cancelled parrot spawn as definition is null!"); return; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java index 44f552dabb9..949dd3240a5 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java @@ -163,11 +163,11 @@ public void setYaw(float yaw) { @Override public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, float headYaw, boolean isOnGround) { super.moveRelative(relX, relY, relZ, yaw, pitch, headYaw, isOnGround); - session.getCollisionManager().updatePlayerBoundingBox(this.position); + session.getCollisionManager().updatePlayerBoundingBox(position()); } @Override - public Entity position(Vector3f position) { + public void position(Vector3f position) { if (valid) { // Don't update during session init session.getCollisionManager().updatePlayerBoundingBox(position); @@ -175,8 +175,7 @@ public Entity position(Vector3f position) { session.setNoClip(false); } } - this.position = position; - return this; + super.position(position); } /** @@ -212,10 +211,10 @@ public void updateOwnRotation(float yaw, float pitch, float headYaw) { * Set the player's position from a position sent in a Bedrock packet */ public void setPositionFromBedrock(Vector3f position) { - this.position = position.down(offset); + position(position.down(offset)); // Player is "above" the void so they're not supposed to no clip. - if (session.isNoClip() && this.position.getY() >= session.getBedrockDimension().minY() - 5) { + if (session.isNoClip() && position().getY() >= session.getBedrockDimension().minY() - 5) { session.setNoClip(false); } } @@ -497,7 +496,7 @@ public boolean isOnClimbableBlock() { if (session.getGameMode() == GameMode.SPECTATOR) { return false; } - BlockState state = session.getGeyser().getWorldManager().blockAt(session, position.toInt()); + BlockState state = session.getGeyser().getWorldManager().blockAt(session, position().toInt()); if (state.block().is(session, BlockTag.CLIMBABLE)) { return true; } @@ -506,7 +505,7 @@ public boolean isOnClimbableBlock() { if (!state.getValue(Properties.OPEN)) { return false; } else { - BlockState belowState = session.getGeyser().getWorldManager().blockAt(session, position.toInt().down()); + BlockState belowState = session.getGeyser().getWorldManager().blockAt(session, position().toInt().down()); return belowState.is(Blocks.LADDER) && belowState.getValue(Properties.HORIZONTAL_FACING) == state.getValue(Properties.HORIZONTAL_FACING); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/vehicle/BoatVehicleComponent.java b/core/src/main/java/org/geysermc/geyser/entity/vehicle/BoatVehicleComponent.java index 5bee4196e47..8bbb9e36f5f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/vehicle/BoatVehicleComponent.java +++ b/core/src/main/java/org/geysermc/geyser/entity/vehicle/BoatVehicleComponent.java @@ -138,28 +138,28 @@ public void tickVehicle() { @Override protected void moveVehicle(Vector3d javaPos, Vector3f lastRotation) { - Vector3f bedrockPos = javaPos.toFloat(); + Vector3f oldPosition = vehicle.position(); + vehicle.position(javaPos.toFloat()); MoveEntityDeltaPacket moveEntityDeltaPacket = new MoveEntityDeltaPacket(); - moveEntityDeltaPacket.setRuntimeEntityId(vehicle.getGeyserId()); + moveEntityDeltaPacket.setRuntimeEntityId(vehicle.geyserId()); if (vehicle.isOnGround()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.ON_GROUND); } - if (vehicle.getPosition().getX() != bedrockPos.getX()) { + if (vehicle.position().getX() != oldPosition.getX()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_X); - moveEntityDeltaPacket.setX(bedrockPos.getX()); + moveEntityDeltaPacket.setX(vehicle.bedrockPosition().getX()); } - if (vehicle.getPosition().getY() != bedrockPos.getY()) { + if (vehicle.position().getY() != oldPosition.getY()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Y); - moveEntityDeltaPacket.setY(bedrockPos.getY() + vehicle.getDefinition().offset()); + moveEntityDeltaPacket.setY(vehicle.bedrockPosition().getY()); } - if (vehicle.getPosition().getZ() != bedrockPos.getZ()) { + if (vehicle.position().getZ() != oldPosition.getZ()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Z); - moveEntityDeltaPacket.setZ(bedrockPos.getZ()); + moveEntityDeltaPacket.setZ(vehicle.bedrockPosition().getZ()); } - vehicle.setPosition(bedrockPos); if (vehicle.getPitch() != lastRotation.getX()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_PITCH); @@ -175,7 +175,7 @@ protected void moveVehicle(Vector3d javaPos, Vector3f lastRotation) { } if (!moveEntityDeltaPacket.getFlags().isEmpty()) { - vehicle.getSession().sendUpstreamPacket(moveEntityDeltaPacket); + vehicle.getSession().sendUpstreamPacketImmediately(moveEntityDeltaPacket); } ServerboundMoveVehiclePacket moveVehiclePacket = new ServerboundMoveVehiclePacket(javaPos, vehicle.getYaw() - 90, vehicle.getPitch(), vehicle.isOnGround()); diff --git a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java index 7f1edfe83f4..02c93b5b6a5 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java +++ b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java @@ -738,7 +738,8 @@ protected Vector2f getRiddenRotation() { * @param lastRotation the previous rotation of the vehicle (pitch, yaw, headYaw) */ protected void moveVehicle(Vector3d javaPos, Vector3f lastRotation) { - Vector3f bedrockPos = javaPos.toFloat(); + Vector3f oldPosition = vehicle.position(); + vehicle.position(javaPos.toFloat()); MoveEntityDeltaPacket moveEntityDeltaPacket = new MoveEntityDeltaPacket(); moveEntityDeltaPacket.setRuntimeEntityId(vehicle.geyserId()); @@ -747,19 +748,18 @@ protected void moveVehicle(Vector3d javaPos, Vector3f lastRotation) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.ON_GROUND); } - if (vehicle.position().getX() != bedrockPos.getX()) { + if (vehicle.position().getX() != oldPosition.getX()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_X); - moveEntityDeltaPacket.setX(bedrockPos.getX()); + moveEntityDeltaPacket.setX(vehicle.bedrockPosition().getX()); } - if (vehicle.position().getY() != bedrockPos.getY()) { + if (vehicle.position().getY() != oldPosition.getY()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Y); - moveEntityDeltaPacket.setY(bedrockPos.getY()); + moveEntityDeltaPacket.setY(vehicle.bedrockPosition().getY()); } - if (vehicle.position().getZ() != bedrockPos.getZ()) { + if (vehicle.position().getZ() != oldPosition.getZ()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Z); - moveEntityDeltaPacket.setZ(bedrockPos.getZ()); + moveEntityDeltaPacket.setZ(vehicle.bedrockPosition().getZ()); } - vehicle.position(bedrockPos); if (vehicle.getPitch() != lastRotation.getX()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_PITCH); diff --git a/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java b/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java index 5fec98b0a1a..a7c4ec075de 100644 --- a/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java +++ b/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java @@ -50,7 +50,7 @@ public class GeyserEntityDataImpl implements GeyserEntityDataType { TYPES.put("scale", new GeyserEntityDataImpl<>(Float.class, "scale", EntityDataTypes.SCALE)); // "custom" - TYPES.put("vertical_offset", new GeyserEntityDataImpl<>(Float.class, "offset", Entity::offset, Entity::getOffset)); + TYPES.put("vertical_offset", new GeyserEntityDataImpl<>(Float.class, "offset", (entity, value) -> entity.offset(value, true), Entity::getOffset)); } public static GeyserEntityDataImpl lookup(Class clazz, String name) { diff --git a/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserListEntityDataImpl.java b/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserListEntityDataImpl.java new file mode 100644 index 00000000000..bb11baf6416 --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserListEntityDataImpl.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.impl.entity; + +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import org.cloudburstmc.nbt.NbtMap; +import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; +import org.geysermc.geyser.api.entity.data.GeyserListEntityDataType; +import org.geysermc.geyser.api.entity.data.types.Hitbox; +import org.geysermc.geyser.entity.type.Entity; + +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.function.BiConsumer; +import java.util.function.Function; + +public class GeyserListEntityDataImpl extends GeyserEntityDataImpl> implements GeyserListEntityDataType { + + public static Map> TYPES; + static { + TYPES = new Object2ObjectOpenHashMap<>(); + TYPES.put("hitboxes", new GeyserListEntityDataImpl<>(Hitbox.class, "hitboxes", + (entity, hitboxes) -> entity.getDirtyMetadata().put(EntityDataTypes.HITBOX, HitboxImpl.toNbtMap(hitboxes)), + (entity -> HitboxImpl.fromMetaData((NbtMap) entity.getMetadata().get(EntityDataTypes.HITBOX))))); + } + + private final Class listTypeClass; + + public GeyserListEntityDataImpl(Class typeClass, String name, BiConsumer> consumer, Function> getter) { + //noinspection unchecked - we do not talk about it + super((Class>) (Class) List.class, name, consumer, getter); + this.listTypeClass = typeClass; + } + + @Override + public Class listTypeClass() { + return listTypeClass; + } + + public static GeyserListEntityDataImpl lookup(Class clazz, Class listTypeClass, String name) { + Objects.requireNonNull(clazz); + Objects.requireNonNull(listTypeClass); + Objects.requireNonNull(name); + + if (clazz != List.class) { + throw new IllegalStateException("Cannot look up list entity data for " + clazz + " and " + listTypeClass + " for " + name); + } + + var type = TYPES.get(name); + if (type == null) { + throw new IllegalArgumentException("Unknown entity data type: " + name); + } + if (type.listTypeClass() == listTypeClass) { + return TYPES.get(name); + } + throw new IllegalArgumentException("Unknown entity data type: " + name); + } +} diff --git a/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java b/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java new file mode 100644 index 00000000000..0e7fd7b8f0c --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.impl.entity; + +import org.checkerframework.checker.nullness.qual.Nullable; +import org.cloudburstmc.math.vector.Vector3f; +import org.cloudburstmc.nbt.NbtMap; +import org.cloudburstmc.nbt.NbtType; +import org.geysermc.geyser.api.entity.data.types.Hitbox; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public record HitboxImpl( + Vector3f min, + Vector3f max, + Vector3f pivot +) implements Hitbox { + + public static List fromMetaData(@Nullable NbtMap metaDataMap) { + if (metaDataMap == null) { + return List.of(); + } + + List boxes = new ArrayList<>(); + List hitboxes = metaDataMap.getList("Hitxboxes", NbtType.COMPOUND); + for (NbtMap hitbox : hitboxes) { + boxes.add(new HitboxImpl( + Vector3f.from(hitbox.getFloat("MinX"), hitbox.getFloat("MinY"), hitbox.getFloat("MinZ")), + Vector3f.from(hitbox.getFloat("MaxX"), hitbox.getFloat("MaxY"), hitbox.getFloat("MaxZ")), + Vector3f.from(hitbox.getFloat("PivotX"),hitbox.getFloat("PivotY"),hitbox.getFloat("PivotZ")) + )); + } + return boxes; + } + + public NbtMap toNbtMap() { + return NbtMap.builder() + .putFloat("MinX", min.getX()) + .putFloat("MinY", min.getY()) + .putFloat("MinZ", min.getZ()) + .putFloat("MaxX", max.getX()) + .putFloat("MaxY", max.getY()) + .putFloat("MaxZ", max.getZ()) + .putFloat("PivotX", pivot.getX()) + .putFloat("PivotY", pivot.getY()) + .putFloat("PivotZ", pivot.getZ()) + .build(); + } + + public static NbtMap toNbtMap(List hitboxes) { + List list = new ArrayList<>(); + for (Hitbox hitbox : hitboxes) { + if (hitbox instanceof HitboxImpl impl) { + list.add(impl.toNbtMap()); + } else { + throw new IllegalArgumentException("Unknown hitbox class implementation: " + hitbox.getClass().getSimpleName()); + } + } + return NbtMap.builder().putList("Hitboxes", NbtType.COMPOUND, list).build(); + } + + public static class Builder implements Hitbox.Builder { + Vector3f min, max, pivot; + + @Override + public Hitbox.Builder min(Vector3f min) { + Objects.requireNonNull(min, "min"); + this.min = min; + return this; + } + + @Override + public Hitbox.Builder max(Vector3f max) { + Objects.requireNonNull(max, "max"); + this.max = max; + return this; + } + + @Override + public Hitbox.Builder origin(Vector3f pivot) { + Objects.requireNonNull(pivot, "pivot"); + this.pivot = pivot; + return this; + } + + @Override + public Hitbox build() { + return new HitboxImpl(min == null ? Vector3f.ZERO : min, max == null ? Vector3f.ZERO : max, pivot == null ? Vector3f.ZERO : pivot); + } + } +} diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java index 67d4b873b5b..0d29e93396f 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java @@ -35,6 +35,8 @@ import org.geysermc.geyser.api.block.custom.nonvanilla.JavaBlockState; import org.geysermc.geyser.api.command.Command; import org.geysermc.geyser.api.entity.data.GeyserEntityDataType; +import org.geysermc.geyser.api.entity.data.GeyserListEntityDataType; +import org.geysermc.geyser.api.entity.data.types.Hitbox; import org.geysermc.geyser.api.entity.definition.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.definition.JavaEntityType; import org.geysermc.geyser.api.event.EventRegistrar; @@ -56,6 +58,8 @@ import org.geysermc.geyser.impl.camera.GeyserCameraFade; import org.geysermc.geyser.impl.camera.GeyserCameraPosition; import org.geysermc.geyser.impl.entity.GeyserEntityDataImpl; +import org.geysermc.geyser.impl.entity.GeyserListEntityDataImpl; +import org.geysermc.geyser.impl.entity.HitboxImpl; import org.geysermc.geyser.item.GeyserCustomItemData; import org.geysermc.geyser.item.GeyserCustomItemOptions; import org.geysermc.geyser.item.GeyserNonVanillaCustomItemData; @@ -119,6 +123,9 @@ public Map, ProviderSupplier> load(Map, ProviderSupplier> prov providers.put(GeyserEntityDefinition.class, args -> BedrockEntityDefinition.getOrCreate((Identifier) args[0])); providers.put(JavaEntityType.class, args -> GeyserEntityType.ofVanilla((Identifier) args[0])); providers.put(GeyserEntityDataType.class, args -> GeyserEntityDataImpl.lookup((Class) args[0], (String) args[1])); + providers.put(GeyserListEntityDataType.class, args -> GeyserListEntityDataImpl.lookup((Class) args[0], (Class) args[1], (String) args[2])); + + providers.put(Hitbox.Builder.class, args -> new HitboxImpl.Builder()); return providers; } diff --git a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java index 784c030f55e..aec57eb22f9 100644 --- a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java @@ -89,7 +89,6 @@ public final class EntityUtils { private static final AtomicInteger RUNTIME_ID_ALLOCATOR = new AtomicInteger(100000); - public static final float PLAYER_ENTITY_OFFSET = 1.62F; /** * A constant array of the two hands that a player can interact with an entity. From 2916f3f18f89c661b4a08e70cb076d26a6318da6 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Wed, 17 Dec 2025 14:58:12 +0100 Subject: [PATCH 34/62] Minor cleanup --- .../api/entity/data/GeyserEntityDataType.java | 7 +++-- .../entity/data/GeyserListEntityDataType.java | 14 +++++---- .../geyser/api/entity/data/types/Hitbox.java | 30 ++++++++++++++++--- .../impl/entity/GeyserEntityDataImpl.java | 5 ++-- .../impl/entity/GeyserListEntityDataImpl.java | 5 ++-- .../geyser/impl/entity/HitboxImpl.java | 2 +- 6 files changed, 46 insertions(+), 17 deletions(-) diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataType.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataType.java index 3484f217bf4..c1c2e79d125 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataType.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.api.entity.data; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.api.GeyserApi; import org.geysermc.geyser.api.entity.type.GeyserEntity; @@ -46,7 +47,7 @@ public interface GeyserEntityDataType { * * @return the class of the value used by this entity data type */ - Class typeClass(); + @NonNull Class typeClass(); /** * Gets the unique name of this data type. @@ -56,12 +57,12 @@ public interface GeyserEntityDataType { * * @return the name of this entity data type */ - String name(); + @NonNull String name(); /** * For API usage only; use the types defined in {@link GeyserEntityDataTypes} */ - static GeyserEntityDataType of(Class typeClass, String name) { + static GeyserEntityDataType of(@NonNull Class typeClass, @NonNull String name) { return GeyserApi.api().provider(GeyserEntityDataType.class, typeClass, name); } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserListEntityDataType.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserListEntityDataType.java index 655a8776059..3cb948f019b 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserListEntityDataType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserListEntityDataType.java @@ -25,24 +25,28 @@ package org.geysermc.geyser.api.entity.data; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.api.GeyserApi; import java.util.List; /** - * Represents a list of objects for an entity data types - * For example, there can be multiple hitboxes on an entity + * Represents a list of objects for specific entity data types. + * For example, there can be multiple hitboxes on an entity. * - * @param + * @param the object type in the list */ public interface GeyserListEntityDataType extends GeyserEntityDataType> { - Class listTypeClass(); + /** + * @return the class of the list entries + */ + @NonNull Class listEntryClass(); /** * API usage only, use the types defined in {@link GeyserEntityDataTypes} */ - static GeyserListEntityDataType of(Class typeClass, String name) { + static GeyserListEntityDataType of(@NonNull Class typeClass, @NonNull String name) { return GeyserApi.api().provider(GeyserListEntityDataType.class, List.class, typeClass, name); } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java index 46d284512f8..f7949eb9791 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.api.entity.data.types; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.api.GeyserApi; @@ -47,7 +48,7 @@ public interface Hitbox { /** * The pivot of the hitbox - * @return + * @return the pivot */ Vector3f pivot(); @@ -60,12 +61,33 @@ static Builder builder() { */ interface Builder { - Builder min(Vector3f min); + /** + * Sets the min corner of the hitbox + * @param min the vector of the corner + * @return this builder + */ + Builder min(@NonNull Vector3f min); - Builder max(Vector3f max); + /** + * Sets the max corner of the hitbox + * @param max the vector of the corner + * @return this builder + */ + Builder max(@NonNull Vector3f max); - Builder origin(Vector3f pivot); + /** + * Sets the pivot of the hitbox + * @param pivot the pivot vector + * @return this builder + */ + Builder pivot(@NonNull Vector3f pivot); + /** + * Builds this hitbox, defaulting to {@code Vector3f.ZERO} if + * any one vector was not provided. + * + * @return a new hitbox + */ Hitbox build(); } } diff --git a/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java b/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java index a7c4ec075de..e2e12e3fd27 100644 --- a/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java +++ b/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java @@ -27,6 +27,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import lombok.AllArgsConstructor; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; @@ -97,12 +98,12 @@ public GeyserEntityDataImpl(Class typeClass, String name, EntityFlag flag) { } @Override - public Class typeClass() { + public @NonNull Class typeClass() { return typeClass; } @Override - public String name() { + public @NonNull String name() { return name; } diff --git a/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserListEntityDataImpl.java b/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserListEntityDataImpl.java index bb11baf6416..0594a3aab31 100644 --- a/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserListEntityDataImpl.java +++ b/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserListEntityDataImpl.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.impl.entity; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.api.entity.data.GeyserListEntityDataType; @@ -57,7 +58,7 @@ public GeyserListEntityDataImpl(Class typeClass, String name, BiConsum } @Override - public Class listTypeClass() { + public @NonNull Class listEntryClass() { return listTypeClass; } @@ -74,7 +75,7 @@ public static GeyserListEntityDataImpl lookup(Class clazz, Class listTy if (type == null) { throw new IllegalArgumentException("Unknown entity data type: " + name); } - if (type.listTypeClass() == listTypeClass) { + if (type.listEntryClass() == listTypeClass) { return TYPES.get(name); } throw new IllegalArgumentException("Unknown entity data type: " + name); diff --git a/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java b/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java index 0e7fd7b8f0c..1bcf22973e1 100644 --- a/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java +++ b/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java @@ -102,7 +102,7 @@ public Hitbox.Builder max(Vector3f max) { } @Override - public Hitbox.Builder origin(Vector3f pivot) { + public Hitbox.Builder pivot(Vector3f pivot) { Objects.requireNonNull(pivot, "pivot"); this.pivot = pivot; return this; From adf406321a1f62bc0395622592ea4c756bf1297a Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Fri, 19 Dec 2025 21:30:57 +0100 Subject: [PATCH 35/62] Log unknown implementations of GeyserEntityDefinition --- .../geysermc/geyser/entity/spawn/EntitySpawnContext.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java index 618af0c8e2a..8b2b9140df6 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java +++ b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java @@ -161,10 +161,11 @@ public int entityId() { public void definition(@Nullable GeyserEntityDefinition entityDefinition) { if (entityDefinition == null) { bedrockEntityDefinition = null; + return; } if (!(entityDefinition instanceof BedrockEntityDefinition definition)) { - throw new IllegalStateException("Unknown implementation of GeyserEntityDefinition"); + throw new IllegalStateException("Unknown implementation of GeyserEntityDefinition! Got: " + entityDefinition.getClass().getSimpleName()); } if (!entityDefinition.registered()) { @@ -212,10 +213,11 @@ public boolean right() { public void definition(@Nullable GeyserEntityDefinition entityDefinition) { if (entityDefinition == null) { bedrockEntityDefinition = null; + return; } if (!(entityDefinition instanceof BedrockEntityDefinition definition)) { - throw new IllegalStateException("Unknown implementation of GeyserEntityDefinition"); + throw new IllegalStateException("Unknown implementation of GeyserEntityDefinition! Got: " + entityDefinition.getClass().getSimpleName()); } if (!entityDefinition.registered()) { From 927b72fd8583825cafedfae8b2bced64e3b037a2 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sun, 21 Dec 2025 14:49:02 +0100 Subject: [PATCH 36/62] Use position setter instead of directly setting entity position --- core/src/main/java/org/geysermc/geyser/entity/type/Entity.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index 2079e093851..365e0a4fb1c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -297,7 +297,8 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float clientVehicle.getVehicleComponent().moveRelative(relX, relY, relZ); } - position = Vector3f.from(position.getX() + relX, position.getY() + relY, position.getZ() + relZ); + // Use fluid setter to ensure bedrockPosition is updated + position(Vector3f.from(position.getX() + relX, position.getY() + relY, position.getZ() + relZ)); MoveEntityDeltaPacket moveEntityPacket = new MoveEntityDeltaPacket(); moveEntityPacket.setRuntimeEntityId(geyserId); From 9aefb366f2a0a46fcc753dd246767f4eccd4d787 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Tue, 23 Dec 2025 00:15:55 +0100 Subject: [PATCH 37/62] Fix client crashing related to sending & unlocking smithing recipes --- .../protocol/java/JavaRecipeBookAddTranslator.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaRecipeBookAddTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaRecipeBookAddTranslator.java index 332ef32db06..fbb8ebeb20d 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaRecipeBookAddTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaRecipeBookAddTranslator.java @@ -168,7 +168,6 @@ public void translate(GeyserSession session, ClientboundRecipeBookAddPacket pack } int i = 0; - List bedrockRecipeIds = new ArrayList<>(); for (ItemDescriptorWithCount template : templates) { for (ItemDescriptorWithCount base : bases) { for (ItemDescriptorWithCount addition : additions) { @@ -176,13 +175,9 @@ public void translate(GeyserSession session, ClientboundRecipeBookAddPacket pack // Note: vanilla inputs use aux value of Short.MAX_VALUE craftingDataPacket.getCraftingData().add(SmithingTransformRecipeData.of(id, template, base, addition, output.right(), "smithing_table", netId++)); - - recipesPacket.getUnlockedRecipes().add(id); - bedrockRecipeIds.add(id); } } } - javaToBedrockRecipeIds.put(contents.id(), bedrockRecipeIds); session.getSmithingRecipes().add(new GeyserSmithingRecipe(smithingRecipe)); } } From 7ef59986bd5ad845e68567c208a41ff77c9e42cc Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sat, 10 Jan 2026 21:30:48 +0100 Subject: [PATCH 38/62] Merge upstream --- .../geyser/entity/type/MinecartEntity.java | 2 +- .../geysermc/geyser/session/cache/FormCache.java | 14 ++------------ .../org/geysermc/geyser/util/PlayerListUtils.java | 2 +- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java index 35e8126fca6..13b7ad2821e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java @@ -220,7 +220,7 @@ protected InteractiveTag testInteraction(Hand hand) { if (javaTypeDefinition == VanillaEntities.CHEST_MINECART || javaTypeDefinition == VanillaEntities.HOPPER_MINECART) { return InteractiveTag.OPEN_CONTAINER; } else { - if (session.isSneaking() || definition == EntityDefinitions.TNT_MINECART) { + if (session.isSneaking() || javaTypeDefinition == VanillaEntities.TNT_MINECART) { return InteractiveTag.NONE; } else if (!passengers.isEmpty()) { // Can't enter if someone is inside diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/FormCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/FormCache.java index 82701e5339c..3ec3a5a5900 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/FormCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/FormCache.java @@ -31,28 +31,18 @@ import it.unimi.dsi.fastutil.ints.IntList; import lombok.RequiredArgsConstructor; import org.cloudburstmc.protocol.bedrock.data.AttributeData; -import org.cloudburstmc.protocol.bedrock.packet.ModalFormRequestPacket; -import org.cloudburstmc.protocol.bedrock.packet.ModalFormResponsePacket; -import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket; -import org.geysermc.cumulus.component.util.ComponentType; -import org.geysermc.cumulus.form.CustomForm; import org.cloudburstmc.protocol.bedrock.packet.ClientboundCloseFormPacket; import org.cloudburstmc.protocol.bedrock.packet.ModalFormRequestPacket; import org.cloudburstmc.protocol.bedrock.packet.ModalFormResponsePacket; -import org.cloudburstmc.protocol.bedrock.packet.NetworkStackLatencyPacket; +import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket; import org.geysermc.cumulus.form.Form; import org.geysermc.cumulus.form.SimpleForm; import org.geysermc.cumulus.form.impl.FormDefinitions; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.entity.attribute.GeyserAttributeType; -import org.geysermc.geyser.network.GameProtocol; import org.geysermc.geyser.session.GeyserSession; -import java.util.ArrayList; import java.util.Collections; -import java.util.List; -import org.geysermc.geyser.session.GeyserSession; - import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -112,7 +102,7 @@ private void sendForm(int formId, Form form) { session.scheduleInEventLoop(() -> { // Hack to fix the url image loading bug UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket(); - attributesPacket.setRuntimeEntityId(session.getPlayerEntity().getGeyserId()); + attributesPacket.setRuntimeEntityId(session.getPlayerEntity().geyserId()); AttributeData attribute = session.getPlayerEntity().getAttributes().get(GeyserAttributeType.EXPERIENCE_LEVEL); if (attribute != null) { diff --git a/core/src/main/java/org/geysermc/geyser/util/PlayerListUtils.java b/core/src/main/java/org/geysermc/geyser/util/PlayerListUtils.java index 76244332ea0..080900d7776 100644 --- a/core/src/main/java/org/geysermc/geyser/util/PlayerListUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/PlayerListUtils.java @@ -69,7 +69,7 @@ public static void batchSendPlayerList(GeyserSession session, List Date: Mon, 12 Jan 2026 01:04:43 +0100 Subject: [PATCH 39/62] Fix hitbox querying, fix offset handling for boats --- .../geyser/api/connection/GeyserConnection.java | 13 ------------- .../kotlin/geyser.publish-conventions.gradle.kts | 6 ------ .../geysermc/geyser/entity/GeyserEntityData.java | 10 +++++++++- .../org/geysermc/geyser/entity/type/BoatEntity.java | 3 ++- .../geysermc/geyser/entity/type/MinecartEntity.java | 1 - .../geyser/entity/type/player/AvatarEntity.java | 4 ++-- .../org/geysermc/geyser/impl/entity/HitboxImpl.java | 9 +++++---- .../org/geysermc/geyser/session/GeyserSession.java | 5 ----- 8 files changed, 18 insertions(+), 33 deletions(-) diff --git a/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java b/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java index 9e96709038a..fd3f95a9b55 100644 --- a/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java +++ b/api/src/main/java/org/geysermc/geyser/api/connection/GeyserConnection.java @@ -25,23 +25,19 @@ package org.geysermc.geyser.api.connection; -import org.checkerframework.checker.index.qual.NonNegative; import org.checkerframework.checker.index.qual.Positive; import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.api.connection.Connection; import org.geysermc.geyser.api.bedrock.camera.CameraData; import org.geysermc.geyser.api.bedrock.camera.CameraShake; import org.geysermc.geyser.api.command.CommandSource; import org.geysermc.geyser.api.entity.EntityData; -import org.geysermc.geyser.api.entity.type.GeyserEntity; import org.geysermc.geyser.api.entity.type.player.GeyserPlayerEntity; import org.geysermc.geyser.api.skin.SkinData; import java.util.NoSuchElementException; import java.util.Set; import java.util.UUID; -import java.util.concurrent.CompletableFuture; /** * Represents a player connection used in Geyser. @@ -166,15 +162,6 @@ public interface GeyserConnection extends Connection, CommandSource { */ void sendSkin(@NonNull UUID player, @NonNull SkinData skinData); - /** - * @param javaId the Java entity ID to look up. - * @return a {@link GeyserEntity} if present in this connection's entity tracker. - * @deprecated Use {@link EntityData#entityByJavaId(int)} instead - */ - @Deprecated - @NonNull - CompletableFuture<@Nullable GeyserEntity> entityByJavaId(@NonNegative int javaId); - /** * Displays a player entity as emoting to this client. * diff --git a/build-logic/src/main/kotlin/geyser.publish-conventions.gradle.kts b/build-logic/src/main/kotlin/geyser.publish-conventions.gradle.kts index 753b245319e..c3885fd13dd 100644 --- a/build-logic/src/main/kotlin/geyser.publish-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/geyser.publish-conventions.gradle.kts @@ -13,9 +13,3 @@ indra { publishSnapshotsTo("geysermc", "https://repo.opencollab.dev/maven-snapshots") publishReleasesTo("geysermc", "https://repo.opencollab.dev/maven-releases") } - -publishing { - // skip shadow jar from publishing. Workaround for https://github.com/johnrengelman/shadow/issues/651 - val javaComponent = project.components["java"] as AdhocComponentWithVariants - javaComponent.withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) { skip() } -} diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java index 06a3b311a57..7e4180dc005 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java @@ -29,11 +29,11 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.protocol.bedrock.packet.EmotePacket; -import org.geysermc.geyser.input.InputLocksFlag; import org.geysermc.geyser.api.entity.EntityData; import org.geysermc.geyser.api.entity.type.GeyserEntity; import org.geysermc.geyser.api.entity.type.player.GeyserPlayerEntity; import org.geysermc.geyser.entity.type.Entity; +import org.geysermc.geyser.input.InputLocksFlag; import org.geysermc.geyser.session.GeyserSession; import java.util.HashSet; @@ -60,6 +60,10 @@ public GeyserEntityData(GeyserSession session) { @Override public @Nullable GeyserEntity byJavaId(@NonNegative int javaId) { + //noinspection ConstantValue + if (javaId < 0) { + throw new IllegalArgumentException("entity id cannot be negative! (got: " + javaId + ")"); + } return session.getEntityCache().getEntityByJavaId(javaId); } @@ -71,6 +75,10 @@ public GeyserEntityData(GeyserSession session) { @Override public @Nullable GeyserEntity byGeyserId(@NonNegative long geyserId) { + //noinspection ConstantValue + if (geyserId < 0) { + throw new IllegalArgumentException("geyser entity id cannot be negative! (got: " + geyserId + ")"); + } return session.getEntityCache().getEntityByGeyserId(geyserId); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java index 8b1e17c868a..2fa7050506c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java @@ -98,6 +98,7 @@ protected void initializeMetadata() { @Override public void moveAbsoluteRaw(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { // We don't include the rotation (y) as it causes the boat to appear sideways + position(javaPosition); setYaw(yaw + 90); setHeadYaw(yaw + 90); setOnGround(isOnGround); @@ -123,7 +124,7 @@ public void moveAbsoluteRaw(Vector3f javaPosition, float yaw, float pitch, float */ // TODO offset public void moveAbsoluteWithoutAdjustments(Vector3f position, float yaw, boolean isOnGround, boolean teleported) { - super.moveAbsoluteRaw(position, yaw, 0, yaw, isOnGround, teleported); + moveAbsoluteRaw(position, yaw, 0, yaw, isOnGround, teleported); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java index 221cedd4a5d..15755a73d0a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java @@ -133,7 +133,6 @@ public void tick() { return; } - // TODO testme float time = 1.0f / this.steps; float lerpXTotal = GenericMath.lerp(position().getX(), this.lerpPosition.getX(), time); float lerpYTotal = GenericMath.lerp(position().getY(), this.lerpPosition.getY(), time); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java index 64ea699c031..636ba7b1bc4 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java @@ -144,10 +144,10 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float @Override public void moveAbsoluteRaw(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - position(javaPosition); setYaw(yaw); setPitch(pitch); setHeadYaw(headYaw); + position(javaPosition); setOnGround(isOnGround); @@ -189,7 +189,7 @@ public void moveRelativeRaw(double relX, double relY, double relZ, float yaw, fl if (getFlag(EntityFlag.SLEEPING)) { if (bedPosition != null && (bedPosition.getY() == 0 || bedPosition.distanceSquared(position().toInt()) > 4)) { // Force the player movement by using a teleport - movePlayerPacket.setPosition(Vector3f.from(position().getX(), position().getY() - offset + 0.2f, position().getZ())); + movePlayerPacket.setPosition(Vector3f.from(position().getX(), position().getY() + 0.2f, position().getZ())); movePlayerPacket.setMode(MovePlayerPacket.Mode.TELEPORT); } } diff --git a/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java b/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java index 1bcf22973e1..7b34bf3c3b2 100644 --- a/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java +++ b/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.impl.entity; +import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.nbt.NbtMap; @@ -47,7 +48,7 @@ public static List fromMetaData(@Nullable NbtMap metaDataMap) { } List boxes = new ArrayList<>(); - List hitboxes = metaDataMap.getList("Hitxboxes", NbtType.COMPOUND); + List hitboxes = metaDataMap.getList("Hitboxes", NbtType.COMPOUND); for (NbtMap hitbox : hitboxes) { boxes.add(new HitboxImpl( Vector3f.from(hitbox.getFloat("MinX"), hitbox.getFloat("MinY"), hitbox.getFloat("MinZ")), @@ -88,21 +89,21 @@ public static class Builder implements Hitbox.Builder { Vector3f min, max, pivot; @Override - public Hitbox.Builder min(Vector3f min) { + public Hitbox.Builder min(@NonNull Vector3f min) { Objects.requireNonNull(min, "min"); this.min = min; return this; } @Override - public Hitbox.Builder max(Vector3f max) { + public Hitbox.Builder max(@NonNull Vector3f max) { Objects.requireNonNull(max, "max"); this.max = max; return this; } @Override - public Hitbox.Builder pivot(Vector3f pivot) { + public Hitbox.Builder pivot(@NonNull Vector3f pivot) { Objects.requireNonNull(pivot, "pivot"); this.pivot = pivot; return this; diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index 32bd5b8ec7a..c9997d948a1 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -2344,11 +2344,6 @@ public boolean transfer(@NonNull String address, @IntRange(from = 0, to = 65535) return true; } - @Override - public @NonNull CompletableFuture<@Nullable GeyserEntity> entityByJavaId(@NonNegative int javaId) { - return entities().entityByJavaId(javaId); - } - @Override public void showEmote(@NonNull GeyserPlayerEntity emoter, @NonNull String emoteId) { entities().showEmote(emoter, emoteId); From a52405c7bd29d8a723457c63833aabffc5ff728e Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Mon, 12 Jan 2026 01:51:34 +0100 Subject: [PATCH 40/62] Fix entity lerping --- .../geysermc/geyser/entity/type/LivingEntity.java | 13 +++---------- .../geysermc/geyser/entity/type/MinecartEntity.java | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java index 02614c17ba9..ebd2818017d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java @@ -389,12 +389,6 @@ public InteractionResult interact(Hand hand) { return super.interact(hand); } - @Override - public void position(Vector3f position) { - super.position(position); - this.lerpPosition = position; - } - @Override public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, float headYaw, boolean isOnGround) { if (this instanceof ClientVehicle clientVehicle) { @@ -413,7 +407,7 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float setPitch(pitch); setHeadYaw(headYaw); - this.lerpPosition = Vector3f.from(lerpPosition.getX() + relX, lerpPosition.getY() + relY, lerpPosition.getZ() + relZ); + this.lerpPosition = Vector3f.from(position().getX() + relX, position().getY() + relY, position().getZ() + relZ); this.lerpSteps = 3; } else { super.moveRelative(relX, relY, relZ, yaw, pitch, headYaw, isOnGround); @@ -426,12 +420,11 @@ public void moveAbsolute(Vector3f javaPosition, float yaw, float pitch, float he setPitch(pitch); setHeadYaw(headYaw); - this.lerpPosition = javaPosition; - // It's vanilla behaviour to lerp if the position is within 64 blocks, however we also check if the position is close enough to the player // position to see if it can actually affect anything to save network. if (shouldLerp() && javaPosition.distanceSquared(position()) < 4096 && javaPosition.distanceSquared(session.getPlayerEntity().position()) < 4096) { this.dirtyPitch = this.dirtyYaw = this.dirtyHeadYaw = true; + this.lerpPosition = javaPosition; this.lerpSteps = 3; } else { super.moveAbsolute(javaPosition, yaw, pitch, headYaw, isOnGround, teleported); @@ -473,7 +466,7 @@ public void tick() { moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_PITCH); } moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.TELEPORTING); - position(Vector3f.from(lerpXTotal, lerpYTotal, lerpZTotal)); + super.position(Vector3f.from(lerpXTotal, lerpYTotal, lerpZTotal)); moveEntityPacket.setRuntimeEntityId(geyserId); moveEntityPacket.setX(bedrockPosition().getX()); moveEntityPacket.setY(bedrockPosition().getY()); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java index 15755a73d0a..971277b9441 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java @@ -161,7 +161,7 @@ public void tick() { moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_PITCH); } moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.TELEPORTING); - position(Vector3f.from(lerpXTotal, lerpYTotal, lerpZTotal)); + super.position(Vector3f.from(lerpXTotal, lerpYTotal, lerpZTotal)); moveEntityPacket.setRuntimeEntityId(geyserId); moveEntityPacket.setX(bedrockPosition().getX()); moveEntityPacket.setY(bedrockPosition().getY()); From c0cac81b695030e3d1fd28afbc58cbbdd6c0b0c5 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Mon, 26 Jan 2026 23:29:17 +0100 Subject: [PATCH 41/62] Remove bedrockPosition variable again, simpler to only store one source of truth --- .../geyser/entity/type/BoatEntity.java | 2 +- .../geysermc/geyser/entity/type/Entity.java | 26 +++++++++---------- .../geyser/entity/type/FireballEntity.java | 2 +- .../geyser/entity/type/ItemEntity.java | 2 +- .../geyser/entity/type/LivingEntity.java | 2 +- .../geyser/entity/type/MinecartEntity.java | 10 ++++--- .../geyser/entity/type/ThrowableEntity.java | 17 ++++++------ .../type/living/merchant/VillagerEntity.java | 2 +- .../living/monster/EnderDragonEntity.java | 12 ++++----- .../living/monster/EnderDragonPartEntity.java | 2 +- .../entity/type/player/AvatarEntity.java | 12 ++++----- .../type/player/SessionPlayerEntity.java | 6 ++--- .../entity/vehicle/BoatVehicleComponent.java | 2 +- .../entity/vehicle/VehicleComponent.java | 2 +- .../BedrockPlayerAuthInputTranslator.java | 2 +- .../java/entity/JavaAddEntityTranslator.java | 2 +- .../player/JavaPlayerPositionTranslator.java | 2 +- .../geysermc/geyser/util/DimensionUtils.java | 2 +- 18 files changed, 55 insertions(+), 52 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java index 2fa7050506c..6cfaad7d0a6 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java @@ -98,7 +98,7 @@ protected void initializeMetadata() { @Override public void moveAbsoluteRaw(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { // We don't include the rotation (y) as it causes the boat to appear sideways - position(javaPosition); + setPosition(javaPosition); setYaw(yaw + 90); setHeadYaw(yaw + 90); setOnGround(isOnGround); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index 0056c8ffbaf..bc92931f0bb 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -113,10 +113,8 @@ public class Entity implements GeyserEntity { /** * The entity position as it is known to the Java server */ - @Accessors(fluent = true) + @Setter private Vector3f position; - @Setter(AccessLevel.NONE) - private Vector3f bedrockPosition; protected Vector3f motion; /** @@ -203,7 +201,7 @@ public Entity(EntitySpawnContext context) { this.valid = false; this.propertyManager = bedrockDefinition.registeredProperties().isEmpty() ? null : new GeyserEntityPropertyManager(bedrockDefinition.registeredProperties()); - position(context.position()); + setPosition(context.position()); setAirSupply(getMaxAir()); initializeMetadata(); @@ -299,8 +297,7 @@ public void moveRelativeRaw(double relX, double relY, double relZ, float yaw, fl clientVehicle.getVehicleComponent().moveRelative(relX, relY, relZ); } - // Use fluid setter to ensure bedrockPosition is updated - position(Vector3f.from(position.getX() + relX, position.getY() + relY, position.getZ() + relZ)); + setPosition(position.add(relX, relY, relZ)); MoveEntityDeltaPacket moveEntityPacket = new MoveEntityDeltaPacket(); moveEntityPacket.setRuntimeEntityId(geyserId); @@ -347,7 +344,7 @@ public void moveAbsolute(Vector3f javaPosition, float yaw, float pitch, float he } public void moveAbsoluteRaw(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - position(position); + setPosition(javaPosition); // Setters are intentional so it can be overridden in places like AbstractArrowEntity setYaw(yaw); setPitch(pitch); @@ -717,13 +714,11 @@ public boolean isAlive() { return this.valid; } - public void position(Vector3f position) { - this.position = position; - this.bedrockPosition = position.up(offset); - } - public Vector3f bedrockPosition() { - return bedrockPosition; + if (this.offset == 0f) { + return position; + } + return position.up(offset); } /** @@ -888,6 +883,11 @@ public void offset(float offset, boolean teleport) { return bedrockDefinition; } + @Override + public @NonNull Vector3f position() { + return position; + } + @Override public void update(@NonNull GeyserEntityDataType dataType, @Nullable T value) { if (dataType instanceof GeyserEntityDataImpl geyserEntityDataImpl) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java index 5eef1d737e4..3842a299e0a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java @@ -63,7 +63,7 @@ protected void moveAbsoluteImmediate(Vector3f javaPosition, float yaw, float pit newPosition = tickMovement(newPosition); } super.moveAbsoluteImmediate(newPosition, yaw, pitch, headYaw, isOnGround, teleported); - position(javaPosition); + setPosition(javaPosition); this.motion = lastMotion; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java index 30a4400e106..84385331761 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ItemEntity.java @@ -118,7 +118,7 @@ protected void moveAbsoluteImmediate(Vector3f javaPosition, float yaw, float pit this.offset = Math.abs(offset); } super.moveAbsoluteImmediate(javaPosition, 0, 0, 0, isOnGround, teleported); - position(javaPosition); + setPosition(javaPosition); waterLevel = session.getGeyser().getWorldManager().getBlockAtAsync(session, javaPosition.getFloorX(), javaPosition.getFloorY(), javaPosition.getFloorZ()) .thenApply(BlockStateValues::getWaterLevel); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java index 217b4f1864a..51bfaf5de85 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java @@ -474,7 +474,7 @@ public void tick() { moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_PITCH); } moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.TELEPORTING); - position(Vector3f.from(lerpXTotal, lerpYTotal, lerpZTotal)); + setPosition(Vector3f.from(lerpXTotal, lerpYTotal, lerpZTotal)); moveEntityPacket.setRuntimeEntityId(geyserId); moveEntityPacket.setX(bedrockPosition().getX()); moveEntityPacket.setY(bedrockPosition().getY()); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java index 0a5315a21a1..b6df5e9f484 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java @@ -141,6 +141,8 @@ public void tick() { float lerpZTotal = GenericMath.lerp(position().getZ(), this.lerpPosition.getZ(), time); MoveEntityDeltaPacket moveEntityPacket = new MoveEntityDeltaPacket(); + moveEntityPacket.setRuntimeEntityId(geyserId); + moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.TELEPORTING); if (onGround) { moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.ON_GROUND); } @@ -162,9 +164,9 @@ public void tick() { if (this.dirtyPitch) { moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_PITCH); } - moveEntityPacket.getFlags().add(MoveEntityDeltaPacket.Flag.TELEPORTING); - position(Vector3f.from(lerpXTotal, lerpYTotal, lerpZTotal)); - moveEntityPacket.setRuntimeEntityId(geyserId); + + setPosition(Vector3f.from(lerpXTotal, lerpYTotal, lerpZTotal)); + moveEntityPacket.setX(bedrockPosition().getX()); moveEntityPacket.setY(bedrockPosition().getY()); moveEntityPacket.setZ(bedrockPosition().getZ()); @@ -202,7 +204,7 @@ public void tick() { Vector3f position = getCurrentLerpPosition(delta).toFloat(); Vector3f movement = getCurrentLerpMovement(delta).toFloat(); - position(position); + setPosition(position); setMotion(movement); setYaw(180.0F - getCurrentLerpYaw(delta)); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java index 5e2cd01b3d5..f03eab733ce 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java @@ -61,8 +61,10 @@ public void tick() { motion = motion.mul(drag).down(gravity); } - // TODO offsets!!! protected void moveAbsoluteImmediate(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + Vector3f oldPosition = position(); + setPosition(javaPosition); + MoveEntityDeltaPacket moveEntityDeltaPacket = new MoveEntityDeltaPacket(); moveEntityDeltaPacket.setRuntimeEntityId(geyserId); @@ -75,19 +77,18 @@ protected void moveAbsoluteImmediate(Vector3f javaPosition, float yaw, float pit moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.TELEPORTING); } - if (this.position().getX() != javaPosition.getX()) { + if (this.position().getX() != oldPosition.getX()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_X); - moveEntityDeltaPacket.setX(javaPosition.getX()); + moveEntityDeltaPacket.setX(bedrockPosition().getX()); } - if (this.position().getY() != javaPosition.getY()) { + if (this.position().getY() != oldPosition.getY()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Y); - moveEntityDeltaPacket.setY(javaPosition.getY() + offset); + moveEntityDeltaPacket.setY(bedrockPosition().getY()); } - if (this.position().getZ() != javaPosition.getZ()) { + if (this.position().getZ() != oldPosition.getZ()) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_Z); - moveEntityDeltaPacket.setZ(javaPosition.getZ()); + moveEntityDeltaPacket.setZ(bedrockPosition().getZ()); } - position(javaPosition); if (getYaw() != yaw) { moveEntityDeltaPacket.getFlags().add(MoveEntityDeltaPacket.Flag.HAS_YAW); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java index 7ef3eaa8467..db9617b2b37 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java @@ -149,7 +149,7 @@ public void moveRelativeRaw(double relX, double relY, double relZ, float yaw, fl setPitch(pitch); setHeadYaw(headYaw); setOnGround(isOnGround); - position(Vector3f.from(position().getX() + relX, position().getY() + relY, position().getZ() + relZ)); + setPosition(Vector3f.from(position().getX() + relX, position().getY() + relY, position().getZ() + relZ)); MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket(); moveEntityPacket.setRuntimeEntityId(geyserId); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java index 410c4b5fc88..7990cb01e22 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonEntity.java @@ -192,13 +192,13 @@ private void updateBoundingBoxes() { headDuck = baseSegment.y - getSegment(0).y; } - head.position(facingDir.up(pitchY).mul(pitchXZ, 1, -pitchXZ).mul(6.5f).up(headDuck)); - neck.position(facingDir.up(pitchY).mul(pitchXZ, 1, -pitchXZ).mul(5.5f).up(headDuck)); - body.position(facingDir.mul(0.5f, 0f, -0.5f)); + head.setPosition(facingDir.up(pitchY).mul(pitchXZ, 1, -pitchXZ).mul(6.5f).up(headDuck)); + neck.setPosition(facingDir.up(pitchY).mul(pitchXZ, 1, -pitchXZ).mul(5.5f).up(headDuck)); + body.setPosition(facingDir.mul(0.5f, 0f, -0.5f)); Vector3f wingPos = Vector3f.createDirectionDeg(0, 90f - getHeadYaw()).mul(4.5f).up(2f); - rightWing.position(wingPos); - leftWing.position(wingPos.mul(-1, 1, -1)); // Mirror horizontally + rightWing.setPosition(wingPos); + leftWing.setPosition(wingPos.mul(-1, 1, -1)); // Mirror horizontally Vector3f tailBase = facingDir.mul(1.5f); for (int i = 0; i < tail.length; i++) { @@ -208,7 +208,7 @@ private void updateBoundingBoxes() { float angle = getHeadYaw() + targetSegment.yaw - baseSegment.yaw; float tailYOffset = targetSegment.y - baseSegment.y - (distance + 1.5f) * pitchY + 1.5f; - tail[i].position(Vector3f.createDirectionDeg(0, angle).mul(distance).add(tailBase).mul(-pitchXZ, 1, pitchXZ).up(tailYOffset)); + tail[i].setPosition(Vector3f.createDirectionDeg(0, angle).mul(distance).add(tailBase).mul(-pitchXZ, 1, pitchXZ).up(tailYOffset)); } // Send updated positions for (EnderDragonPartEntity part : allParts) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java index 3eae044de49..bd1bf97e038 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java @@ -44,7 +44,7 @@ public EnderDragonPartEntity(GeyserSession session, int entityId, long geyserId, @Override public void moveAbsoluteRaw(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - position(position); + setPosition(position); // Setters are intentional so it can be overridden in places like AbstractArrowEntity setYaw(yaw); setPitch(pitch); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java index 3e10fc23b1d..67331d351ca 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java @@ -142,7 +142,7 @@ public void moveAbsoluteRaw(Vector3f javaPosition, float yaw, float pitch, float setYaw(yaw); setPitch(pitch); setHeadYaw(headYaw); - position(javaPosition); + setPosition(javaPosition); setOnGround(isOnGround); @@ -169,7 +169,7 @@ public void moveRelativeRaw(double relX, double relY, double relZ, float yaw, fl setYaw(yaw); setPitch(pitch); setHeadYaw(headYaw); - position(position().add(relX, relY, relZ)); + setPosition(position().add(relX, relY, relZ)); setOnGround(isOnGround); @@ -197,13 +197,13 @@ public void moveRelativeRaw(double relX, double relY, double relZ, float yaw, fl } @Override - public void position(Vector3f position) { + public void setPosition(Vector3f position) { if (this.bedPosition != null) { // As of Bedrock 1.21.22 and Fabric 1.21.1 // Messes with Bedrock if we send this to the client itself, though. - super.position(position.up(0.2f)); + super.setPosition(position.up(0.2f)); } else { - super.position(position); + super.setPosition(position); } } @@ -213,7 +213,7 @@ public void position(Vector3f position) { if (bedPosition != null) { // Required to sync position of entity to bed // Fixes https://github.com/GeyserMC/Geyser/issues/3595 on vanilla 1.19.3 servers - did not happen on Paper - this.position(bedPosition.toFloat()); + this.setPosition(bedPosition.toFloat()); // TODO evaluate if needed int bed = session.getGeyser().getWorldManager().getBlockAt(session, bedPosition); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java index 2b045522e29..673e43371f1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java @@ -173,7 +173,7 @@ public void moveRelativeRaw(double relX, double relY, double relZ, float yaw, fl } @Override - public void position(Vector3f position) { + public void setPosition(Vector3f position) { if (valid) { // Don't update during session init session.getCollisionManager().updatePlayerBoundingBox(position); @@ -181,7 +181,7 @@ public void position(Vector3f position) { session.setNoClip(false); } } - super.position(position); + super.setPosition(position); } /** @@ -217,7 +217,7 @@ public void updateOwnRotation(float yaw, float pitch, float headYaw) { * Set the player's position from a position sent in a Bedrock packet */ public void setPositionFromBedrock(Vector3f position) { - position(position.down(offset)); + this.setPosition(position.down(offset)); // Player is "above" the void so they're not supposed to no clip. if (session.isNoClip() && position().getY() >= session.getBedrockDimension().minY() - 5) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/vehicle/BoatVehicleComponent.java b/core/src/main/java/org/geysermc/geyser/entity/vehicle/BoatVehicleComponent.java index 8bbb9e36f5f..835b3a9fffe 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/vehicle/BoatVehicleComponent.java +++ b/core/src/main/java/org/geysermc/geyser/entity/vehicle/BoatVehicleComponent.java @@ -139,7 +139,7 @@ public void tickVehicle() { @Override protected void moveVehicle(Vector3d javaPos, Vector3f lastRotation) { Vector3f oldPosition = vehicle.position(); - vehicle.position(javaPos.toFloat()); + vehicle.setPosition(javaPos.toFloat()); MoveEntityDeltaPacket moveEntityDeltaPacket = new MoveEntityDeltaPacket(); moveEntityDeltaPacket.setRuntimeEntityId(vehicle.geyserId()); diff --git a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java index 4647a341752..eed4b25103b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java +++ b/core/src/main/java/org/geysermc/geyser/entity/vehicle/VehicleComponent.java @@ -761,7 +761,7 @@ protected Vector2f getRiddenRotation() { */ protected void moveVehicle(Vector3d javaPos, Vector3f lastRotation) { Vector3f oldPosition = vehicle.position(); - vehicle.position(javaPos.toFloat()); + vehicle.setPosition(javaPos.toFloat()); MoveEntityDeltaPacket moveEntityDeltaPacket = new MoveEntityDeltaPacket(); moveEntityDeltaPacket.setRuntimeEntityId(vehicle.geyserId()); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java index 800b4080b75..d9cd286430c 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockPlayerAuthInputTranslator.java @@ -339,7 +339,7 @@ private static void processVehicleInput(GeyserSession session, PlayerAuthInputPa return; } - vehicle.position(vehiclePosition); + vehicle.setPosition(vehiclePosition); ServerboundMoveVehiclePacket moveVehiclePacket = new ServerboundMoveVehiclePacket( vehiclePosition.toDouble(), vehicle instanceof BoatEntity ? vehicleRotation.getY() - 90 : vehicleRotation.getY(), vehiclePosition.getX(), diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java index 286b9849ba8..8e9640e3740 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAddEntityTranslator.java @@ -84,7 +84,7 @@ public void translate(GeyserSession session, ClientboundAddEntityPacket packet) } entity.setEntityId(packet.getEntityId()); - entity.position(context.position()); + entity.setPosition(context.position()); entity.setYaw(packet.getYaw()); entity.setPitch(packet.getPitch()); entity.setHeadYaw(packet.getHeadYaw()); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java index 9fed5c59897..42d9f029786 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerPositionTranslator.java @@ -66,7 +66,7 @@ public void translate(GeyserSession session, ClientboundPlayerPositionPacket pac acceptTeleport(session, position, newYaw, newPitch, teleportId); if (!session.isSpawned()) { - entity.position(position.toFloat()); + entity.setPosition(position.toFloat()); entity.setYaw(packet.getYRot()); entity.setPitch(packet.getXRot()); entity.setHeadYaw(packet.getYRot()); diff --git a/core/src/main/java/org/geysermc/geyser/util/DimensionUtils.java b/core/src/main/java/org/geysermc/geyser/util/DimensionUtils.java index 665201fb89d..cbb7a2c638a 100644 --- a/core/src/main/java/org/geysermc/geyser/util/DimensionUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/DimensionUtils.java @@ -131,7 +131,7 @@ private static void changeDimension(GeyserSession session, int bedrockDimension) setBedrockDimension(session, bedrockDimension); - session.getPlayerEntity().position(pos); + session.getPlayerEntity().setPosition(pos); session.getPlayerEntity().setMotion(Vector3f.ZERO); session.getPlayerEntity().setLastTickEndVelocity(Vector3f.ZERO); session.setSpawned(false); From cdd11e77326956ddbcf4606bb89ca9e06277ca0a Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Mon, 2 Feb 2026 22:28:14 +0100 Subject: [PATCH 42/62] Address issues --- .../entity/data/GeyserEntityDataTypes.java | 25 +++++++++++++++++++ .../geyser/entity/type/LivingEntity.java | 2 +- .../type/living/animal/SnifferEntity.java | 6 ++--- .../geyser/impl/entity/HitboxImpl.java | 2 +- .../session/cache/waypoint/WaypointCache.java | 2 +- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java index d312bbda78b..2ec611b1359 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java @@ -1,3 +1,28 @@ +/* + * Copyright (c) 2025 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + package org.geysermc.geyser.api.entity.data; import org.geysermc.geyser.api.entity.data.types.Hitbox; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java index 4c5ba92d372..ba3d56cba8f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java @@ -420,7 +420,7 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float public void moveAbsolute(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { // It's vanilla behaviour to lerp if the position is within 64 blocks, however we also check if the position is close enough to the player // position to see if it can actually affect anything to save network. - if (shouldLerp() && javaPosition.distanceSquared(javaPosition) < 4096 && javaPosition.distanceSquared(session.getPlayerEntity().position()) < 4096) { + if (shouldLerp() && this.position().distanceSquared(javaPosition) < 4096 && javaPosition.distanceSquared(session.getPlayerEntity().position()) < 4096) { this.dirtyPitch = this.dirtyYaw = this.dirtyHeadYaw = true; setYaw(yaw); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java index 2c29d974a97..f4fc8c49caa 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java @@ -44,13 +44,13 @@ public class SnifferEntity extends AnimalEntity implements Tickable { private static final int DIG_END = 120; private static final int DIG_START = DIG_END - 34; - private final float DIGGING_HEIGHT; + private final float diggingHeight; private Pose pose = Pose.STANDING; // Needed to call setDimensions for DIGGING state private int digTicks; public SnifferEntity(EntitySpawnContext context) { super(context); - DIGGING_HEIGHT = height - 0.4f; + diggingHeight = height - 0.4f; } @Override @@ -62,7 +62,7 @@ public void setPose(Pose pose) { @Override protected void setDimensionsFromPose(Pose pose) { if (getFlag(EntityFlag.DIGGING)) { - setBoundingBoxHeight(DIGGING_HEIGHT); + setBoundingBoxHeight(diggingHeight); setBoundingBoxWidth(width); } else { super.setDimensionsFromPose(pose); diff --git a/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java b/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java index 7b34bf3c3b2..d6dded5b1f9 100644 --- a/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java +++ b/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java @@ -53,7 +53,7 @@ public static List fromMetaData(@Nullable NbtMap metaDataMap) { boxes.add(new HitboxImpl( Vector3f.from(hitbox.getFloat("MinX"), hitbox.getFloat("MinY"), hitbox.getFloat("MinZ")), Vector3f.from(hitbox.getFloat("MaxX"), hitbox.getFloat("MaxY"), hitbox.getFloat("MaxZ")), - Vector3f.from(hitbox.getFloat("PivotX"),hitbox.getFloat("PivotY"),hitbox.getFloat("PivotZ")) + Vector3f.from(hitbox.getFloat("PivotX"), hitbox.getFloat("PivotY"), hitbox.getFloat("PivotZ")) )); } return boxes; diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/waypoint/WaypointCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/waypoint/WaypointCache.java index 5a2f6ee801e..3331e0cccf4 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/waypoint/WaypointCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/waypoint/WaypointCache.java @@ -35,7 +35,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.level.waypoint.WaypointOperation; import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level.ClientboundTrackedWaypointPacket; -import java.awt.*; +import java.awt.Color; import java.util.Map; import java.util.Optional; import java.util.UUID; From 241cb4c5cb9071c98700fe0831be525f7fbd0c6e Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Thu, 5 Feb 2026 18:11:58 +0100 Subject: [PATCH 43/62] Bump mcpl --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a53d3c57a51..94638e285ff 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -18,7 +18,7 @@ protocol-common = "3.0.0.Beta11-20251212.150341-15" protocol-codec = "3.0.0.Beta11-20251212.150341-16" raknet = "1.0.0.CR3-20251208.214317-23" minecraftauth = "5.0.0" -mcprotocollib = "1.21.11-feature-custom-entities" +mcprotocollib = "1.21.11-feature-custom-entities-SNAPSHOT" adventure = "4.25.0" adventure-platform = "4.4.1" junit = "6.0.0" From 8d39a3916a9807fc44b251a1687aeb13b70176d9 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sat, 7 Feb 2026 20:54:14 +0100 Subject: [PATCH 44/62] make it build again --- .../org/geysermc/geyser/session/GeyserSession.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index 7236a9339fe..9ef4989a56b 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -2436,16 +2436,6 @@ public void removeFog(String... fogNameSpaces) { return this.cameraData.fogEffects(); } - @Override - public @NonNull GeyserPlayerEntity playerEntity() { - return playerEntity; - } - - @Override - public void switchHands() { - requestOffhandSwap(); - } - @Override public int ping() { // Can otherwise cause issues if the player isn't logged in yet / already left From d792f0ee989aef80a85f8f8cac28fc1cbe71ce00 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Tue, 10 Feb 2026 00:03:06 +0100 Subject: [PATCH 45/62] Partially address review --- .../geysermc/geyser/impl/entity/GeyserEntityDataImpl.java | 2 +- .../java/org/geysermc/geyser/session/cache/EntityCache.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java b/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java index e2e12e3fd27..5a08f7cbd4f 100644 --- a/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java +++ b/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java @@ -51,7 +51,7 @@ public class GeyserEntityDataImpl implements GeyserEntityDataType { TYPES.put("scale", new GeyserEntityDataImpl<>(Float.class, "scale", EntityDataTypes.SCALE)); // "custom" - TYPES.put("vertical_offset", new GeyserEntityDataImpl<>(Float.class, "offset", (entity, value) -> entity.offset(value, true), Entity::getOffset)); + TYPES.put("vertical_offset", new GeyserEntityDataImpl<>(Float.class, "vertical_offset", (entity, value) -> entity.offset(value, true), Entity::getOffset)); } public static GeyserEntityDataImpl lookup(Class clazz, String name) { diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java index 7edb09309a4..b18d4a5d185 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/EntityCache.java @@ -43,6 +43,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.concurrent.atomic.AtomicLong; @@ -97,7 +98,7 @@ public boolean cacheEntity(Entity entity) { entityIdTranslations.put(entity.getEntityId(), entity.geyserId()); entities.put(entity.geyserId(), entity); if (entity.uuid() != null) { - entityUuidTranslations.put(entity.uuid(), entity.getEntityId()); + entityUuidTranslations.put(entity.uuid(), entity.geyserId()); } return true; } @@ -155,7 +156,7 @@ public Entity getEntityByJavaId(int javaId) { } public Entity getEntityByUuid(UUID uuid) { - if (uuid == session.getPlayerEntity().uuid()) { + if (Objects.equals(uuid, session.getPlayerEntity().uuid())) { return session.getPlayerEntity(); } return entities.get(entityUuidTranslations.getLong(uuid)); From b964780f437395b434a9b63653a2318cb96d6cde Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Wed, 11 Feb 2026 01:16:50 +0100 Subject: [PATCH 46/62] fix le test --- .../scoreboard/network/util/GeyserMockContextScoreboard.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/test/java/org/geysermc/geyser/scoreboard/network/util/GeyserMockContextScoreboard.java b/core/src/test/java/org/geysermc/geyser/scoreboard/network/util/GeyserMockContextScoreboard.java index be67dde48f4..22aadc34ec0 100644 --- a/core/src/test/java/org/geysermc/geyser/scoreboard/network/util/GeyserMockContextScoreboard.java +++ b/core/src/test/java/org/geysermc/geyser/scoreboard/network/util/GeyserMockContextScoreboard.java @@ -100,7 +100,7 @@ public static PlayerEntity spawnPlayerSilently(GeyserMockContext context, String } public static ArmorStandEntity spawnArmorStand(GeyserMockContext context, long geyserId) { - var entitySpawnContext = EntitySpawnContext.DUMMY_CONTEXT.apply(context.session(), UUID.randomUUID(), EntityDefinitions.ARMOR_STAND); + var entitySpawnContext = EntitySpawnContext.DUMMY_CONTEXT.apply(context.session(), UUID.randomUUID(), VanillaEntities.ARMOR_STAND); entitySpawnContext.geyserId(geyserId); entitySpawnContext.javaId((int) geyserId); var armorStand = spy(new ArmorStandEntity(entitySpawnContext)); From beb2498b91b186ea05065d7df3ee721486368a3d Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sat, 28 Feb 2026 15:00:56 +0100 Subject: [PATCH 47/62] Fix: ResourcePackClientResponsePacket's may contain empty pack lists in the send_packs case --- .../geysermc/geyser/network/UpstreamPacketHandler.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java index 8433afe7914..c7987ac44a4 100644 --- a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java @@ -276,14 +276,12 @@ public PacketSignal handle(ResourcePackClientResponsePacket packet) { " (" + session.protocolVersion() + ")")); } case SEND_PACKS -> { - if (packet.getPackIds().isEmpty()) { - GeyserImpl.getInstance().getLogger().warning("Received empty pack ids in resource pack response packet!"); - session.disconnect("Invalid resource pack response packet received!"); - chunkRequestQueue.clear(); + // Bedrock clients can send empty "send_packs" responses, in which case we shouldn't send anything back + if (!packet.getPackIds().isEmpty()) { + packsToSend.addAll(packet.getPackIds()); + sendPackDataInfo(packsToSend.pop()); return PacketSignal.HANDLED; } - packsToSend.addAll(packet.getPackIds()); - sendPackDataInfo(packsToSend.pop()); } case HAVE_ALL_PACKS -> { ResourcePackStackPacket stackPacket = new ResourcePackStackPacket(); From 7d1a16a101a6bf3357cd2848823253cbf97fd675 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sat, 28 Feb 2026 15:03:19 +0100 Subject: [PATCH 48/62] Fix debug log formatting calls --- .../org/geysermc/geyser/item/parser/ItemStackParser.java | 4 ++-- .../geysermc/geyser/network/UpstreamPacketHandler.java | 8 ++++---- .../org/geysermc/geyser/network/netty/Bootstraps.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/item/parser/ItemStackParser.java b/core/src/main/java/org/geysermc/geyser/item/parser/ItemStackParser.java index 1504fe911c8..fdec8d6b4a6 100644 --- a/core/src/main/java/org/geysermc/geyser/item/parser/ItemStackParser.java +++ b/core/src/main/java/org/geysermc/geyser/item/parser/ItemStackParser.java @@ -190,9 +190,9 @@ private static void parseDataComponent(GeyserSession session, Data try { patch.put((DataComponentType) type, parser.parse(session, (Raw) raw)); } catch (ClassCastException exception) { - GeyserImpl.getInstance().getLogger().debug("Received incorrect object type for component " + type + "!", exception); + GeyserImpl.getInstance().getLogger().debug("Received incorrect object type for component " + type + "! Exception: %s", exception); } catch (Exception exception) { - GeyserImpl.getInstance().getLogger().debug("Failed to parse component" + type + " from " + raw + "!", exception); + GeyserImpl.getInstance().getLogger().debug("Failed to parse component" + type + " from " + raw + "! Exception: %s", exception); } } diff --git a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java index c7987ac44a4..929dece594f 100644 --- a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java @@ -375,7 +375,7 @@ public void processNextChunk() { ResourcePackHolder holder = this.resourcePackLoadEvent.getPacks().get(packet.getPackId()); if (holder == null) { - GeyserImpl.getInstance().getLogger().debug("Client {0} tried to request pack id {1} not sent to it!", + GeyserImpl.getInstance().getLogger().debug("Client %s tried to request pack id %s not sent to it!", session.bedrockUsername(), packet.getPackId()); chunkRequestQueue.clear(); session.disconnect("disconnectionScreen.resourcePack"); @@ -438,7 +438,7 @@ private void sendPackDataInfo(String id) { String[] packID = id.split("_"); if (packID.length < 2) { - GeyserImpl.getInstance().getLogger().debug("Client {0} tried to request invalid pack id {1}!", + GeyserImpl.getInstance().getLogger().debug("Client %s tried to request invalid pack id %s!", session.bedrockUsername(), packID); session.disconnect("disconnectionScreen.resourcePack"); return; @@ -448,7 +448,7 @@ private void sendPackDataInfo(String id) { try { packId = UUID.fromString(packID[0]); } catch (IllegalArgumentException e) { - GeyserImpl.getInstance().getLogger().debug("Client {0} tried to request pack with an invalid id {1})", + GeyserImpl.getInstance().getLogger().debug("Client %s tried to request pack with an invalid id %s)", session.bedrockUsername(), id); session.disconnect("disconnectionScreen.resourcePack"); return; @@ -456,7 +456,7 @@ private void sendPackDataInfo(String id) { ResourcePackHolder holder = this.resourcePackLoadEvent.getPacks().get(packId); if (holder == null) { - GeyserImpl.getInstance().getLogger().debug("Client {0} tried to request pack id {1} not sent to it!", + GeyserImpl.getInstance().getLogger().debug("Client %s tried to request pack id %s not sent to it!", session.bedrockUsername(), id); session.disconnect("disconnectionScreen.resourcePack"); return; diff --git a/core/src/main/java/org/geysermc/geyser/network/netty/Bootstraps.java b/core/src/main/java/org/geysermc/geyser/network/netty/Bootstraps.java index e6f4523a3b1..9f055275bb3 100644 --- a/core/src/main/java/org/geysermc/geyser/network/netty/Bootstraps.java +++ b/core/src/main/java/org/geysermc/geyser/network/netty/Bootstraps.java @@ -110,7 +110,7 @@ public static boolean setupBootstrap(AbstractBootstrap bootstrap, TransportHelpe channel.close().awaitUninterruptibly(3, TimeUnit.SECONDS); } } catch (Throwable e) { - GeyserImpl.getInstance().getLogger().debug("Could not set up reuseport check ", e); + GeyserImpl.getInstance().getLogger().debug("Could not set up reuseport check! %s", e); return false; } return success; From bddacf7a89d5ca4bd065b31b1fc772a2c3edc5ca Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sat, 28 Feb 2026 18:12:12 +0100 Subject: [PATCH 49/62] Minor fixes, reviews, etc --- .../geyser/api/entity/EntityData.java | 2 +- .../entity/custom/CustomEntityDefinition.java | 5 +- .../geyser/entity/GeyserEntityType.java | 14 +-- .../NonVanillaEntityTypeDefinition.java | 2 +- .../geyser/extension/TestExtension.java | 117 ------------------ .../geyser/item/parser/ItemStackParser.java | 2 +- .../geyser/network/UpstreamPacketHandler.java | 3 +- .../loader/ProviderRegistryLoader.java | 2 + .../geyser/session/cache/WorldBorder.java | 2 +- .../org/geysermc/geyser/util/EntityUtils.java | 2 +- 10 files changed, 20 insertions(+), 131 deletions(-) delete mode 100644 core/src/main/java/org/geysermc/geyser/extension/TestExtension.java diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java b/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java index 75dedb96824..f3e63baf3b5 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java @@ -42,7 +42,7 @@ public interface EntityData { /** - * @deprecated use {@link #byGeyserId(long)} + * @deprecated use {@link #byJavaId(int)} */ @Deprecated @NonNull CompletableFuture<@Nullable GeyserEntity> entityByJavaId(@NonNegative int javaId); diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java index 034739628c6..00c44c23048 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java @@ -47,7 +47,10 @@ default boolean vanilla() { * @return the CustomEntityDefinition */ static @NonNull CustomEntityDefinition of(@NonNull Identifier identifier) { - return GeyserApi.api().provider(GeyserEntityDefinition.class, identifier); + if (identifier.vanilla()) { + throw new IllegalArgumentException("Use GeyserEntityDefinition#of for vanilla entity lookups!"); + } + return GeyserApi.api().provider(CustomEntityDefinition.class, identifier); } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java index c46b71043ca..619252a82c5 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityType.java @@ -141,7 +141,7 @@ public static GeyserEntityType of(EntityType type) { return type instanceof BuiltinEntityType builtin ? ofVanilla(builtin) : of(type.id()); } - public static GeyserEntityType createCustomAndRegister(Builder builder) { + public static GeyserEntityType createCustomAndRegister(GeyserJavaEntityTypeBuild builder) { Identifier javaIdentifier = Objects.requireNonNull(builder.identifier, "javaIdentifier may not be null"); int javaId = builder.javaId; @@ -161,7 +161,7 @@ public static GeyserEntityType createCustomAndRegister(Builder builder) { } @Getter - public static class Builder implements CustomJavaEntityType.Builder { + public static class GeyserJavaEntityTypeBuild implements CustomJavaEntityType.Builder { private Identifier identifier; private int javaId; private float width; @@ -169,7 +169,7 @@ public static class Builder implements CustomJavaEntityType.Builder { private BedrockEntityDefinition defaultBedrockDefinition; @Override - public Builder type(@NonNull Identifier entityType) { + public GeyserJavaEntityTypeBuild type(@NonNull Identifier entityType) { Objects.requireNonNull(entityType, "entityType may not be null"); if (entityType.vanilla()) { throw new IllegalArgumentException("Cannot register custom entity type in vanilla namespace!" + entityType); @@ -182,7 +182,7 @@ public Builder type(@NonNull Identifier entityType) { } @Override - public Builder javaId(int javaId) { + public GeyserJavaEntityTypeBuild javaId(int javaId) { if (javaId < 0) { throw new IllegalArgumentException("Invalid custom entity type id (may not be negative): " + javaId); } @@ -197,7 +197,7 @@ public Builder javaId(int javaId) { } @Override - public Builder width(@NonNegative float width) { + public GeyserJavaEntityTypeBuild width(@NonNegative float width) { if (width < 0) { throw new IllegalArgumentException("Invalid custom entity type width (may not be negative): " + width); } @@ -206,7 +206,7 @@ public Builder width(@NonNegative float width) { } @Override - public Builder height(@NonNegative float height) { + public GeyserJavaEntityTypeBuild height(@NonNegative float height) { if (height < 0) { throw new IllegalArgumentException("Invalid custom entity type height (may not be negative): " + height); } @@ -215,7 +215,7 @@ public Builder height(@NonNegative float height) { } @Override - public Builder definition(@Nullable GeyserEntityDefinition defaultBedrockDefinition) { + public GeyserJavaEntityTypeBuild definition(@Nullable GeyserEntityDefinition defaultBedrockDefinition) { if (defaultBedrockDefinition == null) { this.defaultBedrockDefinition = null; } else if (defaultBedrockDefinition instanceof BedrockEntityDefinition bedrockEntityDefinition) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/NonVanillaEntityTypeDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/NonVanillaEntityTypeDefinition.java index 07f45d0dc82..6fe92885c41 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/NonVanillaEntityTypeDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/NonVanillaEntityTypeDefinition.java @@ -38,7 +38,7 @@ @ToString(callSuper = true) public class NonVanillaEntityTypeDefinition extends EntityTypeDefinition { - public NonVanillaEntityTypeDefinition(GeyserEntityType.Builder builder, GeyserEntityType entityType) { + public NonVanillaEntityTypeDefinition(GeyserEntityType.GeyserJavaEntityTypeBuild builder, GeyserEntityType entityType) { super(Entity::new, entityType, builder.getWidth(), builder.getHeight(), 0f, builder.getDefaultBedrockDefinition(), VanillaEntityBases.ENTITY.translators); } diff --git a/core/src/main/java/org/geysermc/geyser/extension/TestExtension.java b/core/src/main/java/org/geysermc/geyser/extension/TestExtension.java deleted file mode 100644 index cf3323a402e..00000000000 --- a/core/src/main/java/org/geysermc/geyser/extension/TestExtension.java +++ /dev/null @@ -1,117 +0,0 @@ -///* -// * Copyright (c) 2025 GeyserMC. http://geysermc.org -// * -// * Permission is hereby granted, free of charge, to any person obtaining a copy -// * of this software and associated documentation files (the "Software"), to deal -// * in the Software without restriction, including without limitation the rights -// * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// * copies of the Software, and to permit persons to whom the Software is -// * furnished to do so, subject to the following conditions: -// * -// * The above copyright notice and this permission notice shall be included in -// * all copies or substantial portions of the Software. -// * -// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// * THE SOFTWARE. -// * -// * @author GeyserMC -// * @link https://github.com/GeyserMC/Geyser -// */ -// -//package org.geysermc.geyser.extension; -// -//import org.cloudburstmc.math.vector.Vector3f; -//import org.geysermc.event.subscribe.Subscribe; -//import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; -//import org.geysermc.geyser.api.entity.data.GeyserEntityDataTypes; -//import org.geysermc.geyser.api.entity.data.types.Hitbox; -//import org.geysermc.geyser.api.entity.property.type.GeyserFloatEntityProperty; -//import org.geysermc.geyser.api.event.bedrock.ClientEmoteEvent; -//import org.geysermc.geyser.api.event.java.ServerAttachParrotsEvent; -//import org.geysermc.geyser.api.event.java.ServerSpawnEntityEvent; -//import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; -//import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntityPropertiesEvent; -//import org.geysermc.geyser.api.event.lifecycle.GeyserDefineResourcePacksEvent; -//import org.geysermc.geyser.api.pack.PathPackCodec; -//import org.geysermc.geyser.api.pack.ResourcePack; -//import org.geysermc.geyser.api.util.Identifier; -// -//import java.util.List; -// -//public class TestExtension { -// -// public static CustomEntityDefinition ROBOT = CustomEntityDefinition.of("sample:robot"); -// public static Identifier PARROT = Identifier.of("parrot"); -// // optional; only if you want properties -// public static GeyserFloatEntityProperty MY_FLOAT_PROPERTY; -// -// @Subscribe -// public void onDefineEntities(GeyserDefineEntitiesEvent event) { -// event.register(ROBOT); -// } -// -// // Optional; only if you want them! -// @Subscribe -// public void onDefineEntityProperties(GeyserDefineEntityPropertiesEvent event) { -// MY_FLOAT_PROPERTY = event.registerFloatProperty(ROBOT.identifier(), Identifier.of("sample", "my_float_property"), 0, 100); -// } -// -// @Subscribe -// public void onSpawnEntities(ServerSpawnEntityEvent event) { -// // Chain whatever checks you want -// if (event.entityType().is(PARROT)) { -// event.definition(ROBOT); -// -// // Make the entity smaller -// event.preSpawnConsumer(entity -> { -// entity.update(GeyserEntityDataTypes.SCALE, 2f); -// entity.update(GeyserEntityDataTypes.VARIANT, 0); -// entity.update(GeyserEntityDataTypes.HITBOXES, List.of(Hitbox.builder() -// .min(Vector3f.from(0, 0, 0)) -// .max(Vector3f.from(10, 10, 10)) -// .pivot(Vector3f.ZERO) -// .build())); -// -// List test = entity.value(GeyserEntityDataTypes.HITBOXES); -// System.out.println(test); -// }); -// } -// } -// -// @Subscribe -// public void onParrotEvent(ServerAttachParrotsEvent event) { -// // We also want to make the robot sit on our shoulder! -// // here, for some reason, only variants that aren't one -// event.definition(ROBOT); -// event.preSpawnConsumer(entity -> { -// entity.update(GeyserEntityDataTypes.SCALE, 0.5f); -// entity.updateProperty(MY_FLOAT_PROPERTY, 10f); -// }); -// } -// -// @Subscribe -// public void onGeyserDefineResourcePacksEvent(GeyserDefineResourcePacksEvent event) { -// -// ResourcePack pack = event.resourcePacks().stream().filter( -// resourcePack -> resourcePack.manifest().header().name().equals("Geyser Player Skull Resource Pack")) -// .findFirst().orElse(null); -// -// if (pack == null) { -// logger.warn("Could not find skull pack!"); -// return; -// } -// -// // Unregister skull pack -// event.unregister(pack.uuid()); -// } -// -// @Subscribe -// public void onEmote(ClientEmoteEvent event) { -// event.connection().playerEntity().update(GeyserEntityDataTypes.SCALE, 0.5f); -// } -//} diff --git a/core/src/main/java/org/geysermc/geyser/item/parser/ItemStackParser.java b/core/src/main/java/org/geysermc/geyser/item/parser/ItemStackParser.java index fdec8d6b4a6..e65f4390a7d 100644 --- a/core/src/main/java/org/geysermc/geyser/item/parser/ItemStackParser.java +++ b/core/src/main/java/org/geysermc/geyser/item/parser/ItemStackParser.java @@ -192,7 +192,7 @@ private static void parseDataComponent(GeyserSession session, Data } catch (ClassCastException exception) { GeyserImpl.getInstance().getLogger().debug("Received incorrect object type for component " + type + "! Exception: %s", exception); } catch (Exception exception) { - GeyserImpl.getInstance().getLogger().debug("Failed to parse component" + type + " from " + raw + "! Exception: %s", exception); + GeyserImpl.getInstance().getLogger().debug("Failed to parse component " + type + " from " + raw + "! Exception: %s", exception); } } diff --git a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java index 929dece594f..0e7a1fecee9 100644 --- a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java @@ -78,6 +78,7 @@ import java.nio.ByteBuffer; import java.nio.channels.SeekableByteChannel; import java.util.ArrayDeque; +import java.util.Arrays; import java.util.Deque; import java.util.OptionalInt; import java.util.Queue; @@ -439,7 +440,7 @@ private void sendPackDataInfo(String id) { if (packID.length < 2) { GeyserImpl.getInstance().getLogger().debug("Client %s tried to request invalid pack id %s!", - session.bedrockUsername(), packID); + session.bedrockUsername(), Arrays.toString(packID)); session.disconnect("disconnectionScreen.resourcePack"); return; } diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java index 364d62da074..008adbccf0c 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java @@ -34,6 +34,7 @@ import org.geysermc.geyser.api.block.custom.component.MaterialInstance; import org.geysermc.geyser.api.block.custom.nonvanilla.JavaBlockState; import org.geysermc.geyser.api.command.Command; +import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; import org.geysermc.geyser.api.entity.data.GeyserEntityDataType; import org.geysermc.geyser.api.entity.data.GeyserListEntityDataType; import org.geysermc.geyser.api.entity.data.types.Hitbox; @@ -212,6 +213,7 @@ public Map, ProviderSupplier> load(Map, ProviderSupplier> prov // entities providers.put(GeyserEntityDefinition.class, args -> BedrockEntityDefinition.getOrCreate((Identifier) args[0])); + providers.put(CustomEntityDefinition.class, args -> BedrockEntityDefinition.getOrCreate((Identifier) args[0])); providers.put(JavaEntityType.class, args -> GeyserEntityType.ofVanilla((Identifier) args[0])); providers.put(GeyserEntityDataType.class, args -> GeyserEntityDataImpl.lookup((Class) args[0], (String) args[1])); providers.put(GeyserListEntityDataType.class, args -> GeyserListEntityDataImpl.lookup((Class) args[0], (Class) args[1], (String) args[2])); diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java b/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java index 061ae75cd22..5c8663dc0d0 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java @@ -324,7 +324,7 @@ public void drawWall() { return; } currentWallTick = 0; - Vector3f entityPosition = session.getPlayerEntity().bedrockPosition(); + Vector3f entityPosition = session.getPlayerEntity().position(); float particlePosX = entityPosition.getX(); float particlePosY = entityPosition.getY(); float particlePosZ = entityPosition.getZ(); diff --git a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java index fb2f45a701b..190f1019938 100644 --- a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java @@ -427,7 +427,7 @@ public void register(@NonNull CustomEntityDefinition entityDefinition) { @Override public void registerEntityType(Consumer consumer) { - var builder = new GeyserEntityType.Builder(); + var builder = new GeyserEntityType.GeyserJavaEntityTypeBuild(); consumer.accept(builder); var type = GeyserEntityType.createCustomAndRegister(builder); From c35cd1d87bca828b07f9a29a8aa2beef9eb7f675 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Wed, 4 Mar 2026 21:14:57 +0100 Subject: [PATCH 50/62] Support setting empty hitbox --- .../geyser/api/entity/data/types/Hitbox.java | 5 ++ .../geyser/impl/entity/HitboxImpl.java | 68 ++++++++++++++++--- .../loader/ProviderRegistryLoader.java | 1 + 3 files changed, 66 insertions(+), 8 deletions(-) diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java index f7949eb9791..708a9d2e2c0 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java @@ -34,6 +34,11 @@ */ public interface Hitbox { + /** + * Represents an empty / disabled hitbox. + */ + Hitbox EMPTY = GeyserApi.api().provider(Hitbox.class, true); + /** * The min "corner" of the hitbox * @return the vector of the corner diff --git a/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java b/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java index d6dded5b1f9..d9dee0fbfe9 100644 --- a/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java +++ b/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java @@ -36,11 +36,24 @@ import java.util.List; import java.util.Objects; -public record HitboxImpl( - Vector3f min, - Vector3f max, - Vector3f pivot -) implements Hitbox { +public class HitboxImpl implements Hitbox { + + public static Hitbox EMPTY = new HitboxImpl(Vector3f.ZERO, Vector3f.ZERO, Vector3f.ZERO) { + @Override + public NbtMap toNbtMap() { + return NbtMap.EMPTY; + } + }; + + private final Vector3f min; + private final Vector3f max; + private final Vector3f pivot; + + public HitboxImpl(Vector3f min, Vector3f max, Vector3f pivot) { + this.min = min; + this.max = max; + this.pivot = pivot; + } public static List fromMetaData(@Nullable NbtMap metaDataMap) { if (metaDataMap == null) { @@ -51,9 +64,9 @@ public static List fromMetaData(@Nullable NbtMap metaDataMap) { List hitboxes = metaDataMap.getList("Hitboxes", NbtType.COMPOUND); for (NbtMap hitbox : hitboxes) { boxes.add(new HitboxImpl( - Vector3f.from(hitbox.getFloat("MinX"), hitbox.getFloat("MinY"), hitbox.getFloat("MinZ")), - Vector3f.from(hitbox.getFloat("MaxX"), hitbox.getFloat("MaxY"), hitbox.getFloat("MaxZ")), - Vector3f.from(hitbox.getFloat("PivotX"), hitbox.getFloat("PivotY"), hitbox.getFloat("PivotZ")) + Vector3f.from(hitbox.getFloat("MinX"), hitbox.getFloat("MinY"), hitbox.getFloat("MinZ")), + Vector3f.from(hitbox.getFloat("MaxX"), hitbox.getFloat("MaxY"), hitbox.getFloat("MaxZ")), + Vector3f.from(hitbox.getFloat("PivotX"), hitbox.getFloat("PivotY"), hitbox.getFloat("PivotZ")) )); } return boxes; @@ -85,6 +98,45 @@ public static NbtMap toNbtMap(List hitboxes) { return NbtMap.builder().putList("Hitboxes", NbtType.COMPOUND, list).build(); } + @Override + public Vector3f min() { + return min; + } + + @Override + public Vector3f max() { + return max; + } + + @Override + public Vector3f pivot() { + return pivot; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) return true; + if (obj == null || obj.getClass() != this.getClass()) return false; + var that = (HitboxImpl) obj; + return Objects.equals(this.min, that.min) && + Objects.equals(this.max, that.max) && + Objects.equals(this.pivot, that.pivot); + } + + @Override + public int hashCode() { + return Objects.hash(min, max, pivot); + } + + @Override + public String toString() { + return "HitboxImpl[" + + "min=" + min + ", " + + "max=" + max + ", " + + "pivot=" + pivot + ']'; + } + + public static class Builder implements Hitbox.Builder { Vector3f min, max, pivot; diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java index 008adbccf0c..85b5a31d595 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java @@ -219,6 +219,7 @@ public Map, ProviderSupplier> load(Map, ProviderSupplier> prov providers.put(GeyserListEntityDataType.class, args -> GeyserListEntityDataImpl.lookup((Class) args[0], (Class) args[1], (String) args[2])); providers.put(Hitbox.Builder.class, args -> new HitboxImpl.Builder()); + providers.put(Hitbox.class, args -> HitboxImpl.EMPTY); return providers; } From 0f9ad3809416cab9a74d58ffdc1558ddb5f06faa Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sat, 14 Mar 2026 20:42:26 +0100 Subject: [PATCH 51/62] Reviews and comments --- .../entity/BedrockEntityDefinition.java | 7 +- .../geyser/entity/VanillaEntityType.java | 1 - .../entity/spawn/EntitySpawnContext.java | 6 +- .../entity/type/player/PlayerEntity.java | 2 +- .../geyser/impl/entity/HitboxImpl.java | 90 ++++--------------- .../geyser/item/parser/ItemStackParser.java | 2 +- .../loader/ProviderRegistryLoader.java | 2 +- .../chest/DoubleChestInventoryTranslator.java | 2 +- 8 files changed, 33 insertions(+), 79 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java index 55ef704ad85..bbbd4415296 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java @@ -101,7 +101,12 @@ public Builder properties(GeyserEntityProperties.@Nullable Builder propertiesBui } BedrockEntityDefinition build() { - return new BedrockEntityDefinition(identifier, propertiesBuilder != null ? propertiesBuilder.build() : new GeyserEntityProperties()); + BedrockEntityDefinition definition = new BedrockEntityDefinition( + identifier, + propertiesBuilder != null ? propertiesBuilder.build() : new GeyserEntityProperties() + ); + Registries.BEDROCK_ENTITY_DEFINITIONS.get().put(identifier, definition); + return definition; } } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java index b9edb0d8d63..613c976fed5 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java @@ -160,7 +160,6 @@ public VanillaEntityType build(boolean register) { .properties(propertiesBuilder) .identifier(identifier) .build(); - Registries.BEDROCK_ENTITY_DEFINITIONS.get().put(identifier, bedrockDefinition); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java index a14225b8833..c22f807bf8c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java +++ b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java @@ -188,6 +188,10 @@ public void preSpawnConsumer(Consumer<@NonNull GeyserEntity> consumer) { } public boolean callParrotEvent(PlayerEntity player, int variant, boolean right) { + if (EnvironmentUtils.IS_UNIT_TESTING) { + return true; + } + GeyserImpl.getInstance().eventBus().fire(new ServerAttachParrotsEvent(session) { @Override public GeyserPlayerEntity player() { @@ -246,7 +250,7 @@ public void preSpawnConsumer(Consumer<@NonNull GeyserEntity> consumer) { } }); - return bedrockEntityDefinition == null; + return bedrockEntityDefinition != null; } // Not assigned by default - preparation for cancellable entity spawning diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java index 49d93ce8d69..04d91994860 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java @@ -192,7 +192,7 @@ protected void setParrot(OptionalInt variant, boolean isLeft) { } // The parrot is a separate entity in Bedrock, but part of the player entity in Java EntitySpawnContext context = EntitySpawnContext.inherited(session, VanillaEntities.PARROT, this, position()); - if (context.callParrotEvent(this, variant.getAsInt(), !isLeft)) { + if (!context.callParrotEvent(this, variant.getAsInt(), !isLeft)) { GeyserImpl.getInstance().getLogger().debug(session, "Cancelled parrot spawn as definition is null!"); return; } diff --git a/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java b/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java index d9dee0fbfe9..4020c805c9a 100644 --- a/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java +++ b/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java @@ -36,24 +36,9 @@ import java.util.List; import java.util.Objects; -public class HitboxImpl implements Hitbox { +public record HitboxImpl(Vector3f min, Vector3f max, Vector3f pivot) implements Hitbox { - public static Hitbox EMPTY = new HitboxImpl(Vector3f.ZERO, Vector3f.ZERO, Vector3f.ZERO) { - @Override - public NbtMap toNbtMap() { - return NbtMap.EMPTY; - } - }; - - private final Vector3f min; - private final Vector3f max; - private final Vector3f pivot; - - public HitboxImpl(Vector3f min, Vector3f max, Vector3f pivot) { - this.min = min; - this.max = max; - this.pivot = pivot; - } + public static final Hitbox EMPTY = new HitboxImpl(Vector3f.ZERO, Vector3f.ZERO, Vector3f.ZERO); public static List fromMetaData(@Nullable NbtMap metaDataMap) { if (metaDataMap == null) { @@ -72,72 +57,33 @@ public static List fromMetaData(@Nullable NbtMap metaDataMap) { return boxes; } - public NbtMap toNbtMap() { + public static NbtMap toNbtMap(Hitbox hitbox) { + if (Objects.equals(EMPTY, hitbox)) { + return NbtMap.EMPTY; + } + return NbtMap.builder() - .putFloat("MinX", min.getX()) - .putFloat("MinY", min.getY()) - .putFloat("MinZ", min.getZ()) - .putFloat("MaxX", max.getX()) - .putFloat("MaxY", max.getY()) - .putFloat("MaxZ", max.getZ()) - .putFloat("PivotX", pivot.getX()) - .putFloat("PivotY", pivot.getY()) - .putFloat("PivotZ", pivot.getZ()) + .putFloat("MinX", hitbox.min().getX()) + .putFloat("MinY", hitbox.min().getY()) + .putFloat("MinZ", hitbox.min().getZ()) + .putFloat("MaxX", hitbox.max().getX()) + .putFloat("MaxY", hitbox.max().getY()) + .putFloat("MaxZ", hitbox.max().getZ()) + .putFloat("PivotX", hitbox.pivot().getX()) + .putFloat("PivotY", hitbox.pivot().getY()) + .putFloat("PivotZ", hitbox.pivot().getZ()) .build(); } public static NbtMap toNbtMap(List hitboxes) { List list = new ArrayList<>(); for (Hitbox hitbox : hitboxes) { - if (hitbox instanceof HitboxImpl impl) { - list.add(impl.toNbtMap()); - } else { - throw new IllegalArgumentException("Unknown hitbox class implementation: " + hitbox.getClass().getSimpleName()); - } + list.add(toNbtMap(hitbox)); } return NbtMap.builder().putList("Hitboxes", NbtType.COMPOUND, list).build(); } - @Override - public Vector3f min() { - return min; - } - - @Override - public Vector3f max() { - return max; - } - - @Override - public Vector3f pivot() { - return pivot; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) return true; - if (obj == null || obj.getClass() != this.getClass()) return false; - var that = (HitboxImpl) obj; - return Objects.equals(this.min, that.min) && - Objects.equals(this.max, that.max) && - Objects.equals(this.pivot, that.pivot); - } - - @Override - public int hashCode() { - return Objects.hash(min, max, pivot); - } - - @Override - public String toString() { - return "HitboxImpl[" + - "min=" + min + ", " + - "max=" + max + ", " + - "pivot=" + pivot + ']'; - } - - - public static class Builder implements Hitbox.Builder { + public static class BuilderImpl implements Hitbox.Builder { Vector3f min, max, pivot; @Override diff --git a/core/src/main/java/org/geysermc/geyser/item/parser/ItemStackParser.java b/core/src/main/java/org/geysermc/geyser/item/parser/ItemStackParser.java index e65f4390a7d..bc74129d1b9 100644 --- a/core/src/main/java/org/geysermc/geyser/item/parser/ItemStackParser.java +++ b/core/src/main/java/org/geysermc/geyser/item/parser/ItemStackParser.java @@ -192,7 +192,7 @@ private static void parseDataComponent(GeyserSession session, Data } catch (ClassCastException exception) { GeyserImpl.getInstance().getLogger().debug("Received incorrect object type for component " + type + "! Exception: %s", exception); } catch (Exception exception) { - GeyserImpl.getInstance().getLogger().debug("Failed to parse component " + type + " from " + raw + "! Exception: %s", exception); + GeyserImpl.getInstance().getLogger().debug("Failed to parse component " + type + " from " + raw + "! Exception: %s", exception); } } diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java index 85b5a31d595..a5b0d232e37 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/ProviderRegistryLoader.java @@ -218,7 +218,7 @@ public Map, ProviderSupplier> load(Map, ProviderSupplier> prov providers.put(GeyserEntityDataType.class, args -> GeyserEntityDataImpl.lookup((Class) args[0], (String) args[1])); providers.put(GeyserListEntityDataType.class, args -> GeyserListEntityDataImpl.lookup((Class) args[0], (Class) args[1], (String) args[2])); - providers.put(Hitbox.Builder.class, args -> new HitboxImpl.Builder()); + providers.put(Hitbox.Builder.class, args -> new HitboxImpl.BuilderImpl()); providers.put(Hitbox.class, args -> HitboxImpl.EMPTY); return providers; diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/chest/DoubleChestInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/chest/DoubleChestInventoryTranslator.java index 3ac43eca8d6..49a0bd9b1fc 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/chest/DoubleChestInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/chest/DoubleChestInventoryTranslator.java @@ -202,7 +202,7 @@ public void closeInventory(GeyserSession session, Container container, boolean f private boolean canUseRealBlock(GeyserSession session, Container container) { // See BlockInventoryHolder - same concept there except we're also dealing with a specific block state - if (session.getLastInteractionPlayerPosition().distance(session.getPlayerEntity().position()) < 2) { + if (session.getLastInteractionPlayerPosition().distance(session.getPlayerEntity().bedrockPosition()) < 2) { BlockState state = session.getGeyser().getWorldManager().blockAt(session, session.getLastInteractionBlockPosition()); if (!BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.get().containsKey(state.javaId())) { if (state.block() instanceof ChestBlock && state.getValue(Properties.CHEST_TYPE) != ChestType.SINGLE) { From d9e0c6b3fd38c3560f5596202ace619d261c440f Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sun, 15 Mar 2026 15:38:49 +0100 Subject: [PATCH 52/62] Improve height / width handling This will be later reworked to allow setting a height + width combo that accounts for the entity pose. For now, it's a general override --- .../entity/spawn/EntitySpawnContext.java | 17 ++---- .../geysermc/geyser/entity/type/Entity.java | 59 +++++++++++++++---- .../geyser/entity/type/LivingEntity.java | 14 +---- .../entity/type/living/AgeableEntity.java | 4 +- .../entity/type/living/ArmorStandEntity.java | 8 +-- .../type/living/animal/SnifferEntity.java | 4 +- .../type/living/animal/horse/CamelEntity.java | 4 +- .../living/monster/EnderDragonPartEntity.java | 10 +++- .../type/living/monster/PhantomEntity.java | 6 +- .../type/living/monster/ZoglinEntity.java | 2 +- .../entity/type/player/AvatarEntity.java | 4 +- .../type/player/SessionPlayerEntity.java | 4 +- .../impl/entity/GeyserEntityDataImpl.java | 6 +- .../entity/JavaEntityEventTranslator.java | 2 +- .../org/geysermc/geyser/util/EntityUtils.java | 8 +-- 15 files changed, 87 insertions(+), 65 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java index c22f807bf8c..c154a745c72 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java +++ b/core/src/main/java/org/geysermc/geyser/entity/spawn/EntitySpawnContext.java @@ -66,8 +66,6 @@ public class EntitySpawnContext { private float yaw; private float pitch; private float headYaw; - private float height; - private float width; private float offset; private @Nullable Long geyserId; private @Nullable Collection> consumers; @@ -77,28 +75,27 @@ public class EntitySpawnContext { }); public EntitySpawnContext(GeyserSession session, EntityTypeDefinition type, int javaId, UUID uuid) { - this(session, type, javaId, uuid, type.defaultBedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, - type.height(), type.width(), type.offset(), null); + this(session, type, javaId, uuid, type.defaultBedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, type.offset(), null); } - public EntitySpawnContext(GeyserSession session, EntityTypeDefinition type, int entityId, float height, float width, long geyserId) { - this(session, type, entityId, null, type.defaultBedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, height, width, 0, geyserId); + public EntitySpawnContext(GeyserSession session, EntityTypeDefinition type, int entityId, long geyserId) { + this(session, type, entityId, null, type.defaultBedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, 0, geyserId); } public static EntitySpawnContext fromPacket(GeyserSession session, EntityTypeDefinition definition, ClientboundAddEntityPacket packet) { Vector3f position = Vector3f.from(packet.getX(), packet.getY(), packet.getZ()); Vector3f motion = packet.getMovement().toFloat(); return new EntitySpawnContext(session, definition, packet.getEntityId(), packet.getUuid(), definition.defaultBedrockDefinition(), - position, motion, packet.getYaw(), packet.getPitch(), packet.getHeadYaw(), definition.height(), definition.width(), definition.offset(), null); + position, motion, packet.getYaw(), packet.getPitch(), packet.getHeadYaw(), definition.offset(), null); } public static EntitySpawnContext inherited(GeyserSession session, EntityTypeDefinition definition, Entity base, Vector3f position) { return new EntitySpawnContext(session, definition, 0, null, definition.defaultBedrockDefinition(), position, base.getMotion(), base.getYaw(), - base.getPitch(), base.getHeadYaw(), definition.height(), definition.width(), definition.offset(), null); + base.getPitch(), base.getHeadYaw(), definition.offset(), null); } public EntitySpawnContext(GeyserSession session, EntityTypeDefinition definition, int javaId, UUID uuid, BedrockEntityDefinition bedrockEntityDefinition, Vector3f position, - Vector3f motion, float yaw, float pitch, float headYaw, float height, float width, float offset, @Nullable Long geyserId) { + Vector3f motion, float yaw, float pitch, float headYaw, float offset, @Nullable Long geyserId) { this.session = session; this.entityTypeDefinition = definition; this.javaId = javaId; @@ -109,8 +106,6 @@ public EntitySpawnContext(GeyserSession session, EntityTypeDefinition definit this.yaw = yaw; this.pitch = pitch; this.headYaw = headYaw; - this.height = height; - this.width = width; this.offset = offset; this.geyserId = geyserId; this.consumers = null; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index bb179d7c992..fd343474db4 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -148,6 +148,11 @@ public class Entity implements GeyserEntity { protected boolean silent = false; /* Metadata end */ + // hacky temp solution till i can think of something better + // this would be the height / width of the bounding box regardless of pose etc + private float customBoundingBoxHeight; + private float customBoundingBoxWidth; + protected List passengers = Collections.emptyList(); protected Entity vehicle; /** @@ -174,11 +179,8 @@ public class Entity implements GeyserEntity { @Setter(AccessLevel.PROTECTED) // For players private boolean flagsDirty = false; - @Accessors(fluent = true) - protected float width; - @Accessors(fluent = true) - protected float height; protected float offset; + protected float scale = 1.0F; protected final @Nullable GeyserEntityPropertyManager propertyManager; @@ -194,8 +196,6 @@ public Entity(EntitySpawnContext context) { this.yaw = context.yaw(); this.pitch = context.pitch(); this.headYaw = context.headYaw(); - this.width = context.width(); - this.height = context.height(); this.offset = context.offset(); this.valid = false; this.propertyManager = bedrockDefinition.registeredProperties().isEmpty() ? null : new GeyserEntityPropertyManager(bedrockDefinition.registeredProperties()); @@ -210,12 +210,12 @@ public Entity(EntitySpawnContext context) { * Called on entity spawn. Used to populate the entity metadata and flags with default values. */ protected void initializeMetadata() { - dirtyMetadata.put(EntityDataTypes.WIDTH, width); - dirtyMetadata.put(EntityDataTypes.HEIGHT, height); - dirtyMetadata.put(EntityDataTypes.SCALE, 1f); + dirtyMetadata.put(EntityDataTypes.SCALE, scale); dirtyMetadata.put(EntityDataTypes.COLOR, (byte) 0); dirtyMetadata.put(EntityDataTypes.AIR_SUPPLY_MAX, getMaxAir()); setDimensionsFromPose(Pose.STANDING); + dirtyMetadata.put(EntityDataTypes.WIDTH, getBoundingBoxWidth()); + dirtyMetadata.put(EntityDataTypes.HEIGHT, getBoundingBoxHeight()); setFlag(EntityFlag.HAS_GRAVITY, true); setFlag(EntityFlag.HAS_COLLISION, true); setFlag(EntityFlag.CAN_SHOW_NAME, true); @@ -656,14 +656,14 @@ public void setPose(Pose pose) { */ protected void setDimensionsFromPose(Pose pose) { // No flexibility options for basic entities - setBoundingBoxHeight(height); - setBoundingBoxWidth(width); + setBoundingBoxHeight(javaTypeDefinition.height()); + setBoundingBoxWidth(javaTypeDefinition.width()); } public boolean setBoundingBoxHeight(float height) { if (height != boundingBoxHeight) { boundingBoxHeight = height; - dirtyMetadata.put(EntityDataTypes.HEIGHT, boundingBoxHeight); + dirtyMetadata.put(EntityDataTypes.HEIGHT, getBoundingBoxHeight()); updatePassengerOffsets(); return true; @@ -674,8 +674,41 @@ public boolean setBoundingBoxHeight(float height) { public void setBoundingBoxWidth(float width) { if (width != boundingBoxWidth) { boundingBoxWidth = width; - dirtyMetadata.put(EntityDataTypes.WIDTH, boundingBoxWidth); + dirtyMetadata.put(EntityDataTypes.WIDTH, getBoundingBoxWidth()); + } + } + + public float getBoundingBoxHeight() { + if (customBoundingBoxHeight != 0) { + return customBoundingBoxHeight; + } + return boundingBoxHeight; + } + + public float getBoundingBoxWidth() { + if (customBoundingBoxWidth != 0) { + return customBoundingBoxWidth; } + return boundingBoxWidth; + } + + public void setCustomBoundingBoxWidth(float width) { + this.customBoundingBoxWidth = width; + dirtyMetadata.put(EntityDataTypes.WIDTH, customBoundingBoxWidth); + } + + public void setCustomBoundingBoxHeight(float height) { + this.customBoundingBoxHeight = height; + dirtyMetadata.put(EntityDataTypes.HEIGHT, customBoundingBoxHeight); + } + + public void setScale(float scale) { + this.scale = scale; + applyScale(); + } + + protected void applyScale() { + dirtyMetadata.put(EntityDataTypes.SCALE, scale); } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java index ba3d56cba8f..b24829d55e4 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java @@ -94,12 +94,6 @@ public class LivingEntity extends Entity implements Tickable { */ private boolean isMaxFrozenState = false; - /** - * The base scale entity data, without attributes applied. Used for such cases as baby variants. - */ - @Getter(AccessLevel.NONE) - @Setter(AccessLevel.NONE) - private float scale; /** * The scale sent through the Java attributes packet */ @@ -340,17 +334,13 @@ public float setFreezing(IntEntityMetadata entityMetadata) { return freezingPercentage; } - protected void setScale(float scale) { - this.scale = scale; - applyScale(); - } - protected void setAttributeScale(float scale) { this.attributeScale = MathUtils.clamp(scale, GeyserAttributeType.SCALE.getMinimum(), GeyserAttributeType.SCALE.getMaximum()); applyScale(); } - private void applyScale() { + @Override + protected void applyScale() { // Take any adjustments Bedrock requires, and compute it alongside the attribute's additional changes this.dirtyMetadata.put(EntityDataTypes.SCALE, scale * attributeScale); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java index dc2ce1770b3..48e3e2077fa 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AgeableEntity.java @@ -47,8 +47,8 @@ public void setBaby(BooleanEntityMetadata entityMetadata) { setScale(isBaby ? getBabySize() : getAdultSize()); setFlag(EntityFlag.BABY, isBaby); - setBoundingBoxHeight(height * (isBaby ? getBabySize() : getAdultSize())); - setBoundingBoxWidth(width * (isBaby ? getBabySize() : getAdultSize())); + setBoundingBoxHeight(javaTypeDefinition.height() * (isBaby ? getBabySize() : getAdultSize())); + setBoundingBoxWidth(javaTypeDefinition.width() * (isBaby ? getBabySize() : getAdultSize())); } /** diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java index a016d0daaf2..26ff04ecb06 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java @@ -150,8 +150,8 @@ public void setArmorStandFlags(ByteEntityMetadata entityMetadata) { setBoundingBoxWidth(0.0f); setBoundingBoxHeight(0.0f); } else { - setBoundingBoxWidth(width); - setBoundingBoxHeight(height); + setBoundingBoxWidth(javaTypeDefinition.width()); + setBoundingBoxHeight(javaTypeDefinition.height()); } updateMountOffset(); @@ -412,13 +412,13 @@ public float getYOffset() { if (!positionRequiresOffset || isMarker || secondEntity != null) { return 0; } - return height * getScale(); + return getBoundingBoxHeight() * getScale(); } /** * @return the scale according to Java */ - private float getScale() { + public float getScale() { return isSmall ? 0.5f : 1f; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java index f4fc8c49caa..b997c4e9db3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SnifferEntity.java @@ -50,7 +50,7 @@ public class SnifferEntity extends AnimalEntity implements Tickable { public SnifferEntity(EntitySpawnContext context) { super(context); - diggingHeight = height - 0.4f; + diggingHeight = javaTypeDefinition.height() - 0.4f; } @Override @@ -63,7 +63,7 @@ public void setPose(Pose pose) { protected void setDimensionsFromPose(Pose pose) { if (getFlag(EntityFlag.DIGGING)) { setBoundingBoxHeight(diggingHeight); - setBoundingBoxWidth(width); + setBoundingBoxWidth(javaTypeDefinition.width()); } else { super.setDimensionsFromPose(pose); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java index 06b039ac634..2d0d8152601 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java @@ -108,8 +108,8 @@ public void setPose(Pose pose) { @Override protected void setDimensionsFromPose(Pose pose) { if (pose == Pose.SITTING) { - setBoundingBoxHeight(height - SITTING_HEIGHT_DIFFERENCE); - setBoundingBoxWidth(width); + setBoundingBoxHeight(javaTypeDefinition.height() - SITTING_HEIGHT_DIFFERENCE); + setBoundingBoxWidth(javaTypeDefinition.width()); } else { super.setDimensionsFromPose(pose); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java index bd1bf97e038..cdb43be01b1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/EnderDragonPartEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living.monster; import org.cloudburstmc.math.vector.Vector3f; +import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.MoveEntityAbsolutePacket; import org.geysermc.geyser.entity.VanillaEntities; @@ -36,7 +37,10 @@ public class EnderDragonPartEntity extends Entity { public EnderDragonPartEntity(GeyserSession session, int entityId, long geyserId, float width, float height) { - super(dragonPartSpawnContext(session, entityId, width, height, geyserId)); + super(dragonPartSpawnContext(session, entityId, geyserId)); + + dirtyMetadata.put(EntityDataTypes.WIDTH, width); + dirtyMetadata.put(EntityDataTypes.HEIGHT, height); setFlag(EntityFlag.INVISIBLE, true); setFlag(EntityFlag.FIRE_IMMUNE, true); @@ -61,7 +65,7 @@ public void moveAbsoluteRaw(Vector3f position, float yaw, float pitch, float hea session.getQueuedImmediatelyPackets().add(moveEntityPacket); } - public static EntitySpawnContext dragonPartSpawnContext(GeyserSession session, int entityId, float width, float height, long geyserId) { - return new EntitySpawnContext(session, VanillaEntities.ENDER_DRAGON_PART, entityId, height, width, geyserId); + public static EntitySpawnContext dragonPartSpawnContext(GeyserSession session, int entityId, long geyserId) { + return new EntitySpawnContext(session, VanillaEntities.ENDER_DRAGON_PART, entityId, geyserId); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java index e2d287c6520..ee5f2e7e411 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PhantomEntity.java @@ -37,10 +37,10 @@ public PhantomEntity(EntitySpawnContext context) { public void setPhantomScale(IntEntityMetadata entityMetadata) { int size = entityMetadata.getPrimitiveValue(); float modelScale = 1f + 0.15f * size; - float boundsScale = (1f + (0.2f * size) / width) / modelScale; + float boundsScale = (1f + (0.2f * size) / javaTypeDefinition.width()) / modelScale; - setBoundingBoxWidth(boundsScale * width); - setBoundingBoxHeight(boundsScale * height); + setBoundingBoxWidth(boundsScale * javaTypeDefinition.width()); + setBoundingBoxHeight(boundsScale * javaTypeDefinition.height()); setScale(modelScale); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java index bf5cca23eec..f681d063bc0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZoglinEntity.java @@ -50,7 +50,7 @@ public void setBaby(BooleanEntityMetadata entityMetadata) { @Override public float getBoundingBoxHeight() { float scale = getFlag(EntityFlag.BABY) ? 0.55f : 1f; - return scale * height; + return scale * javaTypeDefinition.height(); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java index 7df978f4492..993fa642395 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/AvatarEntity.java @@ -357,11 +357,11 @@ public void setDimensionsFromPose(Pose pose) { switch (pose) { case SNEAKING -> { height = SNEAKING_POSE_HEIGHT; - width = width(); + width = javaTypeDefinition.width(); } case FALL_FLYING, SPIN_ATTACK, SWIMMING -> { height = 0.6f; - width = width(); + width = javaTypeDefinition.width(); } case DYING -> { height = 0.2f; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java index 86c8704ccbd..96865a89efb 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java @@ -480,8 +480,8 @@ public void setVehicle(Entity entity) { entity.setBoundingBoxHeight(0.5625F); entity.updateBedrockMetadata(); } else if (entity == null && this.vehicle instanceof BoatEntity) { - this.vehicle.setBoundingBoxWidth(this.vehicle.width()); - this.vehicle.setBoundingBoxHeight(this.vehicle.height()); + this.vehicle.setBoundingBoxWidth(this.vehicle.getBoundingBoxWidth()); + this.vehicle.setBoundingBoxHeight(this.vehicle.getBoundingBoxHeight()); this.vehicle.updateBedrockMetadata(); } diff --git a/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java b/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java index 5a08f7cbd4f..67ec30b7f51 100644 --- a/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java +++ b/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java @@ -46,9 +46,9 @@ public class GeyserEntityDataImpl implements GeyserEntityDataType { TYPES = new Object2ObjectOpenHashMap<>(); TYPES.put("color", new GeyserEntityDataImpl<>(Byte.class, "color", EntityDataTypes.COLOR)); TYPES.put("variant", new GeyserEntityDataImpl<>(Integer.class, "variant", EntityDataTypes.VARIANT)); - TYPES.put("width", new GeyserEntityDataImpl<>(Float.class, "width", EntityDataTypes.WIDTH)); - TYPES.put("height", new GeyserEntityDataImpl<>(Float.class, "height", EntityDataTypes.HEIGHT)); - TYPES.put("scale", new GeyserEntityDataImpl<>(Float.class, "scale", EntityDataTypes.SCALE)); + TYPES.put("width", new GeyserEntityDataImpl<>(Float.class, "width", Entity::setCustomBoundingBoxWidth, Entity::getCustomBoundingBoxWidth)); + TYPES.put("height", new GeyserEntityDataImpl<>(Float.class, "height", Entity::setCustomBoundingBoxHeight, Entity::getCustomBoundingBoxHeight)); + TYPES.put("scale", new GeyserEntityDataImpl<>(Float.class, "scale", Entity::setScale, Entity::getScale)); // "custom" TYPES.put("vertical_offset", new GeyserEntityDataImpl<>(Float.class, "vertical_offset", (entity, value) -> entity.offset(value, true), Entity::getOffset)); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java index 930ca1cca67..4f663147ec8 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java @@ -216,7 +216,7 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet case VILLAGER_SWEAT: LevelEventPacket levelEventPacket = new LevelEventPacket(); levelEventPacket.setType(ParticleType.WATER_SPLASH); - levelEventPacket.setPosition(entity.bedrockPosition().up(entity.height())); + levelEventPacket.setPosition(entity.bedrockPosition().up(entity.getBoundingBoxHeight())); session.sendUpstreamPacket(levelEventPacket); return; case IRON_GOLEM_EMPTY_HAND: diff --git a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java index 190f1019938..57ad1295d6a 100644 --- a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java @@ -279,20 +279,20 @@ public static void updateMountOffset(Entity passenger, Entity mount, boolean rid if (mountDefinition.is(BuiltinEntityType.MINECART) || mountDefinition.is(BuiltinEntityType.HOPPER_MINECART) || mountDefinition.is(BuiltinEntityType.TNT_MINECART) || mountDefinition.is(BuiltinEntityType.CHEST_MINECART) || mountDefinition.is(BuiltinEntityType.FURNACE_MINECART) || mountDefinition.is(BuiltinEntityType.SPAWNER_MINECART) || mountDefinition.is(BuiltinEntityType.COMMAND_BLOCK_MINECART)) { - yOffset -= mount.height() * 0.5f; + yOffset -= mount.getBoundingBoxHeight() * 0.5f; } if (passengerDefinition.is(BuiltinEntityType.MINECART) || passengerDefinition.is(BuiltinEntityType.HOPPER_MINECART) || passengerDefinition.is(BuiltinEntityType.TNT_MINECART) || passengerDefinition.is(BuiltinEntityType.CHEST_MINECART) || passengerDefinition.is(BuiltinEntityType.FURNACE_MINECART) || passengerDefinition.is(BuiltinEntityType.SPAWNER_MINECART) || passengerDefinition.is(BuiltinEntityType.COMMAND_BLOCK_MINECART) || passengerDefinition.is(BuiltinEntityType.SHULKER)) { - yOffset += passenger.height() * 0.5f; + yOffset += passenger.getBoundingBoxHeight() * 0.5f; } else if (passengerDefinition.is(BuiltinEntityType.FALLING_BLOCK)) { yOffset += 0.995f; } if (mount instanceof BoatEntity) { - yOffset -= mount.height() * 0.5f; + yOffset -= mount.getBoundingBoxHeight() * 0.5f; } if (passenger instanceof BoatEntity) { - yOffset += passenger.height() * 0.5f; + yOffset += passenger.getBoundingBoxHeight() * 0.5f; } if (mount instanceof ArmorStandEntity armorStand) { yOffset -= armorStand.getYOffset(); From a21d9e81f9a9ee6046190e6dd8ccf563df801558 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sun, 15 Mar 2026 17:35:47 +0100 Subject: [PATCH 53/62] Allow custom height / width to be 0 --- .../main/java/org/geysermc/geyser/entity/type/Entity.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index fd343474db4..6cc52b824a8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -150,8 +150,8 @@ public class Entity implements GeyserEntity { // hacky temp solution till i can think of something better // this would be the height / width of the bounding box regardless of pose etc - private float customBoundingBoxHeight; - private float customBoundingBoxWidth; + private Float customBoundingBoxHeight; + private Float customBoundingBoxWidth; protected List passengers = Collections.emptyList(); protected Entity vehicle; @@ -679,14 +679,14 @@ public void setBoundingBoxWidth(float width) { } public float getBoundingBoxHeight() { - if (customBoundingBoxHeight != 0) { + if (customBoundingBoxHeight != null) { return customBoundingBoxHeight; } return boundingBoxHeight; } public float getBoundingBoxWidth() { - if (customBoundingBoxWidth != 0) { + if (customBoundingBoxWidth != null) { return customBoundingBoxWidth; } return boundingBoxWidth; From 34b1d986b52db9bae2667820cc124a8bcb5696ff Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sat, 21 Mar 2026 00:07:17 +0100 Subject: [PATCH 54/62] Likely fix entity registration --- .../geyser/entity/BedrockEntityDefinition.java | 12 +++++------- .../geysermc/geyser/entity/VanillaEntityType.java | 1 + 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java index bbbd4415296..78d3d355f4e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java @@ -49,7 +49,9 @@ public static Builder builder() { } public static BedrockEntityDefinition ofVanilla(Identifier identifier) { - return builder().identifier(identifier).build(); + BedrockEntityDefinition bedrockEntityDefinition = builder().identifier(identifier).build(); + Registries.BEDROCK_ENTITY_DEFINITIONS.register(identifier, bedrockEntityDefinition); + return bedrockEntityDefinition; } public static BedrockEntityDefinition getOrCreate(@NonNull Identifier identifier) { @@ -101,12 +103,8 @@ public Builder properties(GeyserEntityProperties.@Nullable Builder propertiesBui } BedrockEntityDefinition build() { - BedrockEntityDefinition definition = new BedrockEntityDefinition( - identifier, - propertiesBuilder != null ? propertiesBuilder.build() : new GeyserEntityProperties() - ); - Registries.BEDROCK_ENTITY_DEFINITIONS.get().put(identifier, definition); - return definition; + return new BedrockEntityDefinition(identifier, propertiesBuilder != null ? + propertiesBuilder.build() : new GeyserEntityProperties()); } } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java index 613c976fed5..24ad69def03 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/VanillaEntityType.java @@ -160,6 +160,7 @@ public VanillaEntityType build(boolean register) { .properties(propertiesBuilder) .identifier(identifier) .build(); + Registries.BEDROCK_ENTITY_DEFINITIONS.register(identifier, bedrockDefinition); } } From ed4e0c66e552e49f7de467417e5e829f42695778 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Sat, 11 Apr 2026 23:07:51 +0200 Subject: [PATCH 55/62] Reduce diff, fix issue related to odd entity movement --- .../entity/custom/CustomJavaEntityType.java | 12 +++++++----- .../geyser/api/entity/data/types/Hitbox.java | 15 ++++++++------- .../definition/GeyserEntityDefinition.java | 4 ++-- .../api/entity/definition/JavaEntityType.java | 3 ++- .../lifecycle/GeyserDefineEntitiesEvent.java | 6 +++--- .../geysermc/geyser/api/util/Identifier.java | 2 -- .../geyser/entity/BedrockEntityDefinition.java | 2 +- .../entity/properties/type/PropertyType.java | 6 +++++- .../entity/spawn/EntitySpawnContext.java | 15 ++++++++------- .../geysermc/geyser/entity/type/Entity.java | 2 +- .../geyser/entity/type/EvokerFangsEntity.java | 2 +- .../geyser/entity/type/FireballEntity.java | 8 ++++---- .../geyser/entity/type/FishingHookEntity.java | 18 +++++++++--------- .../geyser/entity/type/InteractionEntity.java | 10 +++++----- .../geyser/entity/type/LivingEntity.java | 2 +- .../geyser/entity/type/PaintingEntity.java | 4 ++-- .../entity/type/living/ArmorStandEntity.java | 8 ++++---- .../entity/type/living/MagmaCubeEntity.java | 4 ++-- .../geyser/entity/type/living/SquidEntity.java | 8 ++++---- .../entity/type/player/PlayerEntity.java | 10 +++++----- .../geyser/impl/entity/HitboxImpl.java | 2 +- .../org/geysermc/geyser/util/EntityUtils.java | 7 ++++--- 22 files changed, 79 insertions(+), 71 deletions(-) diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java index 2181dd2ba5f..6c3b91bf73d 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java @@ -26,7 +26,9 @@ package org.geysermc.geyser.api.entity.custom; import org.checkerframework.checker.index.qual.NonNegative; +import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.common.returnsreceiver.qual.This; import org.geysermc.geyser.api.entity.definition.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.definition.JavaEntityType; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; @@ -52,28 +54,28 @@ interface Builder { * @param entityType the identifier * @return this builder */ - Builder type(Identifier entityType); + @This Builder type(@NonNull Identifier entityType); /** * The entity type's numeric network id. * @param javaId the java id * @return this builder */ - Builder javaId(int javaId); + @This Builder javaId(int javaId); /** * The width of this entity. * @param width the width of this entity * @return this builder */ - Builder width(@NonNegative float width); + @This Builder width(@NonNegative float width); /** * The height of this entity * @param height the height * @return this builder */ - Builder height(@NonNegative float height); + @This Builder height(@NonNegative float height); /** * The default Bedrock edition entity definition. @@ -84,6 +86,6 @@ interface Builder { * @param defaultBedrockDefinition the default Bedrock definition * @return this builder */ - Builder definition(@Nullable GeyserEntityDefinition defaultBedrockDefinition); + @This Builder definition(@Nullable GeyserEntityDefinition defaultBedrockDefinition); } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java index 708a9d2e2c0..915efbfc80a 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.api.entity.data.types; import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.common.returnsreceiver.qual.This; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.api.GeyserApi; @@ -43,19 +44,19 @@ public interface Hitbox { * The min "corner" of the hitbox * @return the vector of the corner */ - Vector3f min(); + @NonNull Vector3f min(); /** * The max "corner" of the hitbox * @return the vector of the corner */ - Vector3f max(); + @NonNull Vector3f max(); /** * The pivot of the hitbox * @return the pivot */ - Vector3f pivot(); + @NonNull Vector3f pivot(); static Builder builder() { return GeyserApi.api().provider(Builder.class); @@ -71,21 +72,21 @@ interface Builder { * @param min the vector of the corner * @return this builder */ - Builder min(@NonNull Vector3f min); + @This Builder min(@NonNull Vector3f min); /** * Sets the max corner of the hitbox * @param max the vector of the corner * @return this builder */ - Builder max(@NonNull Vector3f max); + @This Builder max(@NonNull Vector3f max); /** * Sets the pivot of the hitbox * @param pivot the pivot vector * @return this builder */ - Builder pivot(@NonNull Vector3f pivot); + @This Builder pivot(@NonNull Vector3f pivot); /** * Builds this hitbox, defaulting to {@code Vector3f.ZERO} if @@ -93,6 +94,6 @@ interface Builder { * * @return a new hitbox */ - Hitbox build(); + @NonNull Hitbox build(); } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/definition/GeyserEntityDefinition.java b/api/src/main/java/org/geysermc/geyser/api/entity/definition/GeyserEntityDefinition.java index 6e720e2bc8f..63e8d257a01 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/definition/GeyserEntityDefinition.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/definition/GeyserEntityDefinition.java @@ -43,12 +43,12 @@ public interface GeyserEntityDefinition { /** * @return the Bedrock entity identifier */ - Identifier identifier(); + @NonNull Identifier identifier(); /** * @return the properties registered for this entity type */ - List> properties(); + @NonNull List> properties(); /** * @return whether this entity is a vanilla entity diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/definition/JavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/definition/JavaEntityType.java index c7b7f865c78..67c895a178e 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/definition/JavaEntityType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/definition/JavaEntityType.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.api.entity.definition; +import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.api.util.Identifier; @@ -36,7 +37,7 @@ public interface JavaEntityType { /** * @return the Java identifier of the type */ - Identifier identifier(); + @NonNull Identifier identifier(); /** * @return the numeric Java entity type id diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java index 9bfeb78a27e..42a6aa863e6 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java @@ -44,12 +44,12 @@ public interface GeyserDefineEntitiesEvent extends Event { /** * @return an immutable collection of all registered entity definitions */ - Collection entities(); + @NonNull Collection<@NonNull GeyserEntityDefinition> entities(); /** * @return an immutable collection of all registered custom entity definitions */ - Collection customEntities(); + @NonNull Collection<@NonNull CustomEntityDefinition> customEntities(); /** * Registers a custom entity definition @@ -62,5 +62,5 @@ public interface GeyserDefineEntitiesEvent extends Event { * * @param builderConsumer the builder for the non-vanilla type */ - void registerEntityType(Consumer builderConsumer); + void registerEntityType(@NonNull Consumer builderConsumer); } diff --git a/api/src/main/java/org/geysermc/geyser/api/util/Identifier.java b/api/src/main/java/org/geysermc/geyser/api/util/Identifier.java index 0e4997dd928..069485611f2 100644 --- a/api/src/main/java/org/geysermc/geyser/api/util/Identifier.java +++ b/api/src/main/java/org/geysermc/geyser/api/util/Identifier.java @@ -29,8 +29,6 @@ import org.geysermc.geyser.api.GeyserApi; import org.jetbrains.annotations.ApiStatus; -// TODO: using static Identifiers, both in API and by API users, is not really possible at the moment, since providers have to be registered first, which probably won't have happened -// when a class's clinit is run /** * An identifying object for representing unique objects. * This identifier consists of two parts: diff --git a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java index 78d3d355f4e..6bb318c988f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/BedrockEntityDefinition.java @@ -67,7 +67,7 @@ public static BedrockEntityDefinition getOrCreate(@NonNull Identifier identifier } @Override - public List> properties() { + public @NonNull List> properties() { if (registeredProperties.isEmpty()) { return List.of(); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/properties/type/PropertyType.java b/core/src/main/java/org/geysermc/geyser/entity/properties/type/PropertyType.java index 55af16bb248..bf79ccbb40b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/properties/type/PropertyType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/properties/type/PropertyType.java @@ -28,6 +28,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.protocol.bedrock.data.entity.EntityProperty; +import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.entity.properties.GeyserEntityPropertyManager; @@ -39,7 +40,10 @@ public interface PropertyType type, int javaId, UUID uuid) { - this(session, type, javaId, uuid, type.defaultBedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, type.offset(), null); + this(session, type, javaId, uuid, type.defaultBedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, null); } public EntitySpawnContext(GeyserSession session, EntityTypeDefinition type, int entityId, long geyserId) { - this(session, type, entityId, null, type.defaultBedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, 0, geyserId); + this(session, type, entityId, null, type.defaultBedrockDefinition(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, geyserId); } public static EntitySpawnContext fromPacket(GeyserSession session, EntityTypeDefinition definition, ClientboundAddEntityPacket packet) { Vector3f position = Vector3f.from(packet.getX(), packet.getY(), packet.getZ()); Vector3f motion = packet.getMovement().toFloat(); return new EntitySpawnContext(session, definition, packet.getEntityId(), packet.getUuid(), definition.defaultBedrockDefinition(), - position, motion, packet.getYaw(), packet.getPitch(), packet.getHeadYaw(), definition.offset(), null); + position, motion, packet.getYaw(), packet.getPitch(), packet.getHeadYaw(), null); } public static EntitySpawnContext inherited(GeyserSession session, EntityTypeDefinition definition, Entity base, Vector3f position) { return new EntitySpawnContext(session, definition, 0, null, definition.defaultBedrockDefinition(), position, base.getMotion(), base.getYaw(), - base.getPitch(), base.getHeadYaw(), definition.offset(), null); + base.getPitch(), base.getHeadYaw(), null); } public EntitySpawnContext(GeyserSession session, EntityTypeDefinition definition, int javaId, UUID uuid, BedrockEntityDefinition bedrockEntityDefinition, Vector3f position, - Vector3f motion, float yaw, float pitch, float headYaw, float offset, @Nullable Long geyserId) { + Vector3f motion, float yaw, float pitch, float headYaw, @Nullable Long geyserId) { this.session = session; this.entityTypeDefinition = definition; this.javaId = javaId; this.uuid = uuid; this.position = position; - this.offset = definition.offset(); this.bedrockEntityDefinition = bedrockEntityDefinition; this.motion = motion; this.yaw = yaw; @@ -182,6 +180,9 @@ public void preSpawnConsumer(Consumer<@NonNull GeyserEntity> consumer) { return bedrockEntityDefinition != null; } + /** + * @return true if the parrot should be spawned + */ public boolean callParrotEvent(PlayerEntity player, int variant, boolean right) { if (EnvironmentUtils.IS_UNIT_TESTING) { return true; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index f8ec8711892..3784daefc4c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -195,7 +195,7 @@ public Entity(EntitySpawnContext context) { this.valid = false; this.propertyManager = bedrockDefinition.registeredProperties().isEmpty() ? null : new GeyserEntityPropertyManager(bedrockDefinition.registeredProperties()); - setOffset(context.offset()); + setOffset(javaTypeDefinition.offset()); setPosition(context.position()); setAirSupply(getMaxAir()); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java index 4cce8ea0217..6a79bec4dca 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/EvokerFangsEntity.java @@ -57,7 +57,7 @@ public void setAttackStarted() { if (!silent) { // Play the chomp sound PlaySoundPacket packet = new PlaySoundPacket(); - packet.setPosition(bedrockPosition()); + packet.setPosition(this.bedrockPosition()); packet.setSound("mob.evocation_fangs.attack"); packet.setVolume(1.0f); packet.setPitch(ThreadLocalRandom.current().nextFloat() * 0.2f + 0.85f); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java index 01e9f3a5e9e..9b8cdc02010 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FireballEntity.java @@ -55,15 +55,15 @@ private Vector3f tickMovement(Vector3f position) { } @Override - protected void moveAbsoluteImmediate(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + protected void moveAbsoluteImmediate(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { // Advance the position by a few ticks before sending it to Bedrock Vector3f lastMotion = motion; - Vector3f newPosition = javaPosition; + Vector3f newPosition = position; for (int i = 0; i < futureTicks; i++) { newPosition = tickMovement(newPosition); } super.moveAbsoluteImmediate(newPosition, yaw, pitch, headYaw, isOnGround, teleported); - setPosition(javaPosition); + setPosition(position); this.motion = lastMotion; } @@ -72,6 +72,6 @@ public void tick() { if (removedInVoid() || vehicle != null) { return; } - moveAbsoluteImmediate(tickMovement(position()), getYaw(), getPitch(), getHeadYaw(), false, false); + moveAbsoluteImmediate(tickMovement(position), getYaw(), getPitch(), getHeadYaw(), false, false); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java index e9f16cf672b..3bdbe428c9e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/FishingHookEntity.java @@ -95,10 +95,10 @@ public void setHookedEntity(IntEntityMetadata entityMetadata) { } @Override - protected void moveAbsoluteImmediate(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - boundingBox.setMiddleX(javaPosition.getX()); - boundingBox.setMiddleY(javaPosition.getY() + boundingBox.getSizeY() / 2); - boundingBox.setMiddleZ(javaPosition.getZ()); + protected void moveAbsoluteImmediate(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + boundingBox.setMiddleX(position.getX()); + boundingBox.setMiddleY(position.getY() + boundingBox.getSizeY() / 2); + boundingBox.setMiddleZ(position.getZ()); boolean touchingWater = false; boolean collided = false; @@ -113,7 +113,7 @@ protected void moveAbsoluteImmediate(Vector3f javaPosition, float yaw, float pit } double waterHeight = BlockStateValues.getWaterHeight(blockID); - if (waterHeight != -1 && javaPosition.getY() <= (iter.getY() + waterHeight)) { + if (waterHeight != -1 && position.getY() <= (iter.getY() + waterHeight)) { touchingWater = true; } } @@ -124,9 +124,9 @@ protected void moveAbsoluteImmediate(Vector3f javaPosition, float yaw, float pit inWater = touchingWater; if (!collided) { - super.moveAbsoluteImmediate(javaPosition, yaw, pitch, headYaw, isOnGround, teleported); + super.moveAbsoluteImmediate(position, yaw, pitch, headYaw, isOnGround, teleported); } else { - super.moveAbsoluteImmediate(this.position(), yaw, pitch, headYaw, true, true); + super.moveAbsoluteImmediate(this.position, yaw, pitch, headYaw, true, true); } } @@ -157,7 +157,7 @@ public void tick() { float gravity = getGravity(); motion = motion.down(gravity); - moveAbsoluteImmediate(position().add(motion), getYaw(), getPitch(), getHeadYaw(), isOnGround(), false); + moveAbsoluteImmediate(position.add(motion), getYaw(), getPitch(), getHeadYaw(), isOnGround(), false); float drag = getDrag(); motion = motion.mul(drag); @@ -175,7 +175,7 @@ protected float getGravity() { * @return true if this entity is currently in air. */ protected boolean isInAir() { - int block = session.getGeyser().getWorldManager().getBlockAt(session, position().toInt()); + int block = session.getGeyser().getWorldManager().getBlockAt(session, position.toInt()); return block == Block.JAVA_AIR_ID; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java index aa9a12fcb94..3ee9cda7576 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java @@ -116,15 +116,15 @@ public void despawnEntity() { @Override public void moveRelativeRaw(double relX, double relY, double relZ, float yaw, float pitch, float headYaw, boolean isOnGround) { - moveAbsoluteRaw(position().add(relX, relY, relZ), yaw, pitch, headYaw, isOnGround, false); + moveAbsoluteRaw(position.add(relX, relY, relZ), yaw, pitch, headYaw, isOnGround, false); } @Override - public void moveAbsoluteRaw(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + public void moveAbsoluteRaw(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { if (secondEntity != null) { - secondEntity.moveAbsoluteRaw(javaPosition.up(getBoundingBoxHeight()), yaw, pitch, headYaw, isOnGround, teleported); + secondEntity.moveAbsoluteRaw(position.up(getBoundingBoxHeight()), yaw, pitch, headYaw, isOnGround, teleported); } - super.moveAbsoluteRaw(javaPosition, yaw, pitch, headYaw, isOnGround, teleported); + super.moveAbsoluteRaw(position, yaw, pitch, headYaw, isOnGround, teleported); } public void setWidth(FloatEntityMetadata width) { @@ -138,7 +138,7 @@ public void setHeight(FloatEntityMetadata height) { setBoundingBoxHeight(Math.min(height.getPrimitiveValue(), 64f)); if (secondEntity != null) { - secondEntity.moveAbsoluteRaw(position().up(getBoundingBoxHeight()), yaw, pitch, headYaw, onGround, true); + secondEntity.moveAbsoluteRaw(position.up(getBoundingBoxHeight()), yaw, pitch, headYaw, onGround, true); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java index 0793a22b8fc..8cf2bbf6735 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java @@ -427,7 +427,7 @@ public void moveRelative(double relX, double relY, double relZ, float yaw, float } @Override - public void moveAbsolute(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { // It's vanilla behaviour to lerp if the position is within 64 blocks, however we also check if the position is close enough to the player // position to see if it can actually affect anything to save network. if (shouldLerp() && position.distanceSquared(this.position) < 4096 && position.distanceSquared(session.getPlayerEntity().position()) < 4096) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java index 15c3bf7fc64..f3e9e5fd744 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/PaintingEntity.java @@ -92,7 +92,7 @@ private void updatePainting() { valid = true; - session.getGeyser().getLogger().debug("Spawned painting on " + position()); + session.getGeyser().getLogger().debug("Spawned painting on " + position); } @Override @@ -101,7 +101,7 @@ public void updateHeadLookRotation(float headYaw) { } private Vector3f fixOffset(PaintingType paintingName) { - Vector3f position = position(); + Vector3f position = super.position; // ViaVersion already adds the offset for us on older versions, // so no need to do it then otherwise it will be spaced if (session.isEmulatePost1_18Logic()) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java index c8a85a58559..0dedf63041c 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java @@ -109,13 +109,13 @@ public void moveRelativeRaw(double relX, double relY, double relZ, float yaw, fl } @Override - public void moveAbsoluteRaw(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + public void moveAbsoluteRaw(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { if (secondEntity != null) { - secondEntity.moveAbsoluteRaw(javaPosition, yaw, pitch, headYaw, isOnGround, teleported); + secondEntity.moveAbsoluteRaw(position, yaw, pitch, headYaw, isOnGround, teleported); } // Fake the height to be above where it is so the nametag appears in the right location setOffset(getYOffset()); - super.moveAbsoluteRaw(javaPosition, yaw, yaw, yaw, isOnGround, teleported); + super.moveAbsoluteRaw(position, yaw, yaw, yaw, isOnGround, teleported); } @Override @@ -235,7 +235,7 @@ public void updateBedrockMetadata() { super.updateBedrockMetadata(); if (positionUpdateRequired) { positionUpdateRequired = false; - moveAbsoluteRaw(position(), yaw, pitch, headYaw, onGround, true); + moveAbsoluteRaw(position, yaw, pitch, headYaw, onGround, true); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java index 3f9036d4342..b1c05983c48 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/MagmaCubeEntity.java @@ -42,9 +42,9 @@ public void moveRelativeRaw(double relX, double relY, double relZ, float yaw, fl } @Override - public void moveAbsoluteRaw(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + public void moveAbsoluteRaw(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { updateJump(isOnGround); - super.moveAbsoluteRaw(javaPosition, yaw, pitch, headYaw, isOnGround, teleported); + super.moveAbsoluteRaw(position, yaw, pitch, headYaw, isOnGround, teleported); } public void updateJump(boolean newOnGround) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java index 6954125ad09..12c883afe85 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/SquidEntity.java @@ -44,7 +44,7 @@ public class SquidEntity extends AgeableWaterEntity implements Tickable { public SquidEntity(EntitySpawnContext context) { super(context); - this.lastPosition = position().toInt(); + this.lastPosition = position.toInt(); } @Override @@ -91,8 +91,8 @@ public void moveRelativeRaw(double relX, double relY, double relZ, float yaw, fl } @Override - public void moveAbsoluteRaw(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - super.moveAbsoluteRaw(javaPosition, yaw, pitch, headYaw, isOnGround, teleported); + public void moveAbsoluteRaw(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + super.moveAbsoluteRaw(position, yaw, pitch, headYaw, isOnGround, teleported); checkInWater(); } @@ -132,7 +132,7 @@ public boolean canBeLeashed() { } private void checkInWater() { - Vector3i newPosition = position().toInt(); + Vector3i newPosition = position.toInt(); if (newPosition.equals(lastPosition)) { return; } else { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java index fb474e3eb97..51c11cc072a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java @@ -141,13 +141,13 @@ public void sendPlayer() { } @Override - public void moveAbsoluteRaw(Vector3f javaPosition, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { - super.moveAbsoluteRaw(javaPosition, yaw, pitch, headYaw, isOnGround, teleported); + public void moveAbsoluteRaw(Vector3f position, float yaw, float pitch, float headYaw, boolean isOnGround, boolean teleported) { + super.moveAbsoluteRaw(position, yaw, pitch, headYaw, isOnGround, teleported); if (leftParrot != null) { - leftParrot.moveAbsoluteRaw(javaPosition, yaw, pitch, headYaw, true, teleported); + leftParrot.moveAbsoluteRaw(position, yaw, pitch, headYaw, true, teleported); } if (rightParrot != null) { - rightParrot.moveAbsoluteRaw(javaPosition, yaw, pitch, headYaw, true, teleported); + rightParrot.moveAbsoluteRaw(position, yaw, pitch, headYaw, true, teleported); } } @@ -193,7 +193,7 @@ protected void setParrot(OptionalInt variant, boolean isLeft) { // The parrot is a separate entity in Bedrock, but part of the player entity in Java EntitySpawnContext context = EntitySpawnContext.inherited(session, VanillaEntities.PARROT, this, position()); if (!context.callParrotEvent(this, variant.getAsInt(), !isLeft)) { - GeyserImpl.getInstance().getLogger().debug(session, "Cancelled parrot spawn as definition is null!"); + GeyserImpl.getInstance().getLogger().debug(session, "Cancelled parrot spawn event as definition is null!"); return; } ParrotEntity parrot = new ParrotEntity(context); diff --git a/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java b/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java index 4020c805c9a..902bde27eab 100644 --- a/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java +++ b/core/src/main/java/org/geysermc/geyser/impl/entity/HitboxImpl.java @@ -108,7 +108,7 @@ public Hitbox.Builder pivot(@NonNull Vector3f pivot) { } @Override - public Hitbox build() { + public @NonNull Hitbox build() { return new HitboxImpl(min == null ? Vector3f.ZERO : min, max == null ? Vector3f.ZERO : max, pivot == null ? Vector3f.ZERO : pivot); } } diff --git a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java index 57ad1295d6a..82de2353c80 100644 --- a/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/EntityUtils.java @@ -400,12 +400,12 @@ public static void callEntityEvents() { GeyserImpl.getInstance().getEventBus().fire(new GeyserDefineEntitiesEvent() { @Override - public Collection entities() { + public @NonNull Collection entities() { return Collections.unmodifiableCollection(Registries.BEDROCK_ENTITY_DEFINITIONS.get().values()); } @Override - public Collection customEntities() { + public @NonNull Collection customEntities() { return Collections.unmodifiableCollection(customEntities); } @@ -426,7 +426,8 @@ public void register(@NonNull CustomEntityDefinition entityDefinition) { } @Override - public void registerEntityType(Consumer consumer) { + public void registerEntityType(@NonNull Consumer consumer) { + Objects.requireNonNull(consumer); var builder = new GeyserEntityType.GeyserJavaEntityTypeBuild(); consumer.accept(builder); From f7b6ae81dc87cdf73be444b054a659f15110dc02 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Mon, 27 Apr 2026 03:11:33 +0200 Subject: [PATCH 56/62] Work around pistons creating ghost blocks --- .../geyser/translator/level/block/entity/PistonBlockEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/PistonBlockEntity.java b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/PistonBlockEntity.java index 3e5554436f3..2cfd3ae89d5 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/PistonBlockEntity.java +++ b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/PistonBlockEntity.java @@ -651,7 +651,7 @@ private void placeFinalBlocks() { blockPos = blockPos.add(movement); // Don't place blocks that collide with the player if (!SOLID_BOUNDING_BOX.checkIntersection(blockPos.toDouble(), playerBoundingBox)) { - ChunkUtils.updateBlock(session, state, blockPos); + ChunkUtils.updateBlock(session, session.getGeyser().getWorldManager().blockAt(session, blockPos), blockPos); } }); if (action == PistonValueType.PUSHING) { From 04bd44b3af176a66d55894c157de53a4bbef824f Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Wed, 29 Apr 2026 01:38:02 +0200 Subject: [PATCH 57/62] Feature: Expose basic seat offset / update entity passengers event --- .../entity/data/GeyserEntityDataTypes.java | 9 +++ .../geyser/api/entity/type/GeyserEntity.java | 11 +++ .../ServerUpdateEntityPassengersEvent.java | 71 +++++++++++++++++++ .../geysermc/geyser/entity/type/Entity.java | 15 ++++ .../impl/entity/GeyserEntityDataImpl.java | 2 + .../entity/JavaSetPassengersTranslator.java | 42 ++++++++--- 6 files changed, 142 insertions(+), 8 deletions(-) create mode 100644 api/src/main/java/org/geysermc/geyser/api/event/java/ServerUpdateEntityPassengersEvent.java diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java index 2ec611b1359..e526d0f74c1 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataTypes.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.api.entity.data; +import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.api.entity.data.types.Hitbox; /** @@ -81,6 +82,14 @@ public final class GeyserEntityDataTypes { public static final GeyserListEntityDataType HITBOXES = GeyserListEntityDataType.of(Hitbox.class, "hitboxes"); + /** + * Represents the entity's seat offset. Applied when mounting an entity. + * Note: This can get overridden when a new entity is mounted, in which case, the seat offset + * would need to be updated again! + */ + public static final GeyserEntityDataType SEAT_OFFSET = + GeyserEntityDataType.of(Vector3f.class, "seat_offset"); + private GeyserEntityDataTypes() { // no-op } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java b/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java index 808403da120..2d4d75d6bb3 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java @@ -38,6 +38,7 @@ import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntityPropertiesEvent; +import java.util.List; import java.util.UUID; import java.util.function.Consumer; @@ -78,6 +79,16 @@ public interface GeyserEntity { */ @NonNull Vector3f position(); + /** + * The vehicle this entity is currently on, or null if not present. + */ + @Nullable GeyserEntity vehicle(); + + /** + * The passengers of this entity, or an empty list if none are present. + */ + List passengers(); + /** * Queries the current value of a given {@link GeyserEntityDataType}. * diff --git a/api/src/main/java/org/geysermc/geyser/api/event/java/ServerUpdateEntityPassengersEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerUpdateEntityPassengersEvent.java new file mode 100644 index 00000000000..b02c9b3e62e --- /dev/null +++ b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerUpdateEntityPassengersEvent.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2026 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.api.event.java; + +import org.checkerframework.checker.nullness.qual.NonNull; +import org.geysermc.geyser.api.connection.GeyserConnection; +import org.geysermc.geyser.api.entity.type.GeyserEntity; +import org.geysermc.geyser.api.event.connection.ConnectionEvent; + +/** + * This event is called when an entity's passengers are updated. + * To avoid de-syncs, you cannot cancel this event. + */ +public abstract class ServerUpdateEntityPassengersEvent extends ConnectionEvent { + + /** + * The vehicle entity that gets a passenger update. + * + * @return the vehicle entity + */ + public abstract @NonNull GeyserEntity vehicle(); + + public ServerUpdateEntityPassengersEvent(@NonNull GeyserConnection connection) { + super(connection); + } + + public abstract static class Mount extends ServerUpdateEntityPassengersEvent { + public Mount(@NonNull GeyserConnection connection) { + super(connection); + } + + /** + * @return the passenger that was added to the vehicle + */ + public abstract @NonNull GeyserEntity addedPassenger(); + } + + public abstract static class Dismount extends ServerUpdateEntityPassengersEvent { + public Dismount(@NonNull GeyserConnection connection) { + super(connection); + } + + /** + * @return the passenger that was removed from the vehicle + */ + public abstract @NonNull GeyserEntity removedPassenger(); + } +} diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index 3784daefc4c..ce4811b62c8 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -152,6 +152,10 @@ public class Entity implements GeyserEntity { protected List passengers = Collections.emptyList(); protected Entity vehicle; + + @Getter + private Vector3f riderSeatPosition = Vector3f.ZERO; + /** * A container to store temporary metadata before it's sent to Bedrock. */ @@ -718,6 +722,7 @@ public float setFreezing(IntEntityMetadata entityMetadata) { } public void setRiderSeatPosition(Vector3f position) { + riderSeatPosition = position; dirtyMetadata.put(EntityDataTypes.SEAT_OFFSET, position); } @@ -897,6 +902,16 @@ public final void playEntityEvent(EntityEventType type, int data) { session.sendUpstreamPacket(packet); } + @Override + public @Nullable GeyserEntity vehicle() { + return this.vehicle; + } + + @Override + public List passengers() { + return List.copyOf(this.passengers); + } + @Override public void updatePropertiesBatched(Consumer consumer, boolean immediate) { if (this.propertyManager == null) { diff --git a/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java b/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java index 67ec30b7f51..d328aef4b47 100644 --- a/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java +++ b/core/src/main/java/org/geysermc/geyser/impl/entity/GeyserEntityDataImpl.java @@ -28,6 +28,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import lombok.AllArgsConstructor; import org.checkerframework.checker.nullness.qual.NonNull; +import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; @@ -49,6 +50,7 @@ public class GeyserEntityDataImpl implements GeyserEntityDataType { TYPES.put("width", new GeyserEntityDataImpl<>(Float.class, "width", Entity::setCustomBoundingBoxWidth, Entity::getCustomBoundingBoxWidth)); TYPES.put("height", new GeyserEntityDataImpl<>(Float.class, "height", Entity::setCustomBoundingBoxHeight, Entity::getCustomBoundingBoxHeight)); TYPES.put("scale", new GeyserEntityDataImpl<>(Float.class, "scale", Entity::setScale, Entity::getScale)); + TYPES.put("seat_offset", new GeyserEntityDataImpl<>(Vector3f.class, "seat_offset", Entity::setRiderSeatPosition, Entity::getRiderSeatPosition)); // "custom" TYPES.put("vertical_offset", new GeyserEntityDataImpl<>(Float.class, "vertical_offset", (entity, value) -> entity.offset(value, true), Entity::getOffset)); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java index 81a935c129a..e8561d03a2b 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java @@ -30,6 +30,8 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityLinkData; import org.cloudburstmc.protocol.bedrock.packet.SetEntityLinkPacket; +import org.geysermc.geyser.api.entity.type.GeyserEntity; +import org.geysermc.geyser.api.event.java.ServerUpdateEntityPassengersEvent; import org.geysermc.geyser.entity.type.Entity; import org.geysermc.geyser.entity.vehicle.ClientVehicle; import org.geysermc.geyser.session.GeyserSession; @@ -50,8 +52,10 @@ public void translate(GeyserSession session, ClientboundSetPassengersPacket pack Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId()); if (entity == null) return; + List currentPassengers = entity.getPassengers(); + // Handle new/existing passengers - List newPassengers = new ArrayList<>(); + entity.setPassengers(new ArrayList<>()); int @NonNull [] passengerIds = packet.getPassengerIds(); for (int i = 0; i < passengerIds.length; i++) { int passengerId = passengerIds[i]; @@ -76,7 +80,7 @@ public void translate(GeyserSession session, ClientboundSetPassengersPacket pack SetEntityLinkPacket linkPacket = new SetEntityLinkPacket(); linkPacket.setEntityLink(new EntityLinkData(entity.geyserId(), passenger.geyserId(), type, false, false, 0f)); session.sendUpstreamPacket(linkPacket); - newPassengers.add(passenger); + entity.getPassengers().add(passenger); passenger.setVehicle(entity); EntityUtils.updateRiderRotationLock(passenger, entity, true); @@ -84,16 +88,27 @@ public void translate(GeyserSession session, ClientboundSetPassengersPacket pack // Force an update to the passenger metadata passenger.updateBedrockMetadata(); passenger.setMotion(Vector3f.ZERO); + + session.getGeyser().getEventBus().fire(new ServerUpdateEntityPassengersEvent.Mount(session) { + @Override + public @NonNull GeyserEntity addedPassenger() { + return passenger; + } + + @Override + public @NonNull GeyserEntity vehicle() { + return entity; + } + }); } // Handle passengers that were removed - List passengers = entity.getPassengers(); - for (int i = 0; i < passengers.size(); i++) { - Entity passenger = passengers.get(i); + for (int i = 0; i < currentPassengers.size(); i++) { + Entity passenger = currentPassengers.get(i); if (passenger == null) { continue; } - if (!newPassengers.contains(passenger)) { + if (!entity.getPassengers().contains(passenger)) { SetEntityLinkPacket linkPacket = new SetEntityLinkPacket(); linkPacket.setEntityLink(new EntityLinkData(entity.geyserId(), passenger.geyserId(), EntityLinkData.Type.REMOVE, false, false, 0f)); session.sendUpstreamPacket(linkPacket); @@ -121,11 +136,22 @@ public void translate(GeyserSession session, ClientboundSetPassengersPacket pack clientVehicle.getVehicleComponent().onDismount(); } } + + session.getGeyser().getEventBus().fire(new ServerUpdateEntityPassengersEvent.Dismount(session) { + @Override + public @NonNull GeyserEntity removedPassenger() { + return passenger; + } + + @Override + public @NonNull GeyserEntity vehicle() { + return entity; + } + }); } } - entity.setPassengers(newPassengers); - + // TODO test if we can move this up if (entity.getJavaTypeDefinition().is(BuiltinEntityType.HORSE) || entity.getJavaTypeDefinition().is(BuiltinEntityType.SKELETON_HORSE) || entity.getJavaTypeDefinition().is(BuiltinEntityType.DONKEY) || entity.getJavaTypeDefinition().is(BuiltinEntityType.MULE) || entity.getJavaTypeDefinition().is(BuiltinEntityType.RAVAGER)) { entity.getDirtyMetadata().put(EntityDataTypes.SEAT_ROTATION_OFFSET_DEGREES, 181.0f); From 5473d121574304676c9aa206413dc76b00d43a46 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Wed, 29 Apr 2026 02:11:19 +0200 Subject: [PATCH 58/62] Fix tests --- .../entity/JavaSetPassengersTranslator.java | 20 ++++++++++--------- .../network/util/GeyserMockContext.java | 4 ++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java index e8561d03a2b..aa9625ec3e7 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaSetPassengersTranslator.java @@ -52,10 +52,10 @@ public void translate(GeyserSession session, ClientboundSetPassengersPacket pack Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId()); if (entity == null) return; - List currentPassengers = entity.getPassengers(); + // TODO: ideally update the passengers on the entity directly // Handle new/existing passengers - entity.setPassengers(new ArrayList<>()); + List newPassengers = new ArrayList<>(); int @NonNull [] passengerIds = packet.getPassengerIds(); for (int i = 0; i < passengerIds.length; i++) { int passengerId = passengerIds[i]; @@ -80,7 +80,7 @@ public void translate(GeyserSession session, ClientboundSetPassengersPacket pack SetEntityLinkPacket linkPacket = new SetEntityLinkPacket(); linkPacket.setEntityLink(new EntityLinkData(entity.geyserId(), passenger.geyserId(), type, false, false, 0f)); session.sendUpstreamPacket(linkPacket); - entity.getPassengers().add(passenger); + newPassengers.add(passenger); passenger.setVehicle(entity); EntityUtils.updateRiderRotationLock(passenger, entity, true); @@ -89,7 +89,7 @@ public void translate(GeyserSession session, ClientboundSetPassengersPacket pack passenger.updateBedrockMetadata(); passenger.setMotion(Vector3f.ZERO); - session.getGeyser().getEventBus().fire(new ServerUpdateEntityPassengersEvent.Mount(session) { + session.getGeyser().eventBus().fire(new ServerUpdateEntityPassengersEvent.Mount(session) { @Override public @NonNull GeyserEntity addedPassenger() { return passenger; @@ -102,13 +102,13 @@ public void translate(GeyserSession session, ClientboundSetPassengersPacket pack }); } - // Handle passengers that were removed - for (int i = 0; i < currentPassengers.size(); i++) { - Entity passenger = currentPassengers.get(i); + List passengers = entity.getPassengers(); + for (int i = 0; i < passengers.size(); i++) { + Entity passenger = passengers.get(i); if (passenger == null) { continue; } - if (!entity.getPassengers().contains(passenger)) { + if (!newPassengers.contains(passenger)) { SetEntityLinkPacket linkPacket = new SetEntityLinkPacket(); linkPacket.setEntityLink(new EntityLinkData(entity.geyserId(), passenger.geyserId(), EntityLinkData.Type.REMOVE, false, false, 0f)); session.sendUpstreamPacket(linkPacket); @@ -137,7 +137,7 @@ public void translate(GeyserSession session, ClientboundSetPassengersPacket pack } } - session.getGeyser().getEventBus().fire(new ServerUpdateEntityPassengersEvent.Dismount(session) { + session.getGeyser().eventBus().fire(new ServerUpdateEntityPassengersEvent.Dismount(session) { @Override public @NonNull GeyserEntity removedPassenger() { return passenger; @@ -151,6 +151,8 @@ public void translate(GeyserSession session, ClientboundSetPassengersPacket pack } } + entity.setPassengers(newPassengers); + // TODO test if we can move this up if (entity.getJavaTypeDefinition().is(BuiltinEntityType.HORSE) || entity.getJavaTypeDefinition().is(BuiltinEntityType.SKELETON_HORSE) || entity.getJavaTypeDefinition().is(BuiltinEntityType.DONKEY) || entity.getJavaTypeDefinition().is(BuiltinEntityType.MULE) || entity.getJavaTypeDefinition().is(BuiltinEntityType.RAVAGER)) { diff --git a/core/src/test/java/org/geysermc/geyser/scoreboard/network/util/GeyserMockContext.java b/core/src/test/java/org/geysermc/geyser/scoreboard/network/util/GeyserMockContext.java index 4ddb0df2f79..0b6c44893c4 100644 --- a/core/src/test/java/org/geysermc/geyser/scoreboard/network/util/GeyserMockContext.java +++ b/core/src/test/java/org/geysermc/geyser/scoreboard/network/util/GeyserMockContext.java @@ -28,6 +28,7 @@ import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.configuration.GeyserConfig; +import org.geysermc.geyser.event.GeyserEventBus; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.mockito.Mockito; @@ -58,6 +59,9 @@ public static void mockContext(Consumer geyserContext) { var logger = context.storeObject(new EmptyGeyserLogger()); when(geyserImpl.getLogger()).thenReturn(logger); + var eventBus = new GeyserEventBus(); + when(geyserImpl.eventBus()).thenReturn(eventBus); + try (var geyserImplMock = mockStatic(GeyserImpl.class)) { geyserImplMock.when(GeyserImpl::getInstance).thenReturn(geyserImpl); From 60f0bb528f31b9e8357a02d009e70c11d114b41c Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Tue, 5 May 2026 01:29:17 +0200 Subject: [PATCH 59/62] Temporarily revert "Fix: hide living entity name when it is a vehicle (#6290)" This reverts commit 3e9112967516928c5975e008f87aae89b550d1e2. --- .../geysermc/geyser/entity/type/Entity.java | 16 +-- .../geyser/entity/type/LivingEntity.java | 19 +--- .../entity/type/living/ArmorStandEntity.java | 2 +- .../entity/type/player/PlayerEntity.java | 2 +- .../network/NameVisibilityScoreboardTest.java | 101 ------------------ 5 files changed, 12 insertions(+), 128 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index ce4811b62c8..a52948a6f88 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -587,16 +587,18 @@ public void updateNametag(@Nullable Team team) { } protected void updateNametag(@Nullable Team team, boolean visible) { - if (!visible) { - // The name is not visible to the session player; clear name - setNametag("", false); - return; - } else if (team != null) { + if (team != null) { + String newNametag; // (team) visibility is LivingEntity+, team displayName is Entity+ - setNametag(team.displayName(getDisplayName(true)), false); + if (visible) { + newNametag = team.displayName(getDisplayName(true)); + } else { + // The name is not visible to the session player; clear name + newNametag = ""; + } + setNametag(newNametag, false); return; } - // The name might need to be reset: no more team! setNametag(getDisplayName(customNameVisible), false); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java index 8cf2bbf6735..d3608509b8a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java @@ -28,7 +28,6 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; -import net.kyori.adventure.text.Component; import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.GenericMath; import org.cloudburstmc.math.vector.Vector3f; @@ -200,24 +199,8 @@ protected void initializeMetadata() { @Override public void updateNametag(@Nullable Team team) { - // Java hides the name tag when a living entity has any passengers // if name not visible, don't mark it as visible - updateNametag(team, passengers.isEmpty() && (team == null || team.isVisibleFor(session.getPlayerEntity().getUsername()))); - } - - @Override - public void setPassengers(List passengers) { - super.setPassengers(passengers); - updateNametag(session.getWorldCache().getScoreboard().getTeamFor(teamIdentifier())); - } - - @Override - public void setCustomName(EntityMetadata, ?> entityMetadata) { - // Update custom name, but reset nametag to be empty when there are passengers - super.setCustomName(entityMetadata); - if (!passengers.isEmpty()) { - setNametag("", false); - } + updateNametag(team, team == null || team.isVisibleFor(session.getPlayerEntity().getUsername())); } public void setLivingEntityFlags(ByteEntityMetadata entityMetadata) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java index 0dedf63041c..bc62d3525a2 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java @@ -121,7 +121,7 @@ public void moveAbsoluteRaw(Vector3f position, float yaw, float pitch, float hea @Override public void updateNametag(@Nullable Team team) { // unlike all other LivingEntities, armor stands are not affected by team nametag visibility - super.updateNametag(team, passengers.isEmpty()); + super.updateNametag(team, true); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java index 51c11cc072a..aacf589a7a0 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java @@ -94,7 +94,7 @@ protected void initializeMetadata() { // Since 1.20.60, the nametag does not show properly if this is not set :/ // The nametag does disappear properly when the player is invisible though. - setNametagAlwaysShow(true); + dirtyMetadata.put(EntityDataTypes.NAMETAG_ALWAYS_SHOW, (byte) 1); } @Override diff --git a/core/src/test/java/org/geysermc/geyser/scoreboard/network/NameVisibilityScoreboardTest.java b/core/src/test/java/org/geysermc/geyser/scoreboard/network/NameVisibilityScoreboardTest.java index 024ac3ff94c..305913607bc 100644 --- a/core/src/test/java/org/geysermc/geyser/scoreboard/network/NameVisibilityScoreboardTest.java +++ b/core/src/test/java/org/geysermc/geyser/scoreboard/network/NameVisibilityScoreboardTest.java @@ -29,11 +29,7 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.packet.SetEntityDataPacket; -import org.cloudburstmc.protocol.bedrock.packet.SetEntityLinkPacket; -import org.geysermc.geyser.entity.type.living.ArmorStandEntity; -import org.geysermc.geyser.entity.type.player.PlayerEntity; import org.geysermc.geyser.translator.protocol.java.entity.JavaSetEntityDataTranslator; -import org.geysermc.geyser.translator.protocol.java.entity.JavaSetPassengersTranslator; import org.geysermc.geyser.translator.protocol.java.scoreboard.JavaSetPlayerTeamTranslator; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataTypes; @@ -44,7 +40,6 @@ import org.geysermc.mcprotocollib.protocol.data.game.scoreboard.TeamAction; import org.geysermc.mcprotocollib.protocol.data.game.scoreboard.TeamColor; import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundSetEntityDataPacket; -import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundSetPassengersPacket; import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.scoreboard.ClientboundSetPlayerTeamPacket; import org.junit.jupiter.api.Test; @@ -53,13 +48,10 @@ import java.util.Optional; import static org.geysermc.geyser.scoreboard.network.util.AssertUtils.assertNextPacket; -import static org.geysermc.geyser.scoreboard.network.util.AssertUtils.assertNextPacketMatch; -import static org.geysermc.geyser.scoreboard.network.util.AssertUtils.assertNextPacketType; import static org.geysermc.geyser.scoreboard.network.util.AssertUtils.assertNoNextPacket; import static org.geysermc.geyser.scoreboard.network.util.GeyserMockContextScoreboard.mockContextScoreboard; import static org.geysermc.geyser.scoreboard.network.util.GeyserMockContextScoreboard.spawnArmorStand; import static org.geysermc.geyser.scoreboard.network.util.GeyserMockContextScoreboard.spawnPlayerSilently; -import static org.junit.jupiter.api.Assertions.assertEquals; public class NameVisibilityScoreboardTest { @Test @@ -377,97 +369,4 @@ void teamsDontOverrideCustomName() { assertNoNextPacket(context); }); } - - @Test - void anyPassengersHidePlayerName() { - mockContextScoreboard(context -> { - PlayerEntity player = spawnPlayerSilently(context, "eclipseisoffline", 2L); - spawnArmorStand(context, 3L); - - context.translate(new JavaSetPassengersTranslator(), new ClientboundSetPassengersPacket(2, new int[]{3})); - // Passenger/vehicle link - assertNextPacketType(context, SetEntityLinkPacket.class); - // Passenger metadata - assertNextPacketType(context, SetEntityDataPacket.class); - - // Name metadata doesn't update until called for - player.updateBedrockMetadata(); - assertNextPacket(context, () -> { - SetEntityDataPacket packet = new SetEntityDataPacket(); - packet.setRuntimeEntityId(2); - packet.getMetadata().put(EntityDataTypes.NAME, ""); - return packet; - }); - }); - } - - @Test - void anyPassengersHideArmorStandName() { - mockContextScoreboard(context -> { - ArmorStandEntity vehicle = spawnArmorStand(context, 2L); - spawnArmorStand(context, 3L); - - context.translate(new JavaSetEntityDataTranslator(), new ClientboundSetEntityDataPacket(2, new EntityMetadata[]{ - new ObjectEntityMetadata<>(2, MetadataTypes.OPTIONAL_COMPONENT, Optional.of(Component.text("apples are gud"))) - })); - - assertNextPacketMatch(context, SetEntityDataPacket.class, packet -> { - assertEquals("apples are gud", packet.getMetadata().get(EntityDataTypes.NAME)); - }); - - context.translate(new JavaSetPassengersTranslator(), new ClientboundSetPassengersPacket(2, new int[]{3})); - // Passenger/vehicle link - assertNextPacketType(context, SetEntityLinkPacket.class); - // Passenger metadata - assertNextPacketType(context, SetEntityDataPacket.class); - vehicle.updateBedrockMetadata(); - assertNextPacket(context, () -> { - SetEntityDataPacket packet = new SetEntityDataPacket(); - packet.setRuntimeEntityId(2); - packet.getMetadata().put(EntityDataTypes.NAME, ""); - return packet; - }); - }); - } - - @Test - void noPassengersShowsArmorStandName() { - mockContextScoreboard(context -> { - ArmorStandEntity vehicle = spawnArmorStand(context, 2L); - spawnArmorStand(context, 3L); - - JavaSetPassengersTranslator setPassengersTranslator = new JavaSetPassengersTranslator(); - - context.translate(setPassengersTranslator, new ClientboundSetPassengersPacket(2, new int[]{3})); - // Passenger/vehicle link - assertNextPacketType(context, SetEntityLinkPacket.class); - // Passenger metadata - assertNextPacketType(context, SetEntityDataPacket.class); - - vehicle.updateBedrockMetadata(); - // Since the vehicle has no custom name, no new name should be sent - assertNoNextPacket(context); - - context.translate(new JavaSetEntityDataTranslator(), new ClientboundSetEntityDataPacket(2, new EntityMetadata[]{ - new ObjectEntityMetadata<>(2, MetadataTypes.OPTIONAL_COMPONENT, Optional.of(Component.text("apples are gud"))) - })); - - // Since it's a vehicle, the custom name should not be sent - assertNextPacketMatch(context, SetEntityDataPacket.class, packet -> { - assertEquals("", packet.getMetadata().get(EntityDataTypes.NAME)); - }); - - context.translate(setPassengersTranslator, new ClientboundSetPassengersPacket(2, new int[0])); - // Passenger/vehicle link - assertNextPacketType(context, SetEntityLinkPacket.class); - // Passenger metadata - assertNextPacketType(context, SetEntityDataPacket.class); - - // No longer a vehicle, now the name is sent - vehicle.updateBedrockMetadata(); - assertNextPacketMatch(context, SetEntityDataPacket.class, packet -> { - assertEquals("apples are gud", packet.getMetadata().get(EntityDataTypes.NAME)); - }); - }); - } } From 02b986b0fb3ce683d3073c4b93b68b4968a621d2 Mon Sep 17 00:00:00 2001 From: Eclipse Date: Tue, 5 May 2026 20:57:13 +0000 Subject: [PATCH 60/62] Fix: sent bogus furnace recipes when none are sent by the server Remove debug exception Fix: client crash because no furnace recipes are sent # Conflicts: # core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaRecipeBookAddTranslator.java --- .../recipe/GeyserShapelessRecipe.java | 41 ++++++++++++- .../java/JavaRecipeBookAddTranslator.java | 61 +++++++++++++++++++ 2 files changed, 99 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/inventory/recipe/GeyserShapelessRecipe.java b/core/src/main/java/org/geysermc/geyser/inventory/recipe/GeyserShapelessRecipe.java index 55f6aa17ef7..1a874eb98f2 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/recipe/GeyserShapelessRecipe.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/recipe/GeyserShapelessRecipe.java @@ -25,12 +25,16 @@ package org.geysermc.geyser.inventory.recipe; +import it.unimi.dsi.fastutil.ints.IntList; +import lombok.Getter; +import lombok.experimental.Accessors; import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.RecipeUnlockingRequirement; import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.recipe.RecipeData; import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.recipe.ShapelessRecipeData; import org.cloudburstmc.protocol.bedrock.data.inventory.descriptor.ItemDescriptorWithCount; import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.FurnaceRecipeDisplay; import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.ShapelessCraftingRecipeDisplay; import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.SlotDisplay; @@ -42,10 +46,15 @@ public record GeyserShapelessRecipe(int id, int netId, List ingredients, - SlotDisplay result) implements GeyserRecipe { + SlotDisplay result, + String tag) implements GeyserRecipe { public GeyserShapelessRecipe(int id, int netId, ShapelessCraftingRecipeDisplay data) { - this(id, netId, data.ingredients(), data.result()); + this(id, netId, data.ingredients(), data.result(), "crafting_table"); + } + + public GeyserShapelessRecipe(int id, int netId, FurnaceRecipeDisplay data, int category) { + this(id, netId, List.of(data.ingredient()), data.result(), FurnaceRecipeType.fromCategory(category).tag); } @Override @@ -66,10 +75,36 @@ public List asRecipeData(GeyserSession session) { int i = 0; for (List inputs : left) { recipeData.add(ShapelessRecipeData.shapeless(id + "_" + i, inputs, - Collections.singletonList(output), UUID.randomUUID(), "crafting_table", 0, + Collections.singletonList(output), UUID.randomUUID(), tag, 0, netId + i, RecipeUnlockingRequirement.INVALID)); i++; } return recipeData; } + + public enum FurnaceRecipeType { + FURNACE("furnace", 4, 5, 6), // furnace + BLAST_FURNACE("blast_furnace", 7, 8), // blast_furnace_blocks, blast_furnace_misc + SMOKER("smoker", 9, 12); // smoker_food, campfire + + private final String tag; + @Getter + @Accessors(fluent = true) + private final IntList categories; + + FurnaceRecipeType(String tag, int... categories) { + this.tag = tag; + this.categories = IntList.of(categories); + } + + public static FurnaceRecipeType fromCategory(int category) { + for (FurnaceRecipeType type : values()) { + if (type.categories.contains(category)) { + return type; + } + } + + return FURNACE; // /shrug + } + } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaRecipeBookAddTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaRecipeBookAddTranslator.java index 33e9d1b21b9..559c4c48180 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaRecipeBookAddTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaRecipeBookAddTranslator.java @@ -33,19 +33,27 @@ import org.geysermc.geyser.inventory.recipe.GeyserShapedRecipe; import org.geysermc.geyser.inventory.recipe.GeyserShapelessRecipe; import org.geysermc.geyser.inventory.recipe.GeyserSmithingRecipe; +import org.geysermc.geyser.item.Items; +import org.geysermc.geyser.network.GameProtocol; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.Translator; +import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.FurnaceRecipeDisplay; import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.RecipeDisplay; import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.RecipeDisplayEntry; import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.ShapedCraftingRecipeDisplay; import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.ShapelessCraftingRecipeDisplay; import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.SmithingRecipeDisplay; +import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.AnyFuelSlotDisplay; +import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.ItemSlotDisplay; +import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.SlotDisplay; import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.SmithingTrimDemoSlotDisplay; import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundRecipeBookAddPacket; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; @Translator(packet = ClientboundRecipeBookAddPacket.class) public class JavaRecipeBookAddTranslator extends PacketTranslator { @@ -60,6 +68,9 @@ public void translate(GeyserSession session, ClientboundRecipeBookAddPacket pack UnlockedRecipesPacket recipesPacket = new UnlockedRecipesPacket(); recipesPacket.setAction(packet.isReplace() ? UnlockedRecipesPacket.ActionType.INITIALLY_UNLOCKED : UnlockedRecipesPacket.ActionType.NEWLY_UNLOCKED); + // Hacky fix, see below + Set knownFurnaceRecipes = new HashSet<>(); + for (ClientboundRecipeBookAddPacket.Entry entry : packet.getEntries()) { RecipeDisplayEntry contents = entry.contents(); if (javaToBedrockRecipeIds.containsKey(contents.id())) { @@ -67,6 +78,27 @@ public void translate(GeyserSession session, ClientboundRecipeBookAddPacket pack } RecipeDisplay display = contents.display(); + // Hacky fix: on 1.26.20 and above, the client crashes when there are no furnace recipes. Furnace recipes also have to be shapeless. + // Before this fix, Geyser did not translate furnace recipes at all. + // TODO rewrite this, but properly + if (display instanceof FurnaceRecipeDisplay furnaceRecipe && GameProtocol.is1_26_20orHigher(session.protocolVersion())) { + GeyserRecipe geyserRecipe = new GeyserShapelessRecipe(contents.id(), netId, furnaceRecipe, contents.category()); + knownFurnaceRecipes.add(GeyserShapelessRecipe.FurnaceRecipeType.fromCategory(contents.category())); + + List recipeData = geyserRecipe.asRecipeData(session); + craftingDataPacket.getCraftingData().addAll(recipeData); + + List bedrockRecipeIds = new ArrayList<>(); + for (int i = 0; i < recipeData.size(); i++) { + String recipeId = contents.id() + "_" + i; + recipesPacket.getUnlockedRecipes().add(recipeId); + bedrockRecipeIds.add(recipeId); + geyserRecipes.put(netId++, geyserRecipe); + } + javaToBedrockRecipeIds.put(contents.id(), List.copyOf(bedrockRecipeIds)); + continue; + } + if (display instanceof ShapedCraftingRecipeDisplay shapedRecipe) { GeyserRecipe geyserRecipe = new GeyserShapedRecipe(contents.id(), netId, shapedRecipe); @@ -111,6 +143,35 @@ public void translate(GeyserSession session, ClientboundRecipeBookAddPacket pack } } + if (GameProtocol.is1_26_20orHigher(session.protocolVersion())) { + int placeholderRecipes = 0; + + SlotDisplay stoneSlotDisplay = new ItemSlotDisplay(Items.STONE.javaId()); + FurnaceRecipeDisplay placeholderFurnaceRecipe = new FurnaceRecipeDisplay(stoneSlotDisplay, new AnyFuelSlotDisplay(), stoneSlotDisplay, stoneSlotDisplay, 1, 1.0F); + + for (GeyserShapelessRecipe.FurnaceRecipeType type : GeyserShapelessRecipe.FurnaceRecipeType.values()) { + // Bedrock HAS to have a recipe or else it will crash on 1.26.20 and above, so send a bogus recipe + // Again, very hacky, FIXME please + if (!knownFurnaceRecipes.contains(type)) { + int id = Integer.MIN_VALUE + placeholderRecipes; + GeyserRecipe geyserRecipe = new GeyserShapelessRecipe(id, netId, placeholderFurnaceRecipe, type.categories().get(0)); + + List recipeData = geyserRecipe.asRecipeData(session); + craftingDataPacket.getCraftingData().addAll(recipeData); + + List bedrockRecipeIds = new ArrayList<>(); + for (int i = 0; i < recipeData.size(); i++) { + String recipeId = id + "_" + i; + recipesPacket.getUnlockedRecipes().add(recipeId); + bedrockRecipeIds.add(recipeId); + geyserRecipes.put(netId++, geyserRecipe); + } + javaToBedrockRecipeIds.put(id, List.copyOf(bedrockRecipeIds)); + placeholderRecipes++; + } + } + } + if (!recipesPacket.getUnlockedRecipes().isEmpty()) { // Sending an empty list here will crash the client as of 1.20.60 // This was definitely in the codebase the entire time and did not From e326f58d648fe1ddcf392a9f63e517460809491b Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Tue, 12 May 2026 01:12:46 +0200 Subject: [PATCH 61/62] Update to 26.1 --- .../java/entity/JavaEntityEventTranslator.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java index a1fad6f69e5..b755560d60f 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaEntityEventTranslator.java @@ -78,23 +78,23 @@ public void translate(GeyserSession session, ClientboundEntityEventPacket packet case PLAYER_DISABLE_REDUCED_DEBUG: session.setReducedDebugInfo(false); return; - case PLAYER_OP_PERMISSION_LEVEL_0: + case PLAYER_SET_NO_PERMISSIONS: session.setOpPermissionLevel(0); session.sendAdventureSettings(); return; - case PLAYER_OP_PERMISSION_LEVEL_1: + case PLAYER_SET_MODERATOR: session.setOpPermissionLevel(1); session.sendAdventureSettings(); return; - case PLAYER_OP_PERMISSION_LEVEL_2: + case PLAYER_SET_GAMEMASTER: session.setOpPermissionLevel(2); session.sendAdventureSettings(); return; - case PLAYER_OP_PERMISSION_LEVEL_3: + case PLAYER_SET_ADMIN: session.setOpPermissionLevel(3); session.sendAdventureSettings(); return; - case PLAYER_OP_PERMISSION_LEVEL_4: + case PLAYER_SET_OWNER: session.setOpPermissionLevel(4); session.sendAdventureSettings(); return; From f19502394e7be638813bc26ef18cc68949a50e1f Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Wed, 13 May 2026 18:15:52 +0200 Subject: [PATCH 62/62] Update to jspecify conform nullability annotations --- .../entity/custom/CustomEntityDefinition.java | 5 ++-- .../entity/custom/CustomJavaEntityType.java | 5 ++-- .../api/entity/custom/package-info.java | 29 +++++++++++++++++++ .../api/entity/data/GeyserEntityDataType.java | 7 ++--- .../entity/data/GeyserListEntityDataType.java | 5 ++-- .../geyser/api/entity/data/package-info.java | 29 +++++++++++++++++++ .../geyser/api/entity/data/types/Hitbox.java | 15 +++++----- .../api/entity/data/types/package-info.java | 29 +++++++++++++++++++ .../definition/GeyserEntityDefinition.java | 7 ++--- .../api/entity/definition/JavaEntityType.java | 5 ++-- .../api/entity/definition/package-info.java | 29 +++++++++++++++++++ .../geyser/api/entity/type/GeyserEntity.java | 3 +- .../bedrock/SessionSpawnEntityEvent.java | 7 ++--- .../event/java/ServerAttachParrotsEvent.java | 3 +- .../event/java/ServerSpawnEntityEvent.java | 7 ++--- .../ServerUpdateEntityPassengersEvent.java | 13 ++++----- .../lifecycle/GeyserDefineEntitiesEvent.java | 9 +++--- 17 files changed, 156 insertions(+), 51 deletions(-) create mode 100644 api/src/main/java/org/geysermc/geyser/api/entity/custom/package-info.java create mode 100644 api/src/main/java/org/geysermc/geyser/api/entity/data/package-info.java create mode 100644 api/src/main/java/org/geysermc/geyser/api/entity/data/types/package-info.java create mode 100644 api/src/main/java/org/geysermc/geyser/api/entity/definition/package-info.java diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java index 00c44c23048..929707b7a79 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomEntityDefinition.java @@ -25,7 +25,6 @@ package org.geysermc.geyser.api.entity.custom; -import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.api.GeyserApi; import org.geysermc.geyser.api.entity.definition.GeyserEntityDefinition; import org.geysermc.geyser.api.util.Identifier; @@ -46,7 +45,7 @@ default boolean vanilla() { * @param identifier the Bedrock entity identifier * @return the CustomEntityDefinition */ - static @NonNull CustomEntityDefinition of(@NonNull Identifier identifier) { + static CustomEntityDefinition of(Identifier identifier) { if (identifier.vanilla()) { throw new IllegalArgumentException("Use GeyserEntityDefinition#of for vanilla entity lookups!"); } @@ -59,7 +58,7 @@ default boolean vanilla() { * @param identifier the Bedrock entity identifier, in string format * @return the CustomEntityDefinition */ - static @NonNull CustomEntityDefinition of(@NonNull String identifier) { + static CustomEntityDefinition of(String identifier) { return of(Identifier.of(identifier)); } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java index 6c3b91bf73d..be5d27eacdf 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/custom/CustomJavaEntityType.java @@ -26,13 +26,12 @@ package org.geysermc.geyser.api.entity.custom; import org.checkerframework.checker.index.qual.NonNegative; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.common.returnsreceiver.qual.This; import org.geysermc.geyser.api.entity.definition.GeyserEntityDefinition; import org.geysermc.geyser.api.entity.definition.JavaEntityType; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; import org.geysermc.geyser.api.util.Identifier; +import org.jspecify.annotations.Nullable; /** * Represents a custom Minecraft: Java Edition entity type. @@ -54,7 +53,7 @@ interface Builder { * @param entityType the identifier * @return this builder */ - @This Builder type(@NonNull Identifier entityType); + @This Builder type(Identifier entityType); /** * The entity type's numeric network id. diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/custom/package-info.java b/api/src/main/java/org/geysermc/geyser/api/entity/custom/package-info.java new file mode 100644 index 00000000000..30ed743b1c6 --- /dev/null +++ b/api/src/main/java/org/geysermc/geyser/api/entity/custom/package-info.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2026 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +@NullMarked +package org.geysermc.geyser.api.entity.custom; + +import org.jspecify.annotations.NullMarked; diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataType.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataType.java index c1c2e79d125..3484f217bf4 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserEntityDataType.java @@ -25,7 +25,6 @@ package org.geysermc.geyser.api.entity.data; -import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.api.GeyserApi; import org.geysermc.geyser.api.entity.type.GeyserEntity; @@ -47,7 +46,7 @@ public interface GeyserEntityDataType { * * @return the class of the value used by this entity data type */ - @NonNull Class typeClass(); + Class typeClass(); /** * Gets the unique name of this data type. @@ -57,12 +56,12 @@ public interface GeyserEntityDataType { * * @return the name of this entity data type */ - @NonNull String name(); + String name(); /** * For API usage only; use the types defined in {@link GeyserEntityDataTypes} */ - static GeyserEntityDataType of(@NonNull Class typeClass, @NonNull String name) { + static GeyserEntityDataType of(Class typeClass, String name) { return GeyserApi.api().provider(GeyserEntityDataType.class, typeClass, name); } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserListEntityDataType.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserListEntityDataType.java index 3cb948f019b..cf60351fecd 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserListEntityDataType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/GeyserListEntityDataType.java @@ -25,7 +25,6 @@ package org.geysermc.geyser.api.entity.data; -import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.api.GeyserApi; import java.util.List; @@ -41,12 +40,12 @@ public interface GeyserListEntityDataType extends GeyserEntityDataType listEntryClass(); + Class listEntryClass(); /** * API usage only, use the types defined in {@link GeyserEntityDataTypes} */ - static GeyserListEntityDataType of(@NonNull Class typeClass, @NonNull String name) { + static GeyserListEntityDataType of(Class typeClass, String name) { return GeyserApi.api().provider(GeyserListEntityDataType.class, List.class, typeClass, name); } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/package-info.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/package-info.java new file mode 100644 index 00000000000..4111ccac8d6 --- /dev/null +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/package-info.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2026 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +@NullMarked +package org.geysermc.geyser.api.entity.data; + +import org.jspecify.annotations.NullMarked; diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java index 915efbfc80a..4861d3101b9 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/types/Hitbox.java @@ -25,7 +25,6 @@ package org.geysermc.geyser.api.entity.data.types; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.common.returnsreceiver.qual.This; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.api.GeyserApi; @@ -44,19 +43,19 @@ public interface Hitbox { * The min "corner" of the hitbox * @return the vector of the corner */ - @NonNull Vector3f min(); + Vector3f min(); /** * The max "corner" of the hitbox * @return the vector of the corner */ - @NonNull Vector3f max(); + Vector3f max(); /** * The pivot of the hitbox * @return the pivot */ - @NonNull Vector3f pivot(); + Vector3f pivot(); static Builder builder() { return GeyserApi.api().provider(Builder.class); @@ -72,21 +71,21 @@ interface Builder { * @param min the vector of the corner * @return this builder */ - @This Builder min(@NonNull Vector3f min); + @This Builder min(Vector3f min); /** * Sets the max corner of the hitbox * @param max the vector of the corner * @return this builder */ - @This Builder max(@NonNull Vector3f max); + @This Builder max(Vector3f max); /** * Sets the pivot of the hitbox * @param pivot the pivot vector * @return this builder */ - @This Builder pivot(@NonNull Vector3f pivot); + @This Builder pivot(Vector3f pivot); /** * Builds this hitbox, defaulting to {@code Vector3f.ZERO} if @@ -94,6 +93,6 @@ interface Builder { * * @return a new hitbox */ - @NonNull Hitbox build(); + Hitbox build(); } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/data/types/package-info.java b/api/src/main/java/org/geysermc/geyser/api/entity/data/types/package-info.java new file mode 100644 index 00000000000..13e48938f5f --- /dev/null +++ b/api/src/main/java/org/geysermc/geyser/api/entity/data/types/package-info.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2026 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +@NullMarked +package org.geysermc.geyser.api.entity.data.types; + +import org.jspecify.annotations.NullMarked; diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/definition/GeyserEntityDefinition.java b/api/src/main/java/org/geysermc/geyser/api/entity/definition/GeyserEntityDefinition.java index 63e8d257a01..e6d5ade143f 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/definition/GeyserEntityDefinition.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/definition/GeyserEntityDefinition.java @@ -25,7 +25,6 @@ package org.geysermc.geyser.api.entity.definition; -import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.api.GeyserApi; import org.geysermc.geyser.api.entity.property.GeyserEntityProperty; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; @@ -43,12 +42,12 @@ public interface GeyserEntityDefinition { /** * @return the Bedrock entity identifier */ - @NonNull Identifier identifier(); + Identifier identifier(); /** * @return the properties registered for this entity type */ - @NonNull List> properties(); + List> properties(); /** * @return whether this entity is a vanilla entity @@ -66,7 +65,7 @@ public interface GeyserEntityDefinition { * @param identifier the Bedrock entity identifier * @return the GeyserEntityDefinition */ - static @NonNull GeyserEntityDefinition of(@NonNull Identifier identifier) { + static GeyserEntityDefinition of(Identifier identifier) { return GeyserApi.api().provider(GeyserEntityDefinition.class, identifier); } } diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/definition/JavaEntityType.java b/api/src/main/java/org/geysermc/geyser/api/entity/definition/JavaEntityType.java index 67c895a178e..1b0d245983b 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/definition/JavaEntityType.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/definition/JavaEntityType.java @@ -25,9 +25,8 @@ package org.geysermc.geyser.api.entity.definition; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.api.util.Identifier; +import org.jspecify.annotations.Nullable; /** * Represents a Java edition entity type @@ -37,7 +36,7 @@ public interface JavaEntityType { /** * @return the Java identifier of the type */ - @NonNull Identifier identifier(); + Identifier identifier(); /** * @return the numeric Java entity type id diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/definition/package-info.java b/api/src/main/java/org/geysermc/geyser/api/entity/definition/package-info.java new file mode 100644 index 00000000000..3ccab92d450 --- /dev/null +++ b/api/src/main/java/org/geysermc/geyser/api/entity/definition/package-info.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2026 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +@NullMarked +package org.geysermc.geyser.api.entity.definition; + +import org.jspecify.annotations.NullMarked; diff --git a/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java b/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java index f0d53ba6132..9f923e2d216 100644 --- a/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java +++ b/api/src/main/java/org/geysermc/geyser/api/entity/type/GeyserEntity.java @@ -81,7 +81,8 @@ public interface GeyserEntity { /** * The vehicle this entity is currently on, or null if not present. */ - @Nullable GeyserEntity vehicle(); + @Nullable + GeyserEntity vehicle(); /** * The passengers of this entity, or an empty list if none are present. diff --git a/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionSpawnEntityEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionSpawnEntityEvent.java index 176e84792ed..8feda193da3 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionSpawnEntityEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/bedrock/SessionSpawnEntityEvent.java @@ -25,8 +25,6 @@ package org.geysermc.geyser.api.event.bedrock; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.event.Cancellable; import org.geysermc.geyser.api.connection.GeyserConnection; import org.geysermc.geyser.api.entity.definition.GeyserEntityDefinition; @@ -35,6 +33,7 @@ import org.geysermc.geyser.api.event.java.ServerAttachParrotsEvent; import org.geysermc.geyser.api.event.java.ServerSpawnEntityEvent; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineEntitiesEvent; +import org.jspecify.annotations.Nullable; import java.util.function.Consumer; @@ -43,7 +42,7 @@ */ public abstract class SessionSpawnEntityEvent extends ConnectionEvent implements Cancellable { - public SessionSpawnEntityEvent(@NonNull GeyserConnection connection) { + public SessionSpawnEntityEvent(GeyserConnection connection) { super(connection); } @@ -70,5 +69,5 @@ public SessionSpawnEntityEvent(@NonNull GeyserConnection connection) { * * @param consumer the consumer for the new GeyserEntity */ - public abstract void preSpawnConsumer(Consumer<@NonNull GeyserEntity> consumer); + public abstract void preSpawnConsumer(Consumer consumer); } diff --git a/api/src/main/java/org/geysermc/geyser/api/event/java/ServerAttachParrotsEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerAttachParrotsEvent.java index 04475808327..6d4c9fb0949 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/java/ServerAttachParrotsEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerAttachParrotsEvent.java @@ -25,7 +25,6 @@ package org.geysermc.geyser.api.event.java; -import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.api.connection.GeyserConnection; import org.geysermc.geyser.api.entity.type.player.GeyserPlayerEntity; import org.geysermc.geyser.api.event.bedrock.SessionSpawnEntityEvent; @@ -35,7 +34,7 @@ */ public abstract class ServerAttachParrotsEvent extends SessionSpawnEntityEvent { - public ServerAttachParrotsEvent(@NonNull GeyserConnection connection) { + public ServerAttachParrotsEvent(GeyserConnection connection) { super(connection); } diff --git a/api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java index cb292d9a3d3..338f3faa9a4 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerSpawnEntityEvent.java @@ -25,7 +25,6 @@ package org.geysermc.geyser.api.event.java; -import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.event.Cancellable; import org.geysermc.geyser.api.connection.GeyserConnection; import org.geysermc.geyser.api.entity.definition.JavaEntityType; @@ -38,7 +37,7 @@ */ public abstract class ServerSpawnEntityEvent extends SessionSpawnEntityEvent implements Cancellable { - public ServerSpawnEntityEvent(@NonNull GeyserConnection connection) { + public ServerSpawnEntityEvent(GeyserConnection connection) { super(connection); } @@ -54,12 +53,12 @@ public ServerSpawnEntityEvent(@NonNull GeyserConnection connection) { * * @return the uuid of the entity being spawned */ - public abstract @NonNull UUID uuid(); + public abstract UUID uuid(); /** * Gets the Java entity type sent by the server * * @return the Java edition entity type of the entity being spawned */ - public abstract @NonNull JavaEntityType entityType(); + public abstract JavaEntityType entityType(); } diff --git a/api/src/main/java/org/geysermc/geyser/api/event/java/ServerUpdateEntityPassengersEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerUpdateEntityPassengersEvent.java index b02c9b3e62e..21c299e46aa 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/java/ServerUpdateEntityPassengersEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/java/ServerUpdateEntityPassengersEvent.java @@ -25,7 +25,6 @@ package org.geysermc.geyser.api.event.java; -import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.api.connection.GeyserConnection; import org.geysermc.geyser.api.entity.type.GeyserEntity; import org.geysermc.geyser.api.event.connection.ConnectionEvent; @@ -41,31 +40,31 @@ public abstract class ServerUpdateEntityPassengersEvent extends ConnectionEvent * * @return the vehicle entity */ - public abstract @NonNull GeyserEntity vehicle(); + public abstract GeyserEntity vehicle(); - public ServerUpdateEntityPassengersEvent(@NonNull GeyserConnection connection) { + public ServerUpdateEntityPassengersEvent(GeyserConnection connection) { super(connection); } public abstract static class Mount extends ServerUpdateEntityPassengersEvent { - public Mount(@NonNull GeyserConnection connection) { + public Mount(GeyserConnection connection) { super(connection); } /** * @return the passenger that was added to the vehicle */ - public abstract @NonNull GeyserEntity addedPassenger(); + public abstract GeyserEntity addedPassenger(); } public abstract static class Dismount extends ServerUpdateEntityPassengersEvent { - public Dismount(@NonNull GeyserConnection connection) { + public Dismount(GeyserConnection connection) { super(connection); } /** * @return the passenger that was removed from the vehicle */ - public abstract @NonNull GeyserEntity removedPassenger(); + public abstract GeyserEntity removedPassenger(); } } diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java index 42a6aa863e6..80bb9183bdb 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineEntitiesEvent.java @@ -25,7 +25,6 @@ package org.geysermc.geyser.api.event.lifecycle; -import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.event.Event; import org.geysermc.geyser.api.entity.custom.CustomEntityDefinition; import org.geysermc.geyser.api.entity.custom.CustomJavaEntityType; @@ -44,23 +43,23 @@ public interface GeyserDefineEntitiesEvent extends Event { /** * @return an immutable collection of all registered entity definitions */ - @NonNull Collection<@NonNull GeyserEntityDefinition> entities(); + Collection entities(); /** * @return an immutable collection of all registered custom entity definitions */ - @NonNull Collection<@NonNull CustomEntityDefinition> customEntities(); + Collection customEntities(); /** * Registers a custom entity definition * @param definition the custom entity definition to register */ - void register(@NonNull CustomEntityDefinition definition); + void register(CustomEntityDefinition definition); /** * Registers a non-vanilla Java entity type. * * @param builderConsumer the builder for the non-vanilla type */ - void registerEntityType(@NonNull Consumer builderConsumer); + void registerEntityType(Consumer builderConsumer); }