https://github.com/ladysnake/playerabilitylib
It's your new pal!
https://github.com/ladysnake/playerabilitylib
fabricmc fabricmc-mod hacktoberfest library
Last synced: 3 months ago
JSON representation
It's your new pal!
- Host: GitHub
- URL: https://github.com/ladysnake/playerabilitylib
- Owner: Ladysnake
- License: lgpl-3.0
- Created: 2019-12-26T19:39:55.000Z (over 6 years ago)
- Default Branch: 1.21
- Last Pushed: 2024-06-11T07:17:33.000Z (about 2 years ago)
- Last Synced: 2024-10-20T01:25:35.861Z (over 1 year ago)
- Topics: fabricmc, fabricmc-mod, hacktoberfest, library
- Language: Java
- Homepage:
- Size: 273 KB
- Stars: 13
- Watchers: 2
- Forks: 8
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
# PlayerAbilityLib
[](https://www.curseforge.com/projects/359522) [](https://jitpack.io/#Ladysnake/PlayerAbilityLib)
A lightweight serverside library to provide compatibility between mods that make use of player abilities.
Conflicts arise often when several mods update the same field in `PlayerAbilities`. This library exists so that
all modifications can be made from a single place, keeping track of what mod enabled what ability.
**Looking for the Elytra Flight equivalent? Try [FallFlyingLib](https://github.com/adriantodt/FallFlyingLib) or [CaelusApi](https://github.com/TheIllusiveC4/Caelus).**
*credits to ~~InsomniaPrincess~~ Chloe Dawn for some of the API design*
## Adding PAL to your project
You can add the library by inserting the following in your `build.gradle` :
```gradle
repositories {
maven {
name = 'Ladysnake Mods'
url = 'https://maven.ladysnake.org/releases'
content {
includeGroup 'io.github.ladysnake'
includeGroupByRegex 'org\\.ladysnake.*'
}
}
}
dependencies {
modImplementation "io.github.ladysnake:PlayerAbilityLib:${pal_version}"
include "io.github.ladysnake:PlayerAbilityLib:${pal_version}"
}
```
You can then add the library version to your `gradle.properties`file:
```properties
# PlayerAbilityLib
pal_version = 1.x.y
```
You can find the current version of PAL in the [releases](https://github.com/Ladysnake/PlayerAbilityLib/releases) tab of the repository on Github.
## Using PAL
You can find a couple examples in the [Test Mod](https://github.com/Ladysnake/PlayerAbilityLib/tree/master/src/testmod/java/io/github/ladysnake/paltest).
**Note that PAL interfaces can only be accessed serverside, as no synchronization is done on the ability sources.**
Read accesses can still be done directly on the `PlayerAbilities` instance, both serverside and clientside.
If you want to store more complex data, or to synchronize it between server and client,
you should take a look at [Cardinal Components API](https://github.com/OnyxStudios/Cardinal-Components-API).
[Item that toggles an ability](https://github.com/Ladysnake/PlayerAbilityLib/blob/master/src/testmod/java/io/github/ladysnake/paltest/AbilityToggleItem.java) :
```java
public static final AbilitySource FLIGHT_CHARM = Pal.getAbilitySource("mymod", "flight_charm"); // works like an identifier
@Override
public ActionResult use(World world, PlayerEntity user, Hand hand) {
if (!world.isClient) {
if (FLIGHT_CHARM.grants(user, VanillaAbilities.ALLOW_FLYING)) { // check whether the source is granting the ability
FLIGHT_CHARM.revokeFrom(user, VanillaAbilities.ALLOW_FLYING); // if it is, revoke it
} else {
FLIGHT_CHARM.grantTo(user, VanillaAbilities.ALLOW_FLYING); // otherwise, grant it
}
}
return ActionResult.SUCCESS;
}
```
[Potion that grants an ability](https://github.com/Ladysnake/PlayerAbilityLib/blob/master/src/testmod/java/io/github/ladysnake/paltest/FlightEffect.java) :
```java
public static final AbilitySource FLIGHT_POTION = Pal.getAbilitySource("mymod", "flight_potion");
@Override
public void onApplied(LivingEntity effected, AbstractEntityAttributeContainer attributes, int amplifier) {
if (effected instanceof PlayerEntity) {
Pal.grantAbility((PlayerEntity) effected, VanillaAbilities.ALLOW_FLYING, FLIGHT_POTION);
// equivalent to: FLIGHT_POTION.grantTo((PlayerEntity) effected, VanillaAbilities.ALLOW_FLYING);
}
}
public void onRemoved(LivingEntity effected) {
if (effected instanceof PlayerEntity) {
Pal.revokeAbility((PlayerEntity) effected, VanillaAbilities.ALLOW_FLYING, FLIGHT_POTION);
// equivalent to: FLIGHT_POTION.revokeFrom((PlayerEntity) effected, VanillaAbilities.ALLOW_FLYING);
}
}
```
Note that the `onRemoved` method needs a mixin to work, as the vanilla `StatusEffect#onRemoved` method does not get a `LivingEntity` parameter.
You can find an example of such a mixin [here](https://github.com/Ladysnake/PlayerAbilityLib/blob/master/src/testmod/java/io/github/ladysnake/paltest/mixin/LivingEntityMixin.java)