Skip to content

Commit

Permalink
1.21 update
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvionKirito committed Aug 5, 2024
1 parent 1713539 commit e45566e
Show file tree
Hide file tree
Showing 52 changed files with 1,247 additions and 1,278 deletions.
20 changes: 10 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@ dependencies {
modImplementation("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}")

// Jackson JSON
implementation 'com.fasterxml.jackson.core:jackson-core:2.17.1'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.17.1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.1'
implementation 'com.fasterxml.jackson.core:jackson-core:2.17.2'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.17.2'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.2'

// Nether pathfinder
implementation 'dev.babbaj:nether-pathfinder:1.5'

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
shadow('com.fasterxml.jackson.core:jackson-core:2.17.1')
shadow('com.fasterxml.jackson.core:jackson-annotations:2.17.1')
shadow('com.fasterxml.jackson.core:jackson-databind:2.17.1')
shadow('com.fasterxml.jackson.core:jackson-core:2.17.2')
shadow('com.fasterxml.jackson.core:jackson-annotations:2.17.2')
shadow('com.fasterxml.jackson.core:jackson-databind:2.17.2')

// Thank you georgeagostino for fixing my garbage
if (getProject().hasProperty("altoclef.development")) {
// Must run build from baritone-plus once
modImplementation 'baritone-api-fabric:baritone-unoptimized-fabric-1.20.6-beta1'
include "baritone-api-fabric:baritone-unoptimized-fabric-1.20.6-beta1"
modImplementation 'baritone-api-fabric:baritone-unoptimized-fabric-1.21-beta1'
include "baritone-api-fabric:baritone-unoptimized-fabric-1.21-beta1"
} else {
modImplementation "cabaletta:baritone-unoptimized-fabric:1.20.6-beta1"
include "cabaletta:baritone-unoptimized-fabric:1.20.6-beta1"
modImplementation "cabaletta:baritone-unoptimized-fabric:1.21-beta1"
include "cabaletta:baritone-unoptimized-fabric:1.21-beta1"
}
//modImplementation 'baritone-api-fabric:baritone-api-fabric:1.6.3'
//implementation files('baritone-plus/build/libs/baritone-unoptimized-fabric-1.6.3.jar')
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ org.gradle.caching=true
org.gradle.warning.mode=all
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.3
minecraft_version=1.21
yarn_mappings=1.21+build.9
loader_version=0.15.11
# Mod Properties
mod_version=1.20.6-beta1
mod_version=1.21-beta1
maven_group=gaucho-matrero.altoclef
archives_base_name=altoclef
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.100.2+1.20.6
fabric_version=0.100.7+1.21
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 1 addition & 3 deletions src/main/java/adris/altoclef/chains/FoodChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ public float getPriority(AltoClef mod) {
!mod.getMLGBucketChain().isChorusFruiting() && !mod.getPlayer().isBlocking()) {
Item toUse = _cachedPerfectFood.get();
// Make sure we're not facing a container
if (!LookHelper.tryAvoidingInteractable(mod)) {
return Float.NEGATIVE_INFINITY;
}
LookHelper.tryAvoidingInteractable(mod);
startEat(mod, toUse);
} else {
stopEat(mod);
Expand Down
113 changes: 38 additions & 75 deletions src/main/java/adris/altoclef/chains/MobDefenseChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import adris.altoclef.util.helpers.*;
import adris.altoclef.util.slots.PlayerSlot;
import adris.altoclef.util.slots.Slot;
import adris.altoclef.util.time.TimerGame;
import baritone.Baritone;
import baritone.api.utils.Rotation;
import baritone.api.utils.input.Input;
Expand All @@ -37,7 +36,11 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;

import java.util.*;
import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;

import static java.lang.Math.abs;

Expand All @@ -50,7 +53,6 @@ public class MobDefenseChain extends SingleTaskChain {
private static boolean _shielding = false;
private final DragonBreathTracker _dragonBreathTracker = new DragonBreathTracker();
private final KillAura _killAura = new KillAura();
private final HashMap<Entity, TimerGame> _closeAnnoyingEntities = new HashMap<>();
private Entity _targetEntity;
private boolean _doingFunkyStuff = false;
private boolean _wasPuttingOutFire = false;
Expand Down Expand Up @@ -262,69 +264,21 @@ public float getPriorityInner(AltoClef mod) {
}

List<Entity> toDealWith = new ArrayList<>();

// TODO: I don't think this lock is necessary at all.
if (!hostiles.isEmpty()) {
synchronized (BaritoneHelper.MINECRAFT_LOCK) {
for (Entity hostile : hostiles) {
int annoyingRange = (hostile instanceof SkeletonEntity || hostile instanceof WitchEntity || hostile
instanceof PillagerEntity || hostile instanceof PiglinEntity || hostile instanceof StrayEntity) ? 15 : 8;
boolean isClose = hostile.isInRange(mod.getPlayer(), annoyingRange);

if (isClose) {
isClose = LookHelper.seesPlayer(hostile, mod.getPlayer(), annoyingRange);
for (Entity entity : hostiles) {
if (entity instanceof MobEntity mob) {
boolean isAttackingPlayer = EntityHelper.isAngryAtPlayer(mod, mob);
if (isAttackingPlayer) {
toDealWith.add(mob);
}

// 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 witherSkeletonAttacking = hostile instanceof WitherSkeletonEntity;
boolean hoglinAttacking = hostile instanceof HoglinEntity;
boolean zoglinAttacking = hostile instanceof ZoglinEntity;
boolean piglinBruteAttacking = hostile instanceof PiglinBruteEntity;
boolean vindicatorAttacking = hostile instanceof VindicatorEntity;
if (blazeAttacking || witherSkeletonAttacking || hoglinAttacking || zoglinAttacking ||
piglinBruteAttacking || endermanAttacking || witherAttacking || wardenAttacking || vindicatorAttacking) {
if (mod.getPlayer().getHealth() <= 10) {
_closeAnnoyingEntities.put(hostile, new TimerGame(0));
} else {
_closeAnnoyingEntities.put(hostile, new TimerGame(Float.POSITIVE_INFINITY));
}
} else {
_closeAnnoyingEntities.put(hostile, new TimerGame(0));
}
_closeAnnoyingEntities.get(hostile).reset();
}
if (_closeAnnoyingEntities.get(hostile).elapsed()) {
toDealWith.add(hostile);
}
} else {
_closeAnnoyingEntities.remove(hostile);
}
}
}
}

// Clear dead/non existing hostiles
List<Entity> toRemove = new ArrayList<>();
if (!_closeAnnoyingEntities.keySet().isEmpty()) {
for (Entity check : _closeAnnoyingEntities.keySet()) {
if (!check.isAlive()) {
toRemove.add(check);
}
}
}
if (!toRemove.isEmpty()) {
for (Entity remove : toRemove) _closeAnnoyingEntities.remove(remove);
}
int numberOfProblematicEntities = toDealWith.size();
if (!toDealWith.isEmpty()) {
for (Entity ToDealWith : toDealWith) {
if (ToDealWith.getClass() == SlimeEntity.class || ToDealWith.getClass() == MagmaCubeEntity.class) {
if (ToDealWith instanceof SlimeEntity) {
numberOfProblematicEntities = 1;
break;
}
Expand Down Expand Up @@ -362,31 +316,30 @@ public float getPriorityInner(AltoClef mod) {
// We can deal with it.
_runAwayTask = null;
for (Entity ToDealWith : toDealWith) {
Predicate<Entity> valid = entity -> EntityHelper.isAngryAtPlayer(mod, entity);
// Prioritize ranged enemies first.
if (ToDealWith instanceof SkeletonEntity || ToDealWith instanceof WitchEntity ||
ToDealWith instanceof PillagerEntity || ToDealWith instanceof PiglinEntity ||
ToDealWith instanceof StrayEntity) {
setTask(new KillEntitiesTask(ToDealWith.getClass()));
setTask(new KillEntitiesTask(valid, ToDealWith.getClass()));
return 65;
}
setTask(new KillEntitiesTask(ToDealWith.getClass()));
setTask(new KillEntitiesTask(valid, ToDealWith.getClass()));
return 65;
}
return 65;
} else {
// We can't deal with it
_runAwayTask = new RunAwayFromHostilesTask(DANGER_KEEP_DISTANCE, true);
setTask(_runAwayTask);
return 80;
}
// We can't deal with it
_runAwayTask = new RunAwayFromHostilesTask(DANGER_KEEP_DISTANCE, true);
setTask(_runAwayTask);
return 80;
}
}
// By default if we aren't "immediately" in danger but were running away, keep running away until we're good.
if (_runAwayTask != null && !_runAwayTask.isFinished(mod)) {
setTask(_runAwayTask);
return _cachedLastPriority;
} else {
_runAwayTask = null;
}
_runAwayTask = null;
return 0;
}

Expand Down Expand Up @@ -474,19 +427,19 @@ private CreeperEntity getClosestFusingCreeper(AltoClef mod) {
double worstSafety = Float.POSITIVE_INFINITY;
CreeperEntity target = null;
try {
List<CreeperEntity> creepers = mod.getEntityTracker().getTrackedEntities(CreeperEntity.class);
if (!creepers.isEmpty()) {
for (CreeperEntity creeper : creepers) {
if (creeper == null) continue;
if (creeper.getClientFuseTime(1) < 0.001) continue;

Optional<Entity> creeper = mod.getEntityTracker().getClosestEntity(CreeperEntity.class);
if (creeper.isPresent()) {
CreeperEntity creeperEntity = (CreeperEntity) creeper.get();
if (!(creeperEntity.getClientFuseTime(1) < 0.001)) {
// We want to pick the closest creeper, but FIRST pick creepers about to blow
// At max fuse, the cost goes to basically zero.
double safety = getCreeperSafety(mod.getPlayer().getPos(), creeper);
double safety = getCreeperSafety(mod.getPlayer().getPos(), creeperEntity);
if (safety < worstSafety) {
target = creeper;
target = creeperEntity;
}
}
;

}
} catch (ConcurrentModificationException | ArrayIndexOutOfBoundsException | NullPointerException e) {
// IDK why but these exceptions happen sometimes. It's extremely bizarre and I have no idea why.
Expand Down Expand Up @@ -541,7 +494,17 @@ private boolean isProjectileClose(AltoClef mod) {
if (horizontalDistanceSq < ARROW_KEEP_DISTANCE_HORIZONTAL * ARROW_KEEP_DISTANCE_HORIZONTAL && verticalDistance < ARROW_KEEP_DISTANCE_VERTICAL) {
if (_runAwayTask == null && mod.getClientBaritone().getPathingBehavior().isSafeToCancel()) {
mod.getClientBaritone().getPathingBehavior().requestPause();
if (projectile.projectileType instanceof ProjectileEntity projectileEntity) {
Entity owner = projectileEntity.getOwner();
if (owner != null) {
LookHelper.lookAt(mod, owner.getEyePos());
return true;
}
LookHelper.lookAt(mod, projectile.position);
return true;
}
LookHelper.lookAt(mod, projectile.position);
return true;
}
return true;
}
Expand Down
53 changes: 25 additions & 28 deletions src/main/java/adris/altoclef/chains/PlayerInteractionFixChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@
import adris.altoclef.util.helpers.ItemHelper;
import adris.altoclef.util.helpers.LookHelper;
import adris.altoclef.util.helpers.StorageHelper;
import adris.altoclef.util.slots.PlayerSlot;
import adris.altoclef.util.slots.Slot;
import adris.altoclef.util.time.TimerGame;
import baritone.api.utils.Rotation;
import baritone.api.utils.input.Input;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.gui.screen.DeathScreen;
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.slot.SlotActionType;

Expand Down Expand Up @@ -58,31 +55,31 @@ public float getPriority(AltoClef mod) {

if (!AltoClef.inGame()) return Float.NEGATIVE_INFINITY;

if (mod.getUserTaskChain().isActive() && _betterToolTimer.elapsed()) {
// Equip the right tool for the job if we're not using one.
_betterToolTimer.reset();
if (mod.getControllerExtras().isBreakingBlock()) {
BlockState state = mod.getWorld().getBlockState(mod.getControllerExtras().getBreakingBlockPos());
Optional<Slot> bestToolSlot = StorageHelper.getBestToolSlot(mod, state);
Slot currentEquipped = PlayerSlot.getEquipSlot();

// if baritone is running, only accept tools OUTSIDE OF HOTBAR!
// Baritone will take care of tools inside the hotbar.
if (bestToolSlot.isPresent() && !bestToolSlot.get().equals(currentEquipped)) {
// ONLY equip if the item class is STRICTLY different (otherwise we swap around a lot)
if (StorageHelper.getItemStackInSlot(currentEquipped).getItem() != StorageHelper.getItemStackInSlot(bestToolSlot.get()).getItem()) {
boolean isAllowedToManage = (!mod.getClientBaritone().getPathingBehavior().isPathing() ||
bestToolSlot.get().getInventorySlot() >= 9) && !mod.getFoodChain().isTryingToEat();
if (isAllowedToManage) {
Debug.logMessage("Found better tool in inventory, equipping.");
ItemStack bestToolItemStack = StorageHelper.getItemStackInSlot(bestToolSlot.get());
Item bestToolItem = bestToolItemStack.getItem();
mod.getSlotHandler().forceEquipItem(bestToolItem);
}
}
}
}
}
// if (mod.getUserTaskChain().isActive() && _betterToolTimer.elapsed()) {
// // Equip the right tool for the job if we're not using one.
// _betterToolTimer.reset();
// if (mod.getControllerExtras().isBreakingBlock()) {
// BlockState state = mod.getWorld().getBlockState(mod.getControllerExtras().getBreakingBlockPos());
// Optional<Slot> bestToolSlot = StorageHelper.getBestToolSlot(mod, state);
// Slot currentEquipped = PlayerSlot.getEquipSlot();
//
// // if baritone is running, only accept tools OUTSIDE OF HOTBAR!
// // Baritone will take care of tools inside the hotbar.
// if (bestToolSlot.isPresent() && !bestToolSlot.get().equals(currentEquipped)) {
// // ONLY equip if the item class is STRICTLY different (otherwise we swap around a lot)
// if (StorageHelper.getItemStackInSlot(currentEquipped).getItem() != StorageHelper.getItemStackInSlot(bestToolSlot.get()).getItem()) {
// boolean isAllowedToManage = (!mod.getClientBaritone().getPathingBehavior().isPathing() ||
// bestToolSlot.get().getInventorySlot() >= 9) && !mod.getFoodChain().isTryingToEat();
// if (isAllowedToManage) {
// Debug.logMessage("Found better tool in inventory, equipping.");
// ItemStack bestToolItemStack = StorageHelper.getItemStackInSlot(bestToolSlot.get());
// Item bestToolItem = bestToolItemStack.getItem();
// mod.getSlotHandler().forceEquipItem(bestToolItem);
// }
// }
// }
// }
// }

// Unpress shift (it gets stuck for some reason???)
if (mod.getInputControls().isHeldDown(Input.SNEAK)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package adris.altoclef.eventbus.events;

import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.client.util.math.MatrixStack;

public class ClientRenderEvent {
public MatrixStack stack;
public float tickDelta;
public RenderTickCounter tickDelta;

public ClientRenderEvent(MatrixStack stack, float tickDelta) {
public ClientRenderEvent(MatrixStack stack, RenderTickCounter tickDelta) {
this.stack = stack;
this.tickDelta = tickDelta;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/adris/altoclef/mixins/ClientUIMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import adris.altoclef.eventbus.events.ClientRenderEvent;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.render.RenderTickCounter;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -15,7 +16,7 @@ public final class ClientUIMixin {
method = "render",
at = @At("TAIL")
)
private void clientRender(DrawContext context, float tickDelta, CallbackInfo ci) {
private void clientRender(DrawContext context, RenderTickCounter tickDelta, CallbackInfo ci) {
EventBus.publish(new ClientRenderEvent(context.getMatrices(), tickDelta));
}
}
11 changes: 0 additions & 11 deletions src/main/java/adris/altoclef/mixins/EntityAccessor.java

This file was deleted.

Loading

0 comments on commit e45566e

Please sign in to comment.