Skip to content

Commit

Permalink
feat: config values and data syncing for substitution count
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed May 5, 2022
1 parent de37c5d commit a813057
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ public interface INinjaData extends INBTSerializable<Tag> {
float getChakra();
float getMaxChakra();
float getStamina();

float getSubstitutionCount();

float getMaxStamina();
void setChakra(float amount);
void setStamina(float amount);
void useChakra(float amount, int cooldown);
void useStamina(float amount, int cooldown);
void useSubstitution(float amount);
void addChakra(float amount);
void addStamina(float amount);

Expand Down
53 changes: 37 additions & 16 deletions src/main/java/com/sekwah/narutomod/capabilities/NinjaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@ public class NinjaData implements INinjaData, ICapabilityProvider {
@Sync(minTicks = 1)
private float stamina;

@Sync
private float substitutions;

@Sync
private float maxChakra;

@Sync
private float maxStamina;

@Sync
private float maxSubstitutions;

/**
* If the player can double jump, will be updated by underlying values server side.
*
Expand Down Expand Up @@ -71,19 +77,18 @@ public class NinjaData implements INinjaData, ICapabilityProvider {

public NinjaData(boolean isServer) {
if (isServer) {
this.maxChakra = this.stamina = NarutoConfig.maxChakra;
this.maxStamina = this.chakra = NarutoConfig.maxStamina;
this.getConfigData();
this.stamina = this.maxChakra;
this.chakra = this.maxStamina;
}
this.toggleAbilityData = new ToggleAbilityData();
this.doubleJumpData = new DoubleJumpData(false);
}

class RegenInfo {
public float regenRate;
public int cooldown;

public RegenInfo(float regenRate) {
this.regenRate = regenRate;
public RegenInfo() {
}

/**
Expand All @@ -100,8 +105,8 @@ public boolean canRegen() {
}
}

private RegenInfo chakraRegenInfo = new RegenInfo(0.05f);
private RegenInfo staminaRegenInfo = new RegenInfo(0.4f);
private final RegenInfo chakraRegenInfo = new RegenInfo();
private final RegenInfo staminaRegenInfo = new RegenInfo();

private static final String CHAKRA_TAG = "chakra";
private static final String STAMINA_TAG = "stamina";
Expand All @@ -125,6 +130,11 @@ public float getStamina() {
return this.stamina;
}

@Override
public float getSubstitutionCount() {
return this.substitutions;
}

@Override
public float getMaxStamina() {
return this.maxStamina;
Expand Down Expand Up @@ -152,6 +162,11 @@ public void useStamina(float amount, int cooldown) {
this.staminaRegenInfo.cooldown = Math.max(cooldown, this.staminaRegenInfo.cooldown);
}

@Override
public void useSubstitution(float amount) {
this.substitutions -= amount;
}

@Override
public void addChakra(float amount) {
this.chakra = Math.min(Math.max(this.chakra + amount, 0), maxChakra);
Expand Down Expand Up @@ -213,6 +228,7 @@ public ToggleAbilityData getToggleAbilityData() {

@Override
public void updateDataServer(Player player) {
this.getConfigData();
Iterator<DelayedPlayerTickEvent> iterator = this.delayedTickEvents.iterator();
while (iterator.hasNext()) {
DelayedPlayerTickEvent event = iterator.next();
Expand All @@ -224,12 +240,9 @@ public void updateDataServer(Player player) {
}

// Compile list of keys from cooldown map
ArrayList<String> completeList = new ArrayList<>();
completeList.addAll(cooldownTickEvents.keySet());
Iterator<String> completeCooldownIterator = completeList.iterator();
ArrayList<String> completeList = new ArrayList<>(cooldownTickEvents.keySet());
// loop through to tick and then remove cooldown if complete
while (completeCooldownIterator.hasNext()) {
String name = completeCooldownIterator.next();
for (String name : completeList) {
CooldownTickEvent event = cooldownTickEvents.get(name);
event.tick();
if (event.isComplete()) {
Expand All @@ -238,13 +251,15 @@ public void updateDataServer(Player player) {
}

if (this.staminaRegenInfo.canRegen()) {
this.stamina += staminaRegenInfo.regenRate;
this.stamina += NarutoConfig.staminaRegen;
}
if (this.chakraRegenInfo.canRegen()) {
this.chakra += chakraRegenInfo.regenRate;
this.chakra += NarutoConfig.chakraRegen;
}
this.stamina = Math.min(Math.max(this.stamina, 0), maxStamina);
this.chakra = Math.min(Math.max(this.chakra, 0), maxChakra);
this.substitutions += NarutoConfig.substitutionRegenRate;
this.substitutions = Math.min(Math.max(this.substitutions, 0), this.maxSubstitutions);
this.stamina = Math.min(Math.max(this.stamina, 0), this.maxStamina);
this.chakra = Math.min(Math.max(this.chakra, 0), this.maxChakra);

if (this.currentlyChanneled != null) {
Ability ability = NarutoAbilities.ABILITY_REGISTRY.getValue(this.currentlyChanneled);
Expand All @@ -270,6 +285,12 @@ public void updateDataServer(Player player) {
}
}

private void getConfigData() {
this.maxChakra = NarutoConfig.maxChakra;
this.maxStamina = NarutoConfig.maxStamina;
this.maxSubstitutions = NarutoConfig.maxSubstitutions;
}

@Override
public void scheduleDelayedTickEvent(Consumer<Player> consumer, int tickDelay) {
this.delayedTickEvents.add(new DelayedPlayerTickEvent(consumer, tickDelay));
Expand Down
32 changes: 30 additions & 2 deletions src/main/java/com/sekwah/narutomod/config/NarutoConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ public class NarutoConfig {
private static final ForgeConfigSpec.DoubleValue CONFIG_MAX_STAMINA;
public static float maxStamina;

private static final ForgeConfigSpec.DoubleValue CONFIG_CHAKRA_REGEN;
public static float chakraRegen;

private static final ForgeConfigSpec.DoubleValue CONFIG_STAMINA_REGEN;
public static float staminaRegen;

private static final ForgeConfigSpec.IntValue CONFIG_MAX_SUBSTITUTIONS;
public static int maxSubstitutions;

private static final ForgeConfigSpec.IntValue CONFIG_SUBSTITUTION_REGEN_TIME;
public static float substitutionRegenRate;

private static final ForgeConfigSpec.BooleanValue CONFIG_KUNAI_BLOCK_DAMAGE;
public static boolean kunaiBlockDamage;

Expand Down Expand Up @@ -69,10 +81,22 @@ public class NarutoConfig {
configBuilder.comment("Stuff such as regen rates and maximum (will likely change with updates, e.g. stats system)").push(ENERGY_BARS);

CONFIG_MAX_CHAKRA = configBuilder.comment("Max Chakra")
.defineInRange("maxChakra", 100F , 0d, Integer.MAX_VALUE);
.defineInRange("maxChakra", 100F , 0d, Double.MAX_VALUE);

CONFIG_CHAKRA_REGEN = configBuilder.comment("Chakra Regen")
.defineInRange("chakraRegen", 0.05d , 0d, Double.MAX_VALUE);

CONFIG_MAX_STAMINA = configBuilder.comment("Max Stamina")
.defineInRange("maxStamina", 100F , 0d, Integer.MAX_VALUE);
.defineInRange("maxStamina", 100F , 0d, Double.MAX_VALUE);

CONFIG_STAMINA_REGEN = configBuilder.comment("Stamina Regen")
.defineInRange("staminaRegen", 0.4d , 0d, Double.MAX_VALUE);

CONFIG_MAX_SUBSTITUTIONS = configBuilder.comment("Max Substitutions")
.defineInRange("maxSubstitutions", 3 , 0, Integer.MAX_VALUE);

CONFIG_SUBSTITUTION_REGEN_TIME = configBuilder.comment("Substitution Regen Time (Seconds)")
.defineInRange("substitutionRegenRate", 60 , 0, Integer.MAX_VALUE);

configBuilder.pop();

Expand Down Expand Up @@ -121,6 +145,10 @@ public class NarutoConfig {
public static void loadVariables() {
maxChakra = CONFIG_MAX_CHAKRA.get().floatValue();
maxStamina = CONFIG_MAX_STAMINA.get().floatValue();
staminaRegen = CONFIG_STAMINA_REGEN.get().floatValue();
chakraRegen = CONFIG_CHAKRA_REGEN.get().floatValue();
maxSubstitutions = CONFIG_MAX_SUBSTITUTIONS.get();
substitutionRegenRate = 1f / (CONFIG_SUBSTITUTION_REGEN_TIME.get() * 20f);
kunaiBlockDamage = CONFIG_KUNAI_BLOCK_DAMAGE.get();
kunaiBlockDamage = CONFIG_KUNAI_BLOCK_DAMAGE.get();
kunaiExplosionRadius = CONFIG_KUNAI_EXPLOSION_RADIUS.get().floatValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public static void registerSyncTrackerEvent(RegisterSyncTrackerTypeEvent event)
event.registerSyncTracker(ResourceLocation.class, new ResourceLocationSyncTracker());
event.registerSyncTracker(String.class, new StringSyncTracker());
event.registerSyncTracker(boolean.class, new BoolSyncTracker());
event.registerSyncTracker(byte.class, new ByteSyncTracker());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.sekwah.sekclib.capabilitysync.capabilitysync.tracker.implemented;

import com.sekwah.sekclib.capabilitysync.capabilitysync.tracker.SyncTrackerSerializer;
import net.minecraft.network.FriendlyByteBuf;

public class ByteSyncTracker implements SyncTrackerSerializer<Byte> {

@Override
public void encode(Byte objectToSend, FriendlyByteBuf outBuffer) {
outBuffer.writeByte(objectToSend);
}

@Override
public Byte decode(FriendlyByteBuf inBuffer) {
return inBuffer.readByte();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "narutomod:items/weapons/paperbomb"
"layer0": "narutomod:items/weapons/paper_bomb"
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a813057

Please sign in to comment.