The metamorphosis potions no longer kill you in peaceful, easy, and hardcore mode, and spectral arrows are no longer deadly

This commit is contained in:
Sollace 2023-11-07 19:57:30 +00:00
parent 884ced25f1
commit 6a09b04b8e
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 61 additions and 10 deletions

View file

@ -3,19 +3,24 @@ package com.minelittlepony.unicopia.entity.effect;
import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.ability.magic.Caster;
import com.minelittlepony.unicopia.entity.Equine;
import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.damage.UDamageTypes;
import com.minelittlepony.unicopia.entity.player.MagicReserves;
import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.ExplosionUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.*;
import net.minecraft.entity.player.HungerManager;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.world.World.ExplosionSourceType;
import net.minecraft.registry.Registry;
import net.minecraft.registry.Registries;
@ -49,11 +54,21 @@ public class RaceChangeStatusEffect extends StatusEffect {
return race;
}
private void removeEffect(LivingEntity entity) {
entity.removeStatusEffect(this);
resetTicks(entity);
}
private void resetTicks(LivingEntity entity) {
Pony.of(entity).ifPresent(pony -> pony.setTicksmetamorphising(0));
}
@Override
public void applyUpdateEffect(LivingEntity entity, int amplifier) {
StatusEffectInstance state = entity.getStatusEffect(this);
if (state == null) {
if (state == null || entity.isDead()) {
resetTicks(entity);
return;
}
@ -63,6 +78,13 @@ public class RaceChangeStatusEffect extends StatusEffect {
return;
}
int metaTicks = 0;
if (eq instanceof Pony pony) {
metaTicks = pony.getTicksMetamorphising() + 1;
pony.setTicksmetamorphising(metaTicks);
}
int ticks = Math.max(0, MAX_DURATION - state.getDuration());
Stage stage = Stage.forDuration(ticks / STAGE_DURATION);
@ -77,7 +99,7 @@ public class RaceChangeStatusEffect extends StatusEffect {
if (progression == 0 && entity instanceof PlayerEntity player && stage == Stage.CRAWLING) {
player.sendMessage(Stage.INITIAL.getMessage(race), true);
}
entity.removeStatusEffect(this);
removeEffect(entity);
return;
}
@ -85,42 +107,60 @@ public class RaceChangeStatusEffect extends StatusEffect {
player.sendMessage(stage.getMessage(race), true);
}
entity.setHealth(1);
if (eq instanceof Pony pony) {
MagicReserves magic = pony.getMagicalReserves();
pony.setRespawnRace(race);
magic.getExertion().addPercent(5);
magic.getEnergy().add(3);
magic.getExertion().add(5);
if (magic.getEnergy().get() < 1) {
magic.getEnergy().add(1.1F);
entity.playSound(USounds.BLOCK_CHITIN_AMBIENCE, 0.1F, 2F);
}
magic.getExhaustion().add(3);
if (state.shouldShowParticles()) {
pony.spawnParticles(ParticleTypes.TOTEM_OF_UNDYING, 5);
pony.spawnParticles(ParticleTypes.TOTEM_OF_UNDYING, 1);
}
}
if (stage == Stage.DEATH) {
entity.removeStatusEffect(this);
removeEffect(entity);
if (eq instanceof Caster) {
((Caster<?>)eq).getSpellSlot().clear();
}
if (eq instanceof Pony pony) {
if (eq instanceof Pony pony && metaTicks > 200) {
MagicReserves magic = pony.getMagicalReserves();
magic.getEnergy().set(0.6F);
magic.getExhaustion().set(0);
magic.getExertion().set(0);
if (pony.asEntity().isCreative() || entity.getWorld().getDifficulty().getId() < 2 || entity.getWorld().getLevelProperties().isHardcore()) {
if (!pony.asEntity().isCreative()) {
float cost = entity.getWorld().getLevelProperties().isHardcore() ? 0.75F : switch (entity.getWorld().getDifficulty()) {
case PEACEFUL -> 0.125F;
case EASY -> 0.25F;
default -> 0.5F;
};
entity.setHealth(Math.max(1, entity.getHealth() * cost));
HungerManager hunger = pony.asEntity().getHungerManager();
int food = hunger.getFoodLevel();
pony.asEntity().getHungerManager().setFoodLevel(Math.max(Math.min(1, food), (int)(food * cost)));
}
pony.setSpecies(race);
} else if (!pony.asEntity().isCreative()) {
if (!entity.damage(Living.living(entity).damageOf(UDamageTypes.TRIBE_SWAP), Float.MAX_VALUE)) {
entity.setHealth(0);
pony.setRespawnRace(Race.UNSET);
pony.setSpecies(race);
}
}
entity.getWorld().createExplosion(entity, null, ExplosionUtil.NON_DESTRUCTIVE, entity.getPos(), 5, true, ExplosionSourceType.MOB);
} else {
eq.setSpecies(race);
entity.getWorld().createExplosion(entity, null, ExplosionUtil.NON_DESTRUCTIVE, entity.getPos(), 5, true, ExplosionSourceType.MOB);
}
}
}

View file

@ -100,6 +100,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
private float magicExhaustion = 0;
private int ticksInvulnerable;
private int ticksMetamorphising;
private int ticksInSun;
private boolean hasShades;
@ -275,6 +276,14 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
this.ticksInvulnerable = Math.max(0, ticks);
}
public int getTicksMetamorphising() {
return ticksMetamorphising;
}
public void setTicksmetamorphising(int ticks) {
ticksMetamorphising = ticks;
}
@Override
public Affinity getAffinity() {
return getSpecies().getAffinity();
@ -754,6 +763,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
compound.putInt("levels", levels.get());
compound.putInt("corruption", corruption.get());
compound.putInt("ticksInvulnerable", ticksInvulnerable);
compound.putInt("ticksMetamorphising", ticksMetamorphising);
NbtCompound progress = new NbtCompound();
advancementProgress.forEach((key, count) -> {
@ -778,6 +788,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
ticksInvulnerable = compound.getInt("ticksInvulnerable");
ticksInSun = compound.getInt("ticksInSun");
hasShades = compound.getBoolean("hasShades");
ticksMetamorphising = compound.getInt("ticksMetamorphising");
NbtCompound progress = compound.getCompound("advancementProgress");
advancementProgress.clear();