mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 01:37:35 +01:00
#978: Add Material#getDefaultAttributeModifiers
By: coll1234567 <joshl5324@gmail.com>
This commit is contained in:
parent
28ec7a3566
commit
23b34c080b
@ -7,6 +7,7 @@ import java.util.List;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
|
||||
public class CraftAttributeInstance implements AttributeInstance {
|
||||
|
||||
@ -72,4 +73,8 @@ public class CraftAttributeInstance implements AttributeInstance {
|
||||
public static AttributeModifier convert(net.minecraft.world.entity.ai.attributes.AttributeModifier nms) {
|
||||
return new AttributeModifier(nms.getId(), nms.getName(), nms.getAmount(), AttributeModifier.Operation.values()[nms.getOperation().ordinal()]);
|
||||
}
|
||||
|
||||
public static AttributeModifier convert(net.minecraft.world.entity.ai.attributes.AttributeModifier nms, EquipmentSlot slot) {
|
||||
return new AttributeModifier(nms.getId(), nms.getName(), nms.getAmount(), AttributeModifier.Operation.values()[nms.getOperation().ordinal()], slot);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,9 @@ package org.bukkit.craftbukkit.util;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.io.Files;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@ -16,6 +18,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.minecraft.SharedConstants;
|
||||
@ -32,6 +35,7 @@ import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ChatDeserializer;
|
||||
import net.minecraft.util.datafix.DataConverterRegistry;
|
||||
import net.minecraft.util.datafix.fixes.DataConverterTypes;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeBase;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
@ -44,10 +48,16 @@ import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.UnsafeValues;
|
||||
import org.bukkit.advancement.Advancement;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.attribute.CraftAttributeInstance;
|
||||
import org.bukkit.craftbukkit.attribute.CraftAttributeMap;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.legacy.CraftLegacy;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.plugin.InvalidPluginException;
|
||||
@ -332,6 +342,19 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(Material material, EquipmentSlot slot) {
|
||||
ImmutableMultimap.Builder<Attribute, AttributeModifier> defaultAttributes = ImmutableMultimap.builder();
|
||||
|
||||
Multimap<AttributeBase, net.minecraft.world.entity.ai.attributes.AttributeModifier> nmsDefaultAttributes = getItem(material).getDefaultAttributeModifiers(CraftEquipmentSlot.getNMS(slot));
|
||||
for (Entry<AttributeBase, net.minecraft.world.entity.ai.attributes.AttributeModifier> mapEntry : nmsDefaultAttributes.entries()) {
|
||||
Attribute attribute = CraftAttributeMap.fromMinecraft(IRegistry.ATTRIBUTE.getKey(mapEntry.getKey()).toString());
|
||||
defaultAttributes.put(attribute, CraftAttributeInstance.convert(mapEntry.getValue(), slot));
|
||||
}
|
||||
|
||||
return defaultAttributes.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* This helper class represents the different NBT Tags.
|
||||
* <p>
|
||||
|
Loading…
Reference in New Issue
Block a user