Remap CraftBukkit to Mojang+Yarn Mappings
By: Initial Source <noreply+automated@papermc.io>
This commit is contained in:
@@ -2,7 +2,7 @@ package org.bukkit.craftbukkit.potion;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.effect.MobEffectList;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
@@ -13,43 +13,43 @@ import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.potion.PotionEffectTypeCategory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CraftPotionEffectType extends PotionEffectType implements Handleable<MobEffectList> {
|
||||
public class CraftPotionEffectType extends PotionEffectType implements Handleable<MobEffect> {
|
||||
|
||||
public static PotionEffectType minecraftHolderToBukkit(Holder<MobEffectList> minecraft) {
|
||||
return minecraftToBukkit(minecraft.value());
|
||||
public static PotionEffectType minecraftHolderToBukkit(Holder<MobEffect> minecraft) {
|
||||
return CraftPotionEffectType.minecraftToBukkit(minecraft.value());
|
||||
}
|
||||
|
||||
public static PotionEffectType minecraftToBukkit(MobEffectList minecraft) {
|
||||
public static PotionEffectType minecraftToBukkit(MobEffect minecraft) {
|
||||
return CraftRegistry.minecraftToBukkit(minecraft, Registries.MOB_EFFECT, Registry.EFFECT);
|
||||
}
|
||||
|
||||
public static MobEffectList bukkitToMinecraft(PotionEffectType bukkit) {
|
||||
public static MobEffect bukkitToMinecraft(PotionEffectType bukkit) {
|
||||
return CraftRegistry.bukkitToMinecraft(bukkit);
|
||||
}
|
||||
|
||||
public static Holder<MobEffectList> bukkitToMinecraftHolder(PotionEffectType bukkit) {
|
||||
public static Holder<MobEffect> bukkitToMinecraftHolder(PotionEffectType bukkit) {
|
||||
return CraftRegistry.bukkitToMinecraftHolder(bukkit, Registries.MOB_EFFECT);
|
||||
}
|
||||
|
||||
private final NamespacedKey key;
|
||||
private final MobEffectList handle;
|
||||
private final MobEffect handle;
|
||||
private final int id;
|
||||
|
||||
public CraftPotionEffectType(NamespacedKey key, MobEffectList handle) {
|
||||
public CraftPotionEffectType(NamespacedKey key, MobEffect handle) {
|
||||
this.key = key;
|
||||
this.handle = handle;
|
||||
this.id = CraftRegistry.getMinecraftRegistry(Registries.MOB_EFFECT).getId(handle) + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobEffectList getHandle() {
|
||||
return handle;
|
||||
public MobEffect getHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NamespacedKey getKey() {
|
||||
return key;
|
||||
return this.key;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,12 +59,12 @@ public class CraftPotionEffectType extends PotionEffectType implements Handleabl
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return switch (getId()) {
|
||||
return switch (this.getId()) {
|
||||
case 1 -> "SPEED";
|
||||
case 2 -> "SLOW";
|
||||
case 3 -> "FAST_DIGGING";
|
||||
@@ -98,35 +98,35 @@ public class CraftPotionEffectType extends PotionEffectType implements Handleabl
|
||||
case 31 -> "BAD_OMEN";
|
||||
case 32 -> "HERO_OF_THE_VILLAGE";
|
||||
case 33 -> "DARKNESS";
|
||||
default -> getKey().toString();
|
||||
default -> this.getKey().toString();
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PotionEffect createEffect(int duration, int amplifier) {
|
||||
return new PotionEffect(this, isInstant() ? 1 : (int) (duration * getDurationModifier()), amplifier);
|
||||
return new PotionEffect(this, this.isInstant() ? 1 : (int) (duration * this.getDurationModifier()), amplifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInstant() {
|
||||
return handle.isInstantenous();
|
||||
return this.handle.isInstantenous();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PotionEffectTypeCategory getCategory() {
|
||||
return CraftPotionEffectTypeCategory.minecraftToBukkit(handle.getCategory());
|
||||
return CraftPotionEffectTypeCategory.minecraftToBukkit(this.handle.getCategory());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor() {
|
||||
return Color.fromRGB(handle.getColor());
|
||||
return Color.fromRGB(this.handle.getColor());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getTranslationKey() {
|
||||
return handle.getDescriptionId();
|
||||
return this.handle.getDescriptionId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -139,16 +139,16 @@ public class CraftPotionEffectType extends PotionEffectType implements Handleabl
|
||||
return false;
|
||||
}
|
||||
|
||||
return getKey().equals(((PotionEffectType) other).getKey());
|
||||
return this.getKey().equals(((PotionEffectType) other).getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getKey().hashCode();
|
||||
return this.getKey().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CraftPotionEffectType[" + getKey() + "]";
|
||||
return "CraftPotionEffectType[" + this.getKey() + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package org.bukkit.craftbukkit.potion;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.world.effect.MobEffectInfo;
|
||||
import net.minecraft.world.effect.MobEffectCategory;
|
||||
import org.bukkit.potion.PotionEffectTypeCategory;
|
||||
|
||||
public final class CraftPotionEffectTypeCategory {
|
||||
|
||||
public static PotionEffectTypeCategory minecraftToBukkit(MobEffectInfo minecraft) {
|
||||
public static PotionEffectTypeCategory minecraftToBukkit(MobEffectCategory minecraft) {
|
||||
Preconditions.checkArgument(minecraft != null);
|
||||
return PotionEffectTypeCategory.valueOf(minecraft.name());
|
||||
}
|
||||
|
||||
public static MobEffectInfo bukkitToMinecraft(PotionEffectTypeCategory bukkit) {
|
||||
public static MobEffectCategory bukkitToMinecraft(PotionEffectTypeCategory bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
return MobEffectInfo.valueOf(bukkit.name());
|
||||
return MobEffectCategory.valueOf(bukkit.name());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,8 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Supplier;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.item.alchemy.PotionRegistry;
|
||||
import net.minecraft.world.item.alchemy.Potion;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
@@ -21,14 +20,14 @@ import org.bukkit.potion.PotionType;
|
||||
|
||||
public class CraftPotionType implements PotionType.InternalPotionData {
|
||||
|
||||
public static PotionType minecraftHolderToBukkit(Holder<PotionRegistry> minecraft) {
|
||||
return minecraftToBukkit(minecraft.value());
|
||||
public static PotionType minecraftHolderToBukkit(Holder<Potion> minecraft) {
|
||||
return CraftPotionType.minecraftToBukkit(minecraft.value());
|
||||
}
|
||||
|
||||
public static PotionType minecraftToBukkit(PotionRegistry minecraft) {
|
||||
public static PotionType minecraftToBukkit(Potion minecraft) {
|
||||
Preconditions.checkArgument(minecraft != null);
|
||||
|
||||
IRegistry<PotionRegistry> registry = CraftRegistry.getMinecraftRegistry(Registries.POTION);
|
||||
net.minecraft.core.Registry<Potion> registry = CraftRegistry.getMinecraftRegistry(Registries.POTION);
|
||||
PotionType bukkit = Registry.POTION.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location()));
|
||||
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
@@ -36,19 +35,19 @@ public class CraftPotionType implements PotionType.InternalPotionData {
|
||||
return bukkit;
|
||||
}
|
||||
|
||||
public static PotionRegistry bukkitToMinecraft(PotionType bukkit) {
|
||||
public static Potion bukkitToMinecraft(PotionType bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return CraftRegistry.getMinecraftRegistry(Registries.POTION)
|
||||
.getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow();
|
||||
}
|
||||
|
||||
public static Holder<PotionRegistry> bukkitToMinecraftHolder(PotionType bukkit) {
|
||||
public static Holder<Potion> bukkitToMinecraftHolder(PotionType bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
IRegistry<PotionRegistry> registry = CraftRegistry.getMinecraftRegistry(Registries.POTION);
|
||||
net.minecraft.core.Registry<Potion> registry = CraftRegistry.getMinecraftRegistry(Registries.POTION);
|
||||
|
||||
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<PotionRegistry> holder) {
|
||||
if (registry.wrapAsHolder(CraftPotionType.bukkitToMinecraft(bukkit)) instanceof Holder.Reference<Potion> holder) {
|
||||
return holder;
|
||||
}
|
||||
|
||||
@@ -76,48 +75,48 @@ public class CraftPotionType implements PotionType.InternalPotionData {
|
||||
}
|
||||
|
||||
private final NamespacedKey key;
|
||||
private final PotionRegistry potion;
|
||||
private final Potion potion;
|
||||
private final Supplier<List<PotionEffect>> potionEffects;
|
||||
private final Supplier<Boolean> upgradeable;
|
||||
private final Supplier<Boolean> extendable;
|
||||
private final Supplier<Integer> maxLevel;
|
||||
|
||||
public CraftPotionType(NamespacedKey key, PotionRegistry potion) {
|
||||
public CraftPotionType(NamespacedKey key, Potion potion) {
|
||||
this.key = key;
|
||||
this.potion = potion;
|
||||
this.potionEffects = Suppliers.memoize(() -> potion.getEffects().stream().map(CraftPotionUtil::toBukkit).toList());
|
||||
this.upgradeable = Suppliers.memoize(() -> Registry.POTION.get(new NamespacedKey(key.getNamespace(), "strong_" + key.getKey())) != null);
|
||||
this.extendable = Suppliers.memoize(() -> Registry.POTION.get(new NamespacedKey(key.getNamespace(), "long_" + key.getKey())) != null);
|
||||
this.maxLevel = Suppliers.memoize(() -> isUpgradeable() ? 2 : 1);
|
||||
this.maxLevel = Suppliers.memoize(() -> this.isUpgradeable() ? 2 : 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PotionEffectType getEffectType() {
|
||||
return getPotionEffects().isEmpty() ? null : getPotionEffects().get(0).getType();
|
||||
return this.getPotionEffects().isEmpty() ? null : this.getPotionEffects().get(0).getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PotionEffect> getPotionEffects() {
|
||||
return potionEffects.get();
|
||||
return this.potionEffects.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInstant() {
|
||||
return potion.hasInstantEffects();
|
||||
return this.potion.hasInstantEffects();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpgradeable() {
|
||||
return upgradeable.get();
|
||||
return this.upgradeable.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExtendable() {
|
||||
return extendable.get();
|
||||
return this.extendable.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return maxLevel.get();
|
||||
return this.maxLevel.get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectList;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import org.bukkit.potion.PotionData;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
@@ -47,9 +47,9 @@ public class CraftPotionUtil {
|
||||
|
||||
PotionType type;
|
||||
if (data.isUpgraded()) {
|
||||
type = upgradeable.get(data.getType());
|
||||
type = CraftPotionUtil.upgradeable.get(data.getType());
|
||||
} else if (data.isExtended()) {
|
||||
type = extendable.get(data.getType());
|
||||
type = CraftPotionUtil.extendable.get(data.getType());
|
||||
} else {
|
||||
type = data.getType();
|
||||
}
|
||||
@@ -64,11 +64,11 @@ public class CraftPotionUtil {
|
||||
}
|
||||
|
||||
PotionType potionType;
|
||||
potionType = extendable.inverse().get(type);
|
||||
potionType = CraftPotionUtil.extendable.inverse().get(type);
|
||||
if (potionType != null) {
|
||||
return new PotionData(potionType, true, false);
|
||||
}
|
||||
potionType = upgradeable.inverse().get(type);
|
||||
potionType = CraftPotionUtil.upgradeable.inverse().get(type);
|
||||
if (potionType != null) {
|
||||
return new PotionData(potionType, false, true);
|
||||
}
|
||||
@@ -76,12 +76,12 @@ public class CraftPotionUtil {
|
||||
return new PotionData(type, false, false);
|
||||
}
|
||||
|
||||
public static MobEffect fromBukkit(PotionEffect effect) {
|
||||
Holder<MobEffectList> type = CraftPotionEffectType.bukkitToMinecraftHolder(effect.getType());
|
||||
return new MobEffect(type, effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles());
|
||||
public static MobEffectInstance fromBukkit(PotionEffect effect) {
|
||||
Holder<MobEffect> type = CraftPotionEffectType.bukkitToMinecraftHolder(effect.getType());
|
||||
return new MobEffectInstance(type, effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles());
|
||||
}
|
||||
|
||||
public static PotionEffect toBukkit(MobEffect effect) {
|
||||
public static PotionEffect toBukkit(MobEffectInstance effect) {
|
||||
PotionEffectType type = CraftPotionEffectType.minecraftHolderToBukkit(effect.getEffect());
|
||||
int amp = effect.getAmplifier();
|
||||
int duration = effect.getDuration();
|
||||
@@ -90,7 +90,7 @@ public class CraftPotionUtil {
|
||||
return new PotionEffect(type, duration, amp, ambient, particles);
|
||||
}
|
||||
|
||||
public static boolean equals(Holder<MobEffectList> mobEffect, PotionEffectType type) {
|
||||
public static boolean equals(Holder<MobEffect> mobEffect, PotionEffectType type) {
|
||||
PotionEffectType typeV = CraftPotionEffectType.minecraftHolderToBukkit(mobEffect);
|
||||
return typeV.equals(type);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user