Skip to content

Commit

Permalink
fix: fix ageing and rejuvenation serum interaction with Tadpoles & Frogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Elenterius committed Apr 18, 2023
1 parent e4f72b0 commit af655a6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.github.elenterius.biomancy.mixin;

import net.minecraft.world.entity.animal.frog.Tadpole;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(Tadpole.class)
public interface TadpoleAccessor {
@Invoker("ageUp")
void biomancy$AgeUp();
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.github.elenterius.biomancy.serum;

import com.github.elenterius.biomancy.entity.MobUtil;
import com.github.elenterius.biomancy.mixin.TadpoleAccessor;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.animal.frog.Tadpole;
import net.minecraft.world.entity.monster.Guardian;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.LevelEvent;
Expand All @@ -20,19 +22,29 @@ public AgeingSerum(int color) {

@Override
public boolean canAffectEntity(CompoundTag tag, @Nullable LivingEntity source, LivingEntity target) {
return (target instanceof Mob && target.isBaby()) || target instanceof Guardian;
return (target instanceof Mob && target.isBaby()) || target instanceof Guardian || target instanceof Tadpole;
}

@Override
public void affectEntity(ServerLevel level, CompoundTag tag, @Nullable LivingEntity source, LivingEntity target) {
if (target instanceof Guardian guardian) {
convertToElderGuardian(level, guardian);
}
else if (target instanceof Tadpole tadpole) {
convertToFrog(level, tadpole);
}
else if (target instanceof Mob mob) {
MobUtil.convertToAdult(mob);
}
}

private void convertToFrog(ServerLevel level, Tadpole tadpole) {
((TadpoleAccessor) tadpole).biomancy$AgeUp();
if (!tadpole.isSilent()) {
level.levelEvent(null, LevelEvent.SOUND_ZOMBIE_INFECTED, tadpole.blockPosition(), 0);
}
}

private void convertToElderGuardian(ServerLevel level, Guardian guardian) {
MobUtil.convertMobTo(level, guardian, EntityType.ELDER_GUARDIAN, true, (oldGuardian, elderGuardian) -> {
if (!oldGuardian.isSilent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.animal.frog.Frog;
import net.minecraft.world.entity.monster.ElderGuardian;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.block.LevelEvent;
Expand All @@ -21,19 +22,30 @@ public RejuvenationSerum(int color) {

@Override
public boolean canAffectEntity(CompoundTag tag, @Nullable LivingEntity source, LivingEntity target) {
return (target instanceof Mob && !target.isBaby()) || target instanceof ElderGuardian;
return (target instanceof Mob && !target.isBaby()) || target instanceof ElderGuardian || target instanceof Frog;
}

@Override
public void affectEntity(ServerLevel level, CompoundTag tag, @Nullable LivingEntity source, LivingEntity target) {
if (target instanceof ElderGuardian elderGuardian) {
convertToGuardian(level, elderGuardian);
}
if (target instanceof Mob mob) {
else if (target instanceof Frog frog) {
convertToTadpole(level, frog);
}
else if (target instanceof Mob mob) {
MobUtil.convertToBaby(mob, true); // includes animals, villagers, zombies, etc..
}
}

private void convertToTadpole(ServerLevel level, Frog frog) {
MobUtil.convertMobTo(level, frog, EntityType.TADPOLE, true, (oldFrog, tadpole) -> {
if (!oldFrog.isSilent()) {
level.levelEvent(null, LevelEvent.SOUND_ZOMBIE_INFECTED, oldFrog.blockPosition(), 0);
}
});
}

private void convertToGuardian(ServerLevel level, ElderGuardian elderGuardian) {
MobUtil.convertMobTo(level, elderGuardian, EntityType.GUARDIAN, true, (oldElderGuardian, guardian) -> {
if (!oldElderGuardian.isSilent()) {
Expand Down
13 changes: 2 additions & 11 deletions src/main/resources/mixins.biomancy.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,8 @@
"defaultRequire": 1
},
"mixins": [
"AgeableMobAccessor",
"ArmorStandAccessor",
"LivingEntityAccessor",
"MobEffectInstanceAccessor",
"MobEffectInstanceMixin",
"MobEntityAccessor",
"PlayerMixin",
"SlimeAccessor",
"SwordItemMixinAccessor",
"TextureSlotAccessor",
"ZombieVillagerMixinAccessor"
"AgeableMobAccessor", "ArmorStandAccessor", "LivingEntityAccessor", "MobEffectInstanceAccessor", "MobEffectInstanceMixin", "MobEntityAccessor",
"PlayerMixin", "SlimeAccessor", "SwordItemMixinAccessor", "TadpoleAccessor", "TextureSlotAccessor", "ZombieVillagerMixinAccessor"
],
"client": [
"client.ClientPackListenerMixin",
Expand Down

0 comments on commit af655a6

Please sign in to comment.