diff --git a/api/geyser/src/main/java/org/geysermc/geyser/api/block/custom/component/BoxComponent.java b/api/geyser/src/main/java/org/geysermc/geyser/api/block/custom/component/BoxComponent.java index b114a361c..142878c5b 100644 --- a/api/geyser/src/main/java/org/geysermc/geyser/api/block/custom/component/BoxComponent.java +++ b/api/geyser/src/main/java/org/geysermc/geyser/api/block/custom/component/BoxComponent.java @@ -27,4 +27,10 @@ package org.geysermc.geyser.api.block.custom.component; public record BoxComponent(float originX, float originY, float originZ, float sizeX, float sizeY, float sizeZ) { + public static final BoxComponent FULL_BLOCK = new BoxComponent(-8, 0, -8, 16, 16, 16); + public static final BoxComponent EMPTY_BOX = new BoxComponent(0, 0, 0, 0, 0, 0); + + public boolean isEmpty() { + return sizeX == 0 && sizeY == 0 && sizeZ == 0; + } } diff --git a/api/geyser/src/main/java/org/geysermc/geyser/api/block/custom/component/CustomBlockComponents.java b/api/geyser/src/main/java/org/geysermc/geyser/api/block/custom/component/CustomBlockComponents.java index 92da81db8..f18440b33 100644 --- a/api/geyser/src/main/java/org/geysermc/geyser/api/block/custom/component/CustomBlockComponents.java +++ b/api/geyser/src/main/java/org/geysermc/geyser/api/block/custom/component/CustomBlockComponents.java @@ -47,9 +47,9 @@ public interface CustomBlockComponents { RotationComponent rotation(); interface Builder { - Builder aimCollision(BoxComponent aimCollision); + Builder selectionBox(BoxComponent selectionBox); - Builder entityCollision(BoxComponent entityCollision); + Builder collisionBox(BoxComponent collisionBox); Builder geometry(String geometry); diff --git a/core/src/main/java/org/geysermc/geyser/level/block/GeyserCustomBlockComponents.java b/core/src/main/java/org/geysermc/geyser/level/block/GeyserCustomBlockComponents.java index 61e43b63f..5ac7e2613 100644 --- a/core/src/main/java/org/geysermc/geyser/level/block/GeyserCustomBlockComponents.java +++ b/core/src/main/java/org/geysermc/geyser/level/block/GeyserCustomBlockComponents.java @@ -33,8 +33,8 @@ import org.geysermc.geyser.api.block.custom.component.RotationComponent; import java.util.Map; public class GeyserCustomBlockComponents implements CustomBlockComponents { - private final BoxComponent aimCollision; - private final BoxComponent entityCollision; + private final BoxComponent selectionBox; + private final BoxComponent collisionBox; private final String geometry; private final Map materialInstances; private final Float destroyTime; @@ -44,8 +44,8 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents { private final RotationComponent rotation; private GeyserCustomBlockComponents(CustomBlockComponentsBuilder builder) { - this.aimCollision = builder.aimCollision; - this.entityCollision = builder.entityCollision; + this.selectionBox = builder.selectionBox; + this.collisionBox = builder.collisionBox; this.geometry = builder.geometry; this.materialInstances = builder.materialInstances; this.destroyTime = builder.destroyTime; @@ -57,12 +57,12 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents { @Override public BoxComponent selectionBox() { - return aimCollision; + return selectionBox; } @Override public BoxComponent collisionBox() { - return entityCollision; + return collisionBox; } @Override @@ -101,8 +101,8 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents { } public static class CustomBlockComponentsBuilder implements Builder { - protected BoxComponent aimCollision; - protected BoxComponent entityCollision; + protected BoxComponent selectionBox; + protected BoxComponent collisionBox; protected String geometry; protected Map materialInstances; protected Float destroyTime; @@ -112,14 +112,14 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents { protected RotationComponent rotation; @Override - public Builder aimCollision(BoxComponent aimCollision) { - this.aimCollision = aimCollision; + public Builder selectionBox(BoxComponent selectionBox) { + this.selectionBox = selectionBox; return this; } @Override - public Builder entityCollision(BoxComponent entityCollision) { - this.entityCollision = entityCollision; + public Builder collisionBox(BoxComponent collisionBox) { + this.collisionBox = collisionBox; return this; } diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java index dfc82fe4b..0b37cc313 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java @@ -336,31 +336,21 @@ public class BlockRegistryPopulator { } NbtMapBuilder builder = NbtMap.builder(); if (components.selectionBox() != null) { - BoxComponent selectionBox = components.selectionBox(); - builder.putCompound("minecraft:aim_collision", NbtMap.builder() - .putBoolean("enabled", true) - .putList("origin", NbtType.FLOAT, selectionBox.originX(), selectionBox.originY(), selectionBox.originZ()) - .putList("size", NbtType.FLOAT, selectionBox.sizeX(), selectionBox.sizeY(), selectionBox.sizeZ()) - .build()); + builder.putCompound("minecraft:aim_collision", convertBox(components.selectionBox())); } if (components.collisionBox() != null) { - BoxComponent collisionBox = components.collisionBox(); String tagName = "minecraft:block_collision"; if (protocolVersion >= Bedrock_v534.V534_CODEC.getProtocolVersion()) { tagName = "minecraft:collision_box"; } - builder.putCompound(tagName, NbtMap.builder() - .putBoolean("enabled", true) - .putList("origin", NbtType.FLOAT, collisionBox.originX(), collisionBox.originY(), collisionBox.originZ()) - .putList("size", NbtType.FLOAT, collisionBox.sizeX(), collisionBox.sizeY(), collisionBox.sizeZ()) - .build()); + builder.putCompound(tagName, convertBox(components.collisionBox())); } if (components.geometry() != null) { builder.putCompound("minecraft:geometry", NbtMap.builder() .putString("value", components.geometry()) .build()); } - if (components.materialInstances() != null) { + if (components.materialInstances() != null && !components.materialInstances().isEmpty()) { NbtMapBuilder materialsBuilder = NbtMap.builder(); for (Map.Entry entry : components.materialInstances().entrySet()) { MaterialInstance materialInstance = entry.getValue(); @@ -406,6 +396,14 @@ public class BlockRegistryPopulator { return builder.build(); } + private static NbtMap convertBox(BoxComponent boxComponent) { + return NbtMap.builder() + .putBoolean("enabled", !boxComponent.isEmpty()) + .putList("origin", NbtType.FLOAT, boxComponent.originX(), boxComponent.originY(), boxComponent.originZ()) + .putList("size", NbtType.FLOAT, boxComponent.sizeX(), boxComponent.sizeY(), boxComponent.sizeZ()) + .build(); + } + private static void registerJavaBlocks() { JsonNode blocksJson; try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource("mappings/blocks.json")) { diff --git a/core/src/main/java/org/geysermc/geyser/registry/type/CustomSkull.java b/core/src/main/java/org/geysermc/geyser/registry/type/CustomSkull.java index 3e695d64d..c3b8beb8e 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/type/CustomSkull.java +++ b/core/src/main/java/org/geysermc/geyser/registry/type/CustomSkull.java @@ -131,8 +131,8 @@ public class CustomSkull { for (int i = 0; i < 4; i++) { int floorRotation = 4 * quadrant + i; CustomBlockComponents components = new GeyserCustomBlockComponents.CustomBlockComponentsBuilder() - .aimCollision(box) - .entityCollision(box) + .selectionBox(box) + .collisionBox(box) .geometry("geometry.geyser.player_skull_floor_" + quadrantNames[i]) .rotation(rotation) .build(); @@ -159,8 +159,8 @@ public class CustomSkull { String condition = String.format("query.block_property('%s') == %d && query.block_property('%s') == %d", BITS_A_PROPERTY, i + 1, BITS_B_PROPERTY, 0); CustomBlockComponents components = new GeyserCustomBlockComponents.CustomBlockComponentsBuilder() - .aimCollision(box) - .entityCollision(box) + .selectionBox(box) + .collisionBox(box) .geometry("geometry.geyser.player_skull_wall") .rotation(rotation) .build();