From 1f68916ac986c111647b1467b745703d24070339 Mon Sep 17 00:00:00 2001 From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Date: Thu, 7 Apr 2022 17:49:25 -0400 Subject: [PATCH] Nameable Banner API --- .../block/entity/BannerBlockEntity.java.patch | 10 ++++++++- .../bukkit/craftbukkit/block/CraftBanner.java | 22 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/paper-server/patches/sources/net/minecraft/world/level/block/entity/BannerBlockEntity.java.patch b/paper-server/patches/sources/net/minecraft/world/level/block/entity/BannerBlockEntity.java.patch index 9459c7a493..08e6568eb4 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/block/entity/BannerBlockEntity.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/block/entity/BannerBlockEntity.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/BannerBlockEntity.java +++ b/net/minecraft/world/level/block/entity/BannerBlockEntity.java -@@ -19,6 +19,10 @@ +@@ -19,13 +19,17 @@ import net.minecraft.world.level.block.state.BlockState; import org.slf4j.Logger; @@ -11,6 +11,14 @@ public class BannerBlockEntity extends BlockEntity implements Nameable { private static final Logger LOGGER = LogUtils.getLogger(); + public static final int MAX_PATTERNS = 6; + private static final String TAG_PATTERNS = "patterns"; + @Nullable +- private Component name; ++ public Component name; // Paper - public + public DyeColor baseColor; + private BannerPatternLayers patterns; + @@ -74,7 +78,7 @@ BannerPatternLayers.CODEC.parse(registries.createSerializationContext(NbtOps.INSTANCE), nbt.get("patterns")).resultOrPartial((s) -> { BannerBlockEntity.LOGGER.error("Failed to parse banner patterns: '{}'", s); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java index 5635230fc2..afed8bdb9b 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java @@ -112,4 +112,26 @@ public class CraftBanner extends CraftBlockEntityState implem public CraftBanner copy(Location location) { return new CraftBanner(this, location); } + + // Paper start + @Override + public net.kyori.adventure.text.Component customName() { + return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getSnapshot().getCustomName()); + } + + @Override + public void customName(net.kyori.adventure.text.Component customName) { + this.getSnapshot().name = io.papermc.paper.adventure.PaperAdventure.asVanilla(customName); + } + + @Override + public String getCustomName() { + return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serializeOrNull(this.customName()); + } + + @Override + public void setCustomName(String name) { + this.customName(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserializeOrNull(name)); + } + // Paper end }