Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config option to set a separate feather cost for air-dodges #95

Open
wants to merge 1 commit into
base: 1.19.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class ED2ClientStorage {
private static boolean airborne;
private static double power;
private static double verticality;
private static int airborneCost;
private static boolean animating = ED2ClientConfig.DISPLAY_ANIMATION.get();

public static int getCooldown() {
Expand Down Expand Up @@ -41,6 +42,12 @@ public static double getPower() {
public static void setPower(double power) {
ED2ClientStorage.power = power;
}
public static int getAirborneCost() {
return airborneCost;
}
public static void setAirborneCost(int airborneCost) {
ED2ClientStorage.airborneCost = airborneCost;
}
public static boolean isAnimating() {
return animating;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ED2CommonConfig {


public static final ForgeConfigSpec.ConfigValue<Boolean> DODGE_WHILST_AIRBORNE;
public static final ForgeConfigSpec.ConfigValue<Integer> DODGE_COST_WHILST_AIRBORNE;

//TODO: Add the tutorial back!
static {
Expand All @@ -34,8 +35,10 @@ public class ED2CommonConfig {
DODGE_HEIGHT = BUILDER.comment("How high the player moves when dodging")
.define("Dodge Height", 0.2d);


DODGE_WHILST_AIRBORNE = BUILDER.comment("Whether the player can dodge in mid-air").define("Dodge Whilst Airborne", false);

DODGE_COST_WHILST_AIRBORNE = BUILDER.comment("How many half feathers it costs to dodge while airborne")
.define("Dodge Cost Air", 2);

BUILDER.pop();
SPEC = BUILDER.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void onPlayerJoinWorld(EntityJoinLevelEvent event) {
Level level = event.getLevel();
if (!level.isClientSide && (event.getEntity() instanceof ServerPlayer player)) {
ED2Messages.sendToPlayer(new ConfigSyncSTCPacket(ED2CommonConfig.DODGE_WHILST_AIRBORNE.get(),
ED2CommonConfig.COOLDOWN_TIME.get(), ED2CommonConfig.DODGE_COST.get(), ED2CommonConfig.DODGE_STRENGTH.get(), ED2CommonConfig.DODGE_HEIGHT.get()), player);
ED2CommonConfig.COOLDOWN_TIME.get(), ED2CommonConfig.DODGE_COST.get(), ED2CommonConfig.DODGE_STRENGTH.get(), ED2CommonConfig.DODGE_HEIGHT.get(), ED2CommonConfig.DODGE_COST_WHILST_AIRBORNE.get()), player);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ public class ConfigSyncSTCPacket {
private final int cost;
private final double power;
private final double verticality;
private final int airborneCost;

public ConfigSyncSTCPacket(boolean airborne, int cooldown, int cost, double power, double verticality) {
public ConfigSyncSTCPacket(boolean airborne, int cooldown, int cost, double power, double verticality, int airborneCost) {
this.airborne = airborne;
this.cooldown = cooldown;
this.cost = cost;
this.power = power;
this.verticality = verticality;
this.airborneCost = airborneCost;
}

public ConfigSyncSTCPacket(FriendlyByteBuf buf) {
Expand All @@ -28,6 +30,7 @@ public ConfigSyncSTCPacket(FriendlyByteBuf buf) {
this.cost = buf.readInt();
this.power = buf.readDouble();
this.verticality = buf.readDouble();
this.airborneCost = buf.readInt();
}

public void toBytes(FriendlyByteBuf buf) {
Expand All @@ -36,6 +39,7 @@ public void toBytes(FriendlyByteBuf buf) {
buf.writeInt(cost);
buf.writeDouble(power);
buf.writeDouble(verticality);
buf.writeInt(airborneCost);
}

public boolean handle(Supplier<NetworkEvent.Context> supplier) {
Expand All @@ -46,6 +50,7 @@ public boolean handle(Supplier<NetworkEvent.Context> supplier) {
ED2ClientStorage.setCost(cost);
ED2ClientStorage.setPower(power);
ED2ClientStorage.setVerticality(verticality);
ED2ClientStorage.setAirborneCost(airborneCost);
});
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static void handleDodge(DodgeAnimator.DodgeDirection direction) {
&& !instance.player.isRidingJumpable() && !instance.player.isCrouching()
&& ClientEvents.currentCooldown == 0 && instance.screen == null && !instance.player.isSwimming()
&& (instance.player.getFoodData().getFoodLevel() > 6) && !instance.player.isBlocking()
&&FeathersHelper.spendFeathers(ED2ClientStorage.getCost())) {
&& FeathersHelper.spendFeathers(instance.player.isOnGround() ? ED2ClientStorage.getCost() : ED2ClientStorage.getAirborneCost())) {

String animationDirection = DodgeDirection.BACKWARDS.name();

Expand Down