From 8f7d67bde085612f64b20fb26331110d12a8757b Mon Sep 17 00:00:00 2001 From: davchoo <4722249+davchoo@users.noreply.github.com> Date: Fri, 23 Dec 2022 11:16:50 -0500 Subject: [PATCH] Add display name component and add toggle for client block placing The display name component allows blocks to use other locale keys. placeAir will prevent the client from placing the default block state. --- .../component/CustomBlockComponents.java | 7 +++++ .../block/GeyserCustomBlockComponents.java | 27 +++++++++++++++++++ .../CustomBlockRegistryPopulator.java | 5 ++++ .../geyser/registry/type/CustomSkull.java | 1 + 4 files changed, 40 insertions(+) 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 d3c337ce5..4786bccbe 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 @@ -33,6 +33,7 @@ public interface CustomBlockComponents { BoxComponent selectionBox(); BoxComponent collisionBox(); + String displayName(); String geometry(); @@ -48,11 +49,15 @@ public interface CustomBlockComponents { RotationComponent rotation(); + boolean placeAir(); + interface Builder { Builder selectionBox(BoxComponent selectionBox); Builder collisionBox(BoxComponent collisionBox); + Builder displayName(String displayName); + Builder geometry(String geometry); Builder materialInstance(@NonNull String name, @NonNull MaterialInstance materialInstance); @@ -67,6 +72,8 @@ public interface CustomBlockComponents { Builder rotation(RotationComponent rotation); + Builder placeAir(boolean placeAir); + CustomBlockComponents build(); } } 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 1dbda3434..8a44638f4 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 @@ -45,6 +45,7 @@ import java.util.Set; public class GeyserCustomBlockComponents implements CustomBlockComponents { BoxComponent selectionBox; BoxComponent collisionBox; + String displayName; String geometry; Map materialInstances; Float destroyTime; @@ -52,10 +53,12 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents { Integer lightEmission; Integer lightDampening; RotationComponent rotation; + boolean placeAir; private GeyserCustomBlockComponents(CustomBlockComponentsBuilder builder) { this.selectionBox = builder.selectionBox; this.collisionBox = builder.collisionBox; + this.displayName = builder.displayName; this.geometry = builder.geometry; if (builder.materialInstances.isEmpty()) { this.materialInstances = Object2ObjectMaps.emptyMap(); @@ -67,6 +70,7 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents { this.lightEmission = builder.lightEmission; this.lightDampening = builder.lightDampening; this.rotation = builder.rotation; + this.placeAir = builder.placeAir; } @Override @@ -79,6 +83,11 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents { return collisionBox; } + @Override + public String displayName() { + return displayName; + } + @Override public String geometry() { return geometry; @@ -114,6 +123,11 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents { return rotation; } + @Override + public boolean placeAir() { + return placeAir; + } + public static class CustomBlockComponentsBuilder implements Builder { protected BoxComponent selectionBox; protected BoxComponent collisionBox; @@ -125,6 +139,7 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents { protected Integer lightEmission; protected Integer lightDampening; protected RotationComponent rotation; + protected boolean placeAir = false; private static final Set VALID_MATERIAL_INSTANCE_NAMES = ImmutableSet.of("*", "up", "down", "north", "south", "west", "east"); @@ -160,6 +175,12 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents { return this; } + @Override + public Builder displayName(String displayName) { + this.displayName = displayName; + return this; + } + @Override public Builder geometry(String geometry) { this.geometry = geometry; @@ -226,6 +247,12 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents { return this; } + @Override + public Builder placeAir(boolean placeAir) { + this.placeAir = placeAir; + return this; + } + @Override public CustomBlockComponents build() { return new GeyserCustomBlockComponents(this); diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java index db59fc3a1..6d569bfb5 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java @@ -204,6 +204,11 @@ public class CustomBlockRegistryPopulator { .putFloat("z", components.rotation().z()) .build()); } + if (components.placeAir()) { + builder.putCompound("minecraft:on_player_placing", NbtMap.builder() + .putString("triggerType", "geyser:place_event") + .build()); + } return builder.build(); } 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 9f54b23c0..658dbf044 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 @@ -68,6 +68,7 @@ public class CustomSkull { .destroyTime(1.5f) .materialInstance("*", new MaterialInstance("geyser." + skinHash + "_player_skin", "alpha_test", true, true)) .lightDampening(0) + .placeAir(true) .build(); List permutations = new ArrayList<>();