1
0
mirror of https://github.com/GeyserMC/Geyser.git synced 2026-01-06 15:41:50 +00:00

Another couple changes, start designing an entity data system to set scale/variant/height/width and so forth

This commit is contained in:
onebeastchris
2025-11-27 22:52:47 +01:00
parent 75d5f07170
commit 5a16517d3c
12 changed files with 203 additions and 35 deletions

View File

@@ -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);
}
}

View File

@@ -79,8 +79,7 @@ public interface CustomJavaEntityType extends JavaEntityType {
* 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

View File

@@ -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 {
<T> void updateMetadata(GeyserEntityData<T> type, T value);
}

View File

@@ -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<T> {
/**
* @return the type class
*/
Class<T> 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 <T> the value type
*/
static <T> GeyserEntityData<T> of(Class<T> typeClass, String name) {
return GeyserApi.api().provider(GeyserEntityData.class, typeClass, name);
}
}

View File

@@ -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<Byte> COLOR = GeyserEntityData.of(Byte.class, "COLOR");
public static final GeyserEntityData<Integer> VARIANT = GeyserEntityData.of(Integer.class, "VARIANT");
public static final GeyserEntityData<Float> WIDTH = GeyserEntityData.of(Float.class, "WIDTH");
public static final GeyserEntityData<Float> HEIGHT = GeyserEntityData.of(Float.class, "HEIGHT");
public static final GeyserEntityData<Float> SCALE = GeyserEntityData.of(Float.class, "SCALE");
}

View File

@@ -32,6 +32,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.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 @@ public interface GeyserEntity {
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<BatchEntityDataUpdater> 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

View File

@@ -30,6 +30,7 @@ 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 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.