Skip to content

Commit

Permalink
Fixed tint strategy and added shear command
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Zangl committed Aug 9, 2014
1 parent 04b4103 commit 4073f4c
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public class ColoredBlockItemFilter extends BlockItemFilter {
Blocks.stained_glass_pane, Blocks.carpet };
private final int colorMeta;

/**
* Right names for sheep wool and most blocks.
* <p>
* (15 - color) for dyes
*/
public static final String[] COLORS = new String[] { "White", "Orange",
"Magenta", "LightBlue", "Yellow", "Lime", "Pink", "Gray",
"LightGray", "Cyan", "Purple", "Blue", "Brown", "Green", "Red",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.famzangl.minecraft.minebot.ai.commands.CommandMine;
import net.famzangl.minecraft.minebot.ai.commands.CommandPlant;
import net.famzangl.minecraft.minebot.ai.commands.CommandRun;
import net.famzangl.minecraft.minebot.ai.commands.CommandShear;
import net.famzangl.minecraft.minebot.ai.commands.CommandSit;
import net.famzangl.minecraft.minebot.ai.commands.CommandStop;
import net.famzangl.minecraft.minebot.ai.commands.CommandTint;
Expand Down Expand Up @@ -56,6 +57,7 @@ public class AIChatController {
registerCommand(CommandGetWood.class);
registerCommand(CommandTint.class);
registerCommand(CommandBuildWay.class);
registerCommand(CommandShear.class);

registerCommand(CommandKill.class);
registerCommand(CommandFish.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.famzangl.minecraft.minebot.ai.commands;

import net.famzangl.minecraft.minebot.ai.AIHelper;
import net.famzangl.minecraft.minebot.ai.AIStrategy;
import net.famzangl.minecraft.minebot.ai.command.AICommand;
import net.famzangl.minecraft.minebot.ai.command.AICommandInvocation;
import net.famzangl.minecraft.minebot.ai.command.AICommandParameter;
import net.famzangl.minecraft.minebot.ai.command.ParameterType;
import net.famzangl.minecraft.minebot.ai.strategy.ShearStrategy;

@AICommand(helpText="Shear sheep.", name="minebot")
public class CommandShear {

@AICommandInvocation()
public static AIStrategy run(
AIHelper helper,
@AICommandParameter(type = ParameterType.FIXED, fixedName = "shear", description = "") String nameArg) {
return run(helper, nameArg, -1);
}

@AICommandInvocation()
public static AIStrategy run(
AIHelper helper,
@AICommandParameter(type = ParameterType.FIXED, fixedName = "shear", description = "") String nameArg,
@AICommandParameter(type = ParameterType.COLOR, description = "The color to get") int color) {
return new ShearStrategy(color);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@ public ColorSelector(int color) {

@Override
public boolean isEntityApplicable(Entity var1) {
return (var1 instanceof EntityWolf && ((EntityWolf) var1)
.getCollarColor() == color)
|| (var1 instanceof EntitySheep && ((EntitySheep) var1)
.getFleeceColor() == 15 - color);
if (var1 instanceof EntityWolf) {
return ((EntityWolf) var1).getCollarColor() == color;
} else if (var1 instanceof EntitySheep) {
System.out.println(((EntitySheep) var1).getFleeceColor());
return ((EntitySheep) var1).getFleeceColor() == color;
} else {
return false;
}
}

@Override
public String toString() {
return "ColorSelector [color=" + color + "]";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package net.famzangl.minecraft.minebot.ai.selectors;

import net.minecraft.command.IEntitySelector;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;

public final class ItemSelector implements
IEntitySelector {
@Override
public boolean isEntityApplicable(Entity e) {
return e instanceof EntityItem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import net.famzangl.minecraft.minebot.ai.AIHelper;
import net.famzangl.minecraft.minebot.ai.AIStrategy;
import net.famzangl.minecraft.minebot.ai.animals.AnimalyType;
import net.famzangl.minecraft.minebot.ai.selectors.ItemSelector;
import net.famzangl.minecraft.minebot.ai.selectors.OrSelector;
import net.famzangl.minecraft.minebot.ai.task.AITask;
import net.famzangl.minecraft.minebot.ai.task.FaceAndInteractTask;
import net.minecraft.command.IEntitySelector;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.passive.EntityTameable;

Expand Down Expand Up @@ -44,14 +44,6 @@ public boolean isEntityApplicable(Entity e) {
}
}

private final class ItemSelector implements
IEntitySelector {
@Override
public boolean isEntityApplicable(Entity e) {
return e instanceof EntityItem;
}
}

private static final int DISTANCE = 20;
private final int maxKills;
private final AnimalyType type;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package net.famzangl.minecraft.minebot.ai.strategy;

import net.famzangl.minecraft.minebot.ai.AIHelper;
import net.famzangl.minecraft.minebot.ai.AIStrategy;
import net.famzangl.minecraft.minebot.ai.ItemFilter;
import net.famzangl.minecraft.minebot.ai.selectors.AndSelector;
import net.famzangl.minecraft.minebot.ai.selectors.ColorSelector;
import net.famzangl.minecraft.minebot.ai.selectors.ItemSelector;
import net.famzangl.minecraft.minebot.ai.selectors.OrSelector;
import net.famzangl.minecraft.minebot.ai.task.AITask;
import net.famzangl.minecraft.minebot.ai.task.FaceAndInteractTask;
import net.minecraft.command.IEntitySelector;
import net.minecraft.entity.Entity;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.item.ItemShears;
import net.minecraft.item.ItemStack;

public class ShearStrategy implements AIStrategy {
private static final int DISTANCE = 20;
private final int color;

public ShearStrategy(int color) {
this.color = color;
}

private final class ShearsFilter implements ItemFilter {
@Override
public boolean matches(ItemStack itemStack) {
return itemStack != null && itemStack.getItem() instanceof ItemShears;
}
}

private final class SheepSelector implements IEntitySelector {
@Override
public boolean isEntityApplicable(Entity var1) {
return var1 instanceof EntitySheep
&& ((EntitySheep) var1).isShearable(null, null, 0, 0, 0);
}
}

public static enum TintType {
WOLF,
SHEEP,
ANY;
}

@Override
public void searchTasks(AIHelper helper) {
if (!helper.selectCurrentItem(new ShearsFilter())) {
return;
}

IEntitySelector selector = new SheepSelector();

if (color >= 0) {
selector = new AndSelector(selector, new ColorSelector(color));
}

final Entity found = helper.getClosestEntity(DISTANCE, new OrSelector(
selector, new ItemSelector()));

if (found != null) {
helper.addTask(new FaceAndInteractTask(found, selector));
}
}

@Override
public String getDescription() {
return "Tinting...";
}

@Override
public AITask getOverrideTask(AIHelper helper) {
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public DyeItemFilter(int color) {
public boolean matches(ItemStack itemStack) {
return itemStack != null && itemStack.getItem() != null
&& itemStack.getItem() instanceof ItemDye
&& (color < 0 || itemStack.getItemDamage() == color);
&& (color < 0 || 15 - itemStack.getItemDamage() == color);
}

}
Expand All @@ -81,7 +81,7 @@ public void searchTasks(AIHelper helper) {
}

final EntityClientPlayerMP owner = helper.getMinecraft().thePlayer;
int holdingColor = owner.inventory.getCurrentItem().getItemDamage();
int holdingColor = 15 - owner.inventory.getCurrentItem().getItemDamage();
IEntitySelector wolfSelector = new WolfSelector(owner);
IEntitySelector sheepSelector = new SheepSelector();

Expand Down Expand Up @@ -119,4 +119,12 @@ public AITask getOverrideTask(AIHelper helper) {
return null;
}

@Override
public String toString() {
return "TintStrategy [color=" + color + ", current=" + current
+ ", type=" + type + "]";
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,13 @@ public void runTick(AIHelper h) {
}
ticksRun++;
}

@Override
public String toString() {
return "FaceAndInteractTask [preferedAnimal=" + preferedAnimal
+ ", alsoAcceptedAnimal=" + alsoAcceptedAnimal
+ ", doRightClick=" + doRightClick + "]";
}


}

0 comments on commit 4073f4c

Please sign in to comment.