Add GameEvent tags (#6439)

This commit is contained in:
Jake Potrebic 2022-02-17 18:42:22 -08:00 committed by GitHub
parent 2a4aef3d97
commit f5b9e07a2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 103 additions and 0 deletions

View File

@ -0,0 +1,29 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
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<T extends Keyed> extends Keyed {
*/
@Deprecated(forRemoval = true)
Tag<EntityType> SKELETONS = ENTITY_TYPES_SKELETONS;
+
+ String REGISTRY_GAME_EVENTS = "game_events";
+
+ /**
+ * Tag for game events that trigger sculk sensors
+ */
+ Tag<GameEvent> 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<GameEvent> GAME_EVENT_IGNORE_VIBRATIONS_SNEAKING = Bukkit.getTag(REGISTRY_GAME_EVENTS, NamespacedKey.minecraft("ignore_vibrations_sneaking"), GameEvent.class);
// Paper end
/**

View File

@ -0,0 +1,74 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
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<net.minecraft.world.level.gameevent.GameEvent, GameEvent> {
+
+ public CraftGameEventTag(TagCollection<net.minecraft.world.level.gameevent.GameEvent> 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<GameEvent> 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<T>) 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<T>) 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<EntityType<?>> entityTags = EntityTypeTags.getAllTags();
return entityTags.getAllTags().keySet().stream().map(key -> (org.bukkit.Tag<T>) new CraftEntityTag(entityTags, key)).collect(ImmutableList.toImmutableList());
+ // Paper start
+ case org.bukkit.Tag.REGISTRY_GAME_EVENTS:
+ Preconditions.checkArgument(clazz == org.bukkit.GameEvent.class);
+
+ TagCollection<net.minecraft.world.level.gameevent.GameEvent> gameEvents = net.minecraft.tags.GameEventTags.getAllTags();
+ return gameEvents.getAllTags().keySet().stream().map(key -> (org.bukkit.Tag<T>) new io.papermc.paper.CraftGameEventTag(gameEvents, key)).toList();
+ // Paper end
default:
throw new IllegalArgumentException();
}