-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable parent sensor in brained adult animals
- Loading branch information
Showing
5 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...ysquid/mods/lithium/mixin/ai/useless_sensors/parent_animal_sensor/PassiveEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package me.jellysquid.mods.lithium.mixin.ai.useless_sensors.parent_animal_sensor; | ||
|
||
import me.jellysquid.mods.lithium.common.ai.brain.SensorHelper; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.ai.brain.MemoryModuleType; | ||
import net.minecraft.entity.ai.brain.sensor.SensorType; | ||
import net.minecraft.entity.data.TrackedData; | ||
import net.minecraft.entity.passive.PassiveEntity; | ||
import net.minecraft.world.World; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.util.Optional; | ||
|
||
@Mixin(PassiveEntity.class) | ||
public abstract class PassiveEntityMixin extends LivingEntity { | ||
|
||
@Shadow | ||
public abstract boolean isBaby(); | ||
|
||
protected PassiveEntityMixin(EntityType<? extends LivingEntity> entityType, World world) { | ||
super(entityType, world); | ||
} | ||
|
||
@Inject( | ||
method = "onTrackedDataSet", | ||
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/PassiveEntity;calculateDimensions()V"), | ||
require = 1, allow = 1 | ||
) | ||
private void handleParentSensor(TrackedData<?> data, CallbackInfo ci) { | ||
if (this.getWorld().isClient()) { | ||
return; | ||
} | ||
if (isBaby()) { | ||
SensorHelper.enableSensor((PassiveEntity) (Object) this, SensorType.NEAREST_ADULT, true); | ||
} else { | ||
SensorHelper.disableSensor((PassiveEntity) (Object) this, SensorType.NEAREST_ADULT); | ||
if (this.getBrain().hasMemoryModule(MemoryModuleType.NEAREST_VISIBLE_ADULT)) { | ||
this.getBrain().remember(MemoryModuleType.NEAREST_VISIBLE_ADULT, Optional.empty()); | ||
} | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...e/jellysquid/mods/lithium/mixin/ai/useless_sensors/parent_animal_sensor/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@MixinConfigOption(description = "Disable the parent animal sensor when an animal is not a baby." + | ||
" Would differ from vanilla in the case where an adult animal turns back into a baby animal, as the sensor information is refreshed," + | ||
" leading to a less-outdated value in the first second of turning back into a baby animal. However, there is no way to turn an animal" + | ||
" back into a baby without reinitializing the brain, creating entirely new sensors." | ||
) | ||
package me.jellysquid.mods.lithium.mixin.ai.useless_sensors.parent_animal_sensor; | ||
|
||
import net.caffeinemc.gradle.MixinConfigOption; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters