Skip to content

Commit

Permalink
Implement wither targeting AI tweak, closes #179
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed May 13, 2023
1 parent c763707 commit 868ed0e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ All changes are toggleable via the config file.
* Disable Fancy Missing Model: Improves rendering performance by removing the resource location text on missing models
* Disable Narrator: Disables the narrator functionality entirely
* Disable Sleeping: Disables skipping night by using a bed while making it still able to set spawn
* Disable Wither Targeting AI: Disables withers targeting animals
* Easy Breeding: Enables easy breeding of animals by tossing food on the ground
* End Portal Parallax: Re-implements parallax rendering of the end portal from 1.11 and older
* Fast Dye Blending: Replaces color lookup for sheep to check a predefined table rather than querying the recipe registry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,11 @@ public static class TweaksEntitiesCategory
@Config.Comment("Disables skipping night by using a bed while making it still able to set spawn")
public boolean utSleepingToggle = false;

@Config.RequiresMcRestart
@Config.Name("Disable Wither Targeting AI")
@Config.Comment("Disables withers targeting animals")
public boolean utWitherAIToggle = false;

@Config.RequiresMcRestart
@Config.Name("Husk & Stray Spawning")
@Config.Comment("Lets husks and strays spawn underground like regular zombies and skeletons")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public List<String> getMixinConfigs()
"mixins.tweaks.blocks.lenientpaths.json",
"mixins.tweaks.entities.ai.json",
"mixins.tweaks.entities.ai.saddledwandering.json",
"mixins.tweaks.entities.ai.wither.json",
"mixins.tweaks.entities.autojump.json",
"mixins.tweaks.entities.burning.horses.json",
"mixins.tweaks.entities.damage.collision.json",
Expand Down Expand Up @@ -196,6 +197,7 @@ public List<String> getMixinConfigs()
"mixins.tweaks.blocks.lenientpaths.json",
"mixins.tweaks.entities.ai.json",
"mixins.tweaks.entities.ai.saddledwandering.json",
"mixins.tweaks.entities.ai.wither.json",
"mixins.tweaks.entities.burning.horses.json",
"mixins.tweaks.entities.damage.collision.json",
"mixins.tweaks.entities.damage.falling.json",
Expand Down Expand Up @@ -373,6 +375,8 @@ public boolean shouldMixinConfigQueue(String mixinConfig)
return firstLaunch || UTConfigParser.isPresent("B:\"AI Replacement\"=true");
case "mixins.tweaks.entities.ai.saddledwandering.json":
return firstLaunch || UTConfigParser.isPresent("B:\"No Saddled Wandering\"=true");
case "mixins.tweaks.entities.ai.wither.json":
return !firstLaunch && UTConfigParser.isPresent("B:\"Disable Wither Targeting AI\"=true");
case "mixins.tweaks.entities.burning.horses.json":
return firstLaunch || UTConfigParser.isPresent("B:\"Burning Undead Horses\"=true");
case "mixins.tweaks.entities.damage.collision.json":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package mod.acgaming.universaltweaks.tweaks.entities.ai.wither;

import net.minecraft.entity.Entity;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.boss.EntityWither;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import mod.acgaming.universaltweaks.UniversalTweaks;
import mod.acgaming.universaltweaks.config.UTConfig;

@Mod.EventBusSubscriber(modid = UniversalTweaks.MODID)
public class UTWitherAI
{
@SubscribeEvent
public static void utWitherAI(EntityJoinWorldEvent event)
{
if (!UTConfig.TWEAKS_ENTITIES.utWitherAIToggle) return;
if (UTConfig.DEBUG.utDebugToggle) UniversalTweaks.LOGGER.debug("UTWitherAI ::: Entity join world event");
Entity entity = event.getEntity();
if (entity instanceof EntityWither)
{
EntityWither wither = (EntityWither) entity;
wither.targetTasks.taskEntries.clear();
wither.targetTasks.addTask(1, new EntityAIHurtByTarget(wither, false));
wither.targetTasks.addTask(2, new EntityAINearestAttackableTarget<>(wither, EntityPlayer.class, false, false));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package mod.acgaming.universaltweaks.tweaks.entities.ai.wither.mixin;

import net.minecraft.entity.boss.EntityWither;

import mod.acgaming.universaltweaks.config.UTConfig;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import zone.rong.mixinextras.injector.WrapWithCondition;

@Mixin(EntityWither.class)
public class UTWitherAIMixin
{
@WrapWithCondition(method = "updateAITasks", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/boss/EntityWither;updateWatchedTargetId(II)V", ordinal = 3))
public boolean utWitherAI(EntityWither instance, int targetOffset, int newId)
{
return !UTConfig.TWEAKS_ENTITIES.utWitherAIToggle;
}
}
7 changes: 7 additions & 0 deletions src/main/resources/mixins.tweaks.entities.ai.wither.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"package": "mod.acgaming.universaltweaks.tweaks.entities.ai.wither.mixin",
"refmap": "universaltweaks.refmap.json",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": ["UTWitherAIMixin"]
}

0 comments on commit 868ed0e

Please sign in to comment.