Repository navigation
Damage
import com.gugas749.abysscore.api.damages.AbyssDamage;
// Plain damage (same as target.hurt(source, amount))
AbyssDamage.deal(target, source, 5f);
// Damage + an effect, applied ONLY if the hit landed (not blocked, not invulnerable...)
AbyssDamage.deal(target, source, 4f, new MobEffectInstance(MobEffects.WITHER, 100, 1)); // Wither II, 5 sIt takes a ready MobEffectInstance because the effect type is a Holder<MobEffect> on 1.21.1 and a MobEffect on
1.20.1. new MobEffectInstance(MobEffects.X, duration, amplifier) is the same source code on both.
- Duration is in ticks: 20 = 1 second.
- Amplifier
0= level I,1= level II.
Builds a DamageSource from any damage type key, on both versions:
import com.gugas749.abysscore.api.damages.AbyssDamageSources;
// AbyssCore's corruption damage
DamageSource a = AbyssDamageSources.corruption(level); // no attacker
DamageSource b = AbyssDamageSources.corruption(level, caster); // with an attacker (kill credit, ".player" message)
// ANY damage type, including your own
DamageSource c = AbyssDamageSources.source(MyDamageTypes.CURSE, level);
DamageSource d = AbyssDamageSources.source(MyDamageTypes.CURSE, level, attacker); // melee / spell
DamageSource e = AbyssDamageSources.source(MyDamageTypes.CURSE, level, arrow, shooter); // projectile| Method | Direct entity | Causing entity |
|---|---|---|
source(key, level) |
— | — |
source(key, level, attacker) |
attacker |
attacker |
source(key, level, directEntity, causingEntity) |
what hit (arrow, fireball) | who's responsible (gets the kill credit) |
corruption(level) / corruption(level, attacker)
|
same as above, with CORRUPTION_DAMAGE
|
All of them throw if the damage type doesn't exist as data (see your own damage types).
Shipped in the jar as data/abysscore/damage_type/*.json:
| Key | Id | Scaling | Exhaustion | Death message |
|---|---|---|---|---|
AbyssDamageTypes.CORRUPTION_DAMAGE |
abysscore:corruption_damage |
always |
0.1 | "%1$s was corrupted to death" / "%1$s fell victim to %2$s corruption" |
AbyssDamageTypes.TEST_DAMAGE |
abysscore:test_damage |
always |
0.0 | "%1$s died (test damage)" |
AbyssDamageTypes.bootstrap(ctx::register) produces the same two types in datagen. You don't need it, because the
JSON is already in the jar.
Damage types are data (datapack registry), so you need (1) a key, (2) the JSON, generated or hand-written, and
(3) AbyssDamageSources.source(key, ...) to use it.
1. Key
public final class MyDamageTypes {
public static final ResourceKey<DamageType> CURSE =
ResourceKey.create(Registries.DAMAGE_TYPE, ResourceLocation.fromNamespaceAndPath("mymod", "curse"));
// Forge 1.20.1: new ResourceLocation("mymod", "curse")
public static void bootstrap(BiConsumer<ResourceKey<DamageType>, DamageType> ctx) {
new DamageTypeBuilder(CURSE)
.scaling(DamageScaling.NEVER) // default: WHEN_CAUSED_BY_LIVING_NON_PLAYER
.exhaustion(0.1f) // hunger used per hit, default 0
.effects(DamageEffects.HURT) // hurt sound, default HURT
.deathMessageType(DeathMessageType.DEFAULT)
.register(ctx);
}
}| Builder method | Default | Meaning |
|---|---|---|
scaling(DamageScaling) |
WHEN_CAUSED_BY_LIVING_NON_PLAYER |
Whether difficulty scales the damage: NEVER, ALWAYS, WHEN_CAUSED_BY_LIVING_NON_PLAYER
|
exhaustion(float) |
0.0 |
Hunger exhaustion per hit |
effects(DamageEffects) |
HURT |
Hurt sound: HURT, THORNS, DROWNING, BURNING, POKING, FREEZING
|
deathMessageType(DeathMessageType) |
DEFAULT |
DEFAULT, FALL_VARIANTS, INTENTIONAL_GAME_DESIGN
|
build() |
Returns the DamageType. msgId is always <namespace>.<path>. |
|
register(BiConsumer) |
build() + hand it to the consumer |
register takes a BiConsumer instead of a bootstrap context, because the class is BootstapContext (sic) on
1.20.1 and BootstrapContext on 1.21.1. ctx::register works on both.
2a. Datagen (NeoForge 1.21.1 shown; Forge 1.20.1's DatapackBuiltinEntriesProvider is the same idea):
// In your GatherDataEvent listener
RegistrySetBuilder builder = new RegistrySetBuilder()
.add(Registries.DAMAGE_TYPE, ctx -> MyDamageTypes.bootstrap(ctx::register));
event.getGenerator().addProvider(event.includeServer(),
new DatapackBuiltinEntriesProvider(event.getGenerator().getPackOutput(),
event.getLookupProvider(), builder, Set.of("mymod")));2b. Or write the JSON by hand: src/main/resources/data/mymod/damage_type/curse.json
{
"message_id": "mymod.curse",
"scaling": "never",
"exhaustion": 0.1,
"effects": "hurt",
"death_message_type": "default"
}Death messages (lang file). The key is death.attack.<message_id>:
"death.attack.mymod.curse": "%1$s was consumed by a curse",
"death.attack.mymod.curse.player": "%1$s was cursed to death by %2$s"Optional tags: add the type to data/minecraft/tags/damage_type/bypasses_armor.json and similar tags to change
how it interacts with armor, invulnerability and so on.
3. Use it with AbyssDamageSources.source(...). It's usually worth wrapping in a small helper class of your own:
public final class MyDamageSources {
public static DamageSource curse(Level level) { return AbyssDamageSources.source(MyDamageTypes.CURSE, level); }
public static DamageSource curse(Level level, Entity caster) { return AbyssDamageSources.source(MyDamageTypes.CURSE, level, caster); }
public static DamageSource curse(Level level, Entity orb, Entity caster) {
return AbyssDamageSources.source(MyDamageTypes.CURSE, level, orb, caster);
}
}
AbyssDamage.deal(target, MyDamageSources.curse(level, caster), 6f,
new MobEffectInstance(MobEffects.WEAKNESS, 200, 0));Checking a damage type (in a damage event, or hurt override):
if (source.is(MyDamageTypes.CURSE)) { ... } // exact type
if (source.is(DamageTypeTags.BYPASSES_ARMOR)) { ... } // any type in a tagYou can also tie a screen flash to your damage type, see §9.
- Setup: depending on AbyssCore
- Sides, threads and lifecycle: read this first
- Permissions
- Networking
- Synced player data
- Corruption
- Damage
- Continuous effects
- Screen overlays
- Commands
- GUI toolkit
- GeckoLib
- Outside the API package: vanish and config queries
- Complete example: a mana mod
- Limitations, troubleshooting and changelog
- Quick reference