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

Commit

Permalink
Replace allowShears with "forceTool", which is far more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
TacoTechnica committed Oct 14, 2021
1 parent fc01be2 commit ddf582f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import adris.altoclef.tasksystem.Task;
import adris.altoclef.util.ItemTarget;
import adris.altoclef.util.MiningRequirement;
import adris.altoclef.util.helpers.ItemHelper;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
Expand All @@ -26,7 +27,9 @@ public ShearAndCollectBlockTask(Item item, int count, Block... blocksToMine) {
@Override
protected void onStart(AltoClef mod) {
mod.getBehaviour().push();
mod.getBehaviour().allowShears(true);
mod.getBehaviour().forceUseTool((blockState, itemStack) ->
itemStack.getItem() == Items.SHEARS && ItemHelper.areShearsEffective(blockState.getBlock())
);
super.onStart(mod);
}

Expand Down
20 changes: 12 additions & 8 deletions src/main/java/adris/altoclef/util/control/BotBehaviour.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import baritone.altoclef.AltoClefSettings;
import baritone.api.Settings;
import baritone.api.utils.RayTraceUtils;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.RaycastContext;

import java.util.*;
import java.util.function.BiPredicate;
import java.util.function.Predicate;

/**
Expand Down Expand Up @@ -89,6 +92,11 @@ public void allowWalkingOn(Predicate<BlockPos> pred) {
current().applyState();
}

public void forceUseTool(BiPredicate<BlockState, ItemStack> pred) {
current().forceUseTools.add(pred);
current().applyState();
}

public void setRayTracingFluidHandling(RaycastContext.FluidHandling fluidHandling) {
current().rayFluidHandling = fluidHandling;
//Debug.logMessage("OOF: " + fluidHandling);
Expand Down Expand Up @@ -158,11 +166,6 @@ public boolean shouldAvoidDodgingProjectile(Entity entity) {
return false;
}

public void allowShears(boolean allow) {
current().allowShears = allow;
current().applyState();
}

/// Stack management
public void push() {
if (_states.isEmpty()) {
Expand Down Expand Up @@ -221,8 +224,8 @@ class State {
public List<Predicate<BlockPos>> toAvoidBreaking = new ArrayList<>();
public List<Predicate<BlockPos>> toAvoidPlacing = new ArrayList<>();
public List<Predicate<BlockPos>> allowWalking = new ArrayList<>();
public List<BiPredicate<BlockState, ItemStack>> forceUseTools = new ArrayList<>();
public boolean _allowWalkThroughFlowingWater = false;
public boolean allowShears;

// Minecraft config
public boolean pauseOnLostFocus = true;
Expand Down Expand Up @@ -280,11 +283,11 @@ private void readExtraState(AltoClefSettings settings) {
protectedItems = new ArrayList<>(settings.getProtectedItems());
synchronized (settings.getPropertiesMutex()) {
allowWalking = new ArrayList<>(settings.getForceWalkOnPredicates());
forceUseTools = new ArrayList<>(settings.getForceUseToolPredicates());
}
}
}
_allowWalkThroughFlowingWater = settings.isFlowingWaterPassAllowed();
allowShears = settings.areShearsAllowed();

rayFluidHandling = RayTraceUtils.fluidHandling;
}
Expand Down Expand Up @@ -321,12 +324,13 @@ private void applyState(Settings s, AltoClefSettings sa) {
synchronized (sa.getPropertiesMutex()) {
sa.getForceWalkOnPredicates().clear();
sa.getForceWalkOnPredicates().addAll(allowWalking);
sa.getForceUseToolPredicates().clear();
sa.getForceUseToolPredicates().addAll(forceUseTools);
}
}
}

sa.setFlowingWaterPass(_allowWalkThroughFlowingWater);
sa.allowShears(allowShears);
sa.allowSwimThroughLava(swimThroughLava);

// Extra / hard coded
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/adris/altoclef/util/helpers/ItemHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.tag.BlockTags;
import net.minecraft.util.DyeColor;

import java.util.ArrayList;
Expand Down Expand Up @@ -73,7 +74,7 @@ static Block[] itemsToBlocks(Item[] items) {

Block[] WOOD_SIGNS_ALL = new Block[]{Blocks.ACACIA_SIGN, Blocks.BIRCH_SIGN, Blocks.DARK_OAK_SIGN, Blocks.OAK_SIGN, Blocks.JUNGLE_SIGN, Blocks.SPRUCE_SIGN, Blocks.ACACIA_WALL_SIGN, Blocks.BIRCH_WALL_SIGN, Blocks.DARK_OAK_WALL_SIGN, Blocks.OAK_WALL_SIGN, Blocks.JUNGLE_WALL_SIGN, Blocks.SPRUCE_WALL_SIGN};

Map<Item, Item> _logToPlanks = new HashMap<Item, Item>() {
Map<Item, Item> _logToPlanks = new HashMap<>() {
{
put(Items.ACACIA_LOG, Items.ACACIA_PLANKS);
put(Items.BIRCH_LOG, Items.BIRCH_PLANKS);
Expand Down Expand Up @@ -196,6 +197,10 @@ static String trimItemName(String name) {
return name;
}

static boolean areShearsEffective(Block b) {
return BlockTags.LEAVES.contains(b) || b == Blocks.COBWEB || b == Blocks.GRASS || b == Blocks.TALL_GRASS || b == Blocks.LILY_PAD || b == Blocks.FERN || b == Blocks.DEAD_BUSH || b ==Blocks.VINE || b == Blocks.TRIPWIRE || BlockTags.WOOL.contains(b);
}

class ColorfulItems {
public DyeColor color;
public String colorName;
Expand Down

0 comments on commit ddf582f

Please sign in to comment.