
net.minecraft.server.GenericAttributes Maven / Gradle / Ivy
package net.minecraft.server;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Collection;
import java.util.UUID;
public class GenericAttributes {
// Spigot start
public static final IAttribute MAX_HEALTH = new AttributeRanged(null, "generic.maxHealth", 20.0D, 0.1D, org.spigotmc.SpigotConfig.maxHealth).a("Max Health").a(true);
public static final IAttribute FOLLOW_RANGE = new AttributeRanged(null, "generic.followRange", 32.0D, 0.0D, 2048.0D).a("Follow Range");
public static final IAttribute KNOCKBACK_RESISTANCE = new AttributeRanged(null, "generic.knockbackResistance", 0.0D, 0.0D, 1.0D).a("Knockback Resistance");
public static final IAttribute MOVEMENT_SPEED = new AttributeRanged(null, "generic.movementSpeed", 0.699999988079071D, 0.0D, org.spigotmc.SpigotConfig.movementSpeed).a("Movement Speed").a(true);
public static final IAttribute ATTACK_DAMAGE = new AttributeRanged(null, "generic.attackDamage", 2.0D, 0.0D, org.spigotmc.SpigotConfig.attackDamage);
private static final Logger f = LogManager.getLogger();
// Spigot end
public static NBTTagList a(AttributeMapBase attributes) {
NBTTagList nbttaglist = new NBTTagList();
for (AttributeInstance attributeinstance : attributes.a()) {
nbttaglist.add(a(attributeinstance));
}
return nbttaglist;
}
private static NBTTagCompound a(AttributeInstance attribute) {
NBTTagCompound nbttagcompound = new NBTTagCompound();
IAttribute iattribute = attribute.getAttribute();
nbttagcompound.setString("Name", iattribute.getName());
nbttagcompound.setDouble("Base", attribute.b());
Collection collection = attribute.c();
if (collection != null && !collection.isEmpty()) {
NBTTagList nbttaglist = new NBTTagList();
for (AttributeModifier attributemodifier : collection) {
if (attributemodifier.e()) {
nbttaglist.add(a(attributemodifier));
}
}
nbttagcompound.set("Modifiers", nbttaglist);
}
return nbttagcompound;
}
public static NBTTagCompound a(AttributeModifier attribute) {
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setString("Name", attribute.b());
nbttagcompound.setDouble("Amount", attribute.d());
nbttagcompound.setInt("Operation", attribute.c());
nbttagcompound.setLong("UUIDMost", attribute.a().getMostSignificantBits());
nbttagcompound.setLong("UUIDLeast", attribute.a().getLeastSignificantBits());
return nbttagcompound;
}
public static void a(AttributeMapBase attributes, NBTTagList tag) {
for (int i = 0; i < tag.size(); ++i) {
NBTTagCompound nbttagcompound = tag.getCompound(i);
AttributeInstance attributeinstance = attributes.a(nbttagcompound.getString("Name"));
if (attributeinstance != null) {
a(attributeinstance, nbttagcompound);
} else {
GenericAttributes.f.warn("Ignoring unknown attribute '" + nbttagcompound.getString("Name") + "'");
}
}
}
private static void a(AttributeInstance attribute, NBTTagCompound tag) {
attribute.setValue(tag.getDouble("Base"));
if (tag.hasKeyOfType("Modifiers", 9)) {
NBTTagList nbttaglist = tag.getList("Modifiers", 10);
for (int i = 0; i < nbttaglist.size(); ++i) {
AttributeModifier attributemodifier = a(nbttaglist.getCompound(i));
if (attributemodifier != null) {
AttributeModifier attributemodifier1 = attribute.a(attributemodifier.a());
if (attributemodifier1 != null) {
attribute.c(attributemodifier1);
}
attribute.b(attributemodifier);
}
}
}
}
public static AttributeModifier a(NBTTagCompound tag) {
UUID uuid = new UUID(tag.getLong("UUIDMost"), tag.getLong("UUIDLeast"));
try {
return new AttributeModifier(uuid, tag.getString("Name"), tag.getDouble("Amount"), tag.getInt("Operation"));
} catch (Exception exception) {
GenericAttributes.f.warn("Unable to create attribute: " + exception.getMessage());
return null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy