1
0
mirror of https://github.com/GeyserMC/Geyser.git synced 2025-12-30 20:29:19 +00:00

Expose entity hitboxes in API, store bedrock position to avoid re-calculation

This commit is contained in:
onebeastchris
2025-12-16 23:00:59 +01:00
parent 9f05f1ef9e
commit 199737d1ef
30 changed files with 416 additions and 85 deletions

View File

@@ -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<Float> SCALE =
GeyserEntityDataType.of(Float.class, "scale");
/**
* Represents custom hitboxes for entities
*/
public static final GeyserListEntityDataType<Hitbox> HITBOXES =
GeyserListEntityDataType.of(Hitbox.class, "hitboxes");
private GeyserEntityDataTypes() {
// no-op
}

View File

@@ -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 <T>
*/
public interface GeyserListEntityDataType<T> extends GeyserEntityDataType<List<T>> {
Class<T> listTypeClass();
/**
* API usage only, use the types defined in {@link GeyserEntityDataTypes}
*/
static <T> GeyserListEntityDataType<T> of(Class<T> typeClass, String name) {
return GeyserApi.api().provider(GeyserListEntityDataType.class, List.class, typeClass, name);
}
}

View File

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