Skip to content

Commit

Permalink
Fixing networking issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkona committed Jun 11, 2024
1 parent 213d26a commit b0fe64d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 16 additions & 2 deletions src/main/java/com/darkona/feathers/api/FeathersAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import com.darkona.feathers.capability.Capabilities;
import com.darkona.feathers.config.FeathersCommonConfig;
import com.darkona.feathers.effect.FeathersEffects;
import com.darkona.feathers.effect.effects.StrainEffect;
import com.darkona.feathers.enchantment.FeathersEnchantments;
import com.darkona.feathers.event.FeatherEvent;
import com.darkona.feathers.networking.FeathersMessages;
import com.darkona.feathers.networking.packet.FeatherSTCSyncPacket;
import com.darkona.feathers.networking.packet.FeatherSpendCTSPacket;
import com.darkona.feathers.util.Calculations;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ItemStack;
Expand All @@ -30,6 +33,14 @@ public static int getFeathers(Player player) {
}

public static int getAvailableFeathers(Player player) {
if (isStrained(player)) {
var total = new AtomicInteger(0);
player.getCapability(Capabilities.PLAYER_FEATHERS).ifPresent(f -> {
int strain = FeathersCommonConfig.MAX_STRAIN.get() - (int) Math.ceil(f.getCounter(StrainEffect.STRAIN_COUNTER));
total.set(Math.max(strain, 0));
});
return total.get();
}
return player.getCapability(Capabilities.PLAYER_FEATHERS).map(IFeathers::getAvailableFeathers)
.orElse(0);
}
Expand Down Expand Up @@ -121,15 +132,18 @@ public static boolean spendFeathers(Player player, int amount, int cooldown) thr

if (result.get() && !player.level().isClientSide) {
FeathersMessages.sendToPlayer(new FeatherSTCSyncPacket(f), player);
} else {
FeathersMessages.sendToServer(new FeatherSpendCTSPacket(amount, cooldown));
}
}
});

return result.get();
}

public static void spendFeathersRequest(LocalPlayer player, int amount, int cooldown){
if (player.level().isClientSide) {
FeathersMessages.sendToServer(new FeatherSpendCTSPacket(amount, cooldown));
}
}
public static int getPlayerWeight(Player player) {
if (!FeathersCommonConfig.ENABLE_ARMOR_WEIGHTS.get()) {
return 0;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/elenai/feathers/api/FeathersHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public static boolean spendFeathers(int amount) {
public static boolean spendFeathers(int amount, int cooldown) {
var player = Minecraft.getInstance().player;
if (player == null) return false;
return FeathersAPI.spendFeathers(player, amount, cooldown);
boolean could = FeathersAPI.spendFeathers(player, amount, cooldown);
FeathersAPI.spendFeathersRequest(player, amount, cooldown);
return could;
}

}

0 comments on commit b0fe64d

Please sign in to comment.