Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ This fork aims to improve AltoClef by fixing a lot of bugs and optimizing some t

Because I rewrote a good portion of the `BeatMinecraftTask` a lot of the config settings don't work. Although I plan to implement configs in the future of course.

## 1.21.11 support (this fork)
This branch adds a working **1.21.11** target on top of the above, including a self-built Baritone with the AltoClef integration patches ported over, since no prebuilt Baritone exists for this version yet.

A few real bugs turned up (and got fixed) along the way, in case you're hitting any of these on older versions too:
- 2x2/crafting-table crafting could get stuck permanently trying to move an oversatisfied slot's contents with the wrong click, or silently skip a fillable slot when a wrong-item check was inverted.
- On a real (non-singleplayer) server, recipe lookups could come back empty and crash tasks that relied on them, since the recipe source used only ever works for hosting singleplayer/LAN.
- A `ConcurrentModificationException` could crash the mob-defense "force field" logic (and a few related entity-lookup calls) - the entity tracker was handing out direct references to its own live lists instead of safe snapshots.

Baritone for 1.21.11 isn't on the maven repo yet - the patches are up as their own PR against [baritone_altoclef](https://github.com/MiranCZ/baritone_altoclef) so it can get built and published the normal way. Until that's merged, build Baritone yourself from that branch, drop the jar in `versions/baritone/dist/`, and run with `-Paltoclef.development=true`:

```
./gradlew :1.21.11:build -Paltoclef.development=true
```

## The preprocessor
I am currently using the [replay mod preprocessor](https://github.com/ReplayMod/preprocessor) to keep the mod updated across multiple versions at the same time.

Expand Down
27 changes: 18 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ buildscript {

plugins {
id "maven-publish"
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'xyz.wagyourtail.jvmdowngrader' version '1.2.2'
id 'com.gradleup.shadow' version '9.5.1'
id 'xyz.wagyourtail.jvmdowngrader' version '1.3.6'
}

apply plugin: 'fabric-loom'
Expand All @@ -23,16 +23,18 @@ preprocess {
patternAnnotation.set("adris.altoclef.multiversion.Pattern")
}

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = sourceCompatibility


java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

tasks.withType(JavaCompile).configureEach {
options.release = 21
}

archivesBaseName = project.archives_base_name
base {
archivesName.set(project.archives_base_name)
}
version = "${project.name}-${project.mod_version}"
group = project.maven_group

Expand All @@ -49,6 +51,7 @@ def mappingsVersions = [
12006: "1.20.6+build.3",
12100: "1.21+build.9",
12101: "1.21.1+build.3",
12111: "1.21.11+build.6",
]

def fabricApiVersions = [
Expand All @@ -64,6 +67,7 @@ def fabricApiVersions = [
12006: "0.100.0+1.20.6",
12100: "0.100.7+1.21",
12101: "0.110.0+1.21.1",
12111: "0.141.4+1.21.11",
]

def getJavaVersion() {
Expand Down Expand Up @@ -124,7 +128,12 @@ dependencies {
shadow('com.fasterxml.jackson.core:jackson-databind:2.16.0')

// Thank you georgeagostino for fixing my garbage
if (getProject().hasProperty("altoclef.development")) {
// Per-version: use a locally-built dev jar from ../baritone/dist if one exists for this
// specific version (or "altoclef.development" forces it for every version, old behaviour),
// otherwise fetch the published artifact like normal. This way a version with no published
// Baritone yet (or no local jar) doesn't break every other version's build.
if (getProject().hasProperty("altoclef.development") ||
file("${project.projectDir}/../baritone/dist/baritone-unoptimized-fabric-${project.name}.jar").exists()) {
// Must run build from baritone-plus once
modImplementation "baritone-api-fabric:baritone-unoptimized-fabric-${project.name}"
include "baritone-api-fabric:baritone-unoptimized-fabric-${project.name}"
Expand All @@ -151,7 +160,7 @@ downgradeJar {

tasks.register('replaceJar') {
// do not downgrade java version if we do not need to
if (getJavaVersion() == targetCompatibility) {
if (getJavaVersion() == java.targetCompatibility) {
return
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx8192M
org.gradle.vfs.watch=true
kapt.use.worker.api=true
kapt.include.compile.classpath=false
org.gradle.parallel=true
org.gradle.parallel=false
org.gradle.caching=true
org.gradle.warning.mode=all

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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-9.6.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 6 additions & 1 deletion root.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("fabric-loom") version "1.7-SNAPSHOT" apply false
id("fabric-loom") version "1.14.10" apply false
id("com.replaymod.preprocess") version "c2041a3"
}

Expand All @@ -16,6 +16,10 @@ subprojects {
}

preprocess {
// See settings.gradle.kts - this node only exists once a local 1.21.11 Baritone jar has
// been built and dropped into versions/baritone/dist/.
val mc12111 = if (file("versions/baritone/dist/baritone-unoptimized-fabric-1.21.11.jar").exists())
createNode("1.21.11", 12111, "yarn") else null
val mc12101 = createNode("1.21.1", 12101, "yarn")
val mc12100 = createNode("1.21", 12100, "yarn")
val mc12006 = createNode("1.20.6", 12006, "yarn")
Expand All @@ -29,6 +33,7 @@ preprocess {
val mc11701 = createNode("1.17.1", 11701, "yarn")
val mc11605 = createNode("1.16.5", 11605, "yarn")

mc12111?.link(mc12101)
mc12101.link(mc12100)
mc12100.link(mc12006)
mc12006.link(mc12005)
Expand Down
13 changes: 11 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pluginManagement {
rootProject.name = "altoclef"
rootProject.buildFileName = "root.gradle.kts"

listOf(
val versions = mutableListOf(
"1.21.1",
"1.21",
"1.20.6",
Expand All @@ -33,7 +33,16 @@ listOf(
"1.18",
"1.17.1",
"1.16.5"
).forEach { version ->
)

// 1.21.11's Baritone isn't published yet, so only wire in that target once you've built it
// yourself and dropped the jar in versions/baritone/dist/ - see the README. Without it, this
// project simply doesn't exist and every other version builds exactly as it did before.
if (file("versions/baritone/dist/baritone-unoptimized-fabric-1.21.11.jar").exists()) {
versions.add(0, "1.21.11")
}

versions.forEach { version ->
include(":$version")
project(":$version").apply {
projectDir = file("versions/$version")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public float getPriority() {
lastMLG = null;
}
if (mod.getPlayer().hasStatusEffect(StatusEffects.LEVITATION) &&
!mod.getPlayer().getItemCooldownManager().isCoolingDown(Items.CHORUS_FRUIT) &&
!adris.altoclef.util.helpers.ItemHelper.isCoolingDown(mod.getPlayer(), Items.CHORUS_FRUIT) &&
mod.getPlayer().getActiveStatusEffects().get(StatusEffects.LEVITATION).getDuration() <= 70 &&
mod.getItemStorage().hasItemInventoryOnly(Items.CHORUS_FRUIT) &&
!mod.getItemStorage().hasItemInventoryOnly(Items.WATER_BUCKET)) {
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/adris/altoclef/chains/MobDefenseChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import adris.altoclef.AltoClef;
import adris.altoclef.Debug;
import adris.altoclef.control.KillAura;
import adris.altoclef.multiversion.ToolMaterialVer;
import adris.altoclef.multiversion.versionedfields.Entities;
import adris.altoclef.multiversion.item.ItemVer;
import adris.altoclef.tasks.construction.ProjectileProtectionWallTask;
Expand Down Expand Up @@ -34,7 +35,6 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.SwordItem;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
Expand Down Expand Up @@ -109,7 +109,7 @@ private static int getDangerousnessScore(List<LivingEntity> toDealWithList) {
if (toDealWith instanceof EndermanEntity || toDealWith instanceof SlimeEntity || toDealWith instanceof BlazeEntity) {

numberOfProblematicEntities += 1;
} else if (toDealWith instanceof DrownedEntity && toDealWith.getEquippedItems() == Items.TRIDENT) {
} else if (toDealWith instanceof DrownedEntity && toDealWith.getMainHandStack().getItem() == Items.TRIDENT) {
// Drowned with tridents are also REALLY dangerous, maybe we should increase this??
numberOfProblematicEntities += 5;
}
Expand Down Expand Up @@ -192,14 +192,14 @@ private float getPriorityInner() {

doingFunkyStuff = false;
PlayerSlot offhandSlot = PlayerSlot.OFFHAND_SLOT;
Item offhandItem = StorageHelper.getItemStackInSlot(offhandSlot).getItem();
ItemStack offhandItem = StorageHelper.getItemStackInSlot(offhandSlot);
// Run away from creepers
CreeperEntity blowingUp = getClosestFusingCreeper(mod);
if (blowingUp != null) {
if ((!mod.getFoodChain().needsToEat() || mod.getPlayer().getHealth() < 9)
&& hasShield(mod)
&& !mod.getEntityTracker().entityFound(PotionEntity.class)
&& !mod.getPlayer().getItemCooldownManager().isCoolingDown(offhandItem)
&& !adris.altoclef.util.helpers.ItemHelper.isCoolingDown(mod.getPlayer(), offhandItem)
&& mod.getClientBaritone().getPathingBehavior().isSafeToCancel()
&& blowingUp.getClientFuseTime(blowingUp.getFuseSpeed()) > 0.5) {
LookHelper.lookAt(mod, blowingUp.getEyePos());
Expand All @@ -220,7 +220,7 @@ && hasShield(mod)
// Block projectiles with shield
if (mod.getModSettings().isDodgeProjectiles()
&& hasShield(mod)
&& !mod.getPlayer().getItemCooldownManager().isCoolingDown(offhandItem)
&& !adris.altoclef.util.helpers.ItemHelper.isCoolingDown(mod.getPlayer(), offhandItem)
&& mod.getClientBaritone().getPathingBehavior().isSafeToCancel()
&& !mod.getEntityTracker().entityFound(PotionEntity.class) && isProjectileClose(mod)) {
ItemStack shieldSlot = StorageHelper.getItemStackInSlot(PlayerSlot.OFFHAND_SLOT);
Expand Down Expand Up @@ -319,10 +319,10 @@ && hasShield(mod)
if (!toDealWithList.isEmpty()) {

// Depending on our weapons/armor, we may choose to straight up kill hostiles if we're not dodging their arrows.
SwordItem bestSword = getBestSword(mod);
Item bestSword = getBestSword(mod);

int armor = mod.getPlayer().getArmor();
float damage = bestSword == null ? 0 : (bestSword.getMaterial().getAttackDamage()) + 1;
float damage = bestSword == null ? 0 : (ToolMaterialVer.getMiningLevel(bestSword)) + 1;

int shield = hasShield(mod) && bestSword != null ? 3 : 0;

Expand Down Expand Up @@ -373,14 +373,14 @@ private static boolean hasShield(AltoClef mod) {
return mod.getItemStorage().hasItem(Items.SHIELD) || mod.getItemStorage().hasItemInOffhand(Items.SHIELD);
}

private static SwordItem getBestSword(AltoClef mod) {
private static Item getBestSword(AltoClef mod) {
Item[] SWORDS = new Item[]{Items.NETHERITE_SWORD, Items.DIAMOND_SWORD, Items.IRON_SWORD, Items.GOLDEN_SWORD,
Items.STONE_SWORD, Items.WOODEN_SWORD};

SwordItem bestSword = null;
Item bestSword = null;
for (Item item : SWORDS) {
if (mod.getItemStorage().hasItem(item)) {
bestSword = (SwordItem) item;
bestSword = item;
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public float getPriority() {

// Extinguish with water
if (mod.getModSettings().shouldExtinguishSelfWithWater()) {
if (!(mainTask instanceof EscapeFromLavaTask && isCurrentlyRunning(mod)) && mod.getPlayer().isOnFire() && !mod.getPlayer().hasStatusEffect(StatusEffects.FIRE_RESISTANCE) && !mod.getWorld().getDimension().ultrawarm()) {
if (!(mainTask instanceof EscapeFromLavaTask && isCurrentlyRunning(mod)) && mod.getPlayer().isOnFire() && !mod.getPlayer().hasStatusEffect(StatusEffects.FIRE_RESISTANCE) && mod.getWorld().getRegistryKey() != net.minecraft.world.World.NETHER) {
// Extinguish ourselves
if (mod.getItemStorage().hasItem(Items.WATER_BUCKET)) {
BlockPos targetWaterPos = mod.getPlayer().getBlockPos();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/adris/altoclef/commands/DepositCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import adris.altoclef.util.ItemTarget;
import adris.altoclef.util.helpers.StorageHelper;
import adris.altoclef.util.slots.PlayerSlot;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ToolItem;
import org.apache.commons.lang3.ArrayUtils;

import java.util.List;
Expand All @@ -32,7 +32,7 @@ public static ItemTarget[] getAllNonEquippedOrToolItemsAsTarget(AltoClef mod) {
// Ignore tools
if (!stack.isEmpty()) {
Item item = stack.getItem();
return !(item instanceof ToolItem);
return !item.getComponents().contains(DataComponentTypes.TOOL);
}
return false;
});
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/adris/altoclef/commands/EquipCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import adris.altoclef.tasks.misc.EquipArmorTask;
import adris.altoclef.util.ItemTarget;
import adris.altoclef.util.helpers.ItemHelper;
import net.minecraft.item.Equipment;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.Item;

import java.util.Arrays;
Expand All @@ -36,7 +36,7 @@ protected void call(AltoClef mod, ArgParser parser) throws CommandException {

for (ItemTarget target : items) {
for (Item item : target.getMatches()) {
if (!(item instanceof Equipment)) {
if (!ItemHelper.isEquippable(item)) {
throw new RuntimeCommandException("'"+item.toString().toUpperCase() + "' cannot be equipped!");
}
}
Expand Down Expand Up @@ -84,7 +84,7 @@ public Stream<String> getSuggestions(StringReader reader) {
}

private static boolean isEquipment(String cataloguedItem) {
return Arrays.stream(new ItemTarget(cataloguedItem).getMatches()).anyMatch(i -> i instanceof Equipment);
return Arrays.stream(new ItemTarget(cataloguedItem).getMatches()).anyMatch(ItemHelper::isEquippable);
}
}

Expand Down
16 changes: 9 additions & 7 deletions src/main/java/adris/altoclef/control/KillAura.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package adris.altoclef.control;

import adris.altoclef.AltoClef;
import adris.altoclef.multiversion.ToolMaterialVer;
import adris.altoclef.multiversion.versionedfields.Entities;
import adris.altoclef.multiversion.item.ItemVer;
import adris.altoclef.util.helpers.LookHelper;
Expand All @@ -20,7 +21,7 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.SwordItem;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.util.math.Vec3d;

Expand All @@ -44,11 +45,12 @@ public static void equipWeapon(AltoClef mod) {
if (!invStacks.isEmpty()) {
float handDamage = Float.NEGATIVE_INFINITY;
for (ItemStack invStack : invStacks) {
if (invStack.getItem() instanceof SwordItem item) {
float itemDamage = item.getMaterial().getAttackDamage();
if (invStack.isIn(ItemTags.SWORDS)) {
Item item = invStack.getItem();
float itemDamage = ToolMaterialVer.getMiningLevel(item);
Item handItem = StorageHelper.getItemStackInSlot(PlayerSlot.getEquipSlot()).getItem();
if (handItem instanceof SwordItem handToolItem) {
handDamage = handToolItem.getMaterial().getAttackDamage();
if (handItem.getDefaultStack().isIn(ItemTags.SWORDS)) {
handDamage = ToolMaterialVer.getMiningLevel(handItem);
}
if (itemDamage > handDamage) {
mod.getSlotHandler().forceEquipItem(item);
Expand Down Expand Up @@ -85,12 +87,12 @@ public void tickEnd(AltoClef mod) {
!mod.getMLGBucketChain().isFalling(mod) && mod.getMLGBucketChain().doneMLG() &&
!mod.getMLGBucketChain().isChorusFruiting()) {
PlayerSlot offhandSlot = PlayerSlot.OFFHAND_SLOT;
Item offhandItem = StorageHelper.getItemStackInSlot(offhandSlot).getItem();
ItemStack offhandItem = StorageHelper.getItemStackInSlot(offhandSlot);
if (entities.get().getClass() != CreeperEntity.class && entities.get().getClass() != HoglinEntity.class &&
entities.get().getClass() != ZoglinEntity.class && entities.get().getClass() != Entities.WARDEN &&
entities.get().getClass() != WitherEntity.class
&& (mod.getItemStorage().hasItem(Items.SHIELD) || mod.getItemStorage().hasItemInOffhand(Items.SHIELD))
&& !mod.getPlayer().getItemCooldownManager().isCoolingDown(offhandItem)
&& !adris.altoclef.util.helpers.ItemHelper.isCoolingDown(mod.getPlayer(), offhandItem)
&& mod.getClientBaritone().getPathingBehavior().isSafeToCancel()) {
LookHelper.lookAt(mod, entities.get().getEyePos());
ItemStack shieldSlot = StorageHelper.getItemStackInSlot(PlayerSlot.OFFHAND_SLOT);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/adris/altoclef/control/SlotHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import adris.altoclef.util.time.TimerGame;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.*;
import net.minecraft.screen.slot.SlotActionType;

Expand Down Expand Up @@ -124,7 +125,7 @@ public boolean forceEquipItem(Item toEquip) {
}

public boolean forceDeequipHitTool() {
return forceDeequip(stack -> stack.getItem() instanceof ToolItem);
return forceDeequip(stack -> stack.getItem().getComponents().contains(DataComponentTypes.TOOL));
}

public void forceDeequipRightClickableItem() {
Expand All @@ -148,7 +149,7 @@ public void forceDeequipRightClickableItem() {
|| item instanceof OnAStickItem
|| item == Items.COMPASS
|| item instanceof EmptyMapItem
|| item instanceof Equipment
|| ItemHelper.isEquippable(item)
|| item == Items.LEAD
|| item == Items.SHIELD;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void onBlockBroken(World world, BlockPos pos, BlockState state, PlayerEnt
//#else
//$$ public void onBlockBroken(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfo ci) {
//#endif
if (player.getWorld() == world) {
if (player.getEntityWorld() == world) {
BlockBrokenEvent evt = new BlockBrokenEvent();
evt.blockPos = pos;
evt.blockState = state;
Expand Down
Loading