Skip to content

Commit

Permalink
Fix:
Browse files Browse the repository at this point in the history
0. Added warden and wither to the dangerous mob.

Optimization:
0. Optimized food chain.
  • Loading branch information
MarvionKirito committed Nov 15, 2022
1 parent 68933f0 commit 7c1a7d1
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 60 deletions.
8 changes: 3 additions & 5 deletions src/main/java/adris/altoclef/chains/FoodChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,6 @@ public float getPriority(AltoClef mod) {
// Food eating is handled asynchronously.
return Float.NEGATIVE_INFINITY;
}

public boolean isTryingToEat() {
return _isTryingToEat;
}

@Override
public boolean isActive() {
// We're always checking for food.
Expand All @@ -188,6 +183,9 @@ protected void onStop(AltoClef mod) {
}

public boolean needsToEat() {
if (!hasFood()) {
return false;
}
ClientPlayerEntity player = MinecraftClient.getInstance().player;
assert player != null;
int foodLevel = player.getHungerManager().getFoodLevel();
Expand Down
85 changes: 46 additions & 39 deletions src/main/java/adris/altoclef/chains/MobDefenseChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.minecraft.block.Block;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.boss.WitherEntity;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.mob.*;
import net.minecraft.entity.player.PlayerEntity;
Expand Down Expand Up @@ -50,7 +51,6 @@ public class MobDefenseChain extends SingleTaskChain {
private boolean _shielding = false;
private boolean _doingFunkyStuff = false;
private boolean _wasPuttingOutFire = false;
private boolean wasKillingEntity = false;
private CustomBaritoneGoalTask _runAwayTask;

private float _cachedLastPriority;
Expand Down Expand Up @@ -148,8 +148,9 @@ public float getPriorityInner(AltoClef mod) {
_wasPuttingOutFire = false;
}

if (mod.getFoodChain().needsToEat() || mod.getMLGBucketChain().isFallingOhNo(mod) || !mod.getMLGBucketChain().doneMLG() ||
mod.getMLGBucketChain().isChorusFruiting()) {
if (mod.getFoodChain().needsToEat() || mod.getMLGBucketChain().isFallingOhNo(mod) ||
!mod.getMLGBucketChain().doneMLG() || mod.getMLGBucketChain().isChorusFruiting()) {
_killAura.stopShielding(mod);
stopShielding(mod);
return Float.NEGATIVE_INFINITY;
}
Expand All @@ -171,11 +172,10 @@ public float getPriorityInner(AltoClef mod) {
}

_doingFunkyStuff = false;
wasKillingEntity = false;
// Run away from creepers
CreeperEntity blowingUp = getClosestFusingCreeper(mod);
if (blowingUp != null) {
if (!mod.getFoodChain().isTryingToEat() && (mod.getItemStorage().hasItem(Items.SHIELD) ||
if (!mod.getFoodChain().needsToEat() && (mod.getItemStorage().hasItem(Items.SHIELD) ||
mod.getItemStorage().hasItemInOffhand(Items.SHIELD)) &&
!mod.getEntityTracker().entityFound(PotionEntity.class) && _runAwayTask == null &&
mod.getClientBaritone().getPathingBehavior().isSafeToCancel()) {
Expand All @@ -201,7 +201,7 @@ public float getPriorityInner(AltoClef mod) {
}
}
// Block projectiles with shield
if (!mod.getFoodChain().isTryingToEat() && mod.getModSettings().isDodgeProjectiles() && isProjectileClose(mod) &&
if (!mod.getFoodChain().needsToEat() && mod.getModSettings().isDodgeProjectiles() && isProjectileClose(mod) &&
(mod.getItemStorage().hasItem(Items.SHIELD) || mod.getItemStorage().hasItemInOffhand(Items.SHIELD)) &&
!mod.getEntityTracker().entityFound(PotionEntity.class) && _runAwayTask == null &&
mod.getClientBaritone().getPathingBehavior().isSafeToCancel()) {
Expand All @@ -219,7 +219,7 @@ public float getPriorityInner(AltoClef mod) {
// Dodge projectiles
if (mod.getPlayer().getHealth() <= 10 || _runAwayTask != null || mod.getEntityTracker().entityFound(PotionEntity.class) ||
(!mod.getItemStorage().hasItem(Items.SHIELD) && !mod.getItemStorage().hasItemInOffhand(Items.SHIELD))) {
if (!mod.getFoodChain().isTryingToEat() && mod.getModSettings().isDodgeProjectiles() && isProjectileClose(mod)) {
if (!mod.getFoodChain().needsToEat() && mod.getModSettings().isDodgeProjectiles() && isProjectileClose(mod)) {
_doingFunkyStuff = true;
//Debug.logMessage("DODGING");
_runAwayTask = new DodgeProjectilesTask(ARROW_KEEP_DISTANCE_HORIZONTAL, ARROW_KEEP_DISTANCE_VERTICAL);
Expand Down Expand Up @@ -266,14 +266,16 @@ public float getPriorityInner(AltoClef mod) {
// Give each hostile a timer, if they're close for too long deal with them.
if (isClose) {
if (!_closeAnnoyingEntities.containsKey(hostile)) {
boolean wardenAttacking = hostile instanceof WardenEntity;
boolean witherAttacking = hostile instanceof WitherEntity;
boolean endermanAttacking = hostile instanceof EndermanEntity;
boolean blazeAttacking = hostile instanceof BlazeEntity;
boolean witherAttacking = hostile instanceof WitherSkeletonEntity;
boolean witherSkeletonAttacking = hostile instanceof WitherSkeletonEntity;
boolean hoglinAttacking = hostile instanceof HoglinEntity;
boolean zoglinAttacking = hostile instanceof ZoglinEntity;
boolean piglinBruteAttacking = hostile instanceof PiglinBruteEntity;
if (blazeAttacking || witherAttacking || hoglinAttacking ||
zoglinAttacking || piglinBruteAttacking || endermanAttacking) {
if (blazeAttacking || witherSkeletonAttacking || hoglinAttacking || zoglinAttacking ||
piglinBruteAttacking || endermanAttacking || witherAttacking || wardenAttacking) {
if (mod.getPlayer().getHealth() <= 10) {
_closeAnnoyingEntities.put(hostile, new TimerGame(0));
} else {
Expand Down Expand Up @@ -337,7 +339,6 @@ public float getPriorityInner(AltoClef mod) {
int canDealWith = (int) Math.ceil((armor * 3.6 / 20.0) + (damage * 0.8) + (shield));
canDealWith += 1;
if (canDealWith > numberOfProblematicEntities) {
wasKillingEntity = true;
// We can deal with it.
_runAwayTask = null;
setTask(new KillEntitiesTask(toDealWith.get(0).getClass()));
Expand Down Expand Up @@ -505,42 +506,48 @@ private boolean isProjectileClose(AltoClef mod) {
private Optional<Entity> getUniversallyDangerousMob(AltoClef mod) {
// Wither skeletons are dangerous because of the wither effect. Oof kinda obvious.
// If we merely force field them, we will run into them and get the wither effect which will kill us.
if (mod.getEntityTracker().entityFound(WitherSkeletonEntity.class)) {
Optional<Entity> entity = mod.getEntityTracker().getClosestEntity(mod.getPlayer().getPos(), WitherSkeletonEntity.class);
if (entity.isPresent()) {
double range = SAFE_KEEP_DISTANCE - 2;
if (entity.get().squaredDistanceTo(mod.getPlayer()) < range * range && EntityHelper.isAngryAtPlayer(mod, entity.get())) {
return entity;
}
Optional<Entity> warden = mod.getEntityTracker().getClosestEntity(WardenEntity.class);
if (warden.isPresent()) {
double range = SAFE_KEEP_DISTANCE - 2;
if (warden.get().squaredDistanceTo(mod.getPlayer()) < range * range && EntityHelper.isAngryAtPlayer(mod, warden.get())) {
return warden;
}
}
Optional<Entity> wither = mod.getEntityTracker().getClosestEntity(WitherEntity.class);
if (wither.isPresent()) {
double range = SAFE_KEEP_DISTANCE - 2;
if (wither.get().squaredDistanceTo(mod.getPlayer()) < range * range && EntityHelper.isAngryAtPlayer(mod, wither.get())) {
return wither;
}
}
Optional<Entity> witherSkeleton = mod.getEntityTracker().getClosestEntity(WitherSkeletonEntity.class);
if (witherSkeleton.isPresent()) {
double range = SAFE_KEEP_DISTANCE - 2;
if (witherSkeleton.get().squaredDistanceTo(mod.getPlayer()) < range * range && EntityHelper.isAngryAtPlayer(mod, witherSkeleton.get())) {
return witherSkeleton;
}
}
// Hoglins are dangerous because we can't push them with the force field.
// If we merely force field them and stand still our health will slowly be chipped away until we die
if (mod.getEntityTracker().entityFound(HoglinEntity.class)) {
Optional<Entity> hoglin = mod.getEntityTracker().getClosestEntity(mod.getPlayer().getPos(), HoglinEntity.class);
if (hoglin.isPresent()) {
double range = SAFE_KEEP_DISTANCE - 2;
if (hoglin.get().squaredDistanceTo(mod.getPlayer()) < range * range && EntityHelper.isAngryAtPlayer(mod, hoglin.get())) {
return hoglin;
}
Optional<Entity> hoglin = mod.getEntityTracker().getClosestEntity(HoglinEntity.class);
if (hoglin.isPresent()) {
double range = SAFE_KEEP_DISTANCE - 2;
if (hoglin.get().squaredDistanceTo(mod.getPlayer()) < range * range && EntityHelper.isAngryAtPlayer(mod, hoglin.get())) {
return hoglin;
}
}
if (mod.getEntityTracker().entityFound(ZoglinEntity.class)) {
Optional<Entity> zoglin = mod.getEntityTracker().getClosestEntity(mod.getPlayer().getPos(), ZoglinEntity.class);
if (zoglin.isPresent()) {
double range = SAFE_KEEP_DISTANCE - 2;
if (zoglin.get().squaredDistanceTo(mod.getPlayer()) < range * range && EntityHelper.isAngryAtPlayer(mod, zoglin.get())) {
return zoglin;
}
Optional<Entity> zoglin = mod.getEntityTracker().getClosestEntity(ZoglinEntity.class);
if (zoglin.isPresent()) {
double range = SAFE_KEEP_DISTANCE - 2;
if (zoglin.get().squaredDistanceTo(mod.getPlayer()) < range * range && EntityHelper.isAngryAtPlayer(mod, zoglin.get())) {
return zoglin;
}
}
if (mod.getEntityTracker().entityFound(PiglinBruteEntity.class)) {
Optional<Entity> piglinBrute = mod.getEntityTracker().getClosestEntity(mod.getPlayer().getPos(), PiglinBruteEntity.class);
if (piglinBrute.isPresent()) {
double range = SAFE_KEEP_DISTANCE - 2;
if (piglinBrute.get().squaredDistanceTo(mod.getPlayer()) < range * range && EntityHelper.isAngryAtPlayer(mod, piglinBrute.get())) {
return piglinBrute;
}
Optional<Entity> piglinBrute = mod.getEntityTracker().getClosestEntity(PiglinBruteEntity.class);
if (piglinBrute.isPresent()) {
double range = SAFE_KEEP_DISTANCE - 2;
if (piglinBrute.get().squaredDistanceTo(mod.getPlayer()) < range * range && EntityHelper.isAngryAtPlayer(mod, piglinBrute.get())) {
return piglinBrute;
}
}
return Optional.empty();
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/adris/altoclef/control/KillAura.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import adris.altoclef.util.time.TimerGame;
import baritone.api.utils.input.Input;
import net.minecraft.entity.Entity;
import net.minecraft.entity.boss.WitherEntity;
import net.minecraft.entity.mob.*;
import net.minecraft.entity.projectile.FireballEntity;
import net.minecraft.entity.projectile.thrown.PotionEntity;
Expand All @@ -26,7 +27,6 @@
* Controls and applies killaura
*/
public class KillAura {

// Smart aura data
private final List<Entity> _targets = new ArrayList<>();
private final TimerGame _hitDelay = new TimerGame(0.2);
Expand Down Expand Up @@ -81,7 +81,8 @@ public void tickEnd(AltoClef mod) {
!mod.getMLGBucketChain().isChorusFruiting() &&
mod.getClientBaritone().getPathingBehavior().isSafeToCancel()) {
if (entities.get().getClass() != CreeperEntity.class && entities.get().getClass() != HoglinEntity.class &&
entities.get().getClass() != ZoglinEntity.class) {
entities.get().getClass() != ZoglinEntity.class && entities.get().getClass() != WardenEntity.class &&
entities.get().getClass() != WitherEntity.class) {
LookHelper.lookAt(mod, entities.get().getEyePos());
ItemStack shieldSlot = StorageHelper.getItemStackInSlot(PlayerSlot.OFFHAND_SLOT);
if (shieldSlot.getItem() != Items.SHIELD) {
Expand Down Expand Up @@ -109,7 +110,7 @@ public void tickEnd(AltoClef mod) {
_targets.stream().allMatch(entity -> entity instanceof BlazeEntity)) {
performDelayedAttack(mod);
} else {
if (!mod.getFoodChain().isTryingToEat() && !mod.getMLGBucketChain().isFallingOhNo(mod) &&
if (!mod.getFoodChain().needsToEat() && !mod.getMLGBucketChain().isFallingOhNo(mod) &&
mod.getMLGBucketChain().doneMLG() && !mod.getMLGBucketChain().isChorusFruiting() &&
mod.getClientBaritone().getPathingBehavior().isSafeToCancel()) {
// Attack force mobs ALWAYS.
Expand All @@ -135,7 +136,7 @@ public void tickEnd(AltoClef mod) {
}

private void performDelayedAttack(AltoClef mod) {
if (!mod.getFoodChain().isTryingToEat() && !mod.getMLGBucketChain().isFallingOhNo(mod) &&
if (!mod.getFoodChain().needsToEat() && !mod.getMLGBucketChain().isFallingOhNo(mod) &&
mod.getMLGBucketChain().doneMLG() && !mod.getMLGBucketChain().isChorusFruiting() &&
mod.getClientBaritone().getPathingBehavior().isSafeToCancel()) {
if (_forceHit != null) {
Expand All @@ -157,7 +158,7 @@ private void performDelayedAttack(AltoClef mod) {
}

private void performFastestAttack(AltoClef mod) {
if (!mod.getFoodChain().isTryingToEat() && !mod.getMLGBucketChain().isFallingOhNo(mod) &&
if (!mod.getFoodChain().needsToEat() && !mod.getMLGBucketChain().isFallingOhNo(mod) &&
mod.getMLGBucketChain().doneMLG() && !mod.getMLGBucketChain().isChorusFruiting() &&
mod.getClientBaritone().getPathingBehavior().isSafeToCancel()) {
// Just attack whenever you can
Expand Down Expand Up @@ -197,7 +198,7 @@ private void attack(AltoClef mod, Entity entity, boolean equipSword) {
}
}

private void startShielding(AltoClef mod) {
public void startShielding(AltoClef mod) {
ItemStack handItem = StorageHelper.getItemStackInSlot(PlayerSlot.getEquipSlot());
ItemStack cursor = StorageHelper.getItemStackInCursorSlot();
if (handItem.isFood()) {
Expand All @@ -217,7 +218,7 @@ private void startShielding(AltoClef mod) {
mod.getExtraBaritoneSettings().setInteractionPaused(true);
}

private void stopShielding(AltoClef mod) {
public void stopShielding(AltoClef mod) {
if (_shielding) {
ItemStack cursor = StorageHelper.getItemStackInCursorSlot();
if (cursor.isFood()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/adris/altoclef/control/SlotHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public boolean forceEquipItem(ItemTarget toEquip, boolean unInterruptable) {
if (toEquip == null) return false;

//If the bot try to eat
if (_mod.getFoodChain().isTryingToEat() && !unInterruptable) { //unless we really need to force equip the item
if (_mod.getFoodChain().needsToEat() && !unInterruptable) { //unless we really need to force equip the item
return false; //don't equip the item for now
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public ClickResponse getClickStatus() {
private ClickResponse rightClick(AltoClef mod) {

// Don't interact if baritone can't interact.
if (mod.getExtraBaritoneSettings().isInteractionPaused() || mod.getFoodChain().isTryingToEat() ||
if (mod.getExtraBaritoneSettings().isInteractionPaused() || mod.getFoodChain().needsToEat() ||
mod.getPlayer().isBlocking() || !mod.getClientBaritone().getPathingBehavior().isSafeToCancel())
return ClickResponse.WAIT_FOR_CLICK;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ protected Task onTick(AltoClef mod) {
// We're trying to mine
Optional<Rotation> reach = LookHelper.getReach(_pos);
if (reach.isPresent() && (mod.getPlayer().isTouchingWater() || mod.getPlayer().isOnGround()) &&
!mod.getFoodChain().isTryingToEat() && !WorldHelper.isInNetherPortal(mod) &&
!mod.getFoodChain().needsToEat() && !WorldHelper.isInNetherPortal(mod) &&
mod.getClientBaritone().getPathingBehavior().isSafeToCancel()) {
setDebugState("Block in range, mining...");
stuckCheck.reset();
Expand Down Expand Up @@ -219,7 +219,7 @@ protected Task onTick(AltoClef mod) {
boolean isCloseToMoveBack = _pos.isWithinDistance(mod.getPlayer().getPos(), 2);
if (isCloseToMoveBack) {
if (!mod.getClientBaritone().getPathingBehavior().isPathing() && !mod.getPlayer().isTouchingWater() &&
!mod.getFoodChain().isTryingToEat()) {
!mod.getFoodChain().needsToEat()) {
mod.getInputControls().hold(Input.SNEAK);
mod.getInputControls().hold(Input.MOVE_BACK);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected Task onTick(AltoClef mod) {
// Walk to it and open it

// Wait for food
if (mod.getFoodChain().isTryingToEat()) {
if (mod.getFoodChain().needsToEat()) {
setDebugState("Waiting for eating...");
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void equipWeapon(AltoClef mod) {

@Override
protected Task onEntityInteract(AltoClef mod, Entity entity) {
if (!mod.getFoodChain().isTryingToEat() && !mod.getMLGBucketChain().isFallingOhNo(mod) &&
if (!mod.getFoodChain().needsToEat() && !mod.getMLGBucketChain().isFallingOhNo(mod) &&
mod.getMLGBucketChain().doneMLG() && !mod.getMLGBucketChain().isChorusFruiting() &&
mod.getClientBaritone().getPathingBehavior().isSafeToCancel()) {
float hitProg = mod.getPlayer().getAttackCooldownProgress(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected String toDebugStringName() {
}

private void makeSureToolIsEquipped(AltoClef mod) {
if (_cursorStackTimer.elapsed() && !mod.getFoodChain().isTryingToEat()) {
if (_cursorStackTimer.elapsed() && !mod.getFoodChain().needsToEat()) {
assert MinecraftClient.getInstance().player != null;
ItemStack cursorStack = StorageHelper.getItemStackInCursorSlot();
if (cursorStack != null && !cursorStack.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,7 @@ private Task getEyesOfEnderTask(AltoClef mod, int targetEyes) {
}
}
// Then get shield
if (_config.getShield && !shieldSatisfied && !mod.getFoodChain().isTryingToEat()) {
if (_config.getShield && !shieldSatisfied && !mod.getFoodChain().needsToEat()) {
ItemTarget shield = new ItemTarget(COLLECT_SHIELD);
if (mod.getItemStorage().hasItem(shield) && !StorageHelper.isArmorEquipped(mod, COLLECT_SHIELD)) {
setDebugState("Equipping shield.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public MovementProgressChecker() {
public boolean check(AltoClef mod) {

// Allow pause on eat
if (mod.getFoodChain().isTryingToEat()) {
if (mod.getFoodChain().needsToEat()) {
_distanceChecker.reset();
_mineChecker.reset();
}
Expand Down

0 comments on commit 7c1a7d1

Please sign in to comment.