From c07b432618edfd1a1534412dedeef2e314a39be8 Mon Sep 17 00:00:00 2001 From: Yannick Lamprecht <1420893+yannicklamprecht@users.noreply.github.com> Date: Fri, 5 Feb 2021 23:14:27 +0100 Subject: [PATCH] living entity allow attribute registration (#4723) --- ...-entity-allow-attribute-registration.patch | 25 +++++++ ...-entity-allow-attribute-registration.patch | 69 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 Spigot-API-Patches/living-entity-allow-attribute-registration.patch create mode 100644 Spigot-Server-Patches/living-entity-allow-attribute-registration.patch diff --git a/Spigot-API-Patches/living-entity-allow-attribute-registration.patch b/Spigot-API-Patches/living-entity-allow-attribute-registration.patch new file mode 100644 index 0000000000..e27471ea0d --- /dev/null +++ b/Spigot-API-Patches/living-entity-allow-attribute-registration.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ysl3000 <yannicklamprecht@live.de> +Date: Sat, 24 Oct 2020 16:37:21 +0200 +Subject: [PATCH] living entity allow attribute registration + + +diff --git a/src/main/java/org/bukkit/attribute/Attributable.java b/src/main/java/org/bukkit/attribute/Attributable.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/attribute/Attributable.java ++++ b/src/main/java/org/bukkit/attribute/Attributable.java +@@ -0,0 +0,0 @@ public interface Attributable { + */ + @Nullable + AttributeInstance getAttribute(@NotNull Attribute attribute); ++ ++ // Paper start ++ /** ++ * Registers a generic attribute to that attributable instance. ++ * Allows it to add attributes not registered by default to that entity. ++ * ++ * @param attribute the generic attribute to register ++ */ ++ void registerAttribute(@NotNull Attribute attribute); ++ // Paper end + } diff --git a/Spigot-Server-Patches/living-entity-allow-attribute-registration.patch b/Spigot-Server-Patches/living-entity-allow-attribute-registration.patch new file mode 100644 index 0000000000..dc8be0ee38 --- /dev/null +++ b/Spigot-Server-Patches/living-entity-allow-attribute-registration.patch @@ -0,0 +1,69 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ysl3000 <yannicklamprecht@live.de> +Date: Sat, 24 Oct 2020 16:37:44 +0200 +Subject: [PATCH] living entity allow attribute registration + + +diff --git a/src/main/java/net/minecraft/server/AttributeMapBase.java b/src/main/java/net/minecraft/server/AttributeMapBase.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/AttributeMapBase.java ++++ b/src/main/java/net/minecraft/server/AttributeMapBase.java +@@ -0,0 +0,0 @@ import org.apache.logging.log4j.Logger; + public class AttributeMapBase { + + private static final Logger LOGGER = LogManager.getLogger(); +- private final Map<AttributeBase, AttributeModifiable> b = Maps.newHashMap(); ++ private final Map<AttributeBase, AttributeModifiable> b = Maps.newHashMap(); private final Map<AttributeBase, AttributeModifiable> attributeMap = b; // Paper - OBFHELPER + private final Set<AttributeModifiable> c = Sets.newHashSet(); + private final AttributeProvider d; + +@@ -0,0 +0,0 @@ public class AttributeMapBase { + } + + } ++ ++ // Paper - start ++ public void registerAttribute(AttributeBase attributeBase) { ++ net.minecraft.server.AttributeModifiable attributeModifiable = new net.minecraft.server.AttributeModifiable(attributeBase, net.minecraft.server.AttributeModifiable::getAttribute); ++ attributeMap.put(attributeBase, attributeModifiable); ++ } ++ // Paper - end ++ + } +diff --git a/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeMap.java b/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeMap.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeMap.java ++++ b/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeMap.java +@@ -0,0 +0,0 @@ public class CraftAttributeMap implements Attributable { + return (nms == null) ? null : new CraftAttributeInstance(nms, attribute); + } + ++ // Paper start ++ @Override ++ public void registerAttribute(Attribute attribute) { ++ Preconditions.checkArgument(attribute != null, "attribute"); ++ handle.registerAttribute(CraftAttributeMap.toMinecraft(attribute)); ++ } ++ // Paper end ++ + public static AttributeBase toMinecraft(Attribute attribute) { + return IRegistry.ATTRIBUTE.get(CraftNamespacedKey.toMinecraft(attribute.getKey())); + } +diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java ++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +@@ -0,0 +0,0 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { + return getHandle().craftAttributes.getAttribute(attribute); + } + ++ // Paper start ++ @Override ++ public void registerAttribute(Attribute attribute) { ++ getHandle().craftAttributes.registerAttribute(attribute); ++ } ++ // Paper end ++ + @Override + public void setAI(boolean ai) { + if (this.getHandle() instanceof EntityInsentient) {