living entity allow attribute registration (#4723)

This commit is contained in:
Yannick Lamprecht 2021-02-05 23:14:27 +01:00 committed by GitHub
parent 69a5c67b1d
commit 002f65b8b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 94 additions and 0 deletions

View File

@ -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 0ed96b5af0e6e93590882e0ad8239221bcc3f688..474ed1df364a5ca18661d0fbc29901760e39cb07 100644
--- a/src/main/java/org/bukkit/attribute/Attributable.java
+++ b/src/main/java/org/bukkit/attribute/Attributable.java
@@ -17,4 +17,14 @@ 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
}

View File

@ -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 c57e23e16b79017fe6dc084d634226cfdac772b5..f5f2f31e88433d894ff1e7c2f26686f671744c56 100644
--- a/src/main/java/net/minecraft/server/AttributeMapBase.java
+++ b/src/main/java/net/minecraft/server/AttributeMapBase.java
@@ -16,7 +16,7 @@ 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;
@@ -130,4 +130,12 @@ 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 c5dd25add39298342a6f4b2a05e137de93d1e62b..e343878a1755ee885f84c082ccba2777927c64bb 100644
--- a/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeMap.java
+++ b/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeMap.java
@@ -40,6 +40,14 @@ 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 16e69cfd4994fd6850ee3635ea819379412351c9..c1350bbf62fc5c5e18509f378edf16e8b210cfe8 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
@@ -665,6 +665,13 @@ 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) {