(mapper);
47 | area.accept(visitor, world);
48 | return visitor.getMinimum();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/selectors/IsSittingSelector.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.selectors;
18 |
19 | import net.minecraft.entity.Entity;
20 | import net.minecraft.entity.LivingEntity;
21 | import net.minecraft.entity.passive.WolfEntity;
22 |
23 | public final class IsSittingSelector extends OwnTameableSelector {
24 | private final boolean sitting;
25 |
26 | public IsSittingSelector(boolean sitting, LivingEntity owner) {
27 | super(owner);
28 | this.sitting = sitting;
29 | }
30 |
31 | @Override
32 | public boolean test(Entity entity) {
33 | return super.test(entity)
34 | && ((WolfEntity) entity).isCrouching() == sitting;
35 | }
36 | }
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/strategy/BuildWayStrategy.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.strategy;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 | import net.famzangl.minecraft.minebot.ai.path.BuildWayPathfinder;
21 |
22 | public class BuildWayStrategy extends PathFinderStrategy {
23 |
24 |
25 | public BuildWayStrategy(BuildWayPathfinder pathfinder) {
26 | super(pathfinder, "Build a road.");
27 | }
28 |
29 | @Override
30 | public String getDescription(AIHelper helper) {
31 | return "Build a road";
32 | }
33 |
34 | @Override
35 | public void searchTasks(AIHelper helper) {
36 | super.searchTasks(helper);
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/build/reverse/factories/AbstractBuildTaskFactory.java:
--------------------------------------------------------------------------------
1 | package net.famzangl.minecraft.minebot.build.reverse.factories;
2 |
3 | import net.famzangl.minecraft.minebot.ai.path.world.BlockSet;
4 | import net.famzangl.minecraft.minebot.ai.path.world.WorldData;
5 | import net.famzangl.minecraft.minebot.build.blockbuild.BuildTask;
6 | import net.famzangl.minecraft.minebot.build.reverse.TaskDescription;
7 | import net.famzangl.minecraft.minebot.build.reverse.UnsupportedBlockException;
8 | import net.minecraft.block.BlockState;
9 | import net.minecraft.util.math.BlockPos;
10 | import org.apache.commons.lang3.StringUtils;
11 |
12 | public abstract class AbstractBuildTaskFactory implements BuildTaskFactory {
13 |
14 | @Override
15 | public TaskDescription getTaskDescription(WorldData world, BlockPos position)
16 | throws UnsupportedBlockException {
17 | if (getSupportedBlocks().isAt(world, position)) {
18 | BlockState block = world.getBlockState(position);
19 | BuildTask task = getTaskImpl(position, block);
20 | try {
21 | Object[] args = task.getCommandArguments();
22 | return new TaskDescription(StringUtils.join(args, " "),
23 | task.getStandablePlaces());
24 | } catch (UnsupportedOperationException uoe) {
25 | throw new UnsupportedBlockException(world, position,
26 | "Task could not be converted: " + task);
27 | }
28 | }
29 | return null;
30 | }
31 |
32 | protected abstract BuildTask getTaskImpl(BlockPos position, BlockState block);
33 |
34 | public abstract BlockSet getSupportedBlocks();
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/AimBow/src/net/famzangl/minecraft/aimbow/aiming/ColissionData.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.aimbow.aiming;
18 |
19 | import net.minecraft.entity.Entity;
20 |
21 | public class ColissionData {
22 | public double x, y, z;
23 | public Entity hitEntity;
24 | public int hitStep;
25 |
26 | public ColissionData(double x, double y, double z, Entity hitEntity,
27 | int hitStep) {
28 | super();
29 | this.x = x;
30 | this.y = y;
31 | this.z = z;
32 | this.hitEntity = hitEntity;
33 | this.hitStep = hitStep;
34 | }
35 |
36 | @Override
37 | public String toString() {
38 | return "ColissionData [x=" + x + ", y=" + y + ", z=" + z
39 | + ", hitEntity=" + hitEntity + ", hitStep=" + hitStep + "]";
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/enchanting/TakeEnchantedItemTask.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.enchanting;
18 |
19 | import net.famzangl.minecraft.minebot.ai.task.inventory.TakeResultItem;
20 | import net.minecraft.client.gui.screen.EnchantmentScreen;
21 | import net.minecraft.item.ItemStack;
22 |
23 | /**
24 | * Takes the enchanted item form the opened table.
25 | *
26 | * @author michael
27 | *
28 | */
29 | public class TakeEnchantedItemTask extends TakeResultItem {
30 |
31 | public TakeEnchantedItemTask() {
32 | super(EnchantmentScreen.class, 0);
33 | }
34 |
35 | @Override
36 | protected boolean shouldTakeStack(ItemStack stack) {
37 | return stack.isEnchanted();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/task/inventory/PutInInventoryCraftingSlotTask.java:
--------------------------------------------------------------------------------
1 | package net.famzangl.minecraft.minebot.ai.task.inventory;
2 |
3 | import net.famzangl.minecraft.minebot.ai.AIHelper;
4 | import net.minecraft.item.Item;
5 |
6 | /**
7 | * Put an item in the placer inventory crafting slots.
8 | *
9 | * Screen is the player inventory screen using PlayerContainer
10 | * Slot 0: Crafting result
11 | * Slot 1-4: Crafting input
12 | * Slot 5-8: Armor
13 | * Then Inventory
14 | */
15 | public class PutInInventoryCraftingSlotTask extends MoveInInventoryTask {
16 |
17 | private final int craftingX;
18 | private final int craftingY;
19 | private final Item item;
20 | private final int itemCount;
21 |
22 | public PutInInventoryCraftingSlotTask(int craftingX, int craftingY, Item item,
23 | int itemCount) {
24 | this.craftingX = craftingX;
25 | this.craftingY = craftingY;
26 | this.item = item;
27 | this.itemCount = itemCount;
28 | }
29 |
30 |
31 | @Override
32 | protected int getFromStack(AIHelper aiHelper) {
33 | int inventorySlot = findItemInInventory(aiHelper, item);
34 | if (inventorySlot < 0) {
35 | return -1;
36 | }
37 |
38 | return 9 + convertPlayerInventorySlot(inventorySlot);
39 | }
40 |
41 |
42 | @Override
43 | protected int getToStack(AIHelper aiHelper) {
44 | return (craftingX * 2 + craftingY) + 1;
45 | }
46 |
47 | @Override
48 | protected int getMissingAmount(AIHelper aiHelper, int currentCount) {
49 | return itemCount - currentCount;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/utils/ReverseAcceptingArea.java:
--------------------------------------------------------------------------------
1 | package net.famzangl.minecraft.minebot.ai.utils;
2 |
3 | import net.famzangl.minecraft.minebot.ai.path.world.WorldData;
4 | import net.minecraft.util.math.BlockPos;
5 |
6 | import java.util.ArrayList;
7 |
8 | /**
9 | * This class wraps a block area and simply reverses the accept()-Method.
10 | *
11 | * Reversing takes O(n) space.
12 | * @author Michael Zangl
13 | *
14 | */
15 | public class ReverseAcceptingArea extends BlockArea {
16 | private final BlockArea area;
17 |
18 | private final static class CollectingVisitor implements AreaVisitor {
19 | ArrayList positions = new ArrayList();
20 |
21 | @Override
22 | public void visit(WorldData world, int x, int y, int z) {
23 | positions.add(new BlockPos(x, y, z));
24 | }
25 | }
26 |
27 | public ReverseAcceptingArea(BlockArea area) {
28 | super();
29 | this.area = area;
30 | }
31 |
32 | @Override
33 | public void accept(AreaVisitor visitor, WorldData world) {
34 | CollectingVisitor collected = new CollectingVisitor();
35 | area.accept(collected, world);
36 | ArrayList positions = collected.positions;
37 | for (int i = positions.size() - 1; i >= 0; i--) {
38 | BlockPos pos = positions.get(i);
39 | visitor.visit(world, pos.getX(), pos.getY(), pos.getZ());
40 | }
41 | }
42 |
43 | @Override
44 | public boolean contains(WorldData world, int x, int y, int z) {
45 | return false;
46 | }
47 |
48 | @Override
49 | public String toString() {
50 | return "ReverseAcceptingArea [area=" + area + "]";
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/command/AIHelperBuilder.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.command;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 |
21 | import java.util.ArrayList;
22 |
23 | public class AIHelperBuilder extends ParameterBuilder {
24 |
25 | public AIHelperBuilder(AICommandParameter annot) {
26 | super(annot);
27 | }
28 |
29 | @Override
30 | public void addArguments(ArrayList list) {
31 | // ignored.
32 | }
33 |
34 | @Override
35 | public Object getParameter(AIHelper helper, String[] arguments) {
36 | return helper;
37 | }
38 |
39 | @Override
40 | protected Class> getRequiredParameterClass() {
41 | return AIHelper.class;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/strategy/CreeperComesActionStrategy.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.strategy;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 | import net.minecraft.entity.Entity;
21 | import net.minecraft.entity.monster.CreeperEntity;
22 |
23 | public class CreeperComesActionStrategy extends CloseEntityActionStrategy {
24 |
25 | @Override
26 | protected boolean matches(AIHelper helper, Entity player) {
27 | return player instanceof CreeperEntity;
28 | }
29 |
30 | @Override
31 | protected String getSettingPrefix() {
32 | return "on_creeper_comes_";
33 | }
34 |
35 | @Override
36 | public String getDescription(AIHelper helper) {
37 | return "Watch out for creepers.";
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/enchanting/CloseScreenTask.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.enchanting;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 | import net.famzangl.minecraft.minebot.ai.task.AITask;
21 | import net.famzangl.minecraft.minebot.ai.task.TaskOperations;
22 |
23 | public class CloseScreenTask extends AITask {
24 |
25 | @Override
26 | public boolean isFinished(AIHelper aiHelper) {
27 | return aiHelper.getMinecraft().currentScreen == null;
28 | }
29 |
30 | @Override
31 | public void runTick(AIHelper aiHelper, TaskOperations taskOperations) {
32 | aiHelper.getMinecraft().displayGuiScreen(null);
33 | // TODO: check if it helps: aiHelper.getMinecraft().setIngameFocus();
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/task/UseItemOnBlockTask.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.task;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 | import net.famzangl.minecraft.minebot.ai.path.world.BlockSet;
21 | import net.minecraft.util.math.BlockPos;
22 |
23 |
24 | /**
25 | *
26 | * @author michael
27 | *
28 | */
29 | public abstract class UseItemOnBlockTask extends UseItemTask {
30 |
31 | private final BlockSet allowedBlocks;
32 |
33 | public UseItemOnBlockTask(BlockSet allowedBlocks) {
34 | this.allowedBlocks = allowedBlocks;
35 | }
36 |
37 | @Override
38 | protected boolean isBlockAllowed(AIHelper aiHelper, BlockPos pos) {
39 | return allowedBlocks.contains(aiHelper.getBlockState(pos));
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/map/PlayerPositionLabel.java:
--------------------------------------------------------------------------------
1 | package net.famzangl.minecraft.minebot.map;
2 |
3 | import net.minecraft.util.math.BlockPos;
4 |
5 | import javax.swing.*;
6 | import java.awt.*;
7 | import java.awt.event.MouseAdapter;
8 | import java.awt.event.MouseEvent;
9 |
10 | public final class PlayerPositionLabel extends JPanel {
11 |
12 | public interface FollowPlayerListener {
13 | public void setFollowPlayer(boolean follow);
14 | }
15 |
16 | private final JLabel x = new JLabel();
17 | private final JLabel y = new JLabel();
18 | private final JLabel z = new JLabel();
19 | private final FollowPlayerListener listener;
20 |
21 | public PlayerPositionLabel(FollowPlayerListener listener) {
22 | this.listener = listener;
23 | add(x);
24 | add(y);
25 | add(z);
26 | x.setPreferredSize(new Dimension(50, 15));
27 | y.setPreferredSize(new Dimension(30, 15));
28 | z.setPreferredSize(new Dimension(50, 15));
29 |
30 | addMouseListener(new MouseAdapter() {
31 | @Override
32 | public void mouseClicked(MouseEvent e) {
33 | PlayerPositionLabel.this.listener.setFollowPlayer(true);
34 | }
35 | });
36 | }
37 |
38 | public void setPosition(BlockPos newPlayer) {
39 | x.setText(newPlayer == null ? "?" : newPlayer.getX() + "");
40 | y.setText(newPlayer == null ? "?" : newPlayer.getY() + "");
41 | z.setText(newPlayer == null ? "?" : newPlayer.getZ() + "");
42 |
43 | String pos = newPlayer == null ? "?" : newPlayer.getX() + " " + newPlayer.getY() + " " + newPlayer.getZ();
44 | setToolTipText("Player position: " + pos + ".
Click to follow player.
");
45 | }
46 | }
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/commands/CommandStore.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.commands;
18 |
19 | import com.mojang.brigadier.builder.LiteralArgumentBuilder;
20 | import net.famzangl.minecraft.minebot.ai.command.AICommand;
21 | import net.famzangl.minecraft.minebot.ai.command.IAIControllable;
22 | import net.famzangl.minecraft.minebot.ai.strategy.StoreStrategy;
23 |
24 | @AICommand(name = "minebot", helpText = "Store to chests.")
25 | public class CommandStore {
26 |
27 | public static void register(LiteralArgumentBuilder dispatcher) {
28 | dispatcher.then(
29 | Commands.literal("store")
30 | .executes(context ->
31 | context.getSource().requestUseStrategy(new StoreStrategy())
32 | ));
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/utils/AreaIntersection.java:
--------------------------------------------------------------------------------
1 | package net.famzangl.minecraft.minebot.ai.utils;
2 |
3 | import net.famzangl.minecraft.minebot.ai.path.world.WorldData;
4 |
5 | /**
6 | * Intersection of two block areas
7 | * @param The world type
8 | */
9 | public class AreaIntersection extends BlockArea {
10 | private static class FilteredAreaVisitor implements AreaVisitor {
11 | private AreaVisitor super WorldT> visitor;
12 | private final BlockArea super WorldT> b;
13 |
14 | public FilteredAreaVisitor(AreaVisitor super WorldT> visitor, BlockArea super WorldT> b) {
15 | this.visitor = visitor;
16 | this.b = b;
17 | }
18 |
19 | @Override
20 | public void visit(WorldT world, int x, int y, int z) {
21 | if (!b.contains(world, x, y, z)) {
22 | return;
23 | }
24 | visitor.visit(world, x, y, z);
25 | }
26 |
27 | }
28 |
29 | private final BlockArea super WorldT> a;
30 | private final BlockArea super WorldT> b;
31 |
32 | public AreaIntersection(BlockArea super WorldT> a, BlockArea super WorldT> b) {
33 | this.a = a;
34 | this.b = b;
35 | }
36 |
37 | @Override
38 | public boolean contains(WorldT world, int x, int y, int z) {
39 | return a.contains(world, x, y, z) && b.contains(world, x, y, z);
40 | }
41 |
42 | @Override
43 | public void accept(AreaVisitor super WorldT2> visitor, WorldT2 world) {
44 | a.accept(new FilteredAreaVisitor(visitor, b), world);
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | return a + " ∩ " + b;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/build/reverse/TaskDescription.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.build.reverse;
18 |
19 | import net.minecraft.util.math.BlockPos;
20 |
21 | import java.util.Arrays;
22 |
23 | public class TaskDescription {
24 | private final String commandArgs;
25 | private final BlockPos[] buildableFrom;
26 |
27 | public TaskDescription(String commandArgs, BlockPos[] buildableFrom) {
28 | this.commandArgs = commandArgs;
29 | this.buildableFrom = buildableFrom;
30 | }
31 |
32 | public String getCommandArgs() {
33 | return commandArgs;
34 | }
35 |
36 | @Override
37 | public String toString() {
38 | return "TaskDescription [commandArgs=" + commandArgs
39 | + ", buildableFrom=" + Arrays.toString(buildableFrom) + "]";
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/utils/BlockArea.java:
--------------------------------------------------------------------------------
1 | package net.famzangl.minecraft.minebot.ai.utils;
2 |
3 | import net.famzangl.minecraft.minebot.ai.path.world.WorldData;
4 | import net.minecraft.util.math.BlockPos;
5 |
6 | /**
7 | * This is an area of blocks. It is allowed to be empty. An area is final and
8 | * cannot be changed after being created.
9 | *
10 | * @author Michael Zangl
11 | */
12 | public abstract class BlockArea {
13 | @FunctionalInterface
14 | public interface AreaVisitor {
15 | void visit(WorldT world, int x, int y, int z);
16 | }
17 |
18 | private static class VolumeVisitor implements AreaVisitor {
19 | private int volume = 0;
20 |
21 | @Override
22 | public void visit(WorldData world, int x, int y, int z) {
23 | volume++;
24 | }
25 | }
26 |
27 | public boolean contains(WorldT world, BlockPos position) {
28 | return contains(world, position.getX(), position.getY(), position.getZ());
29 | }
30 |
31 | public abstract void accept(AreaVisitor super WorldT2> visitor, WorldT2 world);
32 |
33 | public abstract boolean contains(WorldT world, int x, int y, int z);
34 |
35 | public int getVolume(WorldT world) {
36 | VolumeVisitor volumeVisitor = new VolumeVisitor();
37 | accept(volumeVisitor, world);
38 | return volumeVisitor.volume;
39 | }
40 |
41 | public AreaIntersection intersectWith(BlockArea other) {
42 | return new AreaIntersection<>(this, other);
43 | }
44 |
45 | public AreaUnion unionWith(BlockArea other) {
46 | return new AreaUnion<>(this, other);
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/strategy/CloseEntityActionStrategy.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.strategy;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 | import net.minecraft.entity.Entity;
21 |
22 | /**
23 | * Do an action when a given entity approaches.
24 | * @author michael
25 | *
26 | */
27 | public abstract class CloseEntityActionStrategy extends ValueActionStrategy {
28 | @Override
29 | protected double getValue(final AIHelper helper) {
30 | final Entity closest = helper.getClosestEntity(50,
31 | player -> matches(helper, player));
32 | return closest == null ? Double.MAX_VALUE : closest
33 | .getDistance(helper.getMinecraft().player);
34 | }
35 |
36 | protected abstract boolean matches(AIHelper helper, Entity player);
37 | }
38 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/strategy/PlayerComesActionStrategy.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.strategy;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 | import net.minecraft.entity.Entity;
21 | import net.minecraft.entity.player.PlayerEntity;
22 |
23 | public class PlayerComesActionStrategy extends CloseEntityActionStrategy {
24 |
25 | @Override
26 | protected boolean matches(AIHelper helper, Entity player) {
27 | return player instanceof PlayerEntity && player != helper.getMinecraft().player;
28 | }
29 |
30 | @Override
31 | protected String getSettingPrefix() {
32 | return "on_player_comes_";
33 | }
34 |
35 | @Override
36 | public String getDescription(AIHelper helper) {
37 | return "Check if other player is comming.";
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/strategy/TimeStrategy.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.strategy;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 |
21 | /**
22 | * A strategy that needs to measure time.
23 | *
24 | * @author michael
25 | *
26 | */
27 | public abstract class TimeStrategy extends AIStrategy {
28 |
29 | private long startTime = -1;
30 |
31 | /**
32 | * Gets how many ticks happend since the first time this was called.
33 | *
34 | * @return 0 or more.
35 | */
36 | protected long getTimeElapsed(AIHelper helper) {
37 | long time = helper.getMinecraft().world.getGameTime();
38 | if (startTime < 0) {
39 | startTime = time;
40 | return 0;
41 | } else {
42 | return time - startTime;
43 | }
44 |
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/commands/CommandRespawn.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.commands;
18 |
19 | import com.mojang.brigadier.builder.LiteralArgumentBuilder;
20 | import net.famzangl.minecraft.minebot.ai.command.AICommand;
21 | import net.famzangl.minecraft.minebot.ai.command.IAIControllable;
22 | import net.famzangl.minecraft.minebot.ai.strategy.RespawnStrategy;
23 |
24 |
25 | @AICommand(helpText = "Respawn if you have died.", name = "minebot")
26 | public class CommandRespawn {
27 |
28 | public static void register(LiteralArgumentBuilder dispatcher) {
29 | dispatcher.then(
30 | Commands.literal("respawn")
31 | .executes(context ->
32 | context.getSource().requestUseStrategy(new RespawnStrategy())
33 | ));
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/enchanting/ClickOnEnchantmentTable.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.enchanting;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 | import net.famzangl.minecraft.minebot.ai.path.world.BlockSet;
21 | import net.famzangl.minecraft.minebot.ai.task.UseItemOnBlockTask;
22 | import net.minecraft.block.Blocks;
23 | import net.minecraft.client.gui.screen.EnchantmentScreen;
24 |
25 | public class ClickOnEnchantmentTable extends UseItemOnBlockTask {
26 |
27 | public ClickOnEnchantmentTable() {
28 | super(BlockSet.builder().add(Blocks.ENCHANTING_TABLE).build());
29 | }
30 |
31 | @Override
32 | public boolean isFinished(AIHelper aiHelper) {
33 | return aiHelper.getMinecraft().currentScreen instanceof EnchantmentScreen;
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/AimBow/src/net/famzangl/minecraft/aimbow/AimBowMod.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.aimbow;
18 |
19 | import net.minecraftforge.fml.common.Mod;
20 | import net.minecraftforge.fml.common.Mod.EventHandler;
21 | import net.minecraftforge.fml.common.Mod.Instance;
22 | import net.minecraftforge.fml.common.event.FMLInitializationEvent;
23 |
24 | @Mod(modid="aimbow-mod", name = "AimBow", version = "0.1.0")
25 | public class AimBowMod {
26 |
27 | @Instance(value = "minebot-mod")
28 | public static AimBowMod instance;
29 |
30 | @EventHandler
31 | public void init(FMLInitializationEvent event) {
32 | final AimBowController controller = new AimBowController();
33 | controller.initialize();
34 | }
35 |
36 | public static String getVersion() {
37 | return AimBowMod.class.getAnnotation(Mod.class).version();
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/tools/rate/Rater.java:
--------------------------------------------------------------------------------
1 | package net.famzangl.minecraft.minebot.ai.tools.rate;
2 |
3 | import net.famzangl.minecraft.minebot.ai.path.world.BlockFloatMap;
4 | import net.minecraft.item.ItemStack;
5 |
6 | public abstract class Rater {
7 |
8 | protected final String name;
9 |
10 | protected final BlockFloatMap values;
11 |
12 | public Rater(String name, BlockFloatMap values) {
13 | super();
14 | this.name = name;
15 | this.values = values;
16 | }
17 |
18 | public final float ratePowed(ItemStack item, int forBlockAndMeta) {
19 | return (float) Math.pow(rate(item, forBlockAndMeta), getPow(item, forBlockAndMeta));
20 | }
21 |
22 | protected double getPow(ItemStack item, int forBlockAndMeta) {
23 | return 1;
24 | }
25 |
26 | public float rate(ItemStack item, int forBlockAndMeta) {
27 | if (isAppleciable(item, forBlockAndMeta)) {
28 | return forBlockAndMeta < 0 ? values.getDefaultValue() : values.get(forBlockAndMeta);
29 | } else {
30 | return 1;
31 | }
32 | }
33 |
34 | protected boolean isAppleciable(ItemStack item, int forBlockAndMeta) {
35 | return true;
36 | }
37 |
38 | public String getName() {
39 | return name;
40 | }
41 |
42 | public BlockFloatMap getValues() {
43 | return values;
44 | }
45 |
46 | @Override
47 | public String toString() {
48 | return "Rater [name=" + name + ", values=" + values + "]";
49 | }
50 |
51 | protected static String createName(Rater[] raters, String sep) {
52 | StringBuilder sb = new StringBuilder();
53 | for (Rater rater : raters) {
54 | if (sb.length() > 0) {
55 | sb.append(sep);
56 | }
57 | sb.append(rater.getName());
58 | }
59 | return sb.toString();
60 | }
61 | }
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/command/AICommand.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.command;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.ElementType;
21 | import java.lang.annotation.Retention;
22 | import java.lang.annotation.RetentionPolicy;
23 | import java.lang.annotation.Target;
24 |
25 | /**
26 | * This represents a command of the AI system. The user can enter the name on
27 | * the console to run it.
28 | *
29 | * Classes of this type always need at least one constructor with a
30 | * {@link AICommandInvocation}-Annotation.
31 | *
32 | * @author michael
33 | *
34 | */
35 | @Documented
36 | @Retention(RetentionPolicy.RUNTIME)
37 | @Target(ElementType.TYPE)
38 | public @interface AICommand {
39 | String name();
40 |
41 | String helpText();
42 | }
43 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/build/reverse/factories/StairBuildTaskFactory.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.build.reverse.factories;
18 |
19 | import net.famzangl.minecraft.minebot.ai.path.world.BlockSet;
20 | import net.famzangl.minecraft.minebot.build.blockbuild.BuildNormalStairsTask;
21 | import net.famzangl.minecraft.minebot.build.blockbuild.BuildTask;
22 | import net.minecraft.block.BlockState;
23 | import net.minecraft.util.math.BlockPos;
24 |
25 | public class StairBuildTaskFactory extends AbstractBuildTaskFactory {
26 |
27 | @Override
28 | public BlockSet getSupportedBlocks() {
29 | // TODO Auto-generated method stub
30 | return null;
31 | }
32 |
33 | @Override
34 | protected BuildTask getTaskImpl(BlockPos position, BlockState block) {
35 | return new BuildNormalStairsTask(position, block);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/commands/CommandFish.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.commands;
18 |
19 | import com.mojang.brigadier.builder.LiteralArgumentBuilder;
20 | import net.famzangl.minecraft.minebot.ai.command.AICommand;
21 | import net.famzangl.minecraft.minebot.ai.command.IAIControllable;
22 | import net.famzangl.minecraft.minebot.ai.command.SafeStrategyRule;
23 | import net.famzangl.minecraft.minebot.ai.strategy.FishStrategy;
24 |
25 | @AICommand(helpText = "Catch some fish.", name = "minebot")
26 | public class CommandFish {
27 |
28 | public static void register(LiteralArgumentBuilder dispatcher) {
29 | dispatcher.then(
30 | Commands.literal("fish").executes(context -> context.getSource().requestUseStrategy(new FishStrategy(), SafeStrategyRule.DEFEND))
31 | );
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/build/reverse/factories/BuildTaskFactories.java:
--------------------------------------------------------------------------------
1 | package net.famzangl.minecraft.minebot.build.reverse.factories;
2 |
3 | import net.famzangl.minecraft.minebot.ai.path.world.BlockSet;
4 | import net.famzangl.minecraft.minebot.ai.path.world.BlockSets;
5 | import net.famzangl.minecraft.minebot.ai.path.world.WorldData;
6 | import net.famzangl.minecraft.minebot.build.reverse.TaskDescription;
7 | import net.famzangl.minecraft.minebot.build.reverse.UnsupportedBlockException;
8 | import net.minecraft.block.Blocks;
9 | import net.minecraft.util.math.BlockPos;
10 |
11 | import java.util.ArrayList;
12 |
13 | public class BuildTaskFactories {
14 |
15 | public static final BlockSet IGNORED_ON_RECONSTRUCT =
16 | BlockSet.builder().add(BlockSets.AIR).add(Blocks.BARREL).build();
17 |
18 | private static final ArrayList factories = new ArrayList();
19 |
20 | static {
21 | register(new BlockBuildTaskFactory());
22 | register(new LogBuildTaskFactory());
23 | register(new SlabBuildTaskFactory());
24 | register(new StairBuildTaskFactory());
25 | }
26 |
27 | public static void register(BuildTaskFactory factory) {
28 | factories.add(factory);
29 | }
30 |
31 | public static TaskDescription getTaskFor(WorldData world, BlockPos position)
32 | throws UnsupportedBlockException {
33 | if (IGNORED_ON_RECONSTRUCT.isAt(world, position)) {
34 | return null;
35 | }
36 |
37 | for (BuildTaskFactory f : factories) {
38 | TaskDescription res = f.getTaskDescription(world, position);
39 | if (res != null) {
40 | return res;
41 | }
42 | }
43 |
44 | throw new UnsupportedBlockException(world, position,
45 | "No handler found for that block.");
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/command/StringNameBuilder.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.command;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 |
21 | import java.util.ArrayList;
22 |
23 | public class StringNameBuilder extends ParameterBuilder {
24 |
25 | private final static class StringArgumentDefinition extends
26 | ArgumentDefinition {
27 |
28 | }
29 |
30 | public StringNameBuilder(AICommandParameter annot) {
31 | super(annot);
32 | }
33 |
34 | @Override
35 | public void addArguments(ArrayList list) {
36 | list.add(new StringArgumentDefinition());
37 | }
38 |
39 | @Override
40 | public Object getParameter(AIHelper helper, String[] arguments) {
41 | return arguments[0];
42 | }
43 |
44 | @Override
45 | protected Class> getRequiredParameterClass() {
46 | return String.class;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/Minebot/src/main/resources/META-INF/mods.toml:
--------------------------------------------------------------------------------
1 | # The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
2 | modLoader="javafml" #mandatory
3 | license="The GNU License (GNU)"
4 | # A version range to match for said mod loader - for regular FML @Mod it will be the forge version
5 | loaderVersion="[34,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
6 | # A URL to refer people to when problems occur with this mod
7 | issueTrackerURL="https://github.com/michaelzangl/minebot/issues" #optional
8 | # A list of mods - how many allowed here is determined by the individual mod loader
9 | [[mods]] #mandatory
10 | # The modid of the mod
11 | modId="minebot-mod" #mandatory
12 | # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
13 | version="${file.jarVersion}" #mandatory
14 | # A display name for the mod
15 | displayName="Minebot" #mandatory
16 | # A URL to query for updates for this mod. See the JSON update specification
17 | #updateJSONURL="http://myurl.me/" #optional
18 | # A URL for the "homepage" for this mod, displayed in the mod UI
19 | displayURL="https://github.com/michaelzangl/minebot/" #optional
20 | # A file name (in the root of the mod JAR) containing a logo for display
21 | #logoFile="examplemod.png" #optional
22 | # A text field displayed in the mod UI
23 | license="The GNU License (GNU)"
24 | #I repeated the license twice but it works (:
25 | #credits="Thanks for this example mod goes to Java" #optional
26 | # A text field displayed in the mod UI
27 | # authors="See github log" #optional
28 | # The description text for the mod (multi line!) (#mandatory)
29 | description='''
30 | A bot that does the dull work for you.
31 | '''
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/task/error/TaskError.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.task.error;
18 |
19 | import net.famzangl.minecraft.minebot.ai.strategy.TaskStrategy;
20 | import net.famzangl.minecraft.minebot.ai.task.TaskOperations;
21 |
22 | /**
23 | * This is an error that occurred while doing a task of a {@link TaskStrategy}.
24 | * You can add as many errors as you like with the
25 | * {@link TaskOperations#desync(TaskError)} method. Multiple errors of the same
26 | * type are automatically filtered.
27 | *
28 | * @author michael
29 | *
30 | */
31 | public class TaskError {
32 | private final String message;
33 |
34 | protected TaskError(String message) {
35 | this.message = message;
36 | }
37 |
38 | public String getMessage() {
39 | return message;
40 | }
41 |
42 | public boolean shouldBeDisplayed() {
43 | return true;
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/enchanting/KillAnyMobTask.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.enchanting;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 | import net.famzangl.minecraft.minebot.ai.task.AITask;
21 | import net.famzangl.minecraft.minebot.ai.task.TaskOperations;
22 | import net.minecraft.util.math.RayTraceResult;
23 |
24 | public class KillAnyMobTask extends AITask {
25 |
26 | int tickCount;
27 |
28 | @Override
29 | public boolean isFinished(AIHelper aiHelper) {
30 | final RayTraceResult position = aiHelper.getObjectMouseOver();
31 | return position == null
32 | || position.getType() != RayTraceResult.Type.ENTITY;
33 | }
34 |
35 | @Override
36 | public void runTick(AIHelper aiHelper, TaskOperations taskOperations) {
37 | tickCount++;
38 | if (tickCount % 10 == 5) {
39 | aiHelper.overrideAttack();
40 | }
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/render/PosMarkerRenderer.java:
--------------------------------------------------------------------------------
1 | package net.famzangl.minecraft.minebot.ai.render;
2 |
3 | import com.mojang.blaze3d.matrix.MatrixStack;
4 | import com.mojang.blaze3d.vertex.IVertexBuilder;
5 | import net.famzangl.minecraft.minebot.ai.utils.BlockCuboid;
6 | import net.minecraft.client.renderer.IRenderTypeBuffer;
7 | import net.minecraft.client.renderer.RenderType;
8 | import net.minecraft.client.renderer.WorldRenderer;
9 | import net.minecraft.client.renderer.debug.DebugRenderer;
10 | import net.minecraft.util.math.AxisAlignedBB;
11 | import net.minecraft.util.math.BlockPos;
12 | import net.minecraft.util.math.shapes.VoxelShape;
13 | import net.minecraft.util.math.shapes.VoxelShapes;
14 |
15 | import javax.annotation.ParametersAreNonnullByDefault;
16 | import java.util.function.Supplier;
17 |
18 | @ParametersAreNonnullByDefault
19 | public class PosMarkerRenderer extends CuboidDebugRenderer {
20 |
21 | private final Supplier pos;
22 | private final String name;
23 |
24 | public PosMarkerRenderer(Supplier pos, float r, float g, float b, String name) {
25 | super(() -> {
26 | BlockPos val = pos.get();
27 | return val != null ? new BlockCuboid<>(val, val) : null;
28 | }, r, g, b);
29 | this.pos = pos;
30 | this.name = name;
31 | }
32 |
33 | @Override
34 | public void render(MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, double camX, double camY, double camZ) {
35 | super.render(matrixStackIn, bufferIn, camX, camY, camZ);
36 |
37 | BlockPos pos = this.pos.get();
38 | if (pos != null) {
39 | DebugRenderer.renderText(name,
40 | pos.getX(), pos.getY(), pos.getZ(), -1);
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/build/blockbuild/BuildFlatOnGroundTask.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.build.blockbuild;
18 |
19 | import net.famzangl.minecraft.minebot.ai.task.AITask;
20 | import net.famzangl.minecraft.minebot.ai.task.place.PlaceBlockAtFloorTask;
21 | import net.minecraft.util.math.BlockPos;
22 |
23 | /**
24 | * Build something that is just standing on the ground.
25 | *
26 | * @author michael
27 | *
28 | */
29 | public abstract class BuildFlatOnGroundTask extends BuildTask {
30 |
31 | protected BuildFlatOnGroundTask(BlockPos forPosition) {
32 | super(forPosition);
33 | }
34 |
35 | @Override
36 | public BlockPos[] getStandablePlaces() {
37 | return new BlockPos[] { forPosition };
38 | }
39 |
40 | @Override
41 | public AITask getPlaceBlockTask(BlockPos relativeFromPos) {
42 | return new PlaceBlockAtFloorTask(forPosition, this.getRequiredItem());
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/strategy/NoneOfFilter.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.strategy;
18 |
19 | import net.famzangl.minecraft.minebot.ai.ItemFilter;
20 | import net.minecraft.item.ItemStack;
21 |
22 | import java.util.Arrays;
23 |
24 | /**
25 | * An inverted {@link ItemFilter}.
26 | *
27 | * @author michael
28 | *
29 | */
30 | public class NoneOfFilter implements ItemFilter {
31 |
32 | private final ItemFilter[] filters;
33 |
34 | public NoneOfFilter(ItemFilter... filters) {
35 | this.filters = filters;
36 | }
37 |
38 | @Override
39 | public boolean matches(ItemStack itemStack) {
40 | for (ItemFilter filter : filters) {
41 | if (filter.matches(itemStack)) {
42 | return false;
43 | }
44 | }
45 | return true;
46 | }
47 |
48 | @Override
49 | public String toString() {
50 | return "NoneOfFilter [filters=" + Arrays.toString(filters) + "]";
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/task/TaskOperations.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.task;
18 |
19 | import net.famzangl.minecraft.minebot.ai.strategy.TaskStrategy;
20 | import net.famzangl.minecraft.minebot.ai.task.error.TaskError;
21 |
22 | /**
23 | * Callbacks for {@link AITask}s to communicate back to the {@link TaskStrategy}
24 | * @author michael
25 | *
26 | */
27 | public interface TaskOperations {
28 |
29 | /**
30 | * This should be called whenever the current task could not achieve it's
31 | * goal. All following tasks are unscheduled.
32 | *
33 | * @param taskError
34 | */
35 | public abstract void desync(TaskError taskError);
36 |
37 | /**
38 | * This can be called by the current task to do a look ahead and already let
39 | * the next task to it's face and destroy. Use with care.
40 | *
41 | * @return
42 | */
43 | public boolean faceAndDestroyForNextTask();
44 | }
45 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/strategy/AbortOnDeathStrategy.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.strategy;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 |
21 | /**
22 | * Aborts the current strategy stack if the player dies.
23 | * @see StrategyStack
24 | * @author michael
25 | *
26 | */
27 | public class AbortOnDeathStrategy extends AIStrategy {
28 |
29 | @Override
30 | public boolean checkShouldTakeOver(AIHelper helper) {
31 | return !helper.isAlive();
32 | }
33 |
34 | @Override
35 | protected TickResult onGameTick(AIHelper helper) {
36 | if (helper.isAlive()) {
37 | return TickResult.NO_MORE_WORK;
38 | } else {
39 | return TickResult.ABORT;
40 | }
41 | }
42 |
43 | @Override
44 | public String getDescription(AIHelper helper) {
45 | return "Stop when dead.";
46 | }
47 |
48 | @Override
49 | public String toString() {
50 | return "AbortOnDeathStrategy{}";
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/strategy/FishStrategy.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.strategy;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 | import net.famzangl.minecraft.minebot.ai.task.DoFishTask;
21 | import net.famzangl.minecraft.minebot.ai.task.ThrowFishingRodTask;
22 | import net.famzangl.minecraft.minebot.ai.task.WaitTask;
23 |
24 | public class FishStrategy extends TaskStrategy {
25 |
26 | @Override
27 | public void searchTasks(AIHelper helper) {
28 | System.out.println("Fish entity: " + helper.getMinecraft().player.fishingBobber);
29 | if (helper.getMinecraft().player.fishingBobber == null) {
30 | addTask(new WaitTask(3));
31 | addTask(new ThrowFishingRodTask());
32 | addTask(new WaitTask(20));
33 | } else {
34 | addTask(new DoFishTask());
35 | }
36 | }
37 |
38 | @Override
39 | public String getDescription(AIHelper helper) {
40 | return "Fishing";
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/scanner/BlockRangeFinder.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.scanner;
18 |
19 | import net.famzangl.minecraft.minebot.ai.path.WalkingPathfinder;
20 | import net.minecraft.util.math.BlockPos;
21 |
22 | public class BlockRangeFinder extends WalkingPathfinder {
23 | protected BlockRangeScanner rangeScanner;
24 |
25 | public BlockRangeFinder() {
26 | }
27 |
28 | @Override
29 | protected boolean runSearch(BlockPos playerPosition) {
30 | if (rangeScanner == null) {
31 | rangeScanner = constructScanner(playerPosition);
32 | //TODO: Pass on a synchronized world instance...
33 | rangeScanner.startAsync(world);
34 | return false;
35 | } else if (!rangeScanner.isScaningFinished()) {
36 | return false;
37 | } else {
38 | return super.runSearch(playerPosition);
39 | }
40 | }
41 |
42 | protected BlockRangeScanner constructScanner(BlockPos playerPosition) {
43 | return new BlockRangeScanner(playerPosition);
44 | }
45 | }
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/map/MapContextMenu.java:
--------------------------------------------------------------------------------
1 | package net.famzangl.minecraft.minebot.map;
2 |
3 | import net.minecraft.util.math.BlockPos;
4 |
5 | import javax.swing.*;
6 | import java.util.Hashtable;
7 | import java.util.Map.Entry;
8 |
9 | public class MapContextMenu extends JPopupMenu {
10 | private final BlockPos pos;
11 |
12 | public static final class CommandMenuItem extends JMenuItem {
13 | private final String command;
14 |
15 | public CommandMenuItem(String label, String command, BlockPos position) {
16 | Hashtable replace = new Hashtable();
17 |
18 | replace.put("x", position.getX() + "");
19 | replace.put("y", position.getY() + "");
20 | replace.put("z", position.getZ() + "");
21 | replace.put("cx", (position.getX() + .5) + "");
22 | replace.put("cy", (position.getY() + .5) + "");
23 | replace.put("cz", (position.getZ() + .5) + "");
24 |
25 | for (Entry r : replace .entrySet()) {
26 | while (command.contains("{" + r.getKey() + "}")) {
27 | command = command.replace("{" + r.getKey() + "}", r.getValue());
28 | }
29 | }
30 | this.command = command;
31 | setText(label);
32 | setToolTipText(command);
33 | setEnabled(false);
34 | }
35 | }
36 |
37 | public MapContextMenu(BlockPos pos) {
38 | this.pos = pos;
39 | JLabel headline = new JLabel("" + pos.getX() + ", " + pos.getY() + ", "
40 | + pos.getZ() + "
");
41 | headline.setAlignmentX(.5f);
42 | add(headline);
43 | add(new JSeparator());
44 |
45 | add(new CommandMenuItem("Walk to this position", "/minebot walk {cx} {cz}", pos));
46 | add(new JSeparator());
47 | add(new CommandMenuItem("Set position 1", "/minebuild pos1 {x} ~0 {z}", pos));
48 | add(new CommandMenuItem("Set position 2", "/minebuild pos2 {x} ~0 {z}", pos));
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/settings/PathfindingSetting.java:
--------------------------------------------------------------------------------
1 | package net.famzangl.minecraft.minebot.settings;
2 |
3 | import net.famzangl.minecraft.minebot.ai.path.world.BlockSet;
4 |
5 | /**
6 | * The settings we use for a pathfinder. This defines the blocks we may walk
7 | * through.
8 | *
9 | * @author michael
10 | *
11 | */
12 | public class PathfindingSetting {
13 | private BlockSet allowedGround;
14 |
15 | /**
16 | * 'Ground' allowed to build upwards. Should include air.
17 | */
18 | private BlockSet allowedGroundWhenUpwards;
19 |
20 | private BlockSet footWalkThrough;
21 |
22 | private BlockSet headWalkThrough;
23 |
24 | private BlockSet upwardsBuildBlocks;
25 |
26 | private String help = "With this, you can add your custom mod blocks to the path finder. Modify this with care. Delete the whole entry to reset to default.";
27 |
28 | public PathfindingSetting() {
29 | // for json parsing
30 | }
31 |
32 | public PathfindingSetting(BlockSet allowedGround,
33 | BlockSet allowedGroundWhenUpwards, BlockSet footWalkThrough,
34 | BlockSet headWalkThrough, BlockSet upwardsBuildBlocks) {
35 | super();
36 | this.allowedGround = allowedGround;
37 | this.allowedGroundWhenUpwards = allowedGroundWhenUpwards;
38 | this.footWalkThrough = footWalkThrough;
39 | this.headWalkThrough = headWalkThrough;
40 | this.upwardsBuildBlocks = upwardsBuildBlocks;
41 | }
42 |
43 | public BlockSet getAllowedGround() {
44 | return allowedGround;
45 | }
46 | public BlockSet getFootWalkThrough() {
47 | return footWalkThrough;
48 | }
49 |
50 | public BlockSet getHeadWalkThrough() {
51 | return headWalkThrough;
52 | }
53 |
54 | public BlockSet getAllowedGroundWhenUpwards() {
55 | return allowedGroundWhenUpwards;
56 | }
57 |
58 | public BlockSet getUpwardsBuildBlocks() {
59 | return upwardsBuildBlocks;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/selectors/ColorSelector.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.selectors;
18 |
19 | import net.minecraft.entity.Entity;
20 | import net.minecraft.entity.passive.SheepEntity;
21 | import net.minecraft.entity.passive.WolfEntity;
22 | import net.minecraft.item.DyeColor;
23 |
24 | import java.util.function.Predicate;
25 |
26 | public final class ColorSelector implements Predicate {
27 | private final DyeColor color;
28 |
29 | public ColorSelector(DyeColor color) {
30 | super();
31 | this.color = color;
32 | }
33 |
34 | @Override
35 | public boolean test(Entity var1) {
36 | if (var1 instanceof WolfEntity) {
37 | return ((WolfEntity) var1).getCollarColor() == color;
38 | } else if (var1 instanceof SheepEntity) {
39 | return ((SheepEntity) var1).getFleeceColor() == color;
40 | } else {
41 | return false;
42 | }
43 | }
44 |
45 | @Override
46 | public String toString() {
47 | return "ColorSelector [color=" + color + "]";
48 | }
49 |
50 | }
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/task/ThrowFishingRodTask.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.task;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 | import net.famzangl.minecraft.minebot.ai.tools.ToolRater;
21 | import net.famzangl.minecraft.minebot.settings.MinebotSettings;
22 |
23 | public class ThrowFishingRodTask extends AITask {
24 |
25 | private int time = 4;
26 |
27 | @Override
28 | public boolean isFinished(AIHelper aiHelper) {
29 | return aiHelper.getMinecraft().player.fishingBobber != null && time < 1;
30 | }
31 |
32 | @Override
33 | public void runTick(AIHelper aiHelper, TaskOperations taskOperations) {
34 | ToolRater settings = MinebotSettings.getSettings().getFishingRater();
35 | if (aiHelper.selectToolFor(null, settings).wasSuccessful()) {
36 | time--;
37 | if (time == 2) {
38 | aiHelper.overrideUseItem();
39 | }
40 | }
41 | }
42 |
43 | @Override
44 | public int getGameTickTimeout(AIHelper helper) {
45 | return 40;
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/scanner/SameItemFilter.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.scanner;
18 |
19 | import net.famzangl.minecraft.minebot.ai.ItemFilter;
20 | import net.minecraft.item.ItemStack;
21 |
22 | /**
23 | * Filters for items that have the same type as the given item stack.
24 | *
25 | * @author michael
26 | *
27 | */
28 | public final class SameItemFilter implements ItemFilter {
29 | private final ItemStack displayed;
30 |
31 | public SameItemFilter(ItemStack displayed) {
32 | this.displayed = displayed;
33 | }
34 |
35 | @Override
36 | public boolean matches(ItemStack itemStack) {
37 | if (itemStack == null) {
38 | return false;
39 | } else if (itemStack.getItem() != displayed.getItem()) {
40 | return false;
41 | } else if (!ItemStack.areItemStackTagsEqual(itemStack, displayed)) {
42 | return false;
43 | }
44 | return true;
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | return "SameItemFilter [displayed=" + displayed + "]";
50 | }
51 |
52 | }
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/build/reverse/ReverseBuildField.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.build.reverse;
18 |
19 | import net.minecraft.block.Block;
20 | import net.minecraft.util.math.BlockPos;
21 |
22 | /**
23 | * A field where all tasks from the build reverser are stored.
24 | *
25 | * @author michael
26 | *
27 | */
28 | public class ReverseBuildField {
29 | private final Block[][][] buildBlocks;
30 | private final TaskDescription[][][] buildNames;
31 |
32 | public ReverseBuildField(int lx, int ly, int lz) {
33 | buildBlocks = new Block[lx][ly][lz];
34 | buildNames = new TaskDescription[lx][ly][lz];
35 | }
36 |
37 | public void setBlockAt(BlockPos relativePos, Block block,
38 | TaskDescription taskString) {
39 | buildBlocks[relativePos.getX()][relativePos.getY()][relativePos.getZ()] = block;
40 | buildNames[relativePos.getX()][relativePos.getY()][relativePos.getZ()] = taskString;
41 | }
42 |
43 | public Block getBlock(int x, int y, int z) {
44 | return buildBlocks[x][y][z];
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/commands/CommandUngrab.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.commands;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 | import net.famzangl.minecraft.minebot.ai.command.AICommand;
21 | import net.famzangl.minecraft.minebot.ai.command.AICommandInvocation;
22 | import net.famzangl.minecraft.minebot.ai.command.AICommandParameter;
23 | import net.famzangl.minecraft.minebot.ai.command.ParameterType;
24 | import net.famzangl.minecraft.minebot.ai.strategy.AIStrategy;
25 |
26 | @AICommand(helpText = "Ungrabs the mouse cursor\n"
27 | + "The bot can then still run while you do other things on your computer.\n"
28 | + "Just click in the window to re-grab the mouse.", name = "minebot")
29 | public class CommandUngrab {
30 |
31 | @AICommandInvocation()
32 | public static AIStrategy run(
33 | AIHelper helper,
34 | @AICommandParameter(type = ParameterType.FIXED, fixedName = "ungrab", description = "") String nameArg) {
35 | helper.ungrab();
36 | return null;
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/commands/CommandPause.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.commands;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 | import net.famzangl.minecraft.minebot.ai.command.AICommand;
21 | import net.famzangl.minecraft.minebot.ai.command.AICommandInvocation;
22 | import net.famzangl.minecraft.minebot.ai.command.AICommandParameter;
23 | import net.famzangl.minecraft.minebot.ai.command.ParameterType;
24 | import net.famzangl.minecraft.minebot.ai.strategy.AIStrategy;
25 | import net.famzangl.minecraft.minebot.ai.strategy.PauseStrategy;
26 |
27 | @AICommand(helpText = "Pause a given time (in seconds).", name = "minebot")
28 | public class CommandPause {
29 | @AICommandInvocation()
30 | public static AIStrategy run(
31 | AIHelper helper,
32 | @AICommandParameter(type = ParameterType.FIXED, fixedName = "pause", description = "") String nameArg,
33 | @AICommandParameter(type = ParameterType.NUMBER, description = "Time (in seconds)") int time) {
34 | return new PauseStrategy(time);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/path/AlongTrackPathFinder.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.path;
18 |
19 | public class AlongTrackPathFinder extends MovePathFinder {
20 | protected final int dx;
21 | protected final int dz;
22 | protected final int cx;
23 | protected final int cy;
24 | protected final int cz;
25 | protected final int length;
26 |
27 | public AlongTrackPathFinder(int dx, int dz, int cx, int cy, int cz, int length) {
28 | this.dx = dx;
29 | this.dz = dz;
30 | this.cx = cx;
31 | this.cy = cy;
32 | this.cz = cz;
33 | this.length = length;
34 | }
35 |
36 | protected boolean isOnTrack(int x, int z) {
37 | return (dz != 0 && x == cx && dz * (z - cz) >= 0 || dx != 0 && z == cz
38 | && dx * (x - cx) >= 0) && (length < 0 || getStepNumber(x, z) <= length);
39 | }
40 |
41 | /**
42 | * Only works if (x, y, z) is on track.
43 | *
44 | * @param x
45 | * @param z
46 | * @return
47 | */
48 | protected int getStepNumber(int x, int z) {
49 | return Math.abs(x - cx + z - cz);
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/render/RenderUtils.java:
--------------------------------------------------------------------------------
1 | package net.famzangl.minecraft.minebot.ai.render;
2 |
3 | import com.mojang.blaze3d.matrix.MatrixStack;
4 | import com.mojang.blaze3d.vertex.IVertexBuilder;
5 | import net.minecraft.util.math.AxisAlignedBB;
6 | import net.minecraft.util.math.shapes.VoxelShape;
7 | import net.minecraft.util.math.shapes.VoxelShapes;
8 | import net.minecraft.util.math.vector.Matrix4f;
9 |
10 | public class RenderUtils {
11 | // Just because WorldRenderer#drawVoxelShapeParts ignores color
12 |
13 | public static void drawVoxelShapeParts(MatrixStack matrixStackIn, IVertexBuilder bufferIn, VoxelShape shapeIn, double xIn, double yIn, double zIn, float red, float green, float blue, float alpha) {
14 | for (AxisAlignedBB axisalignedbb : shapeIn.toBoundingBoxList()) {
15 | drawShape(matrixStackIn, bufferIn, axisalignedbb, xIn, yIn, zIn, red, green, blue, alpha);
16 | }
17 | }
18 |
19 | public static void drawShape(MatrixStack matrixStackIn, IVertexBuilder bufferIn, AxisAlignedBB axisalignedbb, double xIn, double yIn, double zIn, float red, float green, float blue, float alpha) {
20 | drawSingleShape(matrixStackIn, bufferIn, VoxelShapes.create(axisalignedbb), xIn, yIn, zIn, red, green, blue, alpha);
21 | }
22 |
23 | private static void drawSingleShape(MatrixStack matrixStackIn, IVertexBuilder bufferIn, VoxelShape shapeIn, double xIn, double yIn, double zIn, float red, float green, float blue, float alpha) {
24 | Matrix4f matrix4f = matrixStackIn.getLast().getMatrix();
25 | shapeIn.forEachEdge((x1, y1, z1, x2, y2, y3) -> {
26 | bufferIn.pos(matrix4f, (float) (x1 + xIn), (float) (y1 + yIn), (float) (z1 + zIn)).color(red, green, blue, alpha).endVertex();
27 | bufferIn.pos(matrix4f, (float) (x2 + xIn), (float) (y2 + yIn), (float) (y3 + zIn)).color(red, green, blue, alpha).endVertex();
28 | });
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/command/StackBuilder.java:
--------------------------------------------------------------------------------
1 | package net.famzangl.minecraft.minebot.ai.command;
2 |
3 | import net.famzangl.minecraft.minebot.ai.strategy.AIStrategy;
4 | import net.famzangl.minecraft.minebot.ai.strategy.StackStrategy;
5 | import net.famzangl.minecraft.minebot.ai.strategy.StrategyStack;
6 |
7 | import java.util.ArrayList;
8 |
9 | /**
10 | * Schedule a stack of strategies and start using them
11 | */
12 | public class StackBuilder {
13 |
14 | private boolean collecting;
15 | private ArrayList collected = new ArrayList<>();
16 | private SafeStrategyRule hardestSafeRule = SafeStrategyRule.NONE;
17 |
18 | public void startCollecting() {
19 | this.collecting = true;
20 | collected.clear();
21 | hardestSafeRule = SafeStrategyRule.NONE;
22 | }
23 |
24 | public boolean collect(AIStrategy strategy, SafeStrategyRule rule) {
25 | if (collecting) {
26 | collected.add(strategy);
27 | if (rule.ordinal() > hardestSafeRule.ordinal()) {
28 | hardestSafeRule = rule;
29 | }
30 | return true;
31 | } else {
32 | return false;
33 | }
34 | }
35 |
36 | public AIStrategy getStrategy() {
37 | collecting = false;
38 | StrategyStack stack = new StrategyStack();
39 | collected.forEach(stack::addStrategy);
40 |
41 | collected.clear(); // < to save memory
42 | return new StackStrategy(stack);
43 | }
44 |
45 | public void abort() {
46 | collecting = false;
47 | collected.clear(); // < to save memory
48 | }
49 |
50 | public boolean hasCollectedAnyStrategies() {
51 | return !collected.isEmpty();
52 | }
53 |
54 | public boolean isCollecting() {
55 | return collecting;
56 | }
57 |
58 | public SafeStrategyRule getSafeRule() {
59 | return hardestSafeRule;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/path/MineSinglePathFinder.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.path;
18 |
19 | import net.famzangl.minecraft.minebot.ai.path.world.BlockFloatMap;
20 | import net.famzangl.minecraft.minebot.ai.path.world.BlockSet;
21 | import net.minecraft.block.BlockState;
22 | import net.minecraft.util.Direction;
23 |
24 | public class MineSinglePathFinder extends MinePathfinder {
25 |
26 | private final BlockSet blocks;
27 |
28 | public MineSinglePathFinder(BlockSet blocks, Direction preferedDirection,
29 | int preferedLayer) {
30 | super(preferedDirection, preferedLayer);
31 | this.blocks = blocks;
32 | }
33 |
34 | @Override
35 | protected BlockFloatMap getFactorProvider() {
36 | BlockFloatMap map = new BlockFloatMap();
37 | for (BlockState block : blocks) {
38 | map.set(block, 1);
39 | }
40 | map.setDefault(0);
41 | return map;
42 | }
43 |
44 | @Override
45 | protected BlockFloatMap getPointsProvider() {
46 | BlockFloatMap map = new BlockFloatMap();
47 | map.setDefault(0);
48 | return map;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/commands/CommandRun.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.commands;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 | import net.famzangl.minecraft.minebot.ai.command.AICommand;
21 | import net.famzangl.minecraft.minebot.ai.command.AICommandInvocation;
22 | import net.famzangl.minecraft.minebot.ai.command.AICommandParameter;
23 | import net.famzangl.minecraft.minebot.ai.command.ParameterType;
24 | import net.famzangl.minecraft.minebot.ai.strategy.AIStrategy;
25 | import net.famzangl.minecraft.minebot.ai.strategy.RunFileStrategy;
26 |
27 | import java.io.File;
28 |
29 | @AICommand(helpText = "Run commands from a file.", name = "minebot")
30 | public class CommandRun {
31 |
32 | @AICommandInvocation()
33 | public static AIStrategy run(
34 | AIHelper helper,
35 | @AICommandParameter(type = ParameterType.FIXED, fixedName = "run", description = "") String nameArg,
36 | @AICommandParameter(type = ParameterType.FILE, relativeToSettingsFile = "scripts", description = "") File file) {
37 | return new RunFileStrategy(file);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/AimBow/src/net/famzangl/minecraft/aimbow/Pos2.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.aimbow;
18 |
19 | public class Pos2 {
20 | public final int x;
21 | public final int y;
22 |
23 | public Pos2(int x, int y) {
24 | super();
25 | this.x = x;
26 | this.y = y;
27 | }
28 |
29 | @Override
30 | public int hashCode() {
31 | final int prime = 31;
32 | int result = 1;
33 | result = prime * result + x;
34 | result = prime * result + y;
35 | return result;
36 | }
37 |
38 | @Override
39 | public boolean equals(Object obj) {
40 | if (this == obj)
41 | return true;
42 | if (obj == null)
43 | return false;
44 | if (getClass() != obj.getClass())
45 | return false;
46 | Pos2 other = (Pos2) obj;
47 | if (x != other.x)
48 | return false;
49 | if (y != other.y)
50 | return false;
51 | return true;
52 | }
53 |
54 | @Override
55 | public String toString() {
56 | return "Pos2 [x=" + x + ", y=" + y + "]";
57 | }
58 |
59 | public double distanceTo(Pos2 onScreen) {
60 | return Math.sqrt((x - onScreen.x) * (x - onScreen.x) + (y - onScreen.y)
61 | * (y - onScreen.y));
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/commands/CommandLoad.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.commands;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 | import net.famzangl.minecraft.minebot.ai.command.AICommand;
21 | import net.famzangl.minecraft.minebot.ai.command.AICommandInvocation;
22 | import net.famzangl.minecraft.minebot.ai.command.AICommandParameter;
23 | import net.famzangl.minecraft.minebot.ai.command.ParameterType;
24 | import net.famzangl.minecraft.minebot.ai.strategy.AIStrategy;
25 | import net.famzangl.minecraft.minebot.ai.strategy.RunFileStrategy;
26 |
27 | import java.io.File;
28 |
29 | @AICommand(helpText = "Run build commands from a file.", name = "minebuild")
30 | public class CommandLoad {
31 |
32 | @AICommandInvocation()
33 | public static AIStrategy run(
34 | AIHelper helper,
35 | @AICommandParameter(type = ParameterType.FIXED, fixedName = "load", description = "") String nameArg,
36 | @AICommandParameter(type = ParameterType.FILE, relativeToSettingsFile = "build", description = "") File file) {
37 | return new RunFileStrategy(file);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/commands/CommandLookAt.java:
--------------------------------------------------------------------------------
1 | package net.famzangl.minecraft.minebot.ai.commands;
2 |
3 | import net.famzangl.minecraft.minebot.ai.AIHelper;
4 | import net.famzangl.minecraft.minebot.ai.command.AICommand;
5 | import net.famzangl.minecraft.minebot.ai.command.AICommandInvocation;
6 | import net.famzangl.minecraft.minebot.ai.command.AICommandParameter;
7 | import net.famzangl.minecraft.minebot.ai.command.ParameterType;
8 | import net.famzangl.minecraft.minebot.ai.strategy.AIStrategy;
9 | import net.famzangl.minecraft.minebot.ai.strategy.LookAtStrategy;
10 | import net.minecraft.util.Direction;
11 | import net.minecraft.util.math.vector.Vector3d;
12 |
13 | @AICommand(name = "minebot", helpText = "Look at a given position")
14 | public class CommandLookAt {
15 | @AICommandInvocation()
16 | public static AIStrategy run(
17 | AIHelper helper,
18 | @AICommandParameter(type = ParameterType.FIXED, fixedName = "look", description = "") String nameArg,
19 | @AICommandParameter(type = ParameterType.DOUBLE, description = "x") Double x,
20 | @AICommandParameter(type = ParameterType.DOUBLE, description = "y") Double y,
21 | @AICommandParameter(type = ParameterType.DOUBLE, description = "z") Double z) {
22 | return run(helper, new Vector3d(x, y, z));
23 | }
24 |
25 | @AICommandInvocation()
26 | public static AIStrategy run(
27 | AIHelper helper,
28 | @AICommandParameter(type = ParameterType.FIXED, fixedName = "look", description = "") String nameArg,
29 | @AICommandParameter(type = ParameterType.ENUM, description = "direction") Direction direction) {
30 | Vector3d offset = new Vector3d(direction.getXOffset(),
31 | direction.getYOffset()
32 | + helper.getMinecraft().player.getEyeHeight(),
33 | direction.getZOffset());
34 | return run(helper,
35 | helper.getWorld().getExactPlayerPosition().add(offset));
36 | }
37 |
38 | private static LookAtStrategy run(AIHelper helper, Vector3d vec3) {
39 | return new LookAtStrategy(vec3);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/commands/CommandThrow.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.commands;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 | import net.famzangl.minecraft.minebot.ai.command.AICommand;
21 | import net.famzangl.minecraft.minebot.ai.command.AICommandInvocation;
22 | import net.famzangl.minecraft.minebot.ai.command.AICommandParameter;
23 | import net.famzangl.minecraft.minebot.ai.command.ParameterType;
24 | import net.famzangl.minecraft.minebot.ai.strategy.AIStrategy;
25 | import net.famzangl.minecraft.minebot.ai.strategy.ThrowStrategy;
26 | import net.famzangl.minecraft.minebot.ai.strategy.ThrowStrategy.ThrowableThing;
27 |
28 | @AICommand(helpText = "Throw something.", name = "minebot")
29 | public class CommandThrow {
30 | @AICommandInvocation()
31 | public static AIStrategy run(
32 | AIHelper helper,
33 | @AICommandParameter(type = ParameterType.FIXED, fixedName = "throw", description = "") String nameArg,
34 | @AICommandParameter(type = ParameterType.ENUM, description = "what to throw") ThrowableThing what) {
35 | return new ThrowStrategy(what);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/task/inventory/PutInChestTask.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.task.inventory;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 | import net.minecraft.client.gui.screen.inventory.ChestScreen;
21 |
22 | /**
23 | * Put one inventory slot in the chest that is currently open.
24 | *
25 | * @author michael
26 | *
27 | */
28 | public class PutInChestTask extends PutItemInContainerTask {
29 | private final int inventorySlot;
30 |
31 | /**
32 | * Puts the given item in the current chest.
33 | *
34 | * @param inventorySlot
35 | */
36 | public PutInChestTask(int inventorySlot) {
37 | this.inventorySlot = inventorySlot;
38 |
39 | }
40 |
41 | @Override
42 | protected int getStackToPut(AIHelper aiHelper) {
43 | ChestScreen screen = (ChestScreen) aiHelper.getMinecraft().currentScreen;
44 | int slots = screen.getContainer().inventorySlots.size();
45 | int iSlot;
46 | if (inventorySlot < 9) {
47 | iSlot = inventorySlot + 3 * 9;
48 | } else {
49 | iSlot = inventorySlot - 9;
50 | }
51 | return iSlot + (slots - 9 * 4);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/strategy/RunOnceStrategy.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.strategy;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 |
21 | /**
22 | * A strategy that only needs to be run for exactly one game tick.
23 | *
24 | * @author michael
25 | *
26 | */
27 | public abstract class RunOnceStrategy extends AIStrategy {
28 |
29 | private boolean wasRun = false;
30 |
31 | @Override
32 | protected TickResult onGameTick(AIHelper helper) {
33 | if (!wasRun) {
34 | wasRun = true;
35 | return this.doSingleRun(helper);
36 | }
37 | return TickResult.NO_MORE_WORK;
38 | }
39 |
40 | protected TickResult doSingleRun(AIHelper helper) {
41 | this.singleRun(helper);
42 | return TickResult.NO_MORE_WORK;
43 | }
44 |
45 | /**
46 | * The code that should be run once. If you want to modify game state in
47 | * this method, use {@link RunOneTickStrategy}.
48 | *
49 | * @param helper
50 | */
51 | protected abstract void singleRun(AIHelper helper);
52 |
53 | @Override
54 | public boolean checkShouldTakeOver(AIHelper helper) {
55 | return !wasRun;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/path/GoToPathfinderDestructive.java:
--------------------------------------------------------------------------------
1 | package net.famzangl.minecraft.minebot.ai.path;
2 |
3 | import net.famzangl.minecraft.minebot.ai.command.AIChatController;
4 | import net.famzangl.minecraft.minebot.ai.path.world.WorldData;
5 | import net.famzangl.minecraft.minebot.ai.utils.BlockArea;
6 | import net.minecraft.util.math.BlockPos;
7 | import org.apache.logging.log4j.LogManager;
8 | import org.apache.logging.log4j.Logger;
9 |
10 | /**
11 | * Same as the {@link GoToPathfinder}, digging instead of walking
12 | */
13 | public class GoToPathfinderDestructive extends MovePathFinder {
14 | private static final Logger LOGGER = LogManager.getLogger(GoToPathfinder.class);
15 |
16 | private final BlockPos destination;
17 | private BlockArea targetArea;
18 |
19 | public GoToPathfinderDestructive(BlockPos destination) {
20 | this.destination = destination;
21 | }
22 |
23 | @Override
24 | protected boolean runSearch(BlockPos playerPosition) {
25 | if (playerPosition.equals(destination)) {
26 | return true;
27 | }
28 |
29 | targetArea = GoToPathfinder.computeTargetArea(playerPosition, destination);
30 | LOGGER.debug("Destructive pathfind target area is: {}", targetArea);
31 | return super.runSearch(playerPosition);
32 | }
33 |
34 | @Override
35 | protected float rateDestination(int distance, int x, int y, int z) {
36 | return targetArea.contains(world, x, y, z) ? distance : -1;
37 | }
38 |
39 | @Override
40 | protected void noPathFound() {
41 | if (statsVisited < 50) {
42 | AIChatController.addChatLine("Cannot reach destination. Cannot go far from start position.");
43 | }
44 | }
45 |
46 | @Override
47 | public String toString() {
48 | return "GoToPathfinderDestructive{" +
49 | "destination=" + destination +
50 | ", targetArea=" + targetArea +
51 | '}';
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/command/DoubleNameBuilder.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.command;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 |
21 | import java.util.ArrayList;
22 |
23 | public class DoubleNameBuilder extends ParameterBuilder {
24 |
25 | public DoubleNameBuilder(AICommandParameter annot) {
26 | super(annot);
27 | }
28 |
29 | @Override
30 | public void addArguments(ArrayList list) {
31 | list.add(new ArgumentDefinition("Number", annot.description()) {
32 | @Override
33 | public boolean couldEvaluateAgainst(String string) {
34 | return string.matches("^[+-]?(\\d+\\.?\\d*|\\.\\d+)([eE]-?\\d+)?$");
35 | }
36 | });
37 | }
38 |
39 | @Override
40 | public Object getParameter(AIHelper helper, String[] arguments) {
41 | return Double.parseDouble(arguments[0]);
42 | }
43 |
44 | @Override
45 | public boolean isTypeValid(Class> class1) {
46 | return super.isTypeValid(class1) || (class1 == Double.TYPE && !isOptional());
47 | }
48 |
49 | @Override
50 | protected Class> getRequiredParameterClass() {
51 | return Double.class;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/render/CuboidDebugRenderer.java:
--------------------------------------------------------------------------------
1 | package net.famzangl.minecraft.minebot.ai.render;
2 |
3 | import com.mojang.blaze3d.matrix.MatrixStack;
4 | import com.mojang.blaze3d.vertex.IVertexBuilder;
5 | import net.famzangl.minecraft.minebot.ai.utils.BlockCuboid;
6 | import net.minecraft.client.renderer.IRenderTypeBuffer;
7 | import net.minecraft.client.renderer.RenderType;
8 | import net.minecraft.client.renderer.WorldRenderer;
9 | import net.minecraft.client.renderer.debug.DebugRenderer;
10 | import net.minecraft.util.math.AxisAlignedBB;
11 | import net.minecraft.util.math.shapes.VoxelShape;
12 | import net.minecraft.util.math.shapes.VoxelShapes;
13 |
14 | import javax.annotation.ParametersAreNonnullByDefault;
15 | import java.util.function.Supplier;
16 |
17 | @ParametersAreNonnullByDefault
18 | public class CuboidDebugRenderer implements DebugRenderer.IDebugRenderer {
19 |
20 | public static final double EXPAND = .02;
21 | private final Supplier> pos;
22 | private final float r;
23 | private final float g;
24 | private final float b;
25 |
26 | public CuboidDebugRenderer(Supplier> pos, float r, float g, float b) {
27 | this.pos = pos;
28 | this.r = r;
29 | this.g = g;
30 | this.b = b;
31 | }
32 |
33 | @Override
34 | public void render(MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, double camX, double camY, double camZ) {
35 | IVertexBuilder ivertexbuilder = bufferIn.getBuffer(RenderType.getLines());
36 | BlockCuboid> pos = this.pos.get();
37 | if (pos != null) {
38 | AxisAlignedBB box = new AxisAlignedBB(pos.getMin().getX() - EXPAND, pos.getMin().getY() - EXPAND, pos.getMin().getZ() - EXPAND,
39 | pos.getMax().getX() + 1 + EXPAND, pos.getMax().getY() + 1 + EXPAND, pos.getMax().getZ() + 1 + EXPAND);
40 |
41 | RenderUtils.drawShape(matrixStackIn, ivertexbuilder, box, -camX, -camY, -camZ, r, g, b, 1.0F);
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/settings/serialize/ToolRaterAdapter.java:
--------------------------------------------------------------------------------
1 | package net.famzangl.minecraft.minebot.settings.serialize;
2 |
3 | import com.google.gson.JsonDeserializationContext;
4 | import com.google.gson.JsonDeserializer;
5 | import com.google.gson.JsonElement;
6 | import com.google.gson.JsonObject;
7 | import com.google.gson.JsonParseException;
8 | import com.google.gson.JsonSerializationContext;
9 | import com.google.gson.JsonSerializer;
10 | import net.famzangl.minecraft.minebot.ai.path.world.BlockFloatMap;
11 | import net.famzangl.minecraft.minebot.ai.tools.ToolRater;
12 | import net.famzangl.minecraft.minebot.ai.tools.rate.Rater;
13 |
14 | import java.lang.reflect.Type;
15 | import java.util.Map.Entry;
16 |
17 | public class ToolRaterAdapter implements JsonSerializer,
18 | JsonDeserializer {
19 |
20 | @Override
21 | public ToolRater deserialize(JsonElement json, Type typeOfT,
22 | JsonDeserializationContext context) throws JsonParseException {
23 | try {
24 | JsonObject obj = json.getAsJsonObject();
25 | ToolRater rater = new ToolRater();
26 | for (Entry e : obj.entrySet()) {
27 | BlockFloatMap map;
28 | if (e.getValue().isJsonPrimitive()) {
29 | map = new BlockFloatMap();
30 | map.setDefault(e.getValue().getAsFloat());
31 | } else {
32 | map = context. deserialize(e.getValue(),
33 | BlockFloatMap.class);
34 | }
35 | rater.addRater(e.getKey(), map);
36 | }
37 | return rater;
38 | } catch (IllegalArgumentException t) {
39 | throw new JsonParseException("Error creating rater: "
40 | + t.getMessage(), t);
41 | }
42 | }
43 |
44 | @Override
45 | public JsonElement serialize(ToolRater src, Type typeOfSrc,
46 | JsonSerializationContext context) {
47 | JsonObject obj = new JsonObject();
48 | for (Rater rater : src.getRaters()) {
49 | obj.add(rater.getName(),
50 | context.serialize(rater.getValues(), BlockFloatMap.class));
51 | }
52 |
53 | return obj;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/task/move/SneakTowardsTask.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * This file is part of Minebot.
3 | *
4 | * Minebot is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Minebot is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Minebot. If not, see .
16 | *******************************************************************************/
17 | package net.famzangl.minecraft.minebot.ai.task.move;
18 |
19 | import net.famzangl.minecraft.minebot.ai.AIHelper;
20 | import net.famzangl.minecraft.minebot.ai.task.AITask;
21 | import net.famzangl.minecraft.minebot.ai.task.TaskOperations;
22 | import net.minecraft.util.Direction;
23 |
24 | /**
25 | * Sneak standing on (x, y - 1, z) towards the direction, so that we are
26 | * standing on the edge of the block.
27 | *
28 | * @author michael
29 | *
30 | */
31 | public class SneakTowardsTask extends AITask {
32 | private final int x;
33 | private final int y;
34 | private final int z;
35 | private final Direction dir;
36 |
37 | public SneakTowardsTask(int x, int y, int z, Direction dir) {
38 | this.x = x;
39 | this.y = y;
40 | this.z = z;
41 | this.dir = dir;
42 | }
43 |
44 | @Override
45 | public boolean isFinished(AIHelper aiHelper) {
46 | // TODO Auto-generated method stub
47 | return false;
48 | }
49 |
50 | @Override
51 | public void runTick(AIHelper aiHelper, TaskOperations taskOperations) {
52 | // TODO Auto-generated method stub
53 |
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------