mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Players can now gain levels by doing things that use their mana
This commit is contained in:
parent
ea08c78df0
commit
f4bffad815
4 changed files with 61 additions and 6 deletions
|
@ -42,7 +42,7 @@ public interface MagicReserves {
|
||||||
/**
|
/**
|
||||||
* Adds a percentage increment to this bar's current value
|
* Adds a percentage increment to this bar's current value
|
||||||
*/
|
*/
|
||||||
default void add(int step) {
|
default void add(float step) {
|
||||||
set(get() + (step / getMax()));
|
set(get() + (step / getMax()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,14 @@ public class ManaContainer implements MagicReserves {
|
||||||
private final Bar energy;
|
private final Bar energy;
|
||||||
private final Bar exertion;
|
private final Bar exertion;
|
||||||
private final Bar mana;
|
private final Bar mana;
|
||||||
|
private final Bar xp;
|
||||||
|
|
||||||
public ManaContainer(Pony pony) {
|
public ManaContainer(Pony pony) {
|
||||||
this.pony = pony;
|
this.pony = pony;
|
||||||
this.energy = new BarInst(Pony.ENERGY, 100F);
|
this.energy = new BarInst(Pony.ENERGY, 100F);
|
||||||
this.exertion = new BarInst(Pony.EXERTION, 10F);
|
this.exertion = new BarInst(Pony.EXERTION, 10F);
|
||||||
this.mana = new BarInst(Pony.MANA, 100F);
|
this.xp = new BarInst(Pony.XP, 1);
|
||||||
|
this.mana = new XpCollectingBar(Pony.MANA, 100F);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,6 +34,35 @@ public class ManaContainer implements MagicReserves {
|
||||||
return mana;
|
return mana;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Bar getXp() {
|
||||||
|
return xp;
|
||||||
|
}
|
||||||
|
|
||||||
|
class XpCollectingBar extends BarInst {
|
||||||
|
|
||||||
|
XpCollectingBar(TrackedData<Float> marker, float max) {
|
||||||
|
super(marker, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(float value) {
|
||||||
|
float diff = value - get();
|
||||||
|
if (diff < 0) {
|
||||||
|
if (pony.canLevelUp()) {
|
||||||
|
xp.add(-diff / (100 * (1 + pony.getCurrentLevel())));
|
||||||
|
if (xp.getPercentFill() >= 1) {
|
||||||
|
pony.addLevels(1);
|
||||||
|
xp.set(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
value = get() + diff / (1 + pony.getCurrentLevel());
|
||||||
|
}
|
||||||
|
|
||||||
|
super.set(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class BarInst implements Bar {
|
class BarInst implements Bar {
|
||||||
|
|
||||||
private final TrackedData<Float> marker;
|
private final TrackedData<Float> marker;
|
||||||
|
|
|
@ -106,10 +106,12 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
||||||
|
|
||||||
entity.fallDistance = 0;
|
entity.fallDistance = 0;
|
||||||
|
|
||||||
if (ticksInAir > 100) {
|
int level = pony.getCurrentLevel() + 1;
|
||||||
|
|
||||||
|
if (ticksInAir > (level * 100)) {
|
||||||
Bar mana = pony.getMagicalReserves().getMana();
|
Bar mana = pony.getMagicalReserves().getMana();
|
||||||
|
|
||||||
mana.add((int)(-getHorizontalMotion(entity) * 50));
|
mana.add((int)(-getHorizontalMotion(entity) * 50 / level));
|
||||||
|
|
||||||
if (mana.getPercentFill() < 0.2) {
|
if (mana.getPercentFill() < 0.2) {
|
||||||
pony.getMagicalReserves().getExertion().add(2);
|
pony.getMagicalReserves().getExertion().add(2);
|
||||||
|
@ -156,7 +158,7 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
||||||
|
|
||||||
protected void moveFlying(Entity player, MutableVector velocity) {
|
protected void moveFlying(Entity player, MutableVector velocity) {
|
||||||
|
|
||||||
float forward = 0.000015F * (float)Math.sqrt(getHorizontalMotion(player));
|
float forward = 0.000015F * (1 + (pony.getCurrentLevel() / 10F)) * (float)Math.sqrt(getHorizontalMotion(player));
|
||||||
boolean sneak = !player.isSneaking();
|
boolean sneak = !player.isSneaking();
|
||||||
|
|
||||||
// vertical drop due to gravity
|
// vertical drop due to gravity
|
||||||
|
|
|
@ -45,10 +45,13 @@ import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.packet.s2c.play.EntityPassengersSetS2CPacket;
|
import net.minecraft.network.packet.s2c.play.EntityPassengersSetS2CPacket;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import net.minecraft.sound.SoundCategory;
|
||||||
|
import net.minecraft.sound.SoundEvents;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.text.TranslatableText;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmittable, Copieable<Pony> {
|
public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmittable, Copieable<Pony> {
|
||||||
|
@ -58,6 +61,9 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
|
||||||
static final TrackedData<Float> ENERGY = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT);
|
static final TrackedData<Float> ENERGY = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT);
|
||||||
static final TrackedData<Float> EXERTION = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT);
|
static final TrackedData<Float> EXERTION = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT);
|
||||||
static final TrackedData<Float> MANA = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT);
|
static final TrackedData<Float> MANA = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT);
|
||||||
|
static final TrackedData<Float> XP = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT);
|
||||||
|
|
||||||
|
static final TrackedData<Integer> LEVEL = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.INTEGER);
|
||||||
|
|
||||||
private static final TrackedData<CompoundTag> EFFECT = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.TAG_COMPOUND);
|
private static final TrackedData<CompoundTag> EFFECT = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.TAG_COMPOUND);
|
||||||
private static final TrackedData<CompoundTag> HELD_EFFECT = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.TAG_COMPOUND);
|
private static final TrackedData<CompoundTag> HELD_EFFECT = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.TAG_COMPOUND);
|
||||||
|
@ -92,6 +98,7 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
|
||||||
player.getDataTracker().startTracking(RACE, Race.HUMAN.ordinal());
|
player.getDataTracker().startTracking(RACE, Race.HUMAN.ordinal());
|
||||||
player.getDataTracker().startTracking(EFFECT, new CompoundTag());
|
player.getDataTracker().startTracking(EFFECT, new CompoundTag());
|
||||||
player.getDataTracker().startTracking(HELD_EFFECT, new CompoundTag());
|
player.getDataTracker().startTracking(HELD_EFFECT, new CompoundTag());
|
||||||
|
player.getDataTracker().startTracking(LEVEL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerAttributes(DefaultAttributeContainer.Builder builder) {
|
public static void registerAttributes(DefaultAttributeContainer.Builder builder) {
|
||||||
|
@ -293,6 +300,20 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
|
||||||
prevLanded = entity.isOnGround();
|
prevLanded = entity.isOnGround();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addLevels(int levels) {
|
||||||
|
if (levels > 0) {
|
||||||
|
mana.getMana().set(mana.getEnergy().getMax());
|
||||||
|
entity.world.playSound(null, getOrigin(), SoundEvents.ENTITY_PLAYER_LEVELUP, SoundCategory.PLAYERS, 1, 2);
|
||||||
|
}
|
||||||
|
Caster.super.addLevels(levels);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxLevel() {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<Float> onImpact(float distance, float damageMultiplier) {
|
public Optional<Float> onImpact(float distance, float damageMultiplier) {
|
||||||
|
|
||||||
float g = gravity.getGravityModifier();
|
float g = gravity.getGravityModifier();
|
||||||
|
@ -426,11 +447,12 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCurrentLevel() {
|
public int getCurrentLevel() {
|
||||||
return 0;
|
return entity.getDataTracker().get(LEVEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCurrentLevel(int level) {
|
public void setCurrentLevel(int level) {
|
||||||
|
entity.getDataTracker().set(LEVEL, MathHelper.clamp(level, 0, getMaxLevel()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isClientPlayer() {
|
public boolean isClientPlayer() {
|
||||||
|
|
Loading…
Reference in a new issue