Add DamageType RegistryEvent (#11783)
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package io.papermc.paper;
|
||||
|
||||
import org.bukkit.craftbukkit.damage.CraftDamageEffect;
|
||||
import org.bukkit.damage.DamageEffect;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public class PaperServerInternalAPIBridge implements InternalAPIBridge {
|
||||
public static final PaperServerInternalAPIBridge INSTANCE = new PaperServerInternalAPIBridge();
|
||||
|
||||
@Override
|
||||
public DamageEffect getDamageEffect(final String key) {
|
||||
return CraftDamageEffect.getById(key);
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,9 @@ import io.papermc.paper.plugin.storage.ProviderStorage;
|
||||
import io.papermc.paper.plugin.storage.ServerPluginProviderStorage;
|
||||
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Used by the server to register/load plugin bootstrappers and plugins.
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.papermc.paper.adventure.PaperAdventure;
|
||||
import io.papermc.paper.datacomponent.DataComponentTypes;
|
||||
import io.papermc.paper.datacomponent.PaperDataComponentType;
|
||||
import io.papermc.paper.registry.data.PaperBannerPatternRegistryEntry;
|
||||
import io.papermc.paper.registry.data.PaperDamageTypeRegistryEntry;
|
||||
import io.papermc.paper.registry.data.PaperEnchantmentRegistryEntry;
|
||||
import io.papermc.paper.registry.data.PaperGameEventRegistryEntry;
|
||||
import io.papermc.paper.registry.data.PaperPaintingVariantRegistryEntry;
|
||||
@@ -103,7 +104,7 @@ public final class PaperRegistries {
|
||||
start(Registries.STRUCTURE, RegistryKey.STRUCTURE).craft(Structure.class, CraftStructure::new).build().delayed(),
|
||||
start(Registries.TRIM_MATERIAL, RegistryKey.TRIM_MATERIAL).craft(TrimMaterial.class, CraftTrimMaterial::new).build().delayed(),
|
||||
start(Registries.TRIM_PATTERN, RegistryKey.TRIM_PATTERN).craft(TrimPattern.class, CraftTrimPattern::new).build().delayed(),
|
||||
start(Registries.DAMAGE_TYPE, RegistryKey.DAMAGE_TYPE).craft(DamageType.class, CraftDamageType::new).build().delayed(),
|
||||
start(Registries.DAMAGE_TYPE, RegistryKey.DAMAGE_TYPE).craft(DamageType.class, CraftDamageType::new).writable(PaperDamageTypeRegistryEntry.PaperBuilder::new).delayed(),
|
||||
start(Registries.WOLF_VARIANT, RegistryKey.WOLF_VARIANT).craft(Wolf.Variant.class, CraftWolf.CraftVariant::new).build().delayed(),
|
||||
start(Registries.ENCHANTMENT, RegistryKey.ENCHANTMENT).craft(Enchantment.class, CraftEnchantment::new).serializationUpdater(FieldRename.ENCHANTMENT_RENAME).writable(PaperEnchantmentRegistryEntry.PaperBuilder::new).delayed(),
|
||||
start(Registries.JUKEBOX_SONG, RegistryKey.JUKEBOX_SONG).craft(JukeboxSong.class, CraftJukeboxSong::new).build().delayed(),
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
package io.papermc.paper.registry.data;
|
||||
|
||||
import io.papermc.paper.registry.PaperRegistryBuilder;
|
||||
import io.papermc.paper.registry.data.util.Conversions;
|
||||
import net.minecraft.world.damagesource.DamageEffects;
|
||||
import net.minecraft.world.damagesource.DamageScaling;
|
||||
import net.minecraft.world.damagesource.DamageType;
|
||||
import net.minecraft.world.damagesource.DeathMessageType;
|
||||
import org.bukkit.craftbukkit.damage.CraftDamageEffect;
|
||||
import org.bukkit.craftbukkit.damage.CraftDamageType;
|
||||
import org.bukkit.damage.DamageEffect;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.asConfigured;
|
||||
|
||||
public class PaperDamageTypeRegistryEntry implements DamageTypeRegistryEntry {
|
||||
|
||||
protected @Nullable String messageId;
|
||||
protected @Nullable Float exhaustion;
|
||||
protected @Nullable DamageScaling damageScaling;
|
||||
protected DamageEffects damageEffects = DamageEffects.HURT;
|
||||
protected DeathMessageType deathMessageType = DeathMessageType.DEFAULT;
|
||||
|
||||
protected final Conversions conversions;
|
||||
|
||||
public PaperDamageTypeRegistryEntry(
|
||||
final Conversions conversions,
|
||||
final @Nullable DamageType internal
|
||||
) {
|
||||
this.conversions = conversions;
|
||||
if (internal == null) return;
|
||||
|
||||
this.messageId = internal.msgId();
|
||||
this.exhaustion = internal.exhaustion();
|
||||
this.damageScaling = internal.scaling();
|
||||
this.damageEffects = internal.effects();
|
||||
this.deathMessageType = internal.deathMessageType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String messageId() {
|
||||
return asConfigured(messageId, "messsageId");
|
||||
}
|
||||
|
||||
@Override
|
||||
public float exhaustion() {
|
||||
return asConfigured(exhaustion, "exhaustion");
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.damage.DamageScaling damageScaling() {
|
||||
return CraftDamageType.damageScalingToBukkit(asConfigured(this.damageScaling, "damageScaling"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DamageEffect damageEffect() {
|
||||
return CraftDamageEffect.toBukkit(damageEffects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.damage.DeathMessageType deathMessageType() {
|
||||
return CraftDamageType.deathMessageTypeToBukkit(deathMessageType);
|
||||
}
|
||||
|
||||
public static final class PaperBuilder extends PaperDamageTypeRegistryEntry implements DamageTypeRegistryEntry.Builder, PaperRegistryBuilder<DamageType, org.bukkit.damage.DamageType> {
|
||||
|
||||
public PaperBuilder(final Conversions conversions, final @Nullable DamageType internal) {
|
||||
super(conversions, internal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder messageId(final String messageId) {
|
||||
this.messageId = messageId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder exhaustion(final float exhaustion) {
|
||||
this.exhaustion = exhaustion;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder damageScaling(final org.bukkit.damage.DamageScaling scaling) {
|
||||
this.damageScaling = CraftDamageType.damageScalingToNMS(scaling);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder damageEffect(final DamageEffect effect) {
|
||||
this.damageEffects = ((CraftDamageEffect) effect).getHandle();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder deathMessageType(final org.bukkit.damage.DeathMessageType deathMessageType) {
|
||||
this.deathMessageType = CraftDamageType.deathMessageTypeToNMS(deathMessageType);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DamageType build() {
|
||||
return new DamageType(
|
||||
asConfigured(this.messageId, "messsageId"),
|
||||
asConfigured(this.damageScaling, "scaling"),
|
||||
asConfigured(this.exhaustion, "exhaustion"),
|
||||
this.damageEffects,
|
||||
this.deathMessageType
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
io.papermc.paper.PaperServerInternalAPIBridge
|
||||
Reference in New Issue
Block a user