Remap CraftBukkit to Mojang+Yarn Mappings
By: Initial Source <noreply+automated@papermc.io>
This commit is contained in:
@@ -3,9 +3,7 @@ package org.bukkit.craftbukkit.attribute;
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.Locale;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeBase;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
@@ -15,16 +13,16 @@ import org.bukkit.craftbukkit.util.ApiVersion;
|
||||
import org.bukkit.craftbukkit.util.Handleable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CraftAttribute implements Attribute, Handleable<AttributeBase> {
|
||||
public class CraftAttribute implements Attribute, Handleable<net.minecraft.world.entity.ai.attributes.Attribute> {
|
||||
|
||||
private static int count = 0;
|
||||
|
||||
public static Attribute minecraftToBukkit(AttributeBase minecraft) {
|
||||
public static Attribute minecraftToBukkit(net.minecraft.world.entity.ai.attributes.Attribute minecraft) {
|
||||
return CraftRegistry.minecraftToBukkit(minecraft, Registries.ATTRIBUTE, Registry.ATTRIBUTE);
|
||||
}
|
||||
|
||||
public static Attribute minecraftHolderToBukkit(Holder<AttributeBase> minecraft) {
|
||||
return minecraftToBukkit(minecraft.value());
|
||||
public static Attribute minecraftHolderToBukkit(Holder<net.minecraft.world.entity.ai.attributes.Attribute> minecraft) {
|
||||
return CraftAttribute.minecraftToBukkit(minecraft.value());
|
||||
}
|
||||
|
||||
public static Attribute stringToBukkit(String string) {
|
||||
@@ -40,16 +38,16 @@ public class CraftAttribute implements Attribute, Handleable<AttributeBase> {
|
||||
return CraftRegistry.get(Registry.ATTRIBUTE, key, ApiVersion.CURRENT);
|
||||
}
|
||||
|
||||
public static AttributeBase bukkitToMinecraft(Attribute bukkit) {
|
||||
public static net.minecraft.world.entity.ai.attributes.Attribute bukkitToMinecraft(Attribute bukkit) {
|
||||
return CraftRegistry.bukkitToMinecraft(bukkit);
|
||||
}
|
||||
|
||||
public static Holder<AttributeBase> bukkitToMinecraftHolder(Attribute bukkit) {
|
||||
public static Holder<net.minecraft.world.entity.ai.attributes.Attribute> bukkitToMinecraftHolder(Attribute bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
IRegistry<AttributeBase> registry = CraftRegistry.getMinecraftRegistry(Registries.ATTRIBUTE);
|
||||
net.minecraft.core.Registry<net.minecraft.world.entity.ai.attributes.Attribute> registry = CraftRegistry.getMinecraftRegistry(Registries.ATTRIBUTE);
|
||||
|
||||
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<AttributeBase> holder) {
|
||||
if (registry.wrapAsHolder(CraftAttribute.bukkitToMinecraft(bukkit)) instanceof Holder.Reference<net.minecraft.world.entity.ai.attributes.Attribute> holder) {
|
||||
return holder;
|
||||
}
|
||||
|
||||
@@ -64,11 +62,11 @@ public class CraftAttribute implements Attribute, Handleable<AttributeBase> {
|
||||
}
|
||||
|
||||
private final NamespacedKey key;
|
||||
private final AttributeBase attributeBase;
|
||||
private final net.minecraft.world.entity.ai.attributes.Attribute attributeBase;
|
||||
private final String name;
|
||||
private final int ordinal;
|
||||
|
||||
public CraftAttribute(NamespacedKey key, AttributeBase attributeBase) {
|
||||
public CraftAttribute(NamespacedKey key, net.minecraft.world.entity.ai.attributes.Attribute attributeBase) {
|
||||
this.key = key;
|
||||
this.attributeBase = attributeBase;
|
||||
// For backwards compatibility, minecraft values will stile return the uppercase name without the namespace,
|
||||
@@ -80,46 +78,46 @@ public class CraftAttribute implements Attribute, Handleable<AttributeBase> {
|
||||
} else {
|
||||
this.name = key.toString();
|
||||
}
|
||||
this.ordinal = count++;
|
||||
this.ordinal = CraftAttribute.count++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeBase getHandle() {
|
||||
return attributeBase;
|
||||
public net.minecraft.world.entity.ai.attributes.Attribute getHandle() {
|
||||
return this.attributeBase;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NamespacedKey getKey() {
|
||||
return key;
|
||||
return this.key;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getTranslationKey() {
|
||||
return attributeBase.getDescriptionId();
|
||||
return this.attributeBase.getDescriptionId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull Attribute attribute) {
|
||||
return ordinal - attribute.ordinal();
|
||||
return this.ordinal - attribute.ordinal();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String name() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int ordinal() {
|
||||
return ordinal;
|
||||
return this.ordinal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// For backwards compatibility
|
||||
return name();
|
||||
return this.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -132,11 +130,11 @@ public class CraftAttribute implements Attribute, Handleable<AttributeBase> {
|
||||
return false;
|
||||
}
|
||||
|
||||
return getKey().equals(otherAttribute.getKey());
|
||||
return this.getKey().equals(otherAttribute.getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getKey().hashCode();
|
||||
return this.getKey().hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,34 +12,34 @@ import org.bukkit.inventory.EquipmentSlot;
|
||||
|
||||
public class CraftAttributeInstance implements AttributeInstance {
|
||||
|
||||
private final net.minecraft.world.entity.ai.attributes.AttributeModifiable handle;
|
||||
private final net.minecraft.world.entity.ai.attributes.AttributeInstance handle;
|
||||
private final Attribute attribute;
|
||||
|
||||
public CraftAttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeModifiable handle, Attribute attribute) {
|
||||
public CraftAttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance handle, Attribute attribute) {
|
||||
this.handle = handle;
|
||||
this.attribute = attribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attribute getAttribute() {
|
||||
return attribute;
|
||||
return this.attribute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBaseValue() {
|
||||
return handle.getBaseValue();
|
||||
return this.handle.getBaseValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBaseValue(double d) {
|
||||
handle.setBaseValue(d);
|
||||
this.handle.setBaseValue(d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<AttributeModifier> getModifiers() {
|
||||
List<AttributeModifier> result = new ArrayList<AttributeModifier>();
|
||||
for (net.minecraft.world.entity.ai.attributes.AttributeModifier nms : handle.getModifiers()) {
|
||||
result.add(convert(nms));
|
||||
for (net.minecraft.world.entity.ai.attributes.AttributeModifier nms : this.handle.getModifiers()) {
|
||||
result.add(CraftAttributeInstance.convert(nms));
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -48,23 +48,23 @@ public class CraftAttributeInstance implements AttributeInstance {
|
||||
@Override
|
||||
public void addModifier(AttributeModifier modifier) {
|
||||
Preconditions.checkArgument(modifier != null, "modifier");
|
||||
handle.addPermanentModifier(convert(modifier));
|
||||
this.handle.addPermanentModifier(CraftAttributeInstance.convert(modifier));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeModifier(AttributeModifier modifier) {
|
||||
Preconditions.checkArgument(modifier != null, "modifier");
|
||||
handle.removeModifier(convert(modifier));
|
||||
this.handle.removeModifier(CraftAttributeInstance.convert(modifier));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getValue() {
|
||||
return handle.getValue();
|
||||
return this.handle.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDefaultValue() {
|
||||
return handle.getAttribute().value().getDefaultValue();
|
||||
return this.handle.getAttribute().value().getDefaultValue();
|
||||
}
|
||||
|
||||
public static net.minecraft.world.entity.ai.attributes.AttributeModifier convert(AttributeModifier bukkit) {
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
package org.bukkit.craftbukkit.attribute;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeMapBase;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeMap;
|
||||
import org.bukkit.attribute.Attributable;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
|
||||
public class CraftAttributeMap implements Attributable {
|
||||
|
||||
private final AttributeMapBase handle;
|
||||
private final AttributeMap handle;
|
||||
|
||||
public CraftAttributeMap(AttributeMapBase handle) {
|
||||
public CraftAttributeMap(AttributeMap handle) {
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeInstance getAttribute(Attribute attribute) {
|
||||
Preconditions.checkArgument(attribute != null, "attribute");
|
||||
net.minecraft.world.entity.ai.attributes.AttributeModifiable nms = handle.getInstance(CraftAttribute.bukkitToMinecraftHolder(attribute));
|
||||
net.minecraft.world.entity.ai.attributes.AttributeInstance nms = this.handle.getInstance(CraftAttribute.bukkitToMinecraftHolder(attribute));
|
||||
|
||||
return (nms == null) ? null : new CraftAttributeInstance(nms, attribute);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user