Skip to content

Commit

Permalink
feat: make the Corrosion effect able to convert Zombies into Skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
Elenterius committed Jun 16, 2023
1 parent 3fd4c99 commit 8949ed0
Showing 1 changed file with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
package com.github.elenterius.biomancy.statuseffect;

import com.github.elenterius.biomancy.init.ModDamageSources;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffectCategory;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.horse.SkeletonHorse;
import net.minecraft.world.entity.animal.horse.ZombieHorse;
import net.minecraft.world.entity.monster.Skeleton;
import net.minecraft.world.entity.monster.Zombie;
import net.minecraft.world.level.block.LevelEvent;
import net.minecraftforge.event.ForgeEventFactory;

import java.util.UUID;

public class CorrosiveEffect extends StatusEffect {

Expand All @@ -12,7 +23,19 @@ public CorrosiveEffect(MobEffectCategory category, int color) {

@Override
public void applyEffectTick(LivingEntity livingEntity, int amplifier) {
int damage = 2 * (amplifier + 1);
int effectLevel = amplifier + 1;
float conversionProbability = 0.1f + 0.05f * effectLevel;

if (livingEntity.level instanceof ServerLevel serverLevel && livingEntity.level.random.nextFloat() < conversionProbability) {
DamageSource lastDamageSource = livingEntity.getLastDamageSource();
if (lastDamageSource != null && ModDamageSources.isCorrosive(lastDamageSource)) {
convertZombieToSkeleton(serverLevel, livingEntity);
}
}

if (!livingEntity.isAlive()) return;

int damage = 2 * effectLevel;
livingEntity.invulnerableTime = 0; //bypass invulnerable ticks
livingEntity.hurt(ModDamageSources.CORROSIVE_ACID, damage);
}
Expand All @@ -22,4 +45,38 @@ public boolean isDurationEffectTick(int duration, int amplifier) {
return duration % 7 == 0;
}

private boolean convertZombieToSkeleton(ServerLevel level, LivingEntity livingEntity) {
if (livingEntity instanceof Zombie zombie && ForgeEventFactory.canLivingConvert(zombie, EntityType.SKELETON, timer -> {})) {
Skeleton skeleton = zombie.convertTo(EntityType.SKELETON, true); // create new entity with same settings & equipment and remove old entity
if (skeleton != null) {
// skeleton.finalizeSpawn(level, level.getCurrentDifficultyAt(zombie.blockPosition()), MobSpawnType.CONVERSION, null, null);
skeleton.invulnerableTime = 60;
ForgeEventFactory.onLivingConvert(zombie, skeleton);
if (!zombie.isSilent()) {
level.levelEvent(null, LevelEvent.SOUND_ZOMBIE_INFECTED, zombie.blockPosition(), 0);
}
return true;
}
}
else if (livingEntity instanceof ZombieHorse zombieHorse && ForgeEventFactory.canLivingConvert(zombieHorse, EntityType.SKELETON_HORSE, timer -> {})) {
SkeletonHorse horse = zombieHorse.convertTo(EntityType.SKELETON_HORSE, true); // create new entity with same settings & equipment and remove old entity
if (horse != null) {
// horse.finalizeSpawn(level, level.getCurrentDifficultyAt(zombieHorse.blockPosition()), MobSpawnType.CONVERSION, null, null);
horse.invulnerableTime = 60;
UUID owner = zombieHorse.getOwnerUUID();
if (owner != null) {
horse.setOwnerUUID(owner);
}
horse.setTamed(zombieHorse.isTamed());
ForgeEventFactory.onLivingConvert(zombieHorse, horse);
if (!zombieHorse.isSilent()) {
level.levelEvent(null, LevelEvent.SOUND_ZOMBIE_INFECTED, zombieHorse.blockPosition(), 0);
}
return true;
}
}

return false;
}

}

0 comments on commit 8949ed0

Please sign in to comment.