Skip to content

Commit

Permalink
Fire LivingConversionEvent Pre and Post properly for Husk, Tadpole, M…
Browse files Browse the repository at this point in the history
…ooshroom, and Skeleton conversions (#514)
  • Loading branch information
TelepathicGrunt authored Jan 18, 2024
1 parent 69d5eb0 commit af78677
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
this.shear(SoundSource.PLAYERS);
this.gameEvent(GameEvent.SHEAR, p_28941_);
if (!this.level().isClientSide) {
@@ -164,7 +_,16 @@
@@ -164,11 +_,22 @@
}

@Override
Expand All @@ -34,7 +34,13 @@
+ private java.util.List<ItemStack> shearInternal(SoundSource p_28924_) {
this.level().playSound(null, this, SoundEvents.MOOSHROOM_SHEAR, p_28924_, 1.0F, 1.0F);
if (!this.level().isClientSide()) {
+ if (!net.neoforged.neoforge.event.EventHooks.canLivingConvert(this, EntityType.COW, (timer) -> {})) return java.util.Collections.emptyList();
Cow cow = EntityType.COW.create(this.level());
if (cow != null) {
+ net.neoforged.neoforge.event.EventHooks.onLivingConvert(this, cow);
((ServerLevel)this.level()).sendParticles(ParticleTypes.EXPLOSION, this.getX(), this.getY(0.5), this.getZ(), 1, 0.0, 0.0, 0.0, 0.0);
this.discard();
cow.moveTo(this.getX(), this.getY(), this.getZ(), this.getYRot(), this.getXRot());
@@ -186,14 +_,14 @@
cow.setInvulnerable(this.isInvulnerable());
this.level().addFreshEntity(cow);
Expand Down
13 changes: 13 additions & 0 deletions patches/net/minecraft/world/entity/animal/frog/Tadpole.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- a/net/minecraft/world/entity/animal/frog/Tadpole.java
+++ b/net/minecraft/world/entity/animal/frog/Tadpole.java
@@ -226,8 +_,10 @@
private void ageUp() {
Level $$1 = this.level();
if ($$1 instanceof ServerLevel serverlevel) {
+ if (!net.neoforged.neoforge.event.EventHooks.canLivingConvert(this, EntityType.FROG, (timer) -> {})) return;
Frog frog = EntityType.FROG.create(this.level());
if (frog != null) {
+ net.neoforged.neoforge.event.EventHooks.onLivingConvert(this, frog);
frog.moveTo(this.getX(), this.getY(), this.getZ(), this.getYRot(), this.getXRot());
frog.finalizeSpawn(serverlevel, this.level().getCurrentDifficultyAt(frog.blockPosition()), MobSpawnType.CONVERSION, null, null);
frog.setNoAi(this.isNoAi());
10 changes: 10 additions & 0 deletions patches/net/minecraft/world/entity/monster/Husk.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- a/net/minecraft/world/entity/monster/Husk.java
+++ b/net/minecraft/world/entity/monster/Husk.java
@@ -72,6 +_,7 @@

@Override
protected void doUnderWaterConversion() {
+ if (!net.neoforged.neoforge.event.EventHooks.canLivingConvert(this, EntityType.ZOMBIE, (timer) -> this.conversionTime = timer)) return;
this.convertToZombieType(EntityType.ZOMBIE);
if (!this.isSilent()) {
this.level().levelEvent(null, 1041, this.blockPosition(), 0);
13 changes: 13 additions & 0 deletions patches/net/minecraft/world/entity/monster/Skeleton.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- a/net/minecraft/world/entity/monster/Skeleton.java
+++ b/net/minecraft/world/entity/monster/Skeleton.java
@@ -86,7 +_,9 @@
}

protected void doFreezeConversion() {
- this.convertTo(EntityType.STRAY, true);
+ if (!net.neoforged.neoforge.event.EventHooks.canLivingConvert(this, EntityType.STRAY, (timer) -> this.conversionTime = timer)) return;
+ Stray stray = this.convertTo(EntityType.STRAY, true);
+ if (stray != null) net.neoforged.neoforge.event.EventHooks.onLivingConvert(this, stray);
if (!this.isSilent()) {
this.level().levelEvent(null, 1048, this.blockPosition(), 0);
}
17 changes: 8 additions & 9 deletions patches/net/minecraft/world/entity/monster/Zombie.java.patch
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
--- a/net/minecraft/world/entity/monster/Zombie.java
+++ b/net/minecraft/world/entity/monster/Zombie.java
@@ -203,7 +_,7 @@
if (!this.level().isClientSide && this.isAlive() && !this.isNoAi()) {
if (this.isUnderWaterConverting()) {
--this.conversionTime;
- if (this.conversionTime < 0) {
+ if (this.conversionTime < 0 && net.neoforged.neoforge.event.EventHooks.canLivingConvert(this, EntityType.DROWNED, (timer) -> this.conversionTime = timer)) {
this.doUnderWaterConversion();
}
} else if (this.convertsInWater()) {
@@ -254,6 +_,7 @@
}

protected void doUnderWaterConversion() {
+ if (!net.neoforged.neoforge.event.EventHooks.canLivingConvert(this, EntityType.DROWNED, (timer) -> this.conversionTime = timer)) return;
this.convertToZombieType(EntityType.DROWNED);
if (!this.isSilent()) {
this.level().levelEvent(null, 1040, this.blockPosition(), 0);
@@ -265,6 +_,7 @@
if (zombie != null) {
zombie.handleAttributes(zombie.level().getCurrentDifficultyAt(zombie.blockPosition()).getSpecialMultiplier());
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ protected net.minecraft.world.entity.projectile.Projectile <init>(Lnet/minecraft
private-f net.minecraft.world.entity.raid.Raid$RaiderType VALUES # VALUES
public net.minecraft.world.entity.schedule.Activity <init>(Ljava/lang/String;)V # constructor
protected net.minecraft.world.entity.vehicle.VehicleEntity getDropItem()Lnet/minecraft/world/item/Item; # getDropItem - make VehicleEntity implementable
protected net.minecraft.world.entity.monster.Zombie conversionTime
public net.minecraft.world.inventory.AnvilMenu repairItemCountCost # repairItemCountCost
public net.minecraft.world.inventory.MenuType <init>(Lnet/minecraft/world/inventory/MenuType$MenuSupplier;Lnet/minecraft/world/flag/FeatureFlagSet;)V # constructor
public net.minecraft.world.inventory.MenuType$MenuSupplier
Expand Down

0 comments on commit af78677

Please sign in to comment.