├── logs ├── debug.log └── latest.log ├── AimBow ├── .gitignore ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── resources │ └── mcmod.info ├── .classpath ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs └── src │ └── net │ └── famzangl │ └── minecraft │ └── aimbow │ ├── aiming │ ├── CloseEntityAimer.java │ └── ColissionData.java │ ├── AimBowMod.java │ └── Pos2.java ├── doc-files ├── aimbow-hit.png ├── aimbow-miss.png ├── plant-done.png ├── plant-field.png ├── plant-grown.png ├── plant replant.png ├── plant-progress.png └── aimbow-hit-hard-to-see.png ├── Minebot ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── src │ └── main │ │ ├── resources │ │ ├── net │ │ │ └── famzangl │ │ │ │ └── minecraft │ │ │ │ └── minebot │ │ │ │ ├── settings │ │ │ │ └── minebot │ │ │ │ │ ├── scripts │ │ │ │ │ ├── ping.js │ │ │ │ │ └── feed-kill-sheep.js │ │ │ │ │ └── build │ │ │ │ │ ├── blocks.build │ │ │ │ │ └── stairs.build │ │ │ │ ├── map │ │ │ │ ├── icon.png │ │ │ │ ├── icon-death.png │ │ │ │ ├── icon-underground.png │ │ │ │ └── icon-death-underground.png │ │ │ │ └── ai │ │ │ │ └── tools │ │ │ │ └── tools.json │ │ ├── pack.mcmeta │ │ └── META-INF │ │ │ └── mods.toml │ │ └── java │ │ └── net │ │ └── famzangl │ │ └── minecraft │ │ └── minebot │ │ ├── map │ │ ├── IconType.java │ │ ├── PlayerPositionLabel.java │ │ └── MapContextMenu.java │ │ ├── settings │ │ ├── ClampedFloat.java │ │ ├── ConstrainedBlockFloat.java │ │ ├── MinebotSettingObject.java │ │ ├── MinebotSettingsRoot.java │ │ ├── SaferuleSettings.java │ │ ├── PathfindingSetting.java │ │ └── serialize │ │ │ └── ToolRaterAdapter.java │ │ ├── ai │ │ ├── net │ │ │ ├── ChunkListener.java │ │ │ ├── NetworkHelper.java │ │ │ └── PersistentChat.java │ │ ├── blockmap │ │ │ ├── ChunkCubeProvider.java │ │ │ ├── LocalChunkBitset.java │ │ │ ├── BlockCubeCounter.java │ │ │ └── ChunkCubeHashMap.java │ │ ├── strategy │ │ │ ├── RunOneTickStrategy.java │ │ │ ├── crafting │ │ │ │ └── CraftingPossibility.java │ │ │ ├── LookAtStrategy.java │ │ │ ├── StopOnConditionStrategy.java │ │ │ ├── StopStrategy.java │ │ │ ├── RespawnStrategy.java │ │ │ ├── DamageTakenStrategy.java │ │ │ ├── BuildWayStrategy.java │ │ │ ├── CreeperComesActionStrategy.java │ │ │ ├── CloseEntityActionStrategy.java │ │ │ ├── PlayerComesActionStrategy.java │ │ │ ├── TimeStrategy.java │ │ │ ├── NoneOfFilter.java │ │ │ ├── AbortOnDeathStrategy.java │ │ │ ├── FishStrategy.java │ │ │ └── RunOnceStrategy.java │ │ ├── path │ │ │ ├── world │ │ │ │ └── BlockIds.md │ │ │ ├── TaskReceiver.java │ │ │ ├── AlongTrackPathFinder.java │ │ │ ├── MineSinglePathFinder.java │ │ │ └── GoToPathfinderDestructive.java │ │ ├── task │ │ │ ├── RunOnceTask.java │ │ │ ├── ConditionalWaitTask.java │ │ │ ├── BlockHalf.java │ │ │ ├── error │ │ │ │ ├── StrategyDeactivatedError.java │ │ │ │ └── TaskError.java │ │ │ ├── CanWorkWhileApproaching.java │ │ │ ├── SkipWhenSearchingPrefetch.java │ │ │ ├── place │ │ │ │ └── DestroyBlockTask.java │ │ │ ├── DestroyLogInRange.java │ │ │ ├── inventory │ │ │ │ ├── PutInInventoryCraftingSlotTask.java │ │ │ │ └── PutInChestTask.java │ │ │ ├── UseItemOnBlockTask.java │ │ │ ├── TaskOperations.java │ │ │ ├── ThrowFishingRodTask.java │ │ │ └── move │ │ │ │ └── SneakTowardsTask.java │ │ ├── tools │ │ │ └── rate │ │ │ │ ├── FilterRater.java │ │ │ │ ├── NotRater.java │ │ │ │ ├── MatchesRater.java │ │ │ │ ├── MultiplyEnchantmentRater.java │ │ │ │ ├── OrRater.java │ │ │ │ ├── AndRater.java │ │ │ │ ├── EnchantmentRater.java │ │ │ │ └── Rater.java │ │ ├── utils │ │ │ ├── BlockAreaEmpty.java │ │ │ ├── BlockMapper.java │ │ │ ├── BlockFilteredArea.java │ │ │ ├── BlockPosList.java │ │ │ ├── BlockCounter.java │ │ │ ├── AreaUnion.java │ │ │ ├── RandUtils.java │ │ │ ├── AbstractFilteredArea.java │ │ │ ├── BlockUtils.java │ │ │ ├── ReverseAcceptingArea.java │ │ │ ├── AreaIntersection.java │ │ │ └── BlockArea.java │ │ ├── commands │ │ │ ├── CommandResume.java │ │ │ ├── CommandStats.java │ │ │ ├── CommandWalk.java │ │ │ ├── CommandEat.java │ │ │ ├── CommandStore.java │ │ │ ├── CommandRespawn.java │ │ │ ├── CommandFish.java │ │ │ ├── CommandUngrab.java │ │ │ ├── CommandPause.java │ │ │ ├── CommandRun.java │ │ │ ├── CommandLoad.java │ │ │ ├── CommandLookAt.java │ │ │ └── CommandThrow.java │ │ ├── scripting │ │ │ ├── ChatMessage.java │ │ │ ├── StrategyFailedException.java │ │ │ └── WrappedBlockPos.java │ │ ├── PathFinderFieldData.java │ │ ├── AIStrategyFactory.java │ │ ├── command │ │ │ ├── ParameterType.java │ │ │ ├── AICommandInvocation.java │ │ │ ├── CommandEvaluationException.java │ │ │ ├── OptionalParameterBuilder.java │ │ │ ├── AIHelperBuilder.java │ │ │ ├── AICommand.java │ │ │ ├── StringNameBuilder.java │ │ │ ├── StackBuilder.java │ │ │ └── DoubleNameBuilder.java │ │ ├── render │ │ │ ├── StrategyStackRenderer.java │ │ │ ├── ActiveStrategyRenderer.java │ │ │ ├── PosMarkerRenderer.java │ │ │ ├── RenderUtils.java │ │ │ └── CuboidDebugRenderer.java │ │ ├── HumanReadableItemFilter.java │ │ ├── selectors │ │ │ ├── ItemSelector.java │ │ │ ├── XPOrbSelector.java │ │ │ ├── OneOfListSelector.java │ │ │ ├── IsSittingSelector.java │ │ │ └── ColorSelector.java │ │ ├── UngrabScreen.java │ │ ├── enchanting │ │ │ ├── PutLapisInTableTask.java │ │ │ ├── TakeEnchantedItemTask.java │ │ │ ├── CloseScreenTask.java │ │ │ ├── ClickOnEnchantmentTable.java │ │ │ └── KillAnyMobTask.java │ │ ├── ClassItemFilter.java │ │ └── scanner │ │ │ ├── BlockRangeFinder.java │ │ │ └── SameItemFilter.java │ │ ├── build │ │ ├── reverse │ │ │ ├── factories │ │ │ │ ├── BlockBuildTaskFactory.java │ │ │ │ ├── SlabBuildTaskFactory.java │ │ │ │ ├── LogBuildTaskFactory.java │ │ │ │ ├── AbstractBuildTaskFactory.java │ │ │ │ ├── StairBuildTaskFactory.java │ │ │ │ └── BuildTaskFactories.java │ │ │ ├── UnsupportedBlockException.java │ │ │ ├── TaskDescription.java │ │ │ └── ReverseBuildField.java │ │ └── blockbuild │ │ │ ├── MirrorDirection.java │ │ │ └── BuildFlatOnGroundTask.java │ │ └── stats │ │ └── StatsWindow.java └── .idea │ ├── .gitignore │ └── runConfigurations │ └── runClient.xml ├── .idea ├── vcs.xml ├── .gitignore ├── modules.xml ├── minebot.iml ├── misc.xml ├── gradle.xml └── jarRepositories.xml ├── .github └── ISSUE_TEMPLATE │ ├── usage-question.md │ └── bug_report.md ├── .gitignore └── release.sh /logs/debug.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /logs/latest.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /AimBow/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | .gradle 3 | -------------------------------------------------------------------------------- /doc-files/aimbow-hit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelzangl/minebot/HEAD/doc-files/aimbow-hit.png -------------------------------------------------------------------------------- /doc-files/aimbow-miss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelzangl/minebot/HEAD/doc-files/aimbow-miss.png -------------------------------------------------------------------------------- /doc-files/plant-done.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelzangl/minebot/HEAD/doc-files/plant-done.png -------------------------------------------------------------------------------- /doc-files/plant-field.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelzangl/minebot/HEAD/doc-files/plant-field.png -------------------------------------------------------------------------------- /doc-files/plant-grown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelzangl/minebot/HEAD/doc-files/plant-grown.png -------------------------------------------------------------------------------- /doc-files/plant replant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelzangl/minebot/HEAD/doc-files/plant replant.png -------------------------------------------------------------------------------- /doc-files/plant-progress.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelzangl/minebot/HEAD/doc-files/plant-progress.png -------------------------------------------------------------------------------- /doc-files/aimbow-hit-hard-to-see.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelzangl/minebot/HEAD/doc-files/aimbow-hit-hard-to-see.png -------------------------------------------------------------------------------- /AimBow/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelzangl/minebot/HEAD/AimBow/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Minebot/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelzangl/minebot/HEAD/Minebot/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Minebot/src/main/resources/net/famzangl/minecraft/minebot/settings/minebot/scripts/ping.js: -------------------------------------------------------------------------------- 1 | // Simple echo example 2 | minescript.displayChat("Pong!"); -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/map/IconType.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.map; 2 | 3 | public enum IconType { 4 | DEFAULT, DEATH 5 | } -------------------------------------------------------------------------------- /Minebot/src/main/resources/pack.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "pack": { 3 | "description": "minebot resources", 4 | "pack_format": 5, 5 | "_comment": "Empty." 6 | } 7 | } -------------------------------------------------------------------------------- /Minebot/src/main/resources/net/famzangl/minecraft/minebot/map/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelzangl/minebot/HEAD/Minebot/src/main/resources/net/famzangl/minecraft/minebot/map/icon.png -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Minebot/src/main/resources/net/famzangl/minecraft/minebot/map/icon-death.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelzangl/minebot/HEAD/Minebot/src/main/resources/net/famzangl/minecraft/minebot/map/icon-death.png -------------------------------------------------------------------------------- /Minebot/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Users should import this as gradle project. So don't include any project structure / dependencies. 2 | # We only include the run configuration 3 | 4 | * 5 | !runConfigurations 6 | !.gitignore -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/settings/ClampedFloat.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.settings; 2 | 3 | public @interface ClampedFloat { 4 | float min(); 5 | float max(); 6 | } 7 | -------------------------------------------------------------------------------- /Minebot/src/main/resources/net/famzangl/minecraft/minebot/map/icon-underground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelzangl/minebot/HEAD/Minebot/src/main/resources/net/famzangl/minecraft/minebot/map/icon-underground.png -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/net/ChunkListener.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.net; 2 | 3 | public interface ChunkListener { 4 | void chunkChanged(int chunkX, int chunkZ); 5 | } 6 | -------------------------------------------------------------------------------- /Minebot/src/main/resources/net/famzangl/minecraft/minebot/map/icon-death-underground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelzangl/minebot/HEAD/Minebot/src/main/resources/net/famzangl/minecraft/minebot/map/icon-death-underground.png -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/blockmap/ChunkCubeProvider.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.blockmap; 2 | 3 | public interface ChunkCubeProvider { 4 | public T getForChunk(int chunkStartX, int chunkStartY, int chunkStartZ); 5 | } 6 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/settings/ConstrainedBlockFloat.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.settings; 2 | 3 | public @interface ConstrainedBlockFloat { 4 | 5 | float min(); 6 | 7 | float max(); 8 | 9 | float defaultValue(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /AimBow/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Jul 02 15:54:47 CDT 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.0-bin.zip 7 | -------------------------------------------------------------------------------- /Minebot/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Apr 11 10:07:11 CEST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/settings/MinebotSettingObject.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.settings; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | 6 | @Retention(RetentionPolicy.RUNTIME) 7 | public @interface MinebotSettingObject { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/usage-question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Usage Question 3 | about: If you know the bot should be able to do something and don't know how 4 | title: '' 5 | labels: question 6 | assignees: '' 7 | 8 | --- 9 | 10 | **What are you trying to achieve** 11 | 12 | FILL IN HERE 13 | 14 | **What have you tried so far** 15 | 16 | FILL IN HERE 17 | -------------------------------------------------------------------------------- /.idea/minebot.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /AimBow/resources/mcmod.info: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "modid": "aimbow-mod", 4 | "name": "AimBow", 5 | "description": "Helps you aiming your bow.", 6 | "version": "${version}", 7 | "mcversion": "${mcversion}", 8 | "url": "", 9 | "updateUrl": "", 10 | "authors": [""], 11 | "credits": "", 12 | "logoFile": "", 13 | "screenshots": [], 14 | "dependencies": [] 15 | } 16 | ] 17 | -------------------------------------------------------------------------------- /AimBow/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /AimBow/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | AimBow 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | 11 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/strategy/RunOneTickStrategy.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.strategy; 2 | 3 | import net.famzangl.minecraft.minebot.ai.AIHelper; 4 | 5 | /** 6 | * Same as the run once strategy but this strategy at least takes one tick to execute. 7 | * @author Michael Zangl 8 | * 9 | */ 10 | public abstract class RunOneTickStrategy extends RunOnceStrategy { 11 | 12 | protected TickResult doSingleRun(AIHelper helper) { 13 | this.singleRun(helper); 14 | return TickResult.TICK_HANDLED; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | 14 | .metadata 15 | Minebot/.gradle 16 | Minebot/bin 17 | Minebot/build 18 | Minebot/config 19 | Minebot/crash-reports 20 | Minebot/logs 21 | Minebot/minebot.properties 22 | Minebot/minebot 23 | Minebot/options.txt 24 | Minebot/saves 25 | Minebot/screenshots 26 | Minecraft/ 27 | Minebot/run 28 | Minebot/gradle 29 | !gradle-wrapper.jar 30 | 31 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/path/world/BlockIds.md: -------------------------------------------------------------------------------- 1 | # Block ID / Helpers 2 | 3 | Minecraft uses BlockState Objects a lot. Although they are a nice abstraction, they are slow. 4 | 5 | This bot needs a very fast test to see if a block is contained in a set of allowed BlockStates 6 | 7 | For this, we use a BlockSet class. It allows fast isIn checks. 8 | 9 | The checks are run against the raw integer data stored in the minecraft world binary files, but BlockSet attempts to abstract this away. 10 | 11 | You can do conversion between BlockState and id using BlockSet.getStateById / BlockSet.getStateId -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/task/RunOnceTask.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.task; 2 | 3 | import net.famzangl.minecraft.minebot.ai.AIHelper; 4 | 5 | public abstract class RunOnceTask extends AITask { 6 | 7 | private boolean run; 8 | 9 | @Override 10 | public boolean isFinished(AIHelper aiHelper) { 11 | return run; 12 | } 13 | 14 | @Override 15 | public void runTick(AIHelper aiHelper, TaskOperations taskOperations) { 16 | runOnce(aiHelper, taskOperations); 17 | run = true; 18 | } 19 | 20 | protected abstract void runOnce(AIHelper aiHelper, TaskOperations taskOperations); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/net/NetworkHelper.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.net; 2 | 3 | import net.minecraft.entity.Entity; 4 | 5 | import java.util.List; 6 | 7 | public interface NetworkHelper { 8 | 9 | void resetFishState(); 10 | 11 | boolean fishIsCaptured(Entity expectedPos); 12 | 13 | void addChunkChangeListener(ChunkListener l); 14 | 15 | void removeChunkChangeListener(ChunkListener l); 16 | 17 | /** 18 | * Gets a list of chat messages received since game start. 19 | * 20 | * @return The list of chat messages. 21 | */ 22 | public List getChatMessages(); 23 | } 24 | -------------------------------------------------------------------------------- /AimBow/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.7 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.source=1.7 12 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/task/ConditionalWaitTask.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.task; 2 | 3 | import net.famzangl.minecraft.minebot.ai.AIHelper; 4 | 5 | public class ConditionalWaitTask extends WaitTask { 6 | public interface WaitCondition { 7 | public boolean shouldWait(); 8 | } 9 | 10 | private WaitCondition condition; 11 | public ConditionalWaitTask(int time, WaitCondition condition) { 12 | super(time); 13 | this.condition = condition; 14 | } 15 | 16 | @Override 17 | public boolean isFinished(AIHelper aiHelper) { 18 | return !condition.shouldWait() || super.isFinished(aiHelper); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/tools/rate/FilterRater.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.tools.rate; 2 | 3 | import net.famzangl.minecraft.minebot.ai.ItemFilter; 4 | import net.famzangl.minecraft.minebot.ai.path.world.BlockFloatMap; 5 | import net.minecraft.item.ItemStack; 6 | 7 | public class FilterRater extends Rater { 8 | protected final ItemFilter filter; 9 | 10 | public FilterRater(ItemFilter filter, String name, BlockFloatMap values) { 11 | super(name, values); 12 | this.filter = filter; 13 | } 14 | 15 | @Override 16 | protected boolean isAppleciable(ItemStack item, int forBlockAndMeta) { 17 | return filter.matches(item); 18 | } 19 | } -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/blockmap/LocalChunkBitset.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.blockmap; 2 | 3 | import java.util.BitSet; 4 | 5 | /** 6 | * This is a 16 x 16 x 16 bitset. 7 | * @author michael 8 | * 9 | */ 10 | public class LocalChunkBitset { 11 | private BitSet bitset = new BitSet(); 12 | 13 | public static int index(int blockX, int blockY, int blockZ) { 14 | return (blockX & 0xf) << 4 | (blockY & 0xf) << 8 | (blockZ & 0xf); 15 | } 16 | 17 | public boolean get(int blockX, int blockY, int blockZ) { 18 | return bitset.get(index(blockX, blockY, blockZ)); 19 | } 20 | 21 | public void set(int blockX, int blockY, int blockZ, boolean val) { 22 | bitset.set(index(blockX, blockY, blockZ), val); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/tools/rate/NotRater.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 class NotRater extends Rater { 7 | private Rater rater; 8 | 9 | public NotRater(BlockFloatMap values, Rater rater) { 10 | super("!" + rater.getName(), values); 11 | this.rater = rater; 12 | } 13 | @Override 14 | protected double getPow(ItemStack item, int forBlockAndMeta) { 15 | return rater.getPow(item, forBlockAndMeta); 16 | } 17 | 18 | 19 | @Override 20 | protected boolean isAppleciable(ItemStack item, int forBlockAndMeta) { 21 | return !rater.isAppleciable(item, forBlockAndMeta); 22 | } 23 | } -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/utils/BlockAreaEmpty.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.utils; 2 | 3 | import net.famzangl.minecraft.minebot.ai.path.world.WorldData; 4 | 5 | /** 6 | * An area that is empty. 7 | * 8 | * @author Michael Zangl 9 | * 10 | */ 11 | public class BlockAreaEmpty extends BlockArea { 12 | public static final BlockAreaEmpty INSTANCE = new BlockAreaEmpty(); 13 | 14 | public BlockAreaEmpty() { 15 | } 16 | 17 | @Override 18 | public boolean contains(WorldData world, int x, int y, int z) { 19 | return false; 20 | } 21 | 22 | @Override 23 | public void accept(AreaVisitor visitor, WorldT2 world) { 24 | // nothing to visit 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/commands/CommandResume.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.commands; 2 | 3 | import com.mojang.brigadier.builder.LiteralArgumentBuilder; 4 | import net.famzangl.minecraft.minebot.ai.command.AICommand; 5 | import net.famzangl.minecraft.minebot.ai.command.IAIControllable; 6 | 7 | @AICommand(helpText = "Resume the last thing that was aborted.", name = "minebot") 8 | public class CommandResume { 9 | 10 | public static void register(LiteralArgumentBuilder dispatcher) { 11 | dispatcher.then( 12 | Commands.literal("resume") 13 | .executes(context -> 14 | context.getSource().requestUseStrategy(context.getSource().getAiHelper().getResumeStrategy()) 15 | )); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/utils/BlockMapper.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.utils; 2 | 3 | import net.famzangl.minecraft.minebot.ai.path.world.WorldData; 4 | 5 | /** 6 | * This is a function that maps a given value to each block. 7 | * 8 | * @author Michael Zangl 9 | * 10 | */ 11 | public interface BlockMapper { 12 | /** 13 | * Gets the value for a given block. 14 | * 15 | * @param world 16 | * The world we work on. 17 | * @param x 18 | * The x coordinate 19 | * @param y 20 | * The y coordinate 21 | * @param z 22 | * The z coordinate 23 | * @return The value for the position. 24 | */ 25 | ValT getValueFor(WorldData world, int x, int y, int z); 26 | } 27 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 18 | 19 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/build/reverse/factories/BlockBuildTaskFactory.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.build.blockbuild.BlockBuildTask; 5 | import net.famzangl.minecraft.minebot.build.blockbuild.BuildTask; 6 | import net.minecraft.block.BlockState; 7 | import net.minecraft.util.math.BlockPos; 8 | 9 | public class BlockBuildTaskFactory extends AbstractBuildTaskFactory { 10 | 11 | @Override 12 | public BlockSet getSupportedBlocks() { 13 | return BlockBuildTask.BLOCKS; 14 | } 15 | 16 | @Override 17 | public BuildTask getTaskImpl(BlockPos position, BlockState forBlock) { 18 | return new BlockBuildTask(position, forBlock); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/build/reverse/factories/SlabBuildTaskFactory.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.build.blockbuild.BuildTask; 5 | import net.famzangl.minecraft.minebot.build.blockbuild.SlabBuildTask; 6 | import net.minecraft.block.BlockState; 7 | import net.minecraft.util.math.BlockPos; 8 | 9 | public class SlabBuildTaskFactory extends AbstractBuildTaskFactory { 10 | 11 | @Override 12 | protected BuildTask getTaskImpl(BlockPos position, 13 | BlockState block) { 14 | return new SlabBuildTask(position, block); 15 | } 16 | 17 | @Override 18 | public BlockSet getSupportedBlocks() { 19 | return SlabBuildTask.BLOCKS; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/build/reverse/factories/LogBuildTaskFactory.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.build.blockbuild.BuildTask; 5 | import net.famzangl.minecraft.minebot.build.blockbuild.LogBuildTask; 6 | import net.minecraft.block.BlockState; 7 | import net.minecraft.util.math.BlockPos; 8 | 9 | public class LogBuildTaskFactory extends AbstractBuildTaskFactory { 10 | 11 | @Override 12 | protected BuildTask getTaskImpl(BlockPos position, 13 | BlockState block) { 14 | return new LogBuildTask(position, block); 15 | } 16 | 17 | @Override 18 | public BlockSet getSupportedBlocks() { 19 | return LogBuildTask.NORMAL_LOGS; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/utils/BlockFilteredArea.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.utils; 2 | 3 | import net.famzangl.minecraft.minebot.ai.path.world.BlockSet; 4 | import net.famzangl.minecraft.minebot.ai.path.world.WorldData; 5 | 6 | /** 7 | * This is an area that only contains specific blocks. 8 | * 9 | * @author Michael Zangl 10 | * 11 | */ 12 | public class BlockFilteredArea extends AbstractFilteredArea { 13 | private final BlockSet containedBlocks; 14 | 15 | public BlockFilteredArea(BlockArea base, 16 | BlockSet containedBlocks) { 17 | super(base); 18 | this.containedBlocks = containedBlocks; 19 | } 20 | 21 | @Override 22 | protected boolean test(W world, int x, int y, int z) { 23 | return containedBlocks.isAt(world, x, y, z); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Short script to create a release. 3 | 4 | base="$(dirname "$(realpath "$0")")" 5 | cd "$base" 6 | 7 | tag=`git describe --exact-match --tags HEAD` 8 | 9 | if ! [ $? -eq 0 ]; then 10 | echo "You should tag the current git version. Use git tag v1.2.3" 11 | tag=`git rev-parse --short HEAD` 12 | fi 13 | 14 | echo "Using version tag $tag" 15 | 16 | mkdir -p releases/$tag || exit 1 17 | 18 | for mod in Minebot AimBow; do 19 | echo "Starting to compile $mod ..." 20 | cd "$base/$mod" 21 | rm -f "build/libs/"*".jar" 22 | ./gradlew build || exit 1 23 | cp "build/libs/"*".jar" "$base/releases/$tag" || exit 1 24 | #cp "build/libs/$(ls -t1 build/libs/ | tail -n 1)" "$base/releases/$tag" || exit 1 25 | done 26 | 27 | echo "Packing release" 28 | cd "$base/releases" 29 | rm -f "$tag.zip" 30 | zip "$tag.zip" $tag/* 31 | 32 | 33 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/strategy/crafting/CraftingPossibility.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.strategy.crafting; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Apply all RecipeWithListAndCount in that order (used for multiple crafting steps) 7 | */ 8 | public final class CraftingPossibility { 9 | 10 | private final List recipesToApply; 11 | 12 | public CraftingPossibility(List recipesToApply) { 13 | this.recipesToApply = recipesToApply; 14 | } 15 | 16 | public List getRecipesToApply() { 17 | return recipesToApply; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return "CraftingPossibility{" + 23 | "recipesToApply=" + recipesToApply + 24 | '}'; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/scripting/ChatMessage.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.scripting; 2 | 3 | import net.famzangl.minecraft.minebot.ai.net.PersistentChat; 4 | 5 | import javax.script.ScriptEngine; 6 | import javax.script.ScriptException; 7 | 8 | public class ChatMessage { 9 | 10 | public final Object time; 11 | public final String text; 12 | public final String textFormatted; 13 | public final boolean isChat; 14 | 15 | public ChatMessage(PersistentChat m, ScriptEngine engine) 16 | throws ScriptException { 17 | time = engine.eval("new Date(" + m.getTime() + ")"); 18 | text = m.getMessage().getUnformattedComponentText(); 19 | textFormatted = m.getMessage().getString(); 20 | isChat = m.isChat(); 21 | } 22 | 23 | @Override 24 | public String toString() { 25 | return "ChatMessage [text=" + text + "]"; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/strategy/LookAtStrategy.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.strategy; 2 | 3 | import net.famzangl.minecraft.minebot.ai.AIHelper; 4 | import net.minecraft.util.math.vector.Vector3d; 5 | 6 | /** 7 | * Look at the given position. 8 | * @author michael 9 | * 10 | */ 11 | public class LookAtStrategy extends AIStrategy{ 12 | 13 | private Vector3d lookAt; 14 | 15 | public LookAtStrategy(Vector3d lookAt) { 16 | this.lookAt = lookAt; 17 | } 18 | 19 | @Override 20 | protected TickResult onGameTick(AIHelper helper) { 21 | if (helper.isFacing(lookAt)) { 22 | return TickResult.NO_MORE_WORK; 23 | } else { 24 | helper.face(lookAt); 25 | return TickResult.TICK_HANDLED; 26 | } 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "LookAtStrategy [lookAt=" + lookAt + "]"; 32 | } 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/tools/rate/MatchesRater.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.tools.rate; 2 | 3 | import net.famzangl.minecraft.minebot.ai.path.world.BlockFloatMap; 4 | import net.famzangl.minecraft.minebot.ai.path.world.BlockSet; 5 | import net.minecraft.block.Block; 6 | import net.minecraft.item.ItemStack; 7 | 8 | public class MatchesRater extends Rater { 9 | public MatchesRater(String name, BlockFloatMap values) { 10 | super(name, values); 11 | } 12 | 13 | @Override 14 | protected boolean isAppleciable(ItemStack item, int forBlockAndMeta) { 15 | return item != null 16 | && forBlockAndMeta >= 0 17 | && item.getItem() != null 18 | && item.getItem().canHarvestBlock(item, 19 | BlockSet.getStateById(forBlockAndMeta)); 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return "MatchesRater [name=" + name + "]"; 25 | } 26 | } -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/utils/BlockPosList.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.Collection; 7 | import java.util.HashSet; 8 | 9 | public class BlockPosList extends BlockArea { 10 | 11 | public final HashSet positions; 12 | 13 | public BlockPosList(Collection posititons) { 14 | this.positions = new HashSet(posititons); 15 | } 16 | 17 | @Override 18 | public void accept(AreaVisitor visitor, WorldData world) { 19 | for (BlockPos pos : positions) { 20 | visitor.visit(world, pos.getX(), pos.getY(), pos.getZ()); 21 | } 22 | } 23 | 24 | @Override 25 | public boolean contains(WorldData world, int x, int y, int z) { 26 | return positions.contains(new BlockPos(x, y, z)); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/build/reverse/UnsupportedBlockException.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.build.reverse; 2 | 3 | import net.famzangl.minecraft.minebot.ai.path.world.WorldData; 4 | import net.minecraft.util.math.BlockPos; 5 | 6 | public class UnsupportedBlockException extends Exception { 7 | 8 | private final WorldData world; 9 | private final BlockPos pos; 10 | 11 | public UnsupportedBlockException(WorldData world, BlockPos pos, 12 | String message, Throwable cause) { 13 | super(pos + ": " + message, cause); 14 | this.world = world; 15 | this.pos = pos; 16 | } 17 | 18 | public UnsupportedBlockException(WorldData world, BlockPos pos, 19 | String message) { 20 | this(world, pos, message, null); 21 | } 22 | 23 | public UnsupportedBlockException(WorldData world, BlockPos pos, 24 | Throwable cause) { 25 | this(world, pos, "", cause); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/blockmap/BlockCubeCounter.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.blockmap; 2 | 3 | import net.minecraft.util.math.BlockPos; 4 | 5 | /** 6 | * This is a map that assigns an integer to every {@link BlockPos}. It has 7 | * optimizations for empty maps and only covers a 16x16x16 area. 8 | * 9 | * @author Michael Zangl 10 | * 11 | */ 12 | public class BlockCubeCounter { 13 | 14 | private int[] array = null; 15 | 16 | public int get(int blockX, int blockY, int blockZ) { 17 | if (array == null) { 18 | return 0; 19 | } 20 | int index = LocalChunkBitset.index(blockX, blockY, blockZ); 21 | return array[index]; 22 | } 23 | 24 | public void increment(int blockX, int blockY, int blockZ, int delta) { 25 | if (array == null) { 26 | array = new int[16 * 16 * 16]; 27 | } 28 | int index = LocalChunkBitset.index(blockX, blockY, blockZ); 29 | array[index] += delta; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/tools/rate/MultiplyEnchantmentRater.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.enchantment.Enchantment; 5 | import net.minecraft.enchantment.EnchantmentHelper; 6 | import net.minecraft.item.ItemStack; 7 | 8 | public class MultiplyEnchantmentRater extends EnchantmentRater { 9 | public MultiplyEnchantmentRater(Enchantment enchantmentId, String name, 10 | BlockFloatMap values) { 11 | super(enchantmentId, name, values); 12 | } 13 | 14 | @Override 15 | protected double getPow(ItemStack item, int forBlockAndMeta) { 16 | return Math.max(1, 17 | EnchantmentHelper.getEnchantmentLevel(enchantmentId, item)); 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return "MultiplyEnchantmentRater [enchantmentId=" + enchantmentId 23 | + ", name=" + name + "]"; 24 | } 25 | } -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/tools/rate/OrRater.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 class OrRater extends Rater { 7 | private final Rater[] raters; 8 | 9 | public OrRater(BlockFloatMap values, Rater... raters) { 10 | super(createName(raters, "|"), values); 11 | this.raters = raters; 12 | } 13 | 14 | @Override 15 | protected double getPow(ItemStack item, int forBlockAndMeta) { 16 | double pow = 1; 17 | for (Rater r : raters) { 18 | pow = Math.max(r.getPow(item, forBlockAndMeta), pow); 19 | } 20 | return pow; 21 | } 22 | 23 | @Override 24 | protected boolean isAppleciable(ItemStack item, int forBlockAndMeta) { 25 | for (Rater rater : raters) { 26 | if (rater.isAppleciable(item, forBlockAndMeta)) { 27 | return true; 28 | } 29 | } 30 | return false; 31 | } 32 | } -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/tools/rate/AndRater.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 class AndRater extends Rater { 7 | private final Rater[] raters; 8 | 9 | public AndRater(BlockFloatMap values, Rater... raters) { 10 | super(createName(raters, "&"), values); 11 | this.raters = raters; 12 | } 13 | 14 | @Override 15 | protected double getPow(ItemStack item, int forBlockAndMeta) { 16 | double pow = 1; 17 | for (Rater r : raters) { 18 | pow = Math.max(r.getPow(item, forBlockAndMeta), pow); 19 | } 20 | return pow; 21 | } 22 | 23 | @Override 24 | protected boolean isAppleciable(ItemStack item, int forBlockAndMeta) { 25 | for (Rater rater : raters) { 26 | if (!rater.isAppleciable(item, forBlockAndMeta)) { 27 | return false; 28 | } 29 | } 30 | return true; 31 | } 32 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Something did not work as described in the docs 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | 12 | FILL IN 13 | 14 | **To Reproduce** 15 | 16 | Describe your Minecraft world (surrounding blocks, …) 17 | 18 | Which command did you use? 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/tools/rate/EnchantmentRater.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.enchantment.Enchantment; 5 | import net.minecraft.enchantment.EnchantmentHelper; 6 | import net.minecraft.item.ItemStack; 7 | 8 | public class EnchantmentRater extends Rater { 9 | protected final Enchantment enchantmentId; 10 | 11 | public EnchantmentRater(Enchantment enchantmentId, String name, 12 | BlockFloatMap values) { 13 | super(name, values); 14 | this.enchantmentId = enchantmentId; 15 | } 16 | 17 | @Override 18 | protected boolean isAppleciable(ItemStack item, int forBlockAndMeta) { 19 | return EnchantmentHelper.getEnchantmentLevel(enchantmentId, 20 | item) > 0; 21 | } 22 | 23 | @Override 24 | public String toString() { 25 | return "EnchantmentRater [enchantmentId=" + enchantmentId + ", name=" 26 | + name + "]"; 27 | } 28 | } -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/net/PersistentChat.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.net; 2 | 3 | import net.minecraft.network.play.server.SChatPacket; 4 | import net.minecraft.util.text.ITextComponent; 5 | 6 | public class PersistentChat { 7 | 8 | private final ITextComponent message; 9 | 10 | private final boolean chat; 11 | 12 | private final long time = System.currentTimeMillis(); 13 | 14 | public PersistentChat(SChatPacket packetIn) { 15 | chat = !packetIn.isSystem(); 16 | message = packetIn.getChatComponent(); 17 | } 18 | 19 | public ITextComponent getMessage() { 20 | return message; 21 | } 22 | 23 | public boolean isChat() { 24 | return chat; 25 | } 26 | 27 | public long getTime() { 28 | return time; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return "PersistentChat [message=" + message + ", chat=" + chat 34 | + "]"; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /AimBow/src/net/famzangl/minecraft/aimbow/aiming/CloseEntityAimer.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 | 20 | public class CloseEntityAimer { 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Minebot/src/main/resources/net/famzangl/minecraft/minebot/ai/tools/tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "takes_damage": { "defaultValue" : 0.99 }, 3 | "matches": { 4 | "defaultValue" : 2, 5 | "values": { 6 | "minecraft:leaves" : 0.99, 7 | "minecraft:leaves2" : 0.99 8 | } 9 | }, 10 | "is_enchanted": { "defaultValue" : 0.9 }, 11 | "depleted&is_enchanted": { "defaultValue" : 0.1 }, 12 | "matches&fortune": { 13 | "defaultValue" : 0.95, 14 | "values": { 15 | "minecraft:emerald_ore" : 2, 16 | "minecraft:diamond_ore" : 2, 17 | "minecraft:quartz_ore" : 2, 18 | "minecraft:coal_ore" : 1.5, 19 | "minecraft:redstone_ore" : 1.5 20 | } 21 | }, 22 | "unbreaking&matches": { 23 | "defaultValue": 1.01 24 | }, 25 | "silk_touch": { 26 | "defaultValue": 1.0, 27 | "values": { 28 | "minecraft:monster_egg": 100.0 29 | } 30 | }, 31 | "silk_touch&matches": { 32 | "defaultValue" : 1.0, 33 | "values": { 34 | "minecraft:dirt" : [1, 1, 1.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/scripting/StrategyFailedException.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.scripting; 18 | 19 | public class StrategyFailedException extends RuntimeException { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Minebot/src/main/resources/net/famzangl/minecraft/minebot/settings/minebot/build/blocks.build: -------------------------------------------------------------------------------- 1 | # Simple test case. 2 | # Layer 0 3 | /minebuild schedule ~0 ~0 ~0 stonebrick 4 | /minebuild schedule ~0 ~0 ~1 crafting_table 5 | # Missing: ~0 ~0 ~2 Sandstone 6 | # Missing: ~0 ~0 ~3 Sandstone 7 | /minebuild schedule ~0 ~0 ~4 cobblestone 8 | /minebuild schedule ~0 ~0 ~5 dirt 9 | /minebuild schedule ~1 ~0 ~5 dirt 10 | /minebuild schedule ~1 ~0 ~4 sand 11 | /minebuild schedule ~1 ~0 ~3 coal_ore 12 | # Missing: ~1 ~0 ~2 Sandstone 13 | /minebuild schedule ~1 ~0 ~1 diamond_block 14 | /minebuild schedule ~1 ~0 ~0 melon_block 15 | /minebuild schedule ~2 ~0 ~0 nether_brick 16 | /minebuild schedule ~2 ~0 ~1 diamond_ore 17 | /minebuild schedule ~2 ~0 ~2 gold_block 18 | /minebuild schedule ~2 ~0 ~3 iron_ore 19 | /minebuild schedule ~2 ~0 ~4 sand 20 | /minebuild schedule ~2 ~0 ~5 grass 21 | /minebuild schedule ~3 ~0 ~5 stone 22 | /minebuild schedule ~3 ~0 ~4 gravel 23 | /minebuild schedule ~3 ~0 ~3 gold_ore 24 | /minebuild schedule ~3 ~0 ~2 brick_block 25 | /minebuild schedule ~3 ~0 ~1 bookshelf 26 | /minebuild schedule ~3 ~0 ~0 emerald_ore 27 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/utils/BlockCounter.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.utils; 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.ai.utils.BlockArea.AreaVisitor; 6 | 7 | public class BlockCounter implements AreaVisitor { 8 | 9 | private BlockSet[] blockSets; 10 | private int[] count; 11 | 12 | public BlockCounter(BlockSet... blockSets) { 13 | this.blockSets = blockSets; 14 | this.count = new int[blockSets.length]; 15 | } 16 | 17 | public static int[] countBlocks(WorldData world, BlockArea area, BlockSet... blockSets) { 18 | BlockCounter blockCounter = new BlockCounter(blockSets); 19 | area.accept(blockCounter, world); 20 | return blockCounter.getCount(); 21 | } 22 | 23 | @Override 24 | public void visit(WorldData world, int x, int y, int z) { 25 | for (int i = 0; i < blockSets.length; i++) { 26 | if (blockSets[i].isAt(world, x, y, z)) { 27 | count[i]++; 28 | } 29 | } 30 | } 31 | 32 | public int[] getCount() { 33 | return count; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/blockmap/ChunkCubeHashMap.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.blockmap; 2 | 3 | import java.util.HashMap; 4 | 5 | /** 6 | * This is a 16x16x16 cube -> object map.n 7 | * 8 | * @author michael 9 | * 10 | */ 11 | public class ChunkCubeHashMap { 12 | 13 | private HashMap map; 14 | private ChunkCubeProvider provider; 15 | 16 | public ChunkCubeHashMap() { 17 | this(null); 18 | } 19 | 20 | public ChunkCubeHashMap(ChunkCubeProvider provider) { 21 | this.provider = provider; 22 | } 23 | 24 | public T get(int blockX, int blockY, int blockZ) { 25 | long cube = getChunkCubeId(blockX, blockY, blockZ); 26 | T t = map.get(cube); 27 | if (t == null && provider != null) { 28 | t = provider.getForChunk(blockX & ~0xf, blockY & ~0xf, blockZ & ~0xf); 29 | map.put(cube, t); 30 | } 31 | return t; 32 | } 33 | 34 | public static long getChunkCubeId(int blockX, int blockY, int blockZ) { 35 | long id = (blockX >> 4) & 0xfffffffl; 36 | id <<= 28; 37 | id |= (blockZ >> 4) & 0xfffffffl; 38 | id <<= 4; 39 | id |= (blockY >> 4) & 0xf; 40 | return id; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/PathFinderFieldData.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; 18 | 19 | public class PathFinderFieldData { 20 | public int offsetX; 21 | public int offsetY; 22 | public int offsetZ; 23 | 24 | public PathFinderFieldData() { 25 | } 26 | } -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/commands/CommandStats.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.RunOnceStrategy; 10 | import net.famzangl.minecraft.minebot.stats.StatsWindow; 11 | 12 | @AICommand(helpText = "Dump all signs to a text file.", name = "minebot") 13 | public class CommandStats { 14 | @AICommandInvocation() 15 | public static AIStrategy run( 16 | AIHelper helper, 17 | @AICommandParameter(type = ParameterType.FIXED, fixedName = "stats", description = "") String nameArg) { 18 | return new RunOnceStrategy() { 19 | @Override 20 | protected void singleRun(AIHelper helper) { 21 | new StatsWindow(helper.getStats()).setVisible(true); 22 | } 23 | }; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/AIStrategyFactory.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; 18 | 19 | import net.famzangl.minecraft.minebot.ai.strategy.AIStrategy; 20 | 21 | public interface AIStrategyFactory { 22 | public AIStrategy produceStrategy(AIHelper helper); 23 | } 24 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/command/ParameterType.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 | public enum ParameterType { 20 | FIXED, 21 | NUMBER, 22 | DOUBLE, 23 | COMMAND, 24 | COLOR, 25 | FILE, 26 | POSITION, 27 | ENUM, 28 | STRING, 29 | BLOCK_STATE 30 | } 31 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/task/BlockHalf.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 | /** 20 | * The upper/lower half of the block. Useful for placing stairs. 21 | * 22 | * @author michael 23 | * 24 | */ 25 | public enum BlockHalf { 26 | UPPER_HALF, LOWER_HALF, ANY 27 | } -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/utils/AreaUnion.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.utils; 2 | 3 | import net.famzangl.minecraft.minebot.ai.path.world.WorldData; 4 | 5 | public class AreaUnion extends BlockArea { 6 | 7 | private final BlockArea a; 8 | private final BlockArea b; 9 | 10 | public AreaUnion(BlockArea a, BlockArea b) { 11 | this.a = a; 12 | this.b = b; 13 | } 14 | 15 | @Override 16 | public void accept(AreaVisitor visitor, WorldT2 world) { 17 | a.accept(visitor, world); 18 | b.accept((world1, x, y, z) -> { 19 | if (!a.contains(world1, x, y, z)) { 20 | visitor.visit(world1, x, y, z); 21 | } 22 | }, world); 23 | } 24 | 25 | @Override 26 | public boolean contains(WorldT world, int x, int y, int z) { 27 | return a.contains(world, x, y, z) || b.contains(world, x, y, z); 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return a + " ∪ " + b; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/render/StrategyStackRenderer.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.render; 2 | 3 | import com.mojang.blaze3d.matrix.MatrixStack; 4 | import net.famzangl.minecraft.minebot.ai.AIHelper; 5 | import net.famzangl.minecraft.minebot.ai.strategy.AIStrategy; 6 | import net.famzangl.minecraft.minebot.ai.strategy.StrategyStack; 7 | import net.minecraft.client.renderer.IRenderTypeBuffer; 8 | import net.minecraft.client.renderer.debug.DebugRenderer; 9 | 10 | public class StrategyStackRenderer implements DebugRenderer.IDebugRenderer { 11 | private StrategyStack stack; 12 | private AIHelper helper; 13 | 14 | public StrategyStackRenderer(StrategyStack stack, AIHelper helper) { 15 | this.stack = stack; 16 | this.helper = helper; 17 | } 18 | 19 | @Override 20 | public void render(MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, double camX, double camY, double camZ) { 21 | AIStrategy currentStrategy = stack.getCurrentStrategy(); 22 | if (currentStrategy != null) { 23 | currentStrategy.getDebugRenderer(helper).render(matrixStackIn, bufferIn, camX, camY, camZ); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/utils/RandUtils.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.utils; 2 | 3 | import java.util.Random; 4 | 5 | public class RandUtils { 6 | private static final Random RANDOM = new Random(0x837a); 7 | /** 8 | * Get a rand between a and b. 9 | * @param a 10 | * @param b 11 | * @return 12 | */ 13 | public static double getBetween(double a, double b) { 14 | return getBetweenCentered(a, b, 1); 15 | } 16 | 17 | /** 18 | * Gets a rand between .1 and .9, scaled to a...b 19 | * @param a 20 | * @param b 21 | * @return 22 | */ 23 | public static double getBetweenNoCorner(double a, double b) { 24 | return getBetweenCentered(a, b, .8); 25 | } 26 | 27 | public static double getBetweenCentered(double a, double b, double centered) { 28 | if (centered <= 0) { 29 | return (a + b) / 2; 30 | } 31 | 32 | centered = clamp(centered, 0, 1); 33 | double size = centered * (b - a); 34 | double min = (a + b) / 2 - centered * (b - a) / 2; 35 | return RANDOM.nextDouble() * size + min; 36 | 37 | } 38 | 39 | private static double clamp(double value, int min, int max) { 40 | return Math.max(Math.min(value, max), min); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/render/ActiveStrategyRenderer.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.render; 2 | 3 | import com.mojang.blaze3d.matrix.MatrixStack; 4 | import net.famzangl.minecraft.minebot.ai.AIHelper; 5 | import net.famzangl.minecraft.minebot.ai.strategy.AIStrategy; 6 | import net.minecraft.client.renderer.IRenderTypeBuffer; 7 | import net.minecraft.client.renderer.debug.DebugRenderer; 8 | 9 | import java.util.function.Supplier; 10 | 11 | public class ActiveStrategyRenderer implements DebugRenderer.IDebugRenderer { 12 | private final Supplier strategySupplier; 13 | private final AIHelper helper; 14 | 15 | public ActiveStrategyRenderer(Supplier strategySupplier, AIHelper helper) { 16 | this.strategySupplier = strategySupplier; 17 | this.helper = helper; 18 | } 19 | 20 | @Override 21 | public void render(MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, double camX, double camY, double camZ) { 22 | AIStrategy strategy = strategySupplier.get(); 23 | if (strategy != null) { 24 | strategy.getDebugRenderer(helper).render(matrixStackIn, bufferIn, camX, camY, camZ); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/settings/MinebotSettingsRoot.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.settings; 2 | 3 | import net.famzangl.minecraft.minebot.ai.tools.ToolRater; 4 | import net.famzangl.minecraft.minebot.ai.tools.ToolRater.ToolType; 5 | 6 | /** 7 | * This is the root object for our json settings file. 8 | * 9 | * @author Michael Zangl 10 | * 11 | */ 12 | @MinebotSettingObject 13 | public class MinebotSettingsRoot { 14 | private PathfindingSettings pathfinding = new PathfindingSettings(); 15 | 16 | private SaferuleSettings saferules = new SaferuleSettings(); 17 | 18 | private MiningSettings mining = new MiningSettings(); 19 | 20 | private ToolRater toolRater = ToolRater.createDefaultRater(); 21 | 22 | private ToolRater fishingRater = new ToolRater(ToolType.FISHING_ROD); 23 | 24 | public PathfindingSettings getPathfinding() { 25 | return pathfinding; 26 | } 27 | 28 | public MiningSettings getMining() { 29 | return mining ; 30 | } 31 | 32 | public ToolRater getToolRater() { 33 | return toolRater ; 34 | } 35 | 36 | public ToolRater getFishingRater() { 37 | return fishingRater; 38 | } 39 | 40 | public SaferuleSettings getSaferules() { 41 | return saferules; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Minebot/src/main/resources/net/famzangl/minecraft/minebot/settings/minebot/build/stairs.build: -------------------------------------------------------------------------------- 1 | 2 | /minebuild schedule ~0 ~0 ~1 oak_stairs south lower 3 | /minebuild schedule ~0 ~0 ~0 oak_stairs west upper 4 | /minebuild schedule ~0 ~0 ~3 oak_stairs north lower 5 | /minebuild schedule ~0 ~0 ~4 stone_stairs south lower 6 | /minebuild schedule ~1 ~0 ~4 brick_stairs south lower 7 | /minebuild schedule ~1 ~0 ~3 dark_oak_stairs north lower 8 | /minebuild schedule ~2 ~0 ~0 oak_stairs west lower 9 | /minebuild schedule ~2 ~0 ~1 oak_stairs south lower 10 | /minebuild schedule ~2 ~0 ~3 acacia_stairs north lower 11 | /minebuild schedule ~2 ~0 ~4 stone_brick_stairs south lower 12 | /minebuild schedule ~3 ~0 ~4 nether_brick_stairs south lower 13 | /minebuild schedule ~3 ~0 ~3 quartz_stairs north lower 14 | /minebuild schedule ~3 ~0 ~1 oak_stairs east lower 15 | /minebuild schedule ~3 ~0 ~0 oak_stairs north lower 16 | /minebuild schedule ~4 ~0 ~3 jungle_stairs north lower 17 | /minebuild schedule ~4 ~0 ~4 sandstone_stairs south lower 18 | /minebuild schedule ~5 ~0 ~4 spruce_stairs south lower 19 | /minebuild schedule ~5 ~0 ~3 birch_stairs north lower 20 | /minebuild schedule ~5 ~0 ~1 oak_stairs south lower 21 | /minebuild schedule ~5 ~0 ~0 oak_stairs north upper 22 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/commands/CommandWalk.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.command.SafeStrategyRule; 9 | import net.famzangl.minecraft.minebot.ai.strategy.AIStrategy; 10 | import net.famzangl.minecraft.minebot.ai.strategy.WalkTowardsStrategy; 11 | 12 | @AICommand(helpText = "Walk to a given x/z point", name = "minebot") 13 | public class CommandWalk { 14 | @AICommandInvocation(safeRule = SafeStrategyRule.DEFEND) 15 | public static AIStrategy run( 16 | AIHelper helper, 17 | @AICommandParameter(type = ParameterType.FIXED, fixedName = "walk", description = "") String nameArg, 18 | @AICommandParameter(type = ParameterType.DOUBLE, description = "x") Double x, 19 | @AICommandParameter(type = ParameterType.DOUBLE, description = "z") Double z) { 20 | return new WalkTowardsStrategy(x, z); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/HumanReadableItemFilter.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; 18 | 19 | /** 20 | * Item filters implementing this interface can be represented in a human 21 | * readable form. 22 | * 23 | * @author michael 24 | * 25 | */ 26 | public interface HumanReadableItemFilter extends ItemFilter { 27 | public String getDescription(); 28 | } 29 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/build/blockbuild/MirrorDirection.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 | /** 20 | * A simple enum defining in which direction something sould be mirrored. 21 | * 22 | * @author michael 23 | * 24 | */ 25 | public enum MirrorDirection { 26 | /** 27 | * Swap north with south. 28 | */ 29 | NORTH_SOUTH, EAST_WEST; 30 | } 31 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/path/TaskReceiver.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.task.AITask; 20 | 21 | public interface TaskReceiver { 22 | 23 | /** 24 | * Adds a task that should be executed. 25 | * 26 | * @param task 27 | * The new task 28 | */ 29 | public abstract void addTask(AITask task); 30 | } 31 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/settings/SaferuleSettings.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.settings; 2 | 3 | import java.util.regex.Pattern; 4 | 5 | public class SaferuleSettings { 6 | @ClampedFloat(min = 10, max = 180) 7 | private float maxPitchChangeDegrees = 30; 8 | @ClampedFloat(min = 10, max = 180) 9 | private float maxYawChangeDegrees = 40; 10 | 11 | private boolean allowTopOfWorldHit = false; 12 | 13 | private int placeTorchLightLevel = 3; 14 | 15 | private int minimumPlayerDistance = 10; 16 | 17 | private String ignoredPlayerRegex = ""; 18 | 19 | public float getMaxPitchChangeDegrees() { 20 | return maxPitchChangeDegrees; 21 | } 22 | 23 | public float getMaxYawChangeDegrees() { 24 | return maxYawChangeDegrees; 25 | } 26 | 27 | public boolean isAllowTopOfWorldHit() { 28 | return allowTopOfWorldHit; 29 | } 30 | 31 | public int getPlaceTorchLightLevel() { 32 | return placeTorchLightLevel; 33 | } 34 | 35 | public int getMinimumPlayerDistance() { 36 | return minimumPlayerDistance; 37 | } 38 | 39 | public Pattern getIgnoredPlayerRegex() { 40 | if (ignoredPlayerRegex == null || ignoredPlayerRegex.isEmpty()) { 41 | return Pattern.compile("$a"); 42 | } else { 43 | return Pattern.compile(ignoredPlayerRegex); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Minebot/src/main/resources/net/famzangl/minecraft/minebot/settings/minebot/scripts/feed-kill-sheep.js: -------------------------------------------------------------------------------- 1 | var colors = {}; 2 | var totalSheep = 0; 3 | var sheepToLeave = 20; // Total of 320 sheep. Brings you to level 30 by feeding once. 4 | minescript.getEntities(net.minecraft.entity.passive.EntitySheep, 100).forEach(function(sheep) { 5 | if (sheep.getColor() in colors) 6 | colors[sheep.getColor()]++; 7 | else 8 | colors[sheep.getColor()] = 1; 9 | totalSheep++; 10 | }); 11 | 12 | // Print a list of sheep 13 | minescript.displayChat("Sheep around you: " + totalSheep); 14 | sorted = []; 15 | for (color in colors) { 16 | sorted.push(color); 17 | } 18 | sorted.sort(function(a, b) {return -colors[a] + colors[b];}); 19 | for (var i = 0; i < sorted.length; i++) { 20 | minescript.displayChat(sorted[i] + ": " + colors[sorted[i]] + " (" + Math.round(100 * colors[sorted[i]] / totalSheep) + "%)"); 21 | } 22 | 23 | // Now kill those left over 24 | for (color in colors) { 25 | var toKill = colors[color] - sheepToLeave; 26 | minescript.setDescription("Killing " + toKill + " " + color + " sheep"); 27 | if (toKill > 0) { 28 | minescript.doStrategy(minescript.stack( 29 | minescript.strategy("minebot", "eat"), 30 | minescript.strategy("minebot", "kill", "sheep", color, toKill + ""))); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/selectors/ItemSelector.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.item.ItemEntity; 21 | 22 | import java.util.function.Predicate; 23 | 24 | public final class ItemSelector implements Predicate { 25 | @Override 26 | public boolean test(Entity e) { 27 | return e instanceof ItemEntity; 28 | } 29 | } -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/UngrabScreen.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; 18 | 19 | 20 | 21 | import net.minecraft.client.gui.screen.Screen; 22 | import net.minecraft.util.text.StringTextComponent; 23 | 24 | public class UngrabScreen extends Screen { 25 | public UngrabScreen() { 26 | super(new StringTextComponent("")); 27 | //this.field_230711_n_ = true; 28 | //Screen.getMineraft(), first person Renderer 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/selectors/XPOrbSelector.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 com.google.common.base.Predicate; 20 | import net.minecraft.entity.Entity; 21 | import net.minecraft.entity.item.ExperienceOrbEntity; 22 | 23 | public final class XPOrbSelector implements Predicate { 24 | @Override 25 | public boolean apply(Entity e) { 26 | return e instanceof ExperienceOrbEntity; 27 | } 28 | } -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/stats/StatsWindow.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.stats; 18 | 19 | import javax.swing.*; 20 | 21 | /** 22 | * Warning: Dirty, temporary hack. 23 | * @author Michael Zangl 24 | * 25 | */ 26 | public class StatsWindow extends JFrame { 27 | public StatsWindow(StatsManager stats) { 28 | setLayout(new BoxLayout(getContentPane(), BoxLayout.LINE_AXIS)); 29 | add(new StatsTable(stats.getBlockStats())); 30 | pack(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/enchanting/PutLapisInTableTask.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.enchanting; 2 | 3 | import net.famzangl.minecraft.minebot.ai.AIHelper; 4 | import net.famzangl.minecraft.minebot.ai.strategy.TintStrategy; 5 | import net.famzangl.minecraft.minebot.ai.task.inventory.PutItemInContainerTask; 6 | import net.minecraft.client.gui.screen.EnchantmentScreen; 7 | import net.minecraft.inventory.container.Slot; 8 | import net.minecraft.item.DyeColor; 9 | import net.minecraft.item.ItemStack; 10 | 11 | /** 12 | * Put the lapis into the enchantment table. 13 | * 14 | * @author michael 15 | * 16 | */ 17 | public class PutLapisInTableTask extends PutItemInContainerTask { 18 | 19 | private static final int TABLE_INV_OFFSET = 2; 20 | 21 | @Override 22 | protected int getStackToPut(AIHelper aiHelper) { 23 | final EnchantmentScreen screen = (EnchantmentScreen) aiHelper.getMinecraft().currentScreen; 24 | for (int i = TABLE_INV_OFFSET; i < 9 * 4 + TABLE_INV_OFFSET; i++) { 25 | Slot slot = screen.getContainer().getSlot(i); 26 | if (slot == null || !slot.canTakeStack(aiHelper.getMinecraft().player)) { 27 | continue; 28 | } 29 | final ItemStack stack = slot.getStack(); 30 | if (new TintStrategy.DyeItemFilter(DyeColor.BLUE) 31 | .matches(stack)) { 32 | return i; 33 | } 34 | } 35 | return -1; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/scripting/WrappedBlockPos.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.scripting; 2 | 3 | import net.minecraft.util.math.BlockPos; 4 | 5 | public class WrappedBlockPos { 6 | public final int x; 7 | public final int y; 8 | public final int z; 9 | 10 | public WrappedBlockPos(int x, int y, int z) { 11 | super(); 12 | this.x = x; 13 | this.y = y; 14 | this.z = z; 15 | } 16 | 17 | public WrappedBlockPos(BlockPos playerPosition) { 18 | this (playerPosition.getX(), playerPosition.getY(), playerPosition.getZ()); 19 | } 20 | 21 | @Override 22 | public int hashCode() { 23 | final int prime = 31; 24 | int result = 1; 25 | result = prime * result + x; 26 | result = prime * result + y; 27 | result = prime * result + z; 28 | return result; 29 | } 30 | 31 | @Override 32 | public boolean equals(Object obj) { 33 | if (this == obj) 34 | return true; 35 | if (obj == null) 36 | return false; 37 | if (getClass() != obj.getClass()) 38 | return false; 39 | WrappedBlockPos other = (WrappedBlockPos) obj; 40 | if (x != other.x) 41 | return false; 42 | if (y != other.y) 43 | return false; 44 | if (z != other.z) 45 | return false; 46 | return true; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "WrappedBlockPos [x=" + x + ", y=" + y + ", z=" + z + "]"; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/command/AICommandInvocation.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.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | @Retention(RetentionPolicy.RUNTIME) 25 | @Target(ElementType.METHOD) 26 | public @interface AICommandInvocation { 27 | SafeStrategyRule safeRule() default SafeStrategyRule.NONE; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/task/error/StrategyDeactivatedError.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 | public class StrategyDeactivatedError extends TaskError { 20 | 21 | public StrategyDeactivatedError() { 22 | super("The strategy was deactivated."); 23 | } 24 | 25 | @Override 26 | public boolean shouldBeDisplayed() { 27 | return false; 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return "StrategyDeactivatedError{}"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/strategy/StopOnConditionStrategy.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.strategy; 2 | 3 | import net.famzangl.minecraft.minebot.ai.AIHelper; 4 | 5 | public class StopOnConditionStrategy extends AIStrategy { 6 | public interface StopCondition { 7 | boolean shouldStop(AIHelper helper); 8 | } 9 | 10 | private final StopCondition condition; 11 | private final boolean force; 12 | private final String name; 13 | 14 | public StopOnConditionStrategy(StopCondition condition, boolean force, String name) { 15 | super(); 16 | this.condition = condition; 17 | this.force = force; 18 | this.name = name; 19 | } 20 | 21 | @Override 22 | public boolean takesOverAnyTime() { 23 | return force; 24 | } 25 | 26 | @Override 27 | public boolean checkShouldTakeOver(AIHelper helper) { 28 | return condition.shouldStop(helper); 29 | } 30 | 31 | @Override 32 | protected TickResult onGameTick(AIHelper helper) { 33 | if (condition.shouldStop(helper)) { 34 | return TickResult.ABORT; 35 | } else { 36 | return TickResult.NO_MORE_WORK; 37 | } 38 | } 39 | 40 | @Override 41 | public String getDescription(AIHelper helper) { 42 | return "Stop on " + name; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "StopOnConditionStrategy [condition=" + condition + ", force=" 48 | + force + "]"; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/utils/AbstractFilteredArea.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.utils; 2 | 3 | import net.famzangl.minecraft.minebot.ai.path.world.WorldData; 4 | 5 | public abstract class AbstractFilteredArea extends BlockArea { 6 | 7 | protected final BlockArea base; 8 | 9 | public AbstractFilteredArea(BlockArea base) { 10 | this.base = base; 11 | } 12 | 13 | 14 | @Override 15 | public void accept(AreaVisitor visitor, WorldT2 world) { 16 | base.accept(new FilteredVisitor<>(visitor), world); 17 | } 18 | 19 | @Override 20 | public boolean contains(W world, int x, int y, int z) { 21 | return base.contains(world, x, y, z) && test(world, x, y, z); 22 | } 23 | 24 | protected abstract boolean test(W world, int x, int y, int z); 25 | 26 | private class FilteredVisitor implements AreaVisitor { 27 | private final AreaVisitor visitor; 28 | 29 | public FilteredVisitor(AreaVisitor visitor) { 30 | this.visitor = visitor; 31 | } 32 | 33 | @Override 34 | public void visit(W2 world, int x, int y, int z) { 35 | if (test(world, x, y, z)) { 36 | visitor.visit(world, x, y, z); 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/task/CanWorkWhileApproaching.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 | 21 | /** 22 | * The task can do some work while other the bot is still working to the desired positon 23 | */ 24 | public interface CanWorkWhileApproaching { 25 | 26 | /** 27 | * Do the approach work. 28 | * @return true if the request was handled 29 | */ 30 | public boolean doApproachWork(AIHelper helper); 31 | } 32 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/command/CommandEvaluationException.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 | public class CommandEvaluationException extends RuntimeException { 20 | 21 | /** 22 | * 23 | */ 24 | private static final long serialVersionUID = 6305591561818630563L; 25 | 26 | public CommandEvaluationException(String message, Throwable cause) { 27 | super(message, cause); 28 | } 29 | 30 | public CommandEvaluationException(String message) { 31 | super(message); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/task/SkipWhenSearchingPrefetch.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 java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | 22 | /** 23 | * This states that the given task may be ignored when searching for prefetch 24 | * tasks. 25 | * 26 | * See {@link CanPrefaceAndDestroy}. 27 | * 28 | * @author michael 29 | * 30 | */ 31 | @Retention(RetentionPolicy.RUNTIME) 32 | public @interface SkipWhenSearchingPrefetch { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/task/place/DestroyBlockTask.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.place; 18 | 19 | import net.famzangl.minecraft.minebot.ai.task.DestroyInRangeTask; 20 | import net.minecraft.util.math.BlockPos; 21 | 22 | /** 23 | * Simply destroy a block at a given position, assuming it is in reach. 24 | * 25 | * @author michael 26 | * 27 | */ 28 | public class DestroyBlockTask extends DestroyInRangeTask { 29 | 30 | public DestroyBlockTask(BlockPos pos) { 31 | super(pos, pos); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/selectors/OneOfListSelector.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 | 21 | import java.util.List; 22 | import java.util.function.Predicate; 23 | 24 | public class OneOfListSelector implements Predicate { 25 | 26 | private final List list; 27 | 28 | public OneOfListSelector(List list) { 29 | this.list = list; 30 | } 31 | 32 | @Override 33 | public boolean test(Entity var1) { 34 | return list.contains(var1); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/strategy/StopStrategy.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 | * Simply stops the bot. This is a NOP. 23 | * 24 | * @author michael 25 | * 26 | */ 27 | public final class StopStrategy extends AIStrategy { 28 | 29 | @Override 30 | public String getDescription(AIHelper helper) { 31 | return "Stopping"; 32 | } 33 | 34 | @Override 35 | protected TickResult onGameTick(AIHelper helper) { 36 | return TickResult.NO_MORE_WORK; 37 | } 38 | } -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/task/DestroyLogInRange.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.task; 2 | 3 | import net.famzangl.minecraft.minebot.ai.AIHelper; 4 | import net.famzangl.minecraft.minebot.ai.path.world.BlockSet; 5 | import net.famzangl.minecraft.minebot.ai.path.world.BlockSets; 6 | import net.famzangl.minecraft.minebot.ai.path.world.WorldData; 7 | import net.famzangl.minecraft.minebot.ai.utils.BlockArea; 8 | import net.minecraft.block.Block; 9 | import net.minecraft.block.Blocks; 10 | import net.minecraft.util.math.BlockPos; 11 | 12 | /** 13 | * This task attemtps to destroy any log in a given area. 14 | * 15 | * @author michael 16 | * 17 | */ 18 | public class DestroyLogInRange extends DestroyInRangeTask { 19 | 20 | private static final BlockSet LEAVES_OR_LOGS = BlockSet.builder().add(BlockSets.LEAVES).add(BlockSets.LOGS).add(Blocks.VINE).build(); 21 | 22 | public DestroyLogInRange(BlockArea range) { 23 | super(range); 24 | } 25 | 26 | @Override 27 | protected boolean noDestructionRequired(WorldData world, int x, int y, int z) { 28 | if (super.noDestructionRequired(world, x, y, z)) { 29 | return true; 30 | } else { 31 | return !BlockSets.LOGS.isAt(world, x, y, z); 32 | } 33 | } 34 | 35 | protected boolean isAcceptedFacingPos(AIHelper aiHelper, BlockPos n, BlockPos pos) { 36 | return (LEAVES_OR_LOGS.isAt( 37 | aiHelper.getWorld(), pos) && BlockSets.LOGS.isAt(aiHelper.getWorld(), n)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/commands/CommandEat.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.IAIControllable; 21 | import net.famzangl.minecraft.minebot.ai.strategy.EatStrategy; 22 | 23 | public class CommandEat { 24 | public static void register(LiteralArgumentBuilder dispatcher) { 25 | dispatcher.then( 26 | Commands.literal("eat") 27 | .executes(context -> context.getSource().requestUseStrategy(new EatStrategy()))); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/strategy/RespawnStrategy.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 | * Clicks the respawn button (if the respawn screen is shown) 23 | * 24 | * @author michael 25 | * 26 | */ 27 | public class RespawnStrategy extends AIStrategy { 28 | @Override 29 | protected TickResult onGameTick(AIHelper helper) { 30 | if (!helper.isAlive()) { 31 | helper.respawn(); 32 | return TickResult.TICK_HANDLED; 33 | } else { 34 | return TickResult.NO_MORE_WORK; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Minebot/.idea/runConfigurations/runClient.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 24 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/ClassItemFilter.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; 18 | 19 | import net.minecraft.item.Item; 20 | import net.minecraft.item.ItemStack; 21 | 22 | public class ClassItemFilter implements ItemFilter { 23 | private final Class itemClass; 24 | 25 | public ClassItemFilter(Class itemClass) { 26 | this.itemClass = itemClass; 27 | } 28 | 29 | @Override 30 | public boolean matches(ItemStack itemStack) { 31 | return itemStack != null && itemStack.getItem() != null 32 | && itemClass.isInstance(itemStack.getItem()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/command/OptionalParameterBuilder.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 OptionalParameterBuilder extends ParameterBuilder { 24 | 25 | public OptionalParameterBuilder(AICommandParameter annot) { 26 | super(annot); 27 | } 28 | 29 | @Override 30 | public void addArguments(ArrayList list) { 31 | } 32 | 33 | @Override 34 | public Object getParameter(AIHelper helper, String[] arguments) { 35 | return null; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/strategy/DamageTakenStrategy.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 | public class DamageTakenStrategy extends ValueActionStrategy { 22 | 23 | @Override 24 | protected double getValue(AIHelper helper) { 25 | return helper.getMinecraft().player.getHealth(); 26 | } 27 | 28 | @Override 29 | protected String getSettingPrefix() { 30 | return "on_damage_"; 31 | } 32 | 33 | @Override 34 | public String getDescription(AIHelper helper) { 35 | return "Check if health went down."; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Minebot/src/main/java/net/famzangl/minecraft/minebot/ai/utils/BlockUtils.java: -------------------------------------------------------------------------------- 1 | package net.famzangl.minecraft.minebot.ai.utils; 2 | 3 | import net.famzangl.minecraft.minebot.ai.path.world.WorldData; 4 | import net.famzangl.minecraft.minebot.ai.utils.BlockArea.AreaVisitor; 5 | 6 | /** 7 | * Some block utils you might find helpful. 8 | * 9 | * @author Michael Zangl 10 | * 11 | */ 12 | public class BlockUtils { 13 | private static class MinimumVisitor> 14 | implements AreaVisitor { 15 | private ValT minimum = null; 16 | private final BlockMapper mapper; 17 | 18 | public MinimumVisitor(BlockMapper mapper) { 19 | this.mapper = mapper; 20 | } 21 | 22 | public ValT getMinimum() { 23 | return minimum; 24 | } 25 | 26 | @Override 27 | public void visit(WorldData world, int x, int y, int z) { 28 | ValT val = mapper.getValueFor(world, x, y, z); 29 | if (minimum == null || val.compareTo(minimum) < 0) { 30 | minimum = val; 31 | } 32 | } 33 | } 34 | 35 | /** 36 | * Computes the minimum over an area of the world. 37 | * 38 | * @param area 39 | * @param world 40 | * @param mapper 41 | * @return The minimum value for that area or null if the area 42 | * is empty. 43 | */ 44 | public static > ValT getMinimum( 45 | BlockArea area, WorldData world, BlockMapper mapper) { 46 | MinimumVisitor visitor = new MinimumVisitor(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 visitor; 12 | private final BlockArea b; 13 | 14 | public FilteredAreaVisitor(AreaVisitor visitor, BlockArea 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 a; 30 | private final BlockArea b; 31 | 32 | public AreaIntersection(BlockArea a, BlockArea 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 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 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 | --------------------------------------------------------------------------------