Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Finished update to 1.18.2 (#258)
Browse files Browse the repository at this point in the history
* Half way upgraded to 1.18.2 

* Updated AltoClef to 1.18.2

* cleaned up 1.18.2 update

Signed-off-by: James Green <[email protected]>

* cleaned it up with s p a c e
  • Loading branch information
JamesGreen31 authored Apr 16, 2022
1 parent dcded3e commit 0a61ade
Show file tree
Hide file tree
Showing 19 changed files with 69 additions and 39 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ dependencies {
// 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.18'
modImplementation 'baritone-api-fabric:baritone-unoptimized-fabric:1.18.2'
} else {
modImplementation "cabaletta:baritone-unoptimized-fabric:1.18"
include "cabaletta:baritone-unoptimized-fabric:1.18"
modImplementation "cabaletta:baritone-unoptimized-fabric:1.18.2"
include "cabaletta:baritone-unoptimized-fabric:1.18.2"
}
//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.18.1
yarn_mappings=1.18.1+build.22
loader_version=0.12.12
minecraft_version=1.18.2
yarn_mappings=1.18.2+build.3
loader_version=0.13.3
# Mod Properties
mod_version=0.4.0
maven_group=gaucho-matrero.altoclef
archives_base_name=altoclef
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.46.2+1.18
fabric_version=0.50.0+1.18.2
18 changes: 9 additions & 9 deletions src/main/java/adris/altoclef/control/InputControls.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public class InputControls {
private static KeyBinding inputToKeyBinding(Input input) {
GameOptions o = MinecraftClient.getInstance().options;
return switch (input) {
case MOVE_FORWARD -> o.keyForward;
case MOVE_BACK -> o.keyBack;
case MOVE_LEFT -> o.keyLeft;
case MOVE_RIGHT -> o.keyRight;
case CLICK_LEFT -> o.keyAttack;
case CLICK_RIGHT -> o.keyUse;
case JUMP -> o.keyJump;
case SNEAK -> o.keySneak;
case SPRINT -> o.keySprint;
case MOVE_FORWARD -> o.forwardKey;
case MOVE_BACK -> o.backKey;
case MOVE_LEFT -> o.leftKey;
case MOVE_RIGHT -> o.rightKey;
case CLICK_LEFT -> o.attackKey;
case CLICK_RIGHT -> o.useKey;
case JUMP -> o.jumpKey;
case SNEAK -> o.sneakKey;
case SPRINT -> o.sprintKey;
default -> throw new IllegalArgumentException("Invalid key input/not accounted for: " + input);
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/adris/altoclef/tasks/ResourceTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected Task onTick(AltoClef mod) {
if (_currentContainer == null) {
List<ContainerCache> containersWithItem = mod.getItemStorage().getContainersWithItem(Arrays.stream(_itemTargets).reduce(new Item[0], (items, target) -> ArrayUtils.addAll(items, target.getMatches()), ArrayUtils::addAll));
if (!containersWithItem.isEmpty()) {
ContainerCache closest = containersWithItem.stream().min(StlHelper.compareValues(container -> container.getBlockPos().getSquaredDistance(mod.getPlayer().getPos(), true))).get();
ContainerCache closest = containersWithItem.stream().min(StlHelper.compareValues(container -> container.getBlockPos().getSquaredDistance(mod.getPlayer().getPos()))).get();
if (closest.getBlockPos().isWithinDistance(mod.getPlayer().getPos(), mod.getModSettings().getResourceChestLocateRange())) {
_currentContainer = closest;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private BlockPos locateClosePlacePos(AltoClef mod) {
continue;
}
boolean hasBelow = WorldHelper.isSolid(mod, blockPos.down());
double distSq = blockPos.getSquaredDistance(mod.getPlayer().getPos(), false);
double distSq = blockPos.getSquaredDistance(mod.getPlayer().getPos());

double score = distSq + (solid ? 4 : 0) + (hasBelow ? 0 : 10) + (inside ? 3 : 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private Task editSign(AltoClef mod) {
screen.charTyped(c, -1);
//screen.keyPressed(keyCode, -1, )
}
screen.onClose();
screen.close();
_finished = true;

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ protected Task onTick(AltoClef mod) {
_wasSleeping = true;
//Debug.logMessage("Closing sleeping thing");
_spawnSet = true;
screen.onClose();
screen.close(); // may be chat empty ??
return null;
}

Expand Down Expand Up @@ -354,7 +354,7 @@ private BlockPos locateBedRegion(AltoClef mod, BlockPos origin) {
for (int dy = origin.getY() - SCAN_RANGE; dy < origin.getY() + SCAN_RANGE; ++dy) {
// Test range
BlockPos attemptStandPos = new BlockPos(dx, dy, dz);
double distance = attemptStandPos.getSquaredDistance(mod.getPlayer().getPos(), false);
double distance = attemptStandPos.getSquaredDistance(mod.getPlayer().getPos());
if (distance > closestDist) continue;
// Everything from here on out is checking for a BETTER pos.
for (int checkX = 0; checkX < BED_CLEAR_SIZE.getX(); ++checkX) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.item.Items;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeKeys;

import java.util.List;

Expand Down Expand Up @@ -71,7 +72,7 @@ protected Task onTick(AltoClef mod) {
setDebugState("Looting found temple");
return _lootTask;
}
return new SearchWithinBiomeTask(Biome.Category.DESERT);
return new SearchWithinBiomeTask(BiomeKeys.DESERT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeKeys;

public class LocateDesertTempleTask extends Task {

Expand All @@ -27,7 +28,7 @@ protected Task onTick(AltoClef mod) {
setDebugState("Going to found desert temple");
return new GetToBlockTask(_finalPos, false);
}
return new SearchWithinBiomeTask(Biome.Category.DESERT);
return new SearchWithinBiomeTask(BiomeKeys.DESERT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@

import adris.altoclef.AltoClef;
import adris.altoclef.tasksystem.Task;
import net.minecraft.tag.BiomeTags;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeKeys;

/**
* Explores/Loads all chunks of a biome.
*/
public class SearchWithinBiomeTask extends SearchChunksExploreTask {

private final Biome.Category _toSearch;
private final RegistryKey<Biome> _toSearch;

public SearchWithinBiomeTask(Biome.Category toSearch) {
public SearchWithinBiomeTask(RegistryKey<Biome> toSearch) {
_toSearch = toSearch;
}

@Override
protected boolean isChunkWithinSearchSpace(AltoClef mod, ChunkPos pos) {
Biome b = mod.getWorld().getBiome(pos.getStartPos().add(1, 1, 1));
return b.getCategory() == _toSearch;
RegistryEntry<Biome> b = mod.getWorld().getBiome(pos.getStartPos().add(1, 1, 1));
return b.matchesKey(_toSearch);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected Task onResourceTick(AltoClef mod) {
if (sqDistanceToPlayer > SPAWNER_BLAZE_RADIUS * SPAWNER_BLAZE_RADIUS) {
// If the blaze can see us it needs to go lol
BlockHitResult hit = mod.getWorld().raycast(new RaycastContext(mod.getPlayer().getCameraPosVec(1.0F), kill.getCameraPosVec(1.0F), RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.NONE, mod.getPlayer()));
if (hit != null && hit.getBlockPos().getSquaredDistance(mod.getPlayer().getPos(), false) < sqDistanceToPlayer) {
if (hit != null && hit.getBlockPos().getSquaredDistance(mod.getPlayer().getPos()) < sqDistanceToPlayer) {
toKill = Optional.empty();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.item.Items;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeKeys;

import java.util.HashSet;
import java.util.function.Predicate;
Expand Down Expand Up @@ -66,7 +67,7 @@ protected Task onResourceTick(AltoClef mod) {

// Search for jungles
setDebugState("Exploring around jungles");
return new SearchWithinBiomeTask(Biome.Category.JUNGLE);
return new SearchWithinBiomeTask(BiomeKeys.JUNGLE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected Task onResourceTick(AltoClef mod) {
assert !_emptyCropland.isEmpty();
return new DoToClosestBlockTask(
blockPos -> new InteractWithBlockTask(new ItemTarget(_cropSeed, 1), Direction.UP, blockPos.down(), true),
pos -> _emptyCropland.stream().min(StlHelper.compareValues(block -> block.getSquaredDistance(pos, false))),
pos -> _emptyCropland.stream().min(StlHelper.compareValues(block -> block.getSquaredDistance(pos))),
_emptyCropland::contains,
Blocks.FARMLAND); // Blocks.FARMLAND is useless to be put here
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ protected Optional<Object> getClosestTo(AltoClef mod, Vec3d pos) {
closestDrop = mod.getEntityTracker().getClosestItemDrop(pos, _targets);
}

double blockSq = closestBlock.isEmpty() ? Double.POSITIVE_INFINITY : closestBlock.get().getSquaredDistance(pos, true);
double blockSq = closestBlock.isEmpty() ? Double.POSITIVE_INFINITY : closestBlock.get().getSquaredDistance(pos);
double dropSq = closestDrop.isEmpty() ? Double.POSITIVE_INFINITY : closestDrop.get().squaredDistanceTo(pos) + 5; // + 5 to make the bot stop mining a bit less

// We can't mine right now.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ protected Task onTick(AltoClef mod) {
// We have sort of a rounded circle here.
if (Math.abs(dx) == 2 && Math.abs(dz) == 2) continue;
BlockPos toCheck = _exitPortalTop.add(dx, bottomYDelta, dz);
double distSq = toCheck.getSquaredDistance(head.getPos(), false);
double distSq = toCheck.getSquaredDistance(head.getPos());
if (distSq < closestDist) {
closest = toCheck;
closestDist = distSq;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/adris/altoclef/trackers/BlockTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public Optional<BlockPos> getNearestWithinRange(Vec3d pos, double range, Block..
}
if (!valid) continue;
if (check.isWithinDistance(pos, range)) {
double sq = check.getSquaredDistance(pos, false);
double sq = check.getSquaredDistance(pos);
if (sq < closestDistance) {
closestDistance = sq;
nearest = check;
Expand Down Expand Up @@ -649,7 +649,7 @@ public void smartPurge(AltoClef mod, Vec3d playerPos) {
// This is invalid, because some blocks we may want to GO TO not BREAK.
//.filter(pos -> !mod.getExtraBaritoneSettings().shouldAvoidBreaking(pos))
.distinct()
.sorted(StlHelper.compareValues((BlockPos blockpos) -> blockpos.getSquaredDistance(playerPos, true)))
.sorted(StlHelper.compareValues((BlockPos blockpos) -> blockpos.getSquaredDistance(playerPos)))
.collect(Collectors.toList());
tracking = tracking.stream()
.limit(_config.maxCacheSizePerBlockType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public Optional<ContainerCache> getClosestTo(Vec3d pos, Predicate<ContainerCache
toRemove.add(cache.getBlockPos());
continue;
}
double dist = cache.getBlockPos().getSquaredDistance(pos, true);
double dist = cache.getBlockPos().getSquaredDistance(pos);
if (dist < bestDist) {
if (accept.test(cache)) {
bestDist = dist;
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/adris/altoclef/util/helpers/ItemHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
import adris.altoclef.util.WoodType;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.LeavesBlock;
import net.minecraft.block.MapColor;
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.tag.BlockTags;
import net.minecraft.tag.TagKey;
import net.minecraft.util.DyeColor;

import net.minecraft.util.registry.Registry;
import java.util.*;

/**
Expand Down Expand Up @@ -275,7 +277,9 @@ public static String trimItemName(String name) {

public static boolean areShearsEffective(Block b) {
return
BlockTags.LEAVES.contains(b)
//b.getRegistryEntry().streamTags().anyMatch(t -> t ==
// BlockTags.LEAVES); should also work... but is slower
b instanceof LeavesBlock
|| b == Blocks.COBWEB
|| b == Blocks.GRASS
|| b == Blocks.TALL_GRASS
Expand All @@ -284,10 +288,14 @@ public static boolean areShearsEffective(Block b) {
|| b == Blocks.DEAD_BUSH
|| b ==Blocks.VINE
|| b == Blocks.TRIPWIRE
|| BlockTags.WOOL.contains(b)
|| isOfBlockType(b, BlockTags.WOOL)
|| b == Blocks.NETHER_SPROUTS;
}

public static boolean isOfBlockType(Block b, TagKey<Block> tag) {
return Registry.BLOCK.getKey(b).map(e -> Registry.BLOCK.entryOf(e).streamTags().anyMatch(t -> t == tag)).orElse(false);
}

public static class ColorfulItems {
public DyeColor color;
public String colorName;
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/adris/altoclef/util/helpers/WorldHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import net.minecraft.entity.Entity;
import net.minecraft.network.ClientConnection;
import net.minecraft.util.math.*;
import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeKeys;

import java.util.*;

Expand Down Expand Up @@ -246,7 +248,7 @@ static boolean canReach(AltoClef mod, BlockPos pos) {
if (mod.getModSettings().shouldAvoidOcean()) {
// 45 is roughly the ocean floor. We add 2 just cause why not.
// This > 47 can clearly cause a stuck bug.
if (mod.getPlayer().getY() > 47 && mod.getChunkTracker().isChunkLoaded(pos) && mod.getWorld().getBiome(pos).getCategory().equals(Biome.Category.OCEAN)) {
if (mod.getPlayer().getY() > 47 && mod.getChunkTracker().isChunkLoaded(pos) && isOcean(mod.getWorld().getBiome(pos))) { // But if we stuck, add more oceans
// Block is in an ocean biome. If it's below sea level...
if (pos.getY() < 64 && getGroundHeight(mod, pos.getX(), pos.getZ(), Blocks.WATER) > pos.getY()) {
return false;
Expand All @@ -256,6 +258,18 @@ static boolean canReach(AltoClef mod, BlockPos pos) {
return !mod.getBlockTracker().unreachable(pos);
}

static boolean isOcean(RegistryEntry<Biome> b){
return (b.matchesKey(BiomeKeys.OCEAN)
|| b.matchesKey(BiomeKeys.COLD_OCEAN)
|| b.matchesKey(BiomeKeys.DEEP_COLD_OCEAN)
|| b.matchesKey(BiomeKeys.DEEP_OCEAN)
|| b.matchesKey(BiomeKeys.DEEP_FROZEN_OCEAN)
|| b.matchesKey(BiomeKeys.DEEP_LUKEWARM_OCEAN)
|| b.matchesKey(BiomeKeys.LUKEWARM_OCEAN)
|| b.matchesKey(BiomeKeys.WARM_OCEAN)
|| b.matchesKey(BiomeKeys.FROZEN_OCEAN));
}

static boolean isAir(AltoClef mod, BlockPos pos) {
return mod.getBlockTracker().blockIsValid(pos, Blocks.AIR, Blocks.CAVE_AIR, Blocks.VOID_AIR);
//return state.isAir() || isAir(state.getBlock());
Expand Down

0 comments on commit 0a61ade

Please sign in to comment.