Skip to content

ZsoltMolnarrr/ProjectileDamage

Repository files navigation

Projectile Damage Attribute

Java 17 Environment: Client & Server Discord

🏹️ Features

Adds new EntityAttribute to the game, with the following id: projectile_damage:generic. This allows customization of damage done by individual Bow and Crossbow items in the game.

Adds new status effect named Impact, that increases the projectile damage of the entity.

You can use the API provided by this mod, to set custom damage value to your custom ranged weapons.

🔧 Configuration

Server side configuration can be found in the config directory, after running the game with the mod installed.

🔨 Using it as a modder

Installation

Add this mod as dependency into your build.gradle file.

Repository

repositories {
    maven {
        name = 'Modrinth'
        url = 'https://api.modrinth.com/maven'
        content {
            includeGroup 'maven.modrinth'
        }
    }
}

Fabric workspace

dependencies {
    modImplementation "maven.modrinth:projectile-damage-attribute:VERSION-fabric"
}

In fabric.mod.json add a dependency to the mod:

  "depends": {
    "projectile_damage": ">=VERSION"
  },

(Substitute VERSION with the name of the latest release available on Modrinth, for example: 3.0.0)

Forge workspace

dependencies {
    implementation "maven.modrinth:projectile-damage-attribute:VERSION-forge"
}

In mods.toml add a dependency to the mod:

modId="projectile_damage"
mandatory=true
versionRange="[VERSION,)"
ordering="AFTER"
side="BOTH"

(Substitute VERSION with the name of the latest release available on Modrinth, for example: 3.0.0)

Applying projectile damage to weapons

Bows and Crossbows

  1. Make sure your custom Bow or Crossbow inherits from vanilla Bow or Crossbow classes.

  2. Set the projectile damage for your weapon instance, preferably before registering it. (Keep in mind, this doesn't fixate the damage output at a constant value, the vanilla behaviour adding randomness will be applied too)

((IProjectileWeapon)bowInstance).setProjectileDamage(10);

(Note: assigned damage value will be applied on the spawned arrow by this mod, no additional coding is required on your end.)

  1. (Optional) If your weapon releases arrows at a non default velocity, use the following to compensate the velocity and make the weapon perform the expected amount of damage. (Default velocity: bow: 3.0, crossbow: 3.15).
((IProjectileWeapon)bowInstance).setMaxProjectileVelocity(4.2);

Custom weapon types

Custom weapon types such as: canons, blowpipes, etc...

  1. Make sure the inheritance chain of your custom ranged weapon includes the vanilla class ProjectileWeaponItem (yarn:RangedWeaponItem) or provide a custom implementation of net.projectile_damage.api.IProjectileWeapon interface (default implementaion can be found here).

  2. Create a custom weapon type and save it somewhere. This holds the shared properties of your weapon class, which each instance will be scaled against.

public static class MyModItems {
    static RangedWeaponKind CANON = RangedWeaponKind.custom(6, 1.9D);
}
  1. Configure your items.
public static class MyModItems {
    static RangedWeaponKind CANNON = RangedWeaponKind.custom(6, 1.9D);
    
    public static MyCanon woodenCanon;
    public static MyCanon ironCanon;
    public static MyCanon diamondCanon;
    
    static {
        woodenCannon = new MyCannon(...);
        ((IProjectileWeapon)woodenCannon).setRangedWeaponKind(CANNON);
        // No custom damage is configured, default will be used from weapon kind
        
        ironCannon = new MyCannon(...);
        ((IProjectileWeapon)ironCannon).setRangedWeaponKind(CANNON);
        ((IProjectileWeapon)ironCannon).setProjectileDamage(8);
        
        diamondCannon = new MyCannon(...);
        ((IProjectileWeapon)diamondCannon).setRangedWeaponKind(CANNON);
        ((IProjectileWeapon)ironCannon).setProjectileDamage(10);
    } 
}