mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-21 12:24:22 +01:00
Fixed mana regeneration and energy consumption and fixed mana not being loaded correctly between saves
This commit is contained in:
parent
89879494df
commit
17233f425a
4 changed files with 57 additions and 17 deletions
|
@ -35,7 +35,7 @@ public interface Levelled {
|
||||||
void set(int level);
|
void set(int level);
|
||||||
|
|
||||||
default float getScaled(float max) {
|
default float getScaled(float max) {
|
||||||
return (1 + ((float)get() / getMax())) * max;
|
return ((float)get() / getMax()) * max;
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean canLevelUp() {
|
default boolean canLevelUp() {
|
||||||
|
|
|
@ -102,8 +102,8 @@ public class ShieldSpell extends AbstractSpell {
|
||||||
double cost = 2 - source.getLevel().getScaled(2);
|
double cost = 2 - source.getLevel().getScaled(2);
|
||||||
|
|
||||||
cost *= costMultiplier / ((1 + source.getLevel().get()) * 3F);
|
cost *= costMultiplier / ((1 + source.getLevel().get()) * 3F);
|
||||||
cost /= 2.725D;
|
|
||||||
cost /= knowledge;
|
cost /= knowledge;
|
||||||
|
cost += getDrawDropOffRange(source) / 10F;
|
||||||
|
|
||||||
if (!source.subtractEnergyCost(cost)) {
|
if (!source.subtractEnergyCost(cost)) {
|
||||||
setDead();
|
setDead();
|
||||||
|
@ -120,7 +120,7 @@ public class ShieldSpell extends AbstractSpell {
|
||||||
float multiplier = source instanceof Pony pony && pony.getMaster().isSneaking() ? 1 : 2;
|
float multiplier = source instanceof Pony pony && pony.getMaster().isSneaking() ? 1 : 2;
|
||||||
float min = 4 + getTraits().get(Trait.POWER);
|
float min = 4 + getTraits().get(Trait.POWER);
|
||||||
double range = (min + (source.getLevel().getScaled(4) * 2)) / multiplier;
|
double range = (min + (source.getLevel().getScaled(4) * 2)) / multiplier;
|
||||||
if (source instanceof Pony && range > 2) {
|
if (source instanceof Pony && range >= 4) {
|
||||||
range = Math.sqrt(range);
|
range = Math.sqrt(range);
|
||||||
}
|
}
|
||||||
return range;
|
return range;
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package com.minelittlepony.unicopia.entity.player;
|
package com.minelittlepony.unicopia.entity.player;
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
||||||
import com.minelittlepony.unicopia.util.Tickable;
|
import com.minelittlepony.unicopia.util.Tickable;
|
||||||
|
|
||||||
import net.minecraft.entity.data.TrackedData;
|
import net.minecraft.entity.data.TrackedData;
|
||||||
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
public class ManaContainer implements MagicReserves, Tickable {
|
public class ManaContainer implements MagicReserves, Tickable, NbtSerialisable {
|
||||||
private final Pony pony;
|
private final Pony pony;
|
||||||
|
|
||||||
private final BarInst energy;
|
private final BarInst energy;
|
||||||
|
@ -23,6 +25,24 @@ public class ManaContainer implements MagicReserves, Tickable {
|
||||||
this.mana = new XpCollectingBar(Pony.MANA, 100F, 100F);
|
this.mana = new XpCollectingBar(Pony.MANA, 100F, 100F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toNBT(NbtCompound compound) {
|
||||||
|
compound.put("energy", energy.toNBT());
|
||||||
|
compound.put("exhaustion", exhaustion.toNBT());
|
||||||
|
compound.put("exertion", exertion.toNBT());
|
||||||
|
compound.put("mana", mana.toNBT());
|
||||||
|
compound.put("xp", xp.toNBT());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromNBT(NbtCompound compound) {
|
||||||
|
energy.fromNBT(compound.getCompound("energy"));
|
||||||
|
exhaustion.fromNBT(compound.getCompound("exhaustion"));
|
||||||
|
exertion.fromNBT(compound.getCompound("exertion"));
|
||||||
|
mana.fromNBT(compound.getCompound("mana"));
|
||||||
|
xp.fromNBT(compound.getCompound("xp"));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Bar getExertion() {
|
public Bar getExertion() {
|
||||||
return exertion;
|
return exertion;
|
||||||
|
@ -70,8 +90,8 @@ public class ManaContainer implements MagicReserves, Tickable {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pony.getSpecies().canFly() || !pony.getPhysics().isFlying()) {
|
if (!pony.getSpecies().canFly() || !pony.getPhysics().isFlying()) {
|
||||||
if (mana.getShadowFill() <= mana.getPercentFill()) {
|
if (mana.getPercentFill() < 1 && mana.getShadowFill() == mana.getPercentFill()) {
|
||||||
mana.add(18 * pony.getLevel().get());
|
mana.add((mana.getMax() / 10F) * Math.max(1, pony.getLevel().get() * 4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,11 +122,13 @@ public class ManaContainer implements MagicReserves, Tickable {
|
||||||
value = get() + diff / (1 + pony.getLevel().get());
|
value = get() + diff / (1 + pony.getLevel().get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println("Setting mana to: " + value);
|
||||||
super.set(value);
|
super.set(value);
|
||||||
|
System.out.println("Mana set to: " + get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BarInst implements Bar {
|
class BarInst implements Bar, NbtSerialisable {
|
||||||
|
|
||||||
private final TrackedData<Float> marker;
|
private final TrackedData<Float> marker;
|
||||||
private final float max;
|
private final float max;
|
||||||
|
@ -121,7 +143,11 @@ public class ManaContainer implements MagicReserves, Tickable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float get() {
|
public float get() {
|
||||||
return pony.getMaster().getDataTracker().get(marker);
|
float value = pony.getMaster().getDataTracker().get(marker);
|
||||||
|
if (this == mana) {
|
||||||
|
System.out.println("Mana is: " + value);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -131,7 +157,11 @@ public class ManaContainer implements MagicReserves, Tickable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void set(float value) {
|
public void set(float value) {
|
||||||
pony.getMaster().getDataTracker().set(marker, MathHelper.clamp(value, 0, getMax()));
|
load(MathHelper.clamp(value, 0, getMax()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void load(float value) {
|
||||||
|
pony.getMaster().getDataTracker().set(marker, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -141,17 +171,29 @@ public class ManaContainer implements MagicReserves, Tickable {
|
||||||
|
|
||||||
void tick() {
|
void tick() {
|
||||||
float fill = getPercentFill();
|
float fill = getPercentFill();
|
||||||
float tralingIncrement = 0.003F;
|
float trailingIncrement = 0.003F;
|
||||||
|
|
||||||
if (trailingValue > (fill - tralingIncrement) && trailingValue < (fill + tralingIncrement)) {
|
if (trailingValue > (fill - trailingIncrement) && trailingValue < (fill + trailingIncrement)) {
|
||||||
trailingValue = fill;
|
trailingValue = fill;
|
||||||
}
|
}
|
||||||
if (trailingValue < fill) {
|
if (trailingValue < fill) {
|
||||||
trailingValue += tralingIncrement;
|
trailingValue += trailingIncrement;
|
||||||
}
|
}
|
||||||
if (trailingValue > fill) {
|
if (trailingValue > fill) {
|
||||||
trailingValue -= tralingIncrement;
|
trailingValue -= trailingIncrement;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toNBT(NbtCompound compound) {
|
||||||
|
compound.putFloat("shadow", trailingValue);
|
||||||
|
compound.putFloat("value", get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromNBT(NbtCompound compound) {
|
||||||
|
trailingValue = compound.getFloat("shadow");
|
||||||
|
load(compound.getFloat("value"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -527,16 +527,14 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
|
||||||
public void toNBT(NbtCompound compound) {
|
public void toNBT(NbtCompound compound) {
|
||||||
super.toNBT(compound);
|
super.toNBT(compound);
|
||||||
compound.putString("playerSpecies", Race.REGISTRY.getId(getSpecies()).toString());
|
compound.putString("playerSpecies", Race.REGISTRY.getId(getSpecies()).toString());
|
||||||
|
|
||||||
compound.putFloat("magicExhaustion", magicExhaustion);
|
compound.putFloat("magicExhaustion", magicExhaustion);
|
||||||
|
|
||||||
compound.put("powers", powers.toNBT());
|
compound.put("powers", powers.toNBT());
|
||||||
compound.put("gravity", gravity.toNBT());
|
compound.put("gravity", gravity.toNBT());
|
||||||
compound.put("charms", charms.toNBT());
|
compound.put("charms", charms.toNBT());
|
||||||
compound.put("discoveries", discoveries.toNBT());
|
compound.put("discoveries", discoveries.toNBT());
|
||||||
|
compound.put("mana", mana.toNBT());
|
||||||
compound.putInt("levels", levels.get());
|
compound.putInt("levels", levels.get());
|
||||||
compound.putInt("corruption", corruption.get());
|
compound.putInt("corruption", corruption.get());
|
||||||
compound.putFloat("magicXp", mana.getXp().get());
|
|
||||||
|
|
||||||
getSpellSlot().get(true).ifPresent(effect ->{
|
getSpellSlot().get(true).ifPresent(effect ->{
|
||||||
compound.put("effect", Spell.writeNbt(effect));
|
compound.put("effect", Spell.writeNbt(effect));
|
||||||
|
@ -561,7 +559,7 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
|
||||||
discoveries.fromNBT(compound.getCompound("discoveries"));
|
discoveries.fromNBT(compound.getCompound("discoveries"));
|
||||||
levels.set(compound.getInt("levels"));
|
levels.set(compound.getInt("levels"));
|
||||||
corruption.set(compound.getInt("corruption"));
|
corruption.set(compound.getInt("corruption"));
|
||||||
mana.getXp().set(compound.getFloat("magicXp"));
|
mana.fromNBT(compound.getCompound("mana"));
|
||||||
|
|
||||||
magicExhaustion = compound.getFloat("magicExhaustion");
|
magicExhaustion = compound.getFloat("magicExhaustion");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue