Skip to content

Commit

Permalink
Added a fishing rod rater. Fixes #37
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Zangl committed Dec 8, 2015
1 parent 60d0e69 commit 0d0047f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import net.famzangl.minecraft.minebot.ai.AIHelper;
import net.famzangl.minecraft.minebot.ai.ClassItemFilter;
import net.famzangl.minecraft.minebot.ai.tools.ToolRater;
import net.famzangl.minecraft.minebot.settings.MinebotSettings;
import net.minecraft.item.ItemFishingRod;

public class ThrowFishingRodTask extends AITask {
Expand All @@ -31,7 +33,8 @@ public boolean isFinished(AIHelper h) {

@Override
public void runTick(AIHelper h, TaskOperations o) {
if (h.selectCurrentItem(new ClassItemFilter(ItemFishingRod.class))) {
ToolRater settings = MinebotSettings.getSettings().getFishingRater();
if (h.selectToolFor(null, new ToolRater(ToolRater.ToolType.FISHING_ROD)) > 0) {
time--;
if (time == 2) {
h.overrideUseItem();
Expand All @@ -41,7 +44,7 @@ public void runTick(AIHelper h, TaskOperations o) {

@Override
public int getGameTickTimeout(AIHelper helper) {
return 950;
return 40;
}

}
11 changes: 11 additions & 0 deletions Minebot/src/net/famzangl/minecraft/minebot/ai/tools/ToolRater.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.famzangl.minecraft.minebot.ai.ItemFilter.NotItemFilter;
import net.famzangl.minecraft.minebot.ai.path.world.BlockFloatMap;
import net.famzangl.minecraft.minebot.ai.path.world.BlockSet;
import net.famzangl.minecraft.minebot.ai.tools.ToolRater.ToolType;
import net.famzangl.minecraft.minebot.ai.tools.rate.AndRater;
import net.famzangl.minecraft.minebot.ai.tools.rate.EnchantmentRater;
import net.famzangl.minecraft.minebot.ai.tools.rate.FilterRater;
Expand Down Expand Up @@ -181,6 +182,16 @@ public String getName() {
}
}

public ToolRater() {
}

public ToolRater(ToolType requiredToolType) {
BlockFloatMap allBad = new BlockFloatMap();
allBad.setDefault(0);
raters.add(new NotRater(allBad, new FilterRater(requiredToolType,
requiredToolType.getName(), allBad)));
}

private static Rater getCompoundRater(String name, BlockFloatMap values) {
// todo: advanced boolean parsing, parentheses, ...
String[] orPartStrings = name.split("\\s*\\|\\s*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected double getPow(ItemStack item, int forBlockAndMeta) {

public float rate(ItemStack item, int forBlockAndMeta) {
if (isAppleciable(item, forBlockAndMeta)) {
return values.get(forBlockAndMeta);
return forBlockAndMeta < 0 ? values.getDefaultValue() : values.get(forBlockAndMeta);
} else {
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.famzangl.minecraft.minebot.settings;

import net.famzangl.minecraft.minebot.ai.tools.ToolRater;
import net.famzangl.minecraft.minebot.ai.tools.ToolRater.ToolType;

/**
* This is the root object for our json settings file.
Expand All @@ -17,6 +18,8 @@ public class MinebotSettingsRoot {
private MiningSettings mining = new MiningSettings();

private ToolRater toolRater = ToolRater.createDefaultRater();

private ToolRater fishingRater = new ToolRater(ToolType.FISHING_ROD);

public PathfindingSettings getPathfinding() {
return pathfinding;
Expand All @@ -29,4 +32,8 @@ public MiningSettings getMining() {
public ToolRater getToolRater() {
return toolRater ;
}

public ToolRater getFishingRater() {
return fishingRater;
}
}

0 comments on commit 0d0047f

Please sign in to comment.