From 010e99d2dc3b2dfda52d47a4d58594e381b2fa42 Mon Sep 17 00:00:00 2001 From: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> Date: Thu, 5 Jan 2023 19:46:33 -0800 Subject: [PATCH] Add tags --- .../component/CustomBlockComponents.java | 5 +++++ .../block/GeyserCustomBlockComponents.java | 20 +++++++++++++++++++ .../mappings/versions/MappingsReader_v1.java | 12 +++++++++++ .../CustomBlockRegistryPopulator.java | 3 +++ 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 847205c6a..e3d5f081f 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 @@ -28,6 +28,7 @@ package org.geysermc.geyser.api.block.custom.component; import org.checkerframework.checker.nullness.qual.NonNull; import java.util.Map; +import java.util.Set; public interface CustomBlockComponents { BoxComponent selectionBox(); @@ -52,6 +53,8 @@ public interface CustomBlockComponents { boolean placeAir(); + Set tags(); + interface Builder { Builder selectionBox(BoxComponent selectionBox); @@ -75,6 +78,8 @@ public interface CustomBlockComponents { Builder placeAir(boolean placeAir); + Builder tags(Set tags); + 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 7af10c335..dc9f6a39c 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 @@ -25,7 +25,9 @@ package org.geysermc.geyser.level.block; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.api.block.custom.component.BoxComponent; @@ -53,6 +55,7 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents { Integer lightDampening; RotationComponent rotation; boolean placeAir; + Set tags; private GeyserCustomBlockComponents(CustomBlockComponentsBuilder builder) { this.selectionBox = builder.selectionBox; @@ -70,6 +73,11 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents { this.lightDampening = builder.lightDampening; this.rotation = builder.rotation; this.placeAir = builder.placeAir; + if (builder.tags.isEmpty()) { + this.tags = Set.of(); + } else { + this.tags = Set.copyOf(builder.tags); + } } @Override @@ -127,6 +135,11 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents { return placeAir; } + @Override + public Set tags() { + return tags; + } + public static class CustomBlockComponentsBuilder implements Builder { protected BoxComponent selectionBox; protected BoxComponent collisionBox; @@ -139,6 +152,7 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents { protected Integer lightDampening; protected RotationComponent rotation; protected boolean placeAir = false; + protected final Set tags = new HashSet<>(); private void validateBox(BoxComponent box) { if (box == null) { @@ -247,6 +261,12 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents { return this; } + @Override + public Builder tags(Set tags) { + this.tags.addAll(tags); + return this; + } + @Override public CustomBlockComponents build() { return new GeyserCustomBlockComponents(this); diff --git a/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java b/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java index 90a1eeadb..a2afc6b3f 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java +++ b/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java @@ -26,6 +26,8 @@ package org.geysermc.geyser.registry.mappings.versions; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; import com.google.common.base.CharMatcher; import org.geysermc.geyser.GeyserImpl; @@ -383,6 +385,16 @@ public class MappingsReader_v1 extends MappingsReader { } } + if (node.has("tags")) { + JsonNode tags = node.get("tags"); + if (tags.isArray()) { + ArrayNode tagsArray = (ArrayNode) tags; + Set tagsSet = new HashSet<>(); + tagsArray.forEach(tag -> tagsSet.add(tag.asText())); + builder.tags(tagsSet); + } + } + CustomBlockComponents components = builder.build(); return components; 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 1858006f9..f3a75415c 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 @@ -227,6 +227,9 @@ public class CustomBlockRegistryPopulator { .putString("triggerType", "geyser:place_event") .build()); } + if (!components.tags().isEmpty()) { + components.tags().forEach(tag -> builder.putCompound("tag:" + tag, NbtMap.EMPTY)); + } return builder.build(); }