forked from apace100/origins-fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/io/github/apace100/origins/power/PlayerAbilityPower.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.github.apace100.origins.power; | ||
|
||
import io.github.apace100.origins.Origins; | ||
import io.github.ladysnake.pal.PlayerAbility; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
|
||
public class PlayerAbilityPower extends Power { | ||
|
||
PlayerAbility ability; | ||
|
||
public PlayerAbilityPower(PowerType<Power> type, PlayerEntity player, PlayerAbility ability){ | ||
super(type, player); | ||
this.ability = ability; | ||
setTicking(true); | ||
} | ||
|
||
@Override | ||
public void tick() { | ||
if(!player.world.isClient) { | ||
boolean isActive = isActive(); | ||
boolean hasAbility = hasAbility(); | ||
if(isActive && !hasAbility) { | ||
grantAbility(); | ||
} else if(!isActive && hasAbility) { | ||
revokeAbility(); | ||
} | ||
} | ||
} | ||
|
||
// Origins' onChosen is not as consistent as Apoli's onGained so hopefully tick does the job and I don't need to add onAdded/onRespawn callbacks | ||
|
||
@Override | ||
public void onLost() { | ||
if(!player.world.isClient && hasAbility()) { | ||
revokeAbility(); | ||
} | ||
} | ||
|
||
public boolean hasAbility() { | ||
return Origins.POWER_SOURCE.grants(player, ability); | ||
} | ||
|
||
public void grantAbility() { | ||
//Apoli.SCHEDULER.queue(server -> { | ||
Origins.POWER_SOURCE.grantTo(player, ability); | ||
// Apoli.POWER_SOURCE.grantTo((PlayerEntity)entity, VanillaAbilities.FLYING); | ||
//}, 1); | ||
} | ||
|
||
public void revokeAbility() { | ||
Origins.POWER_SOURCE.revokeFrom(player, ability); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters