mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-25 22:24:31 +01:00
Add corruption stat and fix level and xp not actually being saved
This commit is contained in:
parent
50b709fa3c
commit
53c0f1aff8
3 changed files with 45 additions and 14 deletions
|
@ -25,6 +25,8 @@ public interface Levelled {
|
||||||
|
|
||||||
LevelStore getLevel();
|
LevelStore getLevel();
|
||||||
|
|
||||||
|
LevelStore getCorruption();
|
||||||
|
|
||||||
interface LevelStore {
|
interface LevelStore {
|
||||||
int getMax();
|
int getMax();
|
||||||
|
|
||||||
|
|
|
@ -2,30 +2,35 @@ package com.minelittlepony.unicopia.entity.player;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.ability.magic.Levelled;
|
import com.minelittlepony.unicopia.ability.magic.Levelled;
|
||||||
|
|
||||||
import net.minecraft.entity.data.DataTracker;
|
|
||||||
import net.minecraft.entity.data.TrackedData;
|
import net.minecraft.entity.data.TrackedData;
|
||||||
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
|
import net.minecraft.sound.*;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.sound.SoundCategory;
|
|
||||||
import net.minecraft.sound.SoundEvents;
|
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
class PlayerLevelStore implements Levelled.LevelStore {
|
class PlayerLevelStore implements Levelled.LevelStore {
|
||||||
|
|
||||||
private static final TrackedData<Integer> LEVEL = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.INTEGER);
|
|
||||||
|
|
||||||
private final Pony pony;
|
private final Pony pony;
|
||||||
|
|
||||||
PlayerLevelStore(Pony pony) {
|
private final TrackedData<Integer> dataEntry;
|
||||||
|
|
||||||
|
private final boolean upgradeMana;
|
||||||
|
|
||||||
|
private final SoundEvent levelUpSound;
|
||||||
|
|
||||||
|
PlayerLevelStore(Pony pony, TrackedData<Integer> dataEntry, boolean upgradeMana, SoundEvent levelUpSound) {
|
||||||
this.pony = pony;
|
this.pony = pony;
|
||||||
pony.getEntity().getDataTracker().startTracking(LEVEL, 0);
|
this.dataEntry = dataEntry;
|
||||||
|
this.upgradeMana = upgradeMana;
|
||||||
|
this.levelUpSound = levelUpSound;
|
||||||
|
pony.getEntity().getDataTracker().startTracking(dataEntry, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(int levels) {
|
public void add(int levels) {
|
||||||
if (levels > 0) {
|
if (levels > 0) {
|
||||||
|
if (upgradeMana) {
|
||||||
pony.getMagicalReserves().getMana().add(pony.getMagicalReserves().getMana().getMax() / 2);
|
pony.getMagicalReserves().getMana().add(pony.getMagicalReserves().getMana().getMax() / 2);
|
||||||
pony.getReferenceWorld().playSound(null, pony.getOrigin(), SoundEvents.ENTITY_PLAYER_LEVELUP, SoundCategory.PLAYERS, 1, 2);
|
}
|
||||||
|
pony.getReferenceWorld().playSound(null, pony.getOrigin(), levelUpSound, SoundCategory.PLAYERS, 1, 2);
|
||||||
}
|
}
|
||||||
Levelled.LevelStore.super.add(levels);
|
Levelled.LevelStore.super.add(levels);
|
||||||
}
|
}
|
||||||
|
@ -37,11 +42,11 @@ class PlayerLevelStore implements Levelled.LevelStore {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int get() {
|
public int get() {
|
||||||
return pony.getEntity().getDataTracker().get(LEVEL);
|
return pony.getEntity().getDataTracker().get(dataEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void set(int level) {
|
public void set(int level) {
|
||||||
pony.getEntity().getDataTracker().set(LEVEL, MathHelper.clamp(level, 0, getMax()));
|
pony.getEntity().getDataTracker().set(dataEntry, MathHelper.clamp(level, 0, getMax()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ import net.minecraft.nbt.NbtCompound;
|
||||||
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.SoundEvents;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
@ -74,6 +75,8 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
|
||||||
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<Float> XP = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.FLOAT);
|
||||||
|
static final TrackedData<Integer> LEVEL = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.INTEGER);
|
||||||
|
static final TrackedData<Integer> CORRUPTION = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.INTEGER);
|
||||||
|
|
||||||
private static final TrackedData<NbtCompound> EFFECT = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.NBT_COMPOUND);
|
private static final TrackedData<NbtCompound> EFFECT = DataTracker.registerData(PlayerEntity.class, TrackedDataHandlerRegistry.NBT_COMPOUND);
|
||||||
|
|
||||||
|
@ -88,6 +91,7 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
|
||||||
|
|
||||||
private final ManaContainer mana;
|
private final ManaContainer mana;
|
||||||
private final PlayerLevelStore levels;
|
private final PlayerLevelStore levels;
|
||||||
|
private final PlayerLevelStore corruption;
|
||||||
|
|
||||||
private final List<Tickable> tickers;
|
private final List<Tickable> tickers;
|
||||||
|
|
||||||
|
@ -116,7 +120,8 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
|
||||||
public Pony(PlayerEntity player) {
|
public Pony(PlayerEntity player) {
|
||||||
super(player, EFFECT);
|
super(player, EFFECT);
|
||||||
this.mana = new ManaContainer(this);
|
this.mana = new ManaContainer(this);
|
||||||
this.levels = new PlayerLevelStore(this);
|
this.levels = new PlayerLevelStore(this, LEVEL, true, SoundEvents.ENTITY_PLAYER_LEVELUP);
|
||||||
|
this.corruption = new PlayerLevelStore(this, CORRUPTION, false, SoundEvents.PARTICLE_SOUL_ESCAPE);
|
||||||
this.tickers = Lists.newArrayList(gravity, mana, attributes, charms);
|
this.tickers = Lists.newArrayList(gravity, mana, attributes, charms);
|
||||||
|
|
||||||
player.getDataTracker().startTracking(RACE, Race.DEFAULT_ID);
|
player.getDataTracker().startTracking(RACE, Race.DEFAULT_ID);
|
||||||
|
@ -202,6 +207,11 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
|
||||||
return levels;
|
return levels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LevelStore getCorruption() {
|
||||||
|
return corruption;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInvisible() {
|
public boolean isInvisible() {
|
||||||
return invisible && SpellPredicate.IS_DISGUISE.isOn(this);
|
return invisible && SpellPredicate.IS_DISGUISE.isOn(this);
|
||||||
|
@ -528,6 +538,9 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
|
||||||
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.putInt("levels", levels.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));
|
||||||
|
@ -550,6 +563,9 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
|
||||||
gravity.fromNBT(compound.getCompound("gravity"));
|
gravity.fromNBT(compound.getCompound("gravity"));
|
||||||
charms.fromNBT(compound.getCompound("charms"));
|
charms.fromNBT(compound.getCompound("charms"));
|
||||||
discoveries.fromNBT(compound.getCompound("discoveries"));
|
discoveries.fromNBT(compound.getCompound("discoveries"));
|
||||||
|
levels.set(compound.getInt("levels"));
|
||||||
|
corruption.set(compound.getInt("corruption"));
|
||||||
|
mana.getXp().set(compound.getFloat("magicXp"));
|
||||||
|
|
||||||
magicExhaustion = compound.getFloat("magicExhaustion");
|
magicExhaustion = compound.getFloat("magicExhaustion");
|
||||||
|
|
||||||
|
@ -577,12 +593,20 @@ public class Pony extends Living<PlayerEntity> implements Transmittable, Copieab
|
||||||
getDiscoveries().copyFrom(oldPlayer.getDiscoveries());
|
getDiscoveries().copyFrom(oldPlayer.getDiscoveries());
|
||||||
getCharms().equipSpell(Hand.MAIN_HAND, oldPlayer.getCharms().getEquippedSpell(Hand.MAIN_HAND));
|
getCharms().equipSpell(Hand.MAIN_HAND, oldPlayer.getCharms().getEquippedSpell(Hand.MAIN_HAND));
|
||||||
getCharms().equipSpell(Hand.OFF_HAND, oldPlayer.getCharms().getEquippedSpell(Hand.OFF_HAND));
|
getCharms().equipSpell(Hand.OFF_HAND, oldPlayer.getCharms().getEquippedSpell(Hand.OFF_HAND));
|
||||||
|
corruption.set(oldPlayer.getCorruption().get());
|
||||||
|
levels.set(oldPlayer.getLevel().get());
|
||||||
|
mana.getXp().set(oldPlayer.getMagicalReserves().getXp().get());
|
||||||
advancementProgress.putAll(oldPlayer.getAdvancementProgress());
|
advancementProgress.putAll(oldPlayer.getAdvancementProgress());
|
||||||
setDirty();
|
setDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSpellSet(@Nullable Spell spell) {
|
public void onSpellSet(@Nullable Spell spell) {
|
||||||
|
if (spell != null) {
|
||||||
|
if (spell.getAffinity() == Affinity.BAD && entity.getWorld().random.nextInt(120) == 0) {
|
||||||
|
getCorruption().add(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
setDirty();
|
setDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue