Skip to content

Commit

Permalink
Backport creative_flight power
Browse files Browse the repository at this point in the history
  • Loading branch information
Alluysl committed Jul 22, 2021
1 parent 18bb284 commit f5f8952
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ dependencies {
modImplementation "com.jamieswhiteshirt:reach-entity-attributes:${project.reach_version}"
include "com.jamieswhiteshirt:reach-entity-attributes:${project.reach_version}"

modImplementation "io.github.ladysnake:PlayerAbilityLib:${pal_version}"
include "io.github.ladysnake:PlayerAbilityLib:${pal_version}"

modImplementation "com.github.adriantodt:FallFlyingLib:${project.ffl_version}"
include "com.github.adriantodt:FallFlyingLib:${project.ffl_version}"

Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx4G
loader_version=0.11.1

# Mod Properties
mod_version = 0.7.3
mod_version = 0.8.0
maven_group = io.github.apace100.origins
archives_base_name = Origins-1.16.5

Expand All @@ -18,5 +18,6 @@ org.gradle.jvmargs=-Xmx4G
cca_version=2.8.1
reach_version=1.1.1
ffl_version=1.1.0
pal_version=1.2.2
clothconfig_version=4.11.14
modmenu_version=1.16.9
4 changes: 4 additions & 0 deletions src/main/java/io/github/apace100/origins/Origins.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import io.github.apace100.origins.util.ElytraPowerFallFlying;
import io.github.apace100.origins.util.GainedPowerCriterion;
import io.github.apace100.origins.util.OriginsConfigSerializer;
import io.github.ladysnake.pal.AbilitySource;
import io.github.ladysnake.pal.Pal;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.Config;
Expand All @@ -41,6 +43,8 @@ public class Origins implements ModInitializer {

public static ServerConfig config;

public static final AbilitySource POWER_SOURCE = Pal.getAbilitySource(Origins.identifier("power_source"));

@Override
public void onInitialize() {
FabricLoader.getInstance().getModContainer(MODID).ifPresent(modContainer -> {
Expand Down
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.github.apace100.origins.registry.ModDamageSources;
import io.github.apace100.origins.registry.ModRegistries;
import io.github.apace100.origins.util.*;
import io.github.ladysnake.pal.VanillaAbilities;
import net.minecraft.block.pattern.CachedBlockPosition;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.*;
Expand Down Expand Up @@ -89,6 +90,11 @@ public static void register() {
(type, player) ->
new CooldownPower(type, player, data.getInt("cooldown"), (HudRender)data.get("hud_render")))
.allowCondition());
register(new PowerFactory<>(Origins.identifier("creative_flight"),
new SerializableData(),
data ->
(type, player) -> new PlayerAbilityPower(type, player, VanillaAbilities.ALLOW_FLYING))
.allowCondition());
register(new PowerFactory<>(Origins.identifier("effect_immunity"),
new SerializableData()
.add("effect", SerializableDataType.STATUS_EFFECT, null)
Expand Down

0 comments on commit f5f8952

Please # to comment.