From f5b9e07a2a006394961215da3f907f25740bc80d Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Thu, 17 Feb 2022 18:42:22 -0800 Subject: [PATCH] Add GameEvent tags (#6439) --- patches/api/0367-Add-GameEvent-tags.patch | 29 ++++++++ patches/server/0867-Add-GameEvent-tags.patch | 74 ++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 patches/api/0367-Add-GameEvent-tags.patch create mode 100644 patches/server/0867-Add-GameEvent-tags.patch diff --git a/patches/api/0367-Add-GameEvent-tags.patch b/patches/api/0367-Add-GameEvent-tags.patch new file mode 100644 index 0000000000..c0f7113f5f --- /dev/null +++ b/patches/api/0367-Add-GameEvent-tags.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Sat, 18 Dec 2021 10:34:21 -0800 +Subject: [PATCH] Add GameEvent tags + + +diff --git a/src/main/java/org/bukkit/Tag.java b/src/main/java/org/bukkit/Tag.java +index ddd195a834d1756c903644fc1faffe7ebcb238ed..43ab88bb3721ed499549a9d328be352d6f639871 100644 +--- a/src/main/java/org/bukkit/Tag.java ++++ b/src/main/java/org/bukkit/Tag.java +@@ -735,6 +735,18 @@ public interface Tag extends Keyed { + */ + @Deprecated(forRemoval = true) + Tag SKELETONS = ENTITY_TYPES_SKELETONS; ++ ++ String REGISTRY_GAME_EVENTS = "game_events"; ++ ++ /** ++ * Tag for game events that trigger sculk sensors ++ */ ++ Tag GAME_EVENT_VIBRATIONS = Bukkit.getTag(REGISTRY_GAME_EVENTS, NamespacedKey.minecraft("vibrations"), GameEvent.class); ++ ++ /** ++ * Tag for game events that are ignored if the entity is sneaking ++ */ ++ Tag GAME_EVENT_IGNORE_VIBRATIONS_SNEAKING = Bukkit.getTag(REGISTRY_GAME_EVENTS, NamespacedKey.minecraft("ignore_vibrations_sneaking"), GameEvent.class); + // Paper end + + /** diff --git a/patches/server/0867-Add-GameEvent-tags.patch b/patches/server/0867-Add-GameEvent-tags.patch new file mode 100644 index 0000000000..a94785b687 --- /dev/null +++ b/patches/server/0867-Add-GameEvent-tags.patch @@ -0,0 +1,74 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Sun, 3 Jan 2021 20:03:35 -0800 +Subject: [PATCH] Add GameEvent tags + + +diff --git a/src/main/java/io/papermc/paper/CraftGameEventTag.java b/src/main/java/io/papermc/paper/CraftGameEventTag.java +new file mode 100644 +index 0000000000000000000000000000000000000000..b9614196c360d357ae7e4fcaad5256a12e7cc7cd +--- /dev/null ++++ b/src/main/java/io/papermc/paper/CraftGameEventTag.java +@@ -0,0 +1,31 @@ ++package io.papermc.paper; ++ ++import net.minecraft.core.Registry; ++import net.minecraft.resources.ResourceLocation; ++import net.minecraft.tags.TagCollection; ++import org.bukkit.GameEvent; ++import org.bukkit.craftbukkit.tag.CraftTag; ++import org.bukkit.craftbukkit.util.CraftNamespacedKey; ++import org.jetbrains.annotations.NotNull; ++ ++import java.util.Collections; ++import java.util.Objects; ++import java.util.Set; ++import java.util.stream.Collectors; ++ ++public class CraftGameEventTag extends CraftTag { ++ ++ public CraftGameEventTag(TagCollection registry, ResourceLocation tag) { ++ super(registry, tag); ++ } ++ ++ @Override ++ public boolean isTagged(@NotNull GameEvent item) { ++ return this.getHandle().contains(Registry.GAME_EVENT.get(CraftNamespacedKey.toMinecraft(item.getKey()))); ++ } ++ ++ @Override ++ public @NotNull Set getValues() { ++ return this.getHandle().getValues().stream().map(ge -> Objects.requireNonNull(GameEvent.getByKey(CraftNamespacedKey.fromMinecraft(Registry.GAME_EVENT.getKey(ge))), ge + " is not a recognized game event")).collect(Collectors.toUnmodifiableSet()); ++ } ++} +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +index f0629cac377b29246e990a01d60601270cbd77bd..dbbae437123163c60c3f60a48043967a8adbd124 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +@@ -2561,6 +2561,12 @@ public final class CraftServer implements Server { + Preconditions.checkArgument(clazz == org.bukkit.entity.EntityType.class, "Entity type namespace must have entity type"); + + return (org.bukkit.Tag) new CraftEntityTag(EntityTypeTags.getAllTags(), key); ++ // Paper start ++ case org.bukkit.Tag.REGISTRY_GAME_EVENTS: ++ Preconditions.checkArgument(clazz == org.bukkit.GameEvent.class, "Game Event namespace must have GameEvent type"); ++ ++ return (org.bukkit.Tag) new io.papermc.paper.CraftGameEventTag(net.minecraft.tags.GameEventTags.getAllTags(), key); ++ // Paper end + default: + throw new IllegalArgumentException(); + } +@@ -2590,6 +2596,13 @@ public final class CraftServer implements Server { + + TagCollection> entityTags = EntityTypeTags.getAllTags(); + return entityTags.getAllTags().keySet().stream().map(key -> (org.bukkit.Tag) new CraftEntityTag(entityTags, key)).collect(ImmutableList.toImmutableList()); ++ // Paper start ++ case org.bukkit.Tag.REGISTRY_GAME_EVENTS: ++ Preconditions.checkArgument(clazz == org.bukkit.GameEvent.class); ++ ++ TagCollection gameEvents = net.minecraft.tags.GameEventTags.getAllTags(); ++ return gameEvents.getAllTags().keySet().stream().map(key -> (org.bukkit.Tag) new io.papermc.paper.CraftGameEventTag(gameEvents, key)).toList(); ++ // Paper end + default: + throw new IllegalArgumentException(); + }