├── gradlew ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── src └── main │ ├── resources │ ├── assets │ │ └── bedrockminer │ │ │ ├── icon.png │ │ │ └── lang │ │ │ ├── zh_tw.json │ │ │ ├── zh_cn.json │ │ │ └── en_us.json │ ├── bedrock-miner.accesswidener │ ├── bedrock-miner.mixins.json │ └── fabric.mod.json │ └── java │ └── yan │ └── lx │ └── bedrockminer │ ├── task │ ├── TaskSelectionInfo.java │ ├── TaskState.java │ ├── TaskSeekSchemeInfo.java │ ├── TaskSeekBlockInfo.java │ ├── TaskModifyLookHandle.java │ ├── TaskSeekSchemeTools.java │ ├── TaskManager.java │ └── TaskHandler.java │ ├── utils │ ├── MessageUtils.java │ ├── BlockUtils.java │ ├── BlockBreakerUtils.java │ ├── BlockPlacerUtils.java │ ├── CheckingEnvironmentUtils.java │ └── InventoryManagerUtils.java │ ├── Debug.java │ ├── mixins │ ├── MixinClientPlayerInteractionManager.java │ ├── MixinPlayerMoveC2SPacket.java │ └── MixinMinecraftClient.java │ ├── command │ ├── BaseCommand.java │ ├── DisableCommand.java │ ├── DebugCommand.java │ ├── argument │ │ ├── DirectionArgumentType.java │ │ ├── DirectionListArgumentType.java │ │ ├── BlockNameArgument.java │ │ ├── BlockIdentifierArgument.java │ │ └── BlockPosArgumentType.java │ ├── TaskCommand.java │ ├── BlockNameCommand.java │ └── BlockCommand.java │ ├── BedrockMinerMod.java │ ├── BedrockMinerLang.java │ ├── config │ └── Config.java │ └── Test.java ├── settings.gradle ├── .gitignore ├── gradle.properties ├── .github └── workflows │ └── build.yml ├── README_TW.md ├── README.md ├── README_EN.md ├── gradlew.bat └── LICENSE /gradlew: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devjta/Fabric-Bedrock-Miner/HEAD/gradlew -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devjta/Fabric-Bedrock-Miner/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/main/resources/assets/bedrockminer/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devjta/Fabric-Bedrock-Miner/HEAD/src/main/resources/assets/bedrockminer/icon.png -------------------------------------------------------------------------------- /src/main/resources/bedrock-miner.accesswidener: -------------------------------------------------------------------------------- 1 | accessWidener v1 named 2 | accessible method net/minecraft/client/network/ClientPlayerInteractionManager sendSequencedPacket (Lnet/minecraft/client/world/ClientWorld;Lnet/minecraft/client/network/SequencedPacketCreator;)V -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https://services.gradle.org/distributions/gradle-8.12-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | maven { 4 | name = 'Fabric' 5 | url = 'https://maven.fabricmc.net/' 6 | } 7 | maven { url 'https://maven.aliyun.com/repository/public/' } 8 | mavenCentral() 9 | gradlePluginPortal() 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # gradle 2 | 3 | .gradle/ 4 | build/ 5 | out/ 6 | classes/ 7 | 8 | # eclipse 9 | 10 | *.launch 11 | 12 | # idea 13 | 14 | .idea/ 15 | *.iml 16 | *.ipr 17 | *.iws 18 | 19 | # vscode 20 | 21 | .settings/ 22 | .vscode/ 23 | bin/ 24 | .classpath 25 | .project 26 | 27 | # macos 28 | 29 | *.DS_Store 30 | 31 | # fabric 32 | 33 | run/ 34 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/task/TaskSelectionInfo.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.task; 2 | 3 | import net.minecraft.util.math.BlockPos; 4 | 5 | public class TaskSelectionInfo { 6 | public BlockPos pos1; 7 | public BlockPos pos2; 8 | 9 | public TaskSelectionInfo(BlockPos pos1, BlockPos pos2) { 10 | this.pos1 = pos1; 11 | this.pos2 = pos2; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/resources/bedrock-miner.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "minVersion": "0.8", 4 | "package": "yan.lx.bedrockminer.mixins", 5 | "compatibilityLevel": "JAVA_17", 6 | "mixins": [ 7 | "MixinPlayerMoveC2SPacket" 8 | ], 9 | "client": [ 10 | "MixinClientPlayerInteractionManager", 11 | "MixinMinecraftClient" 12 | ], 13 | "injectors": { 14 | "defaultRequire": 1 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/task/TaskState.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.task; 2 | 3 | public enum TaskState { 4 | INITIALIZE, 5 | WAIT_GAME_UPDATE, 6 | WAIT_CUSTOM, 7 | FIND_PISTON, 8 | FIND_REDSTONE_TORCH, 9 | FIND_SLIME_BLOCK, 10 | 11 | PLACE_PISTON, 12 | PLACE_REDSTONE_TORCH, 13 | PLACE_SLIME_BLOCK, 14 | EXECUTE, 15 | TIMEOUT, 16 | FAIL, 17 | RECYCLED_ITEMS, 18 | COMPLETE 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/utils/MessageUtils.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.utils; 2 | 3 | 4 | import net.minecraft.client.MinecraftClient; 5 | import net.minecraft.text.Text; 6 | 7 | public class MessageUtils { 8 | public static void setOverlayMessage(Text message) { 9 | MinecraftClient.getInstance().inGameHud.setOverlayMessage(message, false); 10 | } 11 | 12 | public static void addMessage(Text message) { 13 | MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(message); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/Debug.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer; 2 | 3 | import yan.lx.bedrockminer.config.Config; 4 | 5 | public class Debug { 6 | public static void info(String var1, Object... var2) { 7 | if (Config.INSTANCE.debug) { 8 | BedrockMinerMod.LOGGER.info(var1, var2); 9 | } 10 | } 11 | 12 | public static void info(Object obj) { 13 | if (Config.INSTANCE.debug) { 14 | BedrockMinerMod.LOGGER.info(obj.toString()); 15 | } 16 | } 17 | 18 | public static void info() { 19 | info(""); 20 | } 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/utils/BlockUtils.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.utils; 2 | 3 | import net.minecraft.block.Block; 4 | import net.minecraft.registry.Registries; 5 | import net.minecraft.util.Identifier; 6 | 7 | public class BlockUtils { 8 | 9 | public static String getBlockName(Block block) { 10 | return block.getName().getString(); 11 | } 12 | 13 | public static Identifier getIdentifier(Block block) { 14 | return Registries.BLOCK.getId(block); 15 | } 16 | 17 | public static String getId(Block block) { 18 | return getIdentifier(block).toString(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/task/TaskSeekSchemeInfo.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.task; 2 | 3 | import net.minecraft.util.math.Direction; 4 | 5 | import java.util.List; 6 | 7 | public class TaskSeekSchemeInfo { 8 | public final Direction direction; 9 | public final TaskSeekBlockInfo piston; 10 | public final TaskSeekBlockInfo redstoneTorch; 11 | public final TaskSeekBlockInfo slimeBlock; 12 | 13 | public TaskSeekSchemeInfo(Direction direction, TaskSeekBlockInfo piston, TaskSeekBlockInfo redstoneTorch, TaskSeekBlockInfo slimeBlock) { 14 | this.direction = direction; 15 | this.piston = piston; 16 | this.redstoneTorch = redstoneTorch; 17 | this.slimeBlock = slimeBlock; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/mixins/MixinClientPlayerInteractionManager.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.mixins; 2 | 3 | import net.minecraft.client.network.ClientPlayerInteractionManager; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.injection.At; 6 | import org.spongepowered.asm.mixin.injection.Inject; 7 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 8 | import yan.lx.bedrockminer.task.TaskManager; 9 | import yan.lx.bedrockminer.task.TaskModifyLookHandle; 10 | 11 | @Mixin(ClientPlayerInteractionManager.class) 12 | public class MixinClientPlayerInteractionManager { 13 | @Inject(method = "tick", at = @At("HEAD")) 14 | public void tick(CallbackInfo ci) { 15 | TaskModifyLookHandle.onTick(); 16 | TaskManager.tick(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/task/TaskSeekBlockInfo.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.task; 2 | 3 | import net.minecraft.util.math.BlockPos; 4 | import net.minecraft.util.math.Direction; 5 | 6 | public class TaskSeekBlockInfo { 7 | public final BlockPos pos; 8 | public final Direction facing; 9 | public boolean modify; 10 | public int level; 11 | 12 | public TaskSeekBlockInfo(BlockPos pos, Direction facing, int level) { 13 | this.pos = pos; 14 | this.facing = facing; 15 | this.modify = false; 16 | this.level = level; 17 | } 18 | 19 | public TaskSeekBlockInfo(BlockPos pos, Direction facing) { 20 | this(pos, facing, 0); 21 | } 22 | 23 | public boolean isNeedModify() { 24 | return facing.getAxis().isHorizontal(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/mixins/MixinPlayerMoveC2SPacket.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.mixins; 2 | 3 | import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; 4 | import org.spongepowered.asm.mixin.Mixin; 5 | import org.spongepowered.asm.mixin.injection.At; 6 | import org.spongepowered.asm.mixin.injection.ModifyVariable; 7 | import yan.lx.bedrockminer.task.TaskModifyLookHandle; 8 | 9 | @Mixin(PlayerMoveC2SPacket.class) 10 | public class MixinPlayerMoveC2SPacket { 11 | @ModifyVariable(method = "(DDDFFZZZZ)V", at = @At("HEAD"), ordinal = 0, argsOnly = true) 12 | private static float modifyLookYaw(float yaw) { 13 | return TaskModifyLookHandle.onModifyLookYaw(yaw); 14 | } 15 | 16 | @ModifyVariable(method = "(DDDFFZZZZ)V", at = @At("HEAD"), ordinal = 1, argsOnly = true) 17 | private static float modifyLookPitch(float pitch) { 18 | return TaskModifyLookHandle.onModifyLookPitch(pitch); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/resources/fabric.mod.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": 1, 3 | "id": "bedrockminer", 4 | "version": "${version}", 5 | "name": "Bedrock Miner", 6 | "description": "Client mod to mine bedrock!", 7 | "authors": [ 8 | "Bunny_i", 9 | "LXYan", 10 | "bunnyi116" 11 | ], 12 | "contact": { 13 | "homepage": "https://github.com/bunnyi116/fabric-bedrock-miner", 14 | "sources": "https://github.com/bunnyi116/fabric-bedrock-miner" 15 | }, 16 | "license": "", 17 | "icon": "assets/bedrockminer/icon.png", 18 | "environment": "*", 19 | "entrypoints": { 20 | "main": [ 21 | "yan.lx.bedrockminer.BedrockMinerMod" 22 | ] 23 | }, 24 | "mixins": [ 25 | "bedrock-miner.mixins.json" 26 | ], 27 | "depends": { 28 | "fabricloader": ">=${loader_version}", 29 | "minecraft": ">=${minecraft_version}", 30 | "java": ">=${java_version}" 31 | }, 32 | "suggests": { 33 | "another-mod": "*" 34 | }, 35 | "accessWidener" : "bedrock-miner.accesswidener" 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/command/BaseCommand.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.command; 2 | 3 | import com.mojang.brigadier.CommandDispatcher; 4 | import com.mojang.brigadier.builder.LiteralArgumentBuilder; 5 | import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; 6 | import net.minecraft.command.CommandRegistryAccess; 7 | import yan.lx.bedrockminer.BedrockMinerMod; 8 | 9 | import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; 10 | 11 | public abstract class BaseCommand { 12 | public abstract String getName(); 13 | 14 | public abstract void build(LiteralArgumentBuilder builder, CommandRegistryAccess registryAccess); 15 | 16 | public final void register(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { 17 | var builder = literal(this.getName()); 18 | build(builder, registryAccess); 19 | dispatcher.register(literal(BedrockMinerMod.COMMAND_PREFIX).then(builder)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/command/DisableCommand.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.command; 2 | 3 | import com.mojang.brigadier.builder.LiteralArgumentBuilder; 4 | import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; 5 | import net.minecraft.command.CommandRegistryAccess; 6 | import yan.lx.bedrockminer.BedrockMinerLang; 7 | import yan.lx.bedrockminer.config.Config; 8 | import yan.lx.bedrockminer.utils.MessageUtils; 9 | 10 | public class DisableCommand extends BaseCommand { 11 | 12 | @Override 13 | public String getName() { 14 | return "disable"; 15 | } 16 | 17 | @Override 18 | public void build(LiteralArgumentBuilder builder, CommandRegistryAccess registryAccess) { 19 | builder.executes(context -> toggleSwitch()); 20 | } 21 | 22 | private int toggleSwitch() { 23 | if (Config.INSTANCE.disable) { 24 | Config.INSTANCE.disable = false; 25 | MessageUtils.addMessage(BedrockMinerLang.COMMAND_DISABLE_OFF); 26 | } else { 27 | Config.INSTANCE.disable = true; 28 | MessageUtils.addMessage(BedrockMinerLang.COMMAND_DISABLE_ON); 29 | } 30 | Config.save(); 31 | return 0; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/command/DebugCommand.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.command; 2 | 3 | import com.mojang.brigadier.builder.LiteralArgumentBuilder; 4 | import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; 5 | import net.minecraft.command.CommandRegistryAccess; 6 | import yan.lx.bedrockminer.BedrockMinerLang; 7 | import yan.lx.bedrockminer.config.Config; 8 | import yan.lx.bedrockminer.utils.MessageUtils; 9 | 10 | import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.*; 11 | 12 | public class DebugCommand extends BaseCommand { 13 | 14 | @Override 15 | public String getName() { 16 | return "debug"; 17 | } 18 | 19 | @Override 20 | public void build(LiteralArgumentBuilder builder, CommandRegistryAccess registryAccess) { 21 | builder.then(literal("true").executes(context -> toggleSwitch(true))) 22 | .then(literal("false").executes(context -> toggleSwitch(false))); 23 | } 24 | 25 | private int toggleSwitch(boolean b) { 26 | if (b) { 27 | MessageUtils.addMessage(BedrockMinerLang.DEBUG_ON); 28 | } else { 29 | MessageUtils.addMessage(BedrockMinerLang.DEBUG_OFF); 30 | } 31 | Config.INSTANCE.debug = b; 32 | Config.save(); 33 | return 0; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Done to increase the memory available to gradle. 2 | org.gradle.jvmargs=-Xmx1G 3 | org.gradle.parallel=true 4 | 5 | # Mod Properties 6 | mod_version=1.2.27_devjta 7 | maven_group=yan.lx.bedrockMiner 8 | archives_base_name=bedrock-miner 9 | java_version=21 10 | 11 | # Fabric Properties 12 | # check these on https://fabricmc.net/develop/ 13 | # Dependencies 14 | minecraft_version=1.21.6 15 | yarn_mappings=1.21.6+build.1 16 | loader_version=0.16.14 17 | loom_version=1.10-SNAPSHOT 18 | 19 | # Fabric API 20 | fabric_version=0.127.0+1.21.6 21 | 22 | 23 | # Loom image source 24 | #loom_libraries_base=https://bmclapi2.bangbang93.com/maven/ 25 | #loom_resources_base=https://bmclapi2.bangbang93.com/assets/ 26 | #loom_version_manifests=https://bmclapi2.bangbang93.com/mc/game/version_manifest.json 27 | #loom_experimental_versions=https://maven.fabricmc.net/net/minecraft/experimental_versions.json 28 | #loom_fabric_repository=https://repository.hanbings.io/proxy/ 29 | 30 | # Proxy 31 | systemProp.http.proxyHost=127.0.0.1 32 | systemProp.http.proxyPort=10809 33 | systemProp.http.nonProxyHosts=10.*|localhost 34 | 35 | systemProp.socks.proxyHost=localhost 36 | systemProp.socks.proxyPort=10808 37 | systemProp.socks.nonProxyHosts=10.*|localhost 38 | 39 | #systemProp.https.proxyHost=127.0.0.1 40 | #systemProp.https.proxyPort=1081 41 | #systemProp.https.nonProxyHosts=10.*|localhost 42 | 43 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Mod Build 2 | on: [push, pull_request, workflow_dispatch] 3 | 4 | jobs: 5 | build: 6 | strategy: 7 | matrix: 8 | java: [21] 9 | os: [ubuntu-latest] 10 | 11 | runs-on: ${{ matrix.os }} 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v4 15 | 16 | - name: Validate Gradle Wrapper 17 | uses: gradle/wrapper-validation-action@v1 18 | 19 | - name: Setup Java 20 | uses: actions/setup-java@v3.6.0 21 | with: 22 | distribution: 'zulu' 23 | java-version: ${{ matrix.java }} 24 | 25 | - name: Make Gradle Wrapper Executable 26 | run: chmod +x ./gradlew 27 | 28 | - name: Setup Cache 29 | uses: actions/cache@v3 30 | with: 31 | path: | 32 | ~/.gradle/caches 33 | ~/.gradle/wrapper 34 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} 35 | 36 | - name: Build with Gradle 37 | run: ./gradlew build --info 38 | continue-on-error: false # 根据需要决定是否添加此选项 39 | 40 | - name: Find correct JAR 41 | id: find-jar 42 | run: | 43 | output=$(ls build/libs/*.jar | grep -v '-dev\|-sources' | head -1) 44 | echo "jarname=$output" >> $GITHUB_OUTPUT 45 | 46 | - name: Update Build Artifacts 47 | if: success() 48 | uses: actions/upload-artifact@v3 49 | with: 50 | name: build-Mod 51 | path: build/libs/ -------------------------------------------------------------------------------- /src/main/resources/assets/bedrockminer/lang/zh_tw.json: -------------------------------------------------------------------------------- 1 | { 2 | "bedrockminer": "Bedrock Miner", 3 | "bedrockminer.debug.on": "§2成功啟動除錯模式!", 4 | "bedrockminer.debug.off": "§7成功關閉除錯模式!", 5 | "bedrockminer.toggle.on": "§2Bedrock Miner 已啟動!", 6 | "bedrockminer.toggle.off": "§7Bedrock Miner 已關閉。", 7 | "bedrockminer.warn.multiplayer": "§7看起來你在伺服器上使用Bedrock Miner?§r\n§7在使用本模組之前請先徵詢其他玩家的意見。§r", 8 | "bedrockminer.fail.place.piston": "無法放置活塞!(該位置沒有放置條件或放置點有實體或玩家)", 9 | "bedrockminer.fail.place.redstonetorch": "無法放置紅石火把!", 10 | "bedrockminer.fail.place.slimeBlock": "無法放置史萊姆方塊!(該位置沒有放置條件或放置點有實體或玩家)", 11 | "bedrockminer.fail.missing.survival": "僅限生存模式!", 12 | "bedrockminer.fail.missing.piston": "活塞不足!", 13 | "bedrockminer.fail.missing.redstonetorch": "紅石火把不足!", 14 | "bedrockminer.fail.missing.slime": "史萊姆方塊不足!", 15 | "bedrockminer.fail.missing.instantmine": "無法瞬破活塞!請確保有效率V附魔及挖掘加速II效果", 16 | "bedrockminer.command.block.whitelist.add": "§7成功新增白名單方塊 \"%blockName%\"!", 17 | "bedrockminer.command.block.whitelist.remove": "§7成功移除白名單方塊 \"%blockName%\"!", 18 | "bedrockminer.command.block.blacklist.add": "§7成功新增黑名單方塊 \"%blockName%\"!", 19 | "bedrockminer.command.block.blacklist.remove": "§7成功移除名單方塊 \"%blockName%\"!", 20 | "bedrockminer.command.exception.invalidString": "§7未知的字串 \"%input%\"!", 21 | "bedrockminer.command.task.limit": "§2成功將執行上限設為: %limit%", 22 | "bedrockminer.command.task.clear": "§2成功清除快取!", 23 | "bedrockminer.command.disable.on": "§2已停用!", 24 | "bedrockminer.command.disable.off": "§7已啟用!", 25 | "bedrockminer.command.task.mode.set": "§7設定 %mode% 成功!", 26 | "bedrockminer.handle.seek": "目前位置(%BlockPos%)沒有可執行的放置方案" 27 | } 28 | -------------------------------------------------------------------------------- /src/main/resources/assets/bedrockminer/lang/zh_cn.json: -------------------------------------------------------------------------------- 1 | { 2 | "bedrockminer": "Bedrock Miner", 3 | "bedrockminer.debug.on": "§2启动调适模式成功!", 4 | "bedrockminer.debug.off": "§7关闭调适模式成功!", 5 | "bedrockminer.toggle.on": "§2Bedrock Miner 启动成功!", 6 | "bedrockminer.toggle.off": "§7Bedrock Miner 关闭成功。", 7 | "bedrockminer.warn.multiplayer": "§7看起来你好像是在服务器使用Bedrock Miner?§r\n§7在使用本mod前请先征询其他玩家的意见。§r", 8 | "bedrockminer.fail.place.piston": "无法放置活塞!(该位置没有放置条件或放置点有实体或玩家)", 9 | "bedrockminer.fail.place.redstonetorch": "无法放置红石火把!", 10 | "bedrockminer.fail.place.slimeBlock": "无法放置粘液块!(该位置没有放置条件或放置点有实体或玩家)", 11 | "bedrockminer.fail.missing.survival": "仅限生存模式!", 12 | "bedrockminer.fail.missing.piston": "活塞不够啦!", 13 | "bedrockminer.fail.missing.redstonetorch": "红石火把不够啦!", 14 | "bedrockminer.fail.missing.slime": "黏液块不够啦!", 15 | "bedrockminer.fail.missing.instantmine": "无法秒破活塞!请确保效率Ⅴ+急迫Ⅱ", 16 | "bedrockminer.command.block.whitelist.add": "§7添加白名单方块 \"%blockName%\" 成功!", 17 | "bedrockminer.command.block.whitelist.remove": "§7删除白名单方块 \"%blockName%\" 成功!", 18 | "bedrockminer.command.block.blacklist.add": "§7添加黑名单方块 \"%blockName%\" 成功!", 19 | "bedrockminer.command.block.blacklist.remove": "§7删除黑名单方块 \"%blockName%\" 成功!", 20 | "bedrockminer.command.exception.invalidString": "§7输入的 \"%input%\" 字符串错误!", 21 | "bedrockminer.command.task.limit": "§2成功将任务执行上限调整为: %limit%", 22 | "bedrockminer.command.task.clear": "§2成功将任务缓存清空!", 23 | "bedrockminer.command.disable.on": "§2禁用成功!", 24 | "bedrockminer.command.disable.off": "§7启用成功!", 25 | "bedrockminer.command.task.mode.set": "§7设置 %mode% 成功!", 26 | "bedrockminer.handle.seek": "当前位置(%BlockPos%)没有可以执行的放置方案" 27 | } -------------------------------------------------------------------------------- /README_TW.md: -------------------------------------------------------------------------------- 1 | **繁體中文** | [简体中文](./README.md) | [English](./README_EN.md) 2 | 3 | # Fabric-Bedrock-Miner 4 | 幫你 "挖掘" 基岩的Fabric使用者端模組! 5 | 6 | # 說明 7 | 此項目從 [LXYan2333/Fabric-Bedrock-Miner](https://github.com/LXYan2333/Fabric-Bedrock-Miner) fork 進行修改 8 | 9 | ## 預設方塊列表清單 10 | 11 | #### 白名單方塊(支援破壞) 12 | - 基岩 13 | 14 | #### 黑名單方塊(不支援破壞) 15 | - 無 16 | 17 | #### 伺服器黑名單方塊(不支援破壞,無法透過指令更改,內建過濾器) 18 | - 屏障 19 | - 指令方塊 20 | - 連鎖型指令方塊 21 | - 重複型指令方塊 22 | - 結構空位 23 | - 結構方塊 24 | - 拼圖方塊 25 | 26 | #### 方塊增加指令過濾器 27 | - 空氣 28 | - 可替換方塊 29 | 30 | ## 使用者端指令說明 31 | - `/bedrockMiner` 開啟/關閉 32 | - `/bedrockMiner disable` 停用模組(開啟後模組將不會繼續處理) 33 | - `/bedrockMiner block whitelist add ` 增加白名單方塊 34 | - `/bedrockMiner block whitelist remove ` 移除白名單方塊 35 | - `/bedrockMiner block blacklist add ` 增加黑名單方塊 36 | - `/bedrockMiner block blacklist remove ` 移除黑名單方塊 37 | - `/bedrockMiner blockName blacklist add ` 增加黑名單方塊列表 38 | - `/bedrockMiner blockName blacklist remove ` 移除黑名單方塊列表 39 | - `/bedrockMiner task add ` 新增任務 40 | - `/bedrockMiner task clear` 清空任務 41 | - `/bedrockMiner debug true` 開啟除錯模式 42 | - `/bedrockMiner debug false` 關閉除錯模式 43 | 44 | # 影片 45 | https://www.youtube.com/watch?v=b8Y86yxjr_Y 46 |
47 | https://www.bilibili.com/video/BV1Fv411P7Vc 48 | 49 | # 使用 50 | 準備好以下物品: 51 | 1. 效率V 鑽石/獄隨鎬 52 | 2. 挖掘加速II 烽火台 53 | 3. 一些活塞 54 | 4. 一些紅石火把 55 | 5. 一些史萊姆方塊 56 | 57 | **空手**右鍵基岩啟動模組(注意要空手) 58 | 59 | 啟動後,左鍵基岩,模組會自動破除基岩。 60 | 61 | 再次空手右鍵基岩關閉模組。 62 | 63 | 如果本模組幫你解省了大量時間的話,請考慮給個Star吧。 64 | 65 | ## Q群 66 | 67 | ![群組QR Code](https://github.com/Bunnui/Fabric-Bedrock-Miner/assets/37466008/7f1c2bc7-876b-4d34-9534-c72a3b555a2a) 68 | 69 | ## 愛發電 70 | 71 | https://afdian.net/a/bunny_i 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [繁體中文](./README_TW.md) | **简体中文** | [English](./README_EN.md) 2 | 3 | # Fabric-Bedrock-Miner 4 | 帮你 "挖掘" 基岩的客户端 Fabric mod! 5 | 6 | # 说明 7 | 该项目复刻自 [LXYan2333/Fabric-Bedrock-Miner](https://github.com/LXYan2333/Fabric-Bedrock-Miner) 进行修改 8 | 9 | ## 默认方块列表清单 10 | 11 | #### 破坏方块白名单(支持破坏) 12 | - 基岩 13 | 14 | #### 破坏方块黑名单 (不支持破坏) 15 | - 暂无 16 | 17 | #### 服务器方块黑名单(不支持破坏,无法通过指令更改,内置过滤器) 18 | - 屏障 19 | - 普通型命令方块 20 | - 连锁型命令方块 21 | - 循环型命令方块 22 | - 结构空位 23 | - 结构方块 24 | - 拼图方块 25 | 26 | #### 方块添加命令过滤器 27 | - 空气 28 | - 可替换方块 29 | 30 | ## 客户端指命说明 31 | - `/bedrockMiner` 开启/关闭 32 | - `/bedrockMiner disable` 禁用模组(开启后模组将不会继续处理) 33 | - `/bedrockMiner block whitelist add ` 添加白名单方块列表 34 | - `/bedrockMiner block whitelist remove ` 移除白名单方块列表 35 | - `/bedrockMiner block blacklist add ` 添加黑名单方块列表 36 | - `/bedrockMiner block blacklist remove ` 移除黑名单方块列表 37 | - `/bedrockMiner blockName blacklist add ` 添加黑名单方块列表 38 | - `/bedrockMiner blockName blacklist remove ` 移除黑名单方块列表 39 | - `/bedrockMiner task add ` 添加任务 40 | - `/bedrockMiner task clear` 清理任务 41 | - `/bedrockMiner debug true` 开启调试模式 42 | - `/bedrockMiner debug false` 关闭调试模式 43 | 44 | # 视频教程 45 | https://www.youtube.com/watch?v=b8Y86yxjr_Y 46 |
47 | https://www.bilibili.com/video/BV1Fv411P7Vc 48 | 49 | # 使用方法 50 | 使用前需准备好如下物品: 51 | 1. 效率 Ⅴ 钻石镐(下界合金也行) 52 | 2. 急迫 Ⅱ 信标 53 | 3. 一些活塞 54 | 4. 一些红石火把 55 | 5. 黏液块若干 56 | 57 | **空手**右键基岩启动此模组(注意要空手) 58 | 59 | 启动后,左键基岩,模组会尝试自动破除基岩。 60 | 61 | 再次空手右键基岩关闭此模组。 62 | 63 | 如果本模组帮你节省了大量时间的话,请给个 Star 呗 QwQ。 64 | 65 | ## Q群 66 | 67 | ![群二维码](https://github.com/Bunnui/Fabric-Bedrock-Miner/assets/37466008/7f1c2bc7-876b-4d34-9534-c72a3b555a2a) 68 | 69 | ## 爱发电 70 | 71 | https://afdian.net/a/bunny_i 72 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/utils/BlockBreakerUtils.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.utils; 2 | 3 | import net.minecraft.client.MinecraftClient; 4 | import net.minecraft.client.network.ClientPlayerEntity; 5 | import net.minecraft.client.network.ClientPlayerInteractionManager; 6 | import net.minecraft.client.world.ClientWorld; 7 | import net.minecraft.entity.player.PlayerInventory; 8 | import net.minecraft.util.math.BlockPos; 9 | import net.minecraft.util.math.Direction; 10 | import org.jetbrains.annotations.Nullable; 11 | import yan.lx.bedrockminer.BedrockMinerMod; 12 | import yan.lx.bedrockminer.Debug; 13 | 14 | 15 | public class BlockBreakerUtils { 16 | public static boolean simpleBreakBlock(BlockPos pos) { 17 | return breakBlock(pos, Direction.UP); 18 | } 19 | 20 | public static boolean breakBlock(BlockPos blockPos, Direction direction) { 21 | MinecraftClient client = MinecraftClient.getInstance(); 22 | ClientPlayerEntity player = client.player; 23 | ClientWorld world = client.world; 24 | ClientPlayerInteractionManager interactionManager = client.interactionManager; 25 | if (player == null || world == null || interactionManager == null || blockPos == null) { 26 | return false; 27 | } 28 | PlayerInventory playerInventory = player.getInventory(); 29 | 30 | // 预检查 31 | if (world.getBlockState(blockPos).isReplaceable()) return true; 32 | if (world.getBlockState(blockPos).getBlock().getHardness() < 0) return false; 33 | 34 | // InventoryManagerUtils.autoSwitch(); 35 | 36 | // interactionManager.attackBlock(blockPos, direction); 37 | // 更新方块正在破坏进程 38 | if (interactionManager.updateBlockBreakingProgress(blockPos, direction)) { 39 | client.particleManager.addBlockBreakingParticles(blockPos, direction); 40 | } 41 | // 检查是否已经成功 42 | return world.getBlockState(blockPos).isReplaceable(); 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/BedrockMinerMod.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer; 2 | 3 | import net.fabricmc.api.ModInitializer; 4 | import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import yan.lx.bedrockminer.command.*; 8 | import yan.lx.bedrockminer.task.TaskManager; 9 | 10 | import java.util.ArrayList; 11 | 12 | import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; 13 | 14 | public class BedrockMinerMod implements ModInitializer { 15 | public static final String MOD_NAME = "Bedrock Miner"; 16 | public static final String MOD_ID = "bedrockminer"; 17 | public static final String COMMAND_PREFIX = "bedrockMiner"; 18 | public static final Logger LOGGER = LoggerFactory.getLogger(MOD_NAME); 19 | public static final boolean TEST = true; 20 | 21 | @Override 22 | public void onInitialize() { 23 | registerCommand(); 24 | Debug.info("模组初始化成功"); 25 | } 26 | 27 | private void registerCommand() { 28 | // 初始化命令实例 29 | var commands = new ArrayList(); 30 | commands.add(new BlockCommand()); 31 | commands.add(new BlockNameCommand()); 32 | commands.add(new DebugCommand()); 33 | commands.add(new TaskCommand()); 34 | commands.add(new DisableCommand()); 35 | 36 | // 开始注册 37 | ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { 38 | // 子命令 39 | for (var command : commands) { 40 | command.register(dispatcher, registryAccess); 41 | } 42 | // 主命令执行 43 | var root = literal(COMMAND_PREFIX).executes(context -> { 44 | TaskManager.setWorking(!TaskManager.isWorking()); 45 | return 0; 46 | }); 47 | if (TEST) { 48 | Test.register(root); 49 | } 50 | dispatcher.register(root); 51 | }); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/resources/assets/bedrockminer/lang/en_us.json: -------------------------------------------------------------------------------- 1 | { 2 | "bedrockminer": "Bedrock Miner", 3 | "bedrockminer.debug.on": "§2Startup debug mode successful!", 4 | "bedrockminer.debug.off": "§2Closed debug mode successful!", 5 | "bedrockminer.toggle.on": "§2Bedrock Miner Successful startup! ", 6 | "bedrockminer.toggle.off": "§7Bedrock Miner Closed successfully.", 7 | "bedrockminer.warn.multiplayer": "§7It seems that you are playing on a server? §r\n§7Please ask other players' opinions first.§r", 8 | "bedrockminer.fail.place.piston": "Failed to place piston! (There are no placement conditions or there are entities or players at the placement point)", 9 | "bedrockminer.fail.place.redstonetorch": "Failed to place redstone torch!", 10 | "bedrockminer.fail.place.slimeBlock": "Failed to place slime block (There are no placement conditions or there are entities or players at the placement point)!", 11 | "bedrockminer.fail.missing.survival": "Survival Only!", 12 | "bedrockminer.fail.missing.piston": "Needs more piston!", 13 | "bedrockminer.fail.missing.redstonetorch": "Needs more redstone torch!", 14 | "bedrockminer.fail.missing.slime": "Needs more slime block!", 15 | "bedrockminer.fail.missing.instantmine": "Can't instantly mine piston! EfficiencyⅤ+HasteⅡ required!", 16 | "bedrockminer.command.block.whitelist.add": "§7Add whitelist block \"%blockName%\" success!", 17 | "bedrockminer.command.block.whitelist.remove": "§7Remove whitelist block \"%blockName%\" success!", 18 | "bedrockminer.command.block.blacklist.add": "§7Add blacklist block \"%blockName%\" succeeded!", 19 | "bedrockminer.command.block.blacklist.remove": "§7Remove blacklist Block \"%blockName%\" succeeded!", 20 | "bedrockminer.command.exception.invalidString": "§2The input string \"%s\" is incorrect.", 21 | "bedrockminer.command.task.limit": "§7The task limit has been successfully adjusted to %limit%.", 22 | "bedrockminer.command.task.clear": "§7Successfully cleared task cache!", 23 | "bedrockminer.command.disable.on": "§2disable Successfully!", 24 | "bedrockminer.command.disable.off": "§7enable Successfully!", 25 | "bedrockminer.command.task.mode.set": "§set %mode% Successfully!", 26 | "bedrockminer.handle.seek": "There is no placement scheme that can be executed at the current location(%BlockPos%)" 27 | } -------------------------------------------------------------------------------- /README_EN.md: -------------------------------------------------------------------------------- 1 | [繁體中文](./README_TW.md) | [简体中文](./README.md) | **English** 2 | 3 | # Fabric-Bedrock-Miner 4 | A Fabric client mod to "mine" bedrock! 5 | 6 | # illustrate 7 | This project fork modified from [LXYan2333/Fabric-Bedrock-Miner](https://github.com/LXYan2333/Fabric-Bedrock-Miner)
8 | 9 | ## Default block list list 10 | 11 | #### Block whitelist (break supported) 12 | - Bedrock 13 | 14 | #### Block blacklist (Break is not supported) 15 | - None 16 | 17 | #### Server block blacklist (Break is not supported, cannot be changed by command, built-in filter) 18 | - Command Block 19 | - Chain Command Block 20 | - Repeating Command Block 21 | - Structure Void 22 | - Structure Block 23 | - Jigsaw Block 24 | 25 | #### Block to add command filters 26 | - Air 27 | - Replaceable blocks 28 | 29 | ### Command description 30 | - `/bedrockMiner` on/off 31 | - `/bedrockMiner disable` disable the mod (the mod will not continue to process after it is turned on) 32 | - `/bedrockMiner block whitelist add ` add whitelist block list 33 | - `/bedrockMiner block whitelist remove ` remove whitelist block list 34 | - `/bedrockMiner block blacklist add ` add blacklist block list 35 | - `/bedrockMiner block blacklist remove ` remove blacklist block list 36 | - `/bedrockMiner block blockName add ` add blacklist block list 37 | - `/bedrockMiner block blockName remove ` remove blacklist block list 38 | - `/bedrockMiner task add ` add a task 39 | - `/bedrockMiner task clear` clear the task 40 | - `/bedrockMiner debug true` enables debug mode 41 | - `/bedrockMiner debug false` turn off debug mode 42 | 43 | # Showcase 44 | https://www.youtube.com/watch?v=b8Y86yxjr_Y 45 | https://www.bilibili.com/video/BV1Fv411P7Vc 46 | 47 | # Usage 48 | Have the following items ready: 49 | 1. Efficiency V diamond (or netherite) pickaxe 50 | 2. Haste II beacon 51 | 3. Pistons 52 | 4. Redstone torches 53 | 5. Slime blocks 54 | 55 | Right click bedrock **with an empty hand** to switch on/off. 56 | 57 | While the mod is enabled, left click bedrock to "mine" it. 58 | 59 | If my mod saves you tons of time, please considering leave me a star. 60 | 61 | # Compile 62 | Checkout to the corresponding Minecraft version and compile following the Fabric wiki. 63 | 64 | ## Q群 65 | 66 | ![群二维码](https://github.com/Bunnui/Fabric-Bedrock-Miner/assets/37466008/7f1c2bc7-876b-4d34-9534-c72a3b555a2a) 67 | 68 | ## 爱发电 69 | 70 | https://afdian.net/a/bunny_i 71 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/mixins/MixinMinecraftClient.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.mixins; 2 | 3 | import net.minecraft.client.MinecraftClient; 4 | import net.minecraft.client.network.ClientPlayerEntity; 5 | import net.minecraft.client.world.ClientWorld; 6 | import net.minecraft.util.hit.BlockHitResult; 7 | import net.minecraft.util.hit.HitResult; 8 | import net.minecraft.util.math.BlockPos; 9 | import net.minecraft.util.math.Direction; 10 | import org.jetbrains.annotations.Nullable; 11 | import org.spongepowered.asm.mixin.Mixin; 12 | import org.spongepowered.asm.mixin.Shadow; 13 | import org.spongepowered.asm.mixin.injection.At; 14 | import org.spongepowered.asm.mixin.injection.Inject; 15 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 16 | import org.spongepowered.asm.mixin.injection.callback.LocalCapture; 17 | import yan.lx.bedrockminer.task.TaskManager; 18 | 19 | @Mixin(MinecraftClient.class) 20 | public class MixinMinecraftClient { 21 | @Shadow 22 | @Nullable 23 | public ClientWorld world; 24 | 25 | @Shadow 26 | @Nullable 27 | public ClientPlayerEntity player; 28 | 29 | @Shadow 30 | @Nullable 31 | public HitResult crosshairTarget; 32 | 33 | 34 | @Inject(method = "doItemUse", at = @At(value = "HEAD")) 35 | private void doItemUse(CallbackInfo ci) { 36 | if (crosshairTarget == null || world == null || player == null) { 37 | return; 38 | } 39 | if (crosshairTarget.getType() != HitResult.Type.BLOCK || !player.getMainHandStack().isEmpty()) { 40 | return; 41 | } 42 | var blockHitResult = (BlockHitResult) crosshairTarget; 43 | var blockPos = blockHitResult.getBlockPos(); 44 | var blockState = world.getBlockState(blockPos); 45 | var block = blockState.getBlock(); 46 | TaskManager.switchOnOff(block); 47 | } 48 | 49 | @Inject(method = "handleBlockBreaking", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"), locals = LocalCapture.CAPTURE_FAILSOFT) 50 | private void handleBlockBreaking(boolean bl, CallbackInfo ci, BlockHitResult blockHitResult, BlockPos blockPos, Direction direction) { 51 | if (world == null) { 52 | return; 53 | } 54 | var blockState = world.getBlockState(blockPos); 55 | var block = blockState.getBlock(); 56 | TaskManager.addTask(block, blockPos, world); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/command/argument/DirectionArgumentType.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.command.argument; 2 | 3 | import com.mojang.brigadier.StringReader; 4 | import com.mojang.brigadier.arguments.ArgumentType; 5 | import com.mojang.brigadier.context.CommandContext; 6 | import com.mojang.brigadier.exceptions.CommandSyntaxException; 7 | import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; 8 | import com.mojang.brigadier.suggestion.Suggestions; 9 | import com.mojang.brigadier.suggestion.SuggestionsBuilder; 10 | import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; 11 | import net.minecraft.text.Text; 12 | import net.minecraft.util.math.Direction; 13 | import yan.lx.bedrockminer.BedrockMinerLang; 14 | 15 | import java.util.concurrent.CompletableFuture; 16 | 17 | public class DirectionArgumentType implements ArgumentType { 18 | private static final DynamicCommandExceptionType INVALID_STRING_EXCEPTION = new DynamicCommandExceptionType(input -> Text.literal(BedrockMinerLang.EXCEPTION_INVALID_STRING.getString().replace("%input%", input.toString()))); 19 | 20 | public static Direction getDirection(CommandContext context, String name) { 21 | return context.getArgument(name, Direction.class); 22 | } 23 | 24 | public Direction parse(StringReader reader) throws CommandSyntaxException { 25 | var i = reader.getCursor(); 26 | while (reader.canRead()) { 27 | reader.skip(); 28 | } 29 | var string = reader.getString().substring(i, reader.getCursor()); 30 | for (Direction direction : Direction.values()) { 31 | if (string.equalsIgnoreCase(direction.asString())) { 32 | return direction; 33 | } 34 | } 35 | reader.setCursor(i); 36 | throw INVALID_STRING_EXCEPTION.create(string); 37 | } 38 | 39 | 40 | public CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder) { 41 | StringReader reader = new StringReader(builder.getInput()); 42 | reader.setCursor(builder.getStart()); 43 | var i = reader.getCursor(); 44 | while (reader.canRead()) { 45 | reader.skip(); 46 | } 47 | var string = reader.getString().substring(i, reader.getCursor()); 48 | for (Direction direction : Direction.values()) { 49 | if (direction.asString().contains(string)) { 50 | builder.suggest(direction.asString()); 51 | } 52 | } 53 | return builder.buildFuture(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/BedrockMinerLang.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer; 2 | 3 | import net.minecraft.text.Text; 4 | 5 | public class BedrockMinerLang { 6 | public static final Text TOGGLE_ON = Text.translatable("bedrockminer.toggle.on"); 7 | public static final Text TOGGLE_OFF = Text.translatable("bedrockminer.toggle.off"); 8 | 9 | public static final Text DEBUG_ON = Text.translatable("bedrockminer.debug.on"); 10 | public static final Text DEBUG_OFF = Text.translatable("bedrockminer.debug.off"); 11 | 12 | public static final Text WARN_MULTIPLAYER = Text.translatable("bedrockminer.warn.multiplayer"); 13 | public static final Text FAIL_MISSING_SURVIVAL = Text.translatable("bedrockminer.fail.missing.survival"); 14 | public static final Text FAIL_MISSING_PISTON = Text.translatable("bedrockminer.fail.missing.piston"); 15 | public static final Text FAIL_MISSING_REDSTONETORCH = Text.translatable("bedrockminer.fail.missing.redstonetorch"); 16 | public static final Text FAIL_MISSING_SLIME = Text.translatable("bedrockminer.fail.missing.slime"); 17 | public static final Text FAIL_MISSING_INSTANTMINE = Text.translatable("bedrockminer.fail.missing.instantmine"); 18 | 19 | public static final Text FAIL_PLACE_PISTON = Text.translatable("bedrockminer.fail.place.piston"); 20 | public static final Text FAIL_PLACE_REDSTONETORCH = Text.translatable("bedrockminer.fail.place.redstonetorch"); 21 | public static final Text FAIL_PLACE_SLIMEBLOCK = Text.translatable("bedrockminer.fail.place.slimeBlock"); 22 | 23 | public static final Text COMMAND_BLOCK_WHITELIST_ADD = Text.translatable("bedrockminer.command.block.whitelist.add"); 24 | public static final Text COMMAND_BLOCK_WHITELIST_REMOVE = Text.translatable("bedrockminer.command.block.whitelist.remove"); 25 | 26 | public static final Text COMMAND_BLOCK_BLACKLIST_ADD = Text.translatable("bedrockminer.command.block.blacklist.add"); 27 | public static final Text COMMAND_BLOCK_BLACKLIST_REMOVE = Text.translatable("bedrockminer.command.block.blacklist.remove"); 28 | 29 | public static final Text COMMAND_TASK_LIMIT = Text.translatable("bedrockminer.command.task.limit"); 30 | public static final Text COMMAND_TASK_CLEAR = Text.translatable("bedrockminer.command.task.clear"); 31 | 32 | public static final Text COMMAND_DISABLE_ON = Text.translatable("bedrockminer.command.disable.on"); 33 | public static final Text COMMAND_DISABLE_OFF = Text.translatable("bedrockminer.command.disable.off"); 34 | 35 | public static final Text COMMAND_TASK_MODE_SET = Text.translatable("bedrockminer.command.task.mode.set"); 36 | public static final Text EXCEPTION_INVALID_STRING = Text.translatable("bedrockminer.command.exception.invalidString"); 37 | public static final Text HANDLE_SEEK = Text.translatable("bedrockminer.handle.seek"); 38 | } 39 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/command/argument/DirectionListArgumentType.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.command.argument; 2 | 3 | import com.mojang.brigadier.StringReader; 4 | import com.mojang.brigadier.arguments.ArgumentType; 5 | import com.mojang.brigadier.context.CommandContext; 6 | import com.mojang.brigadier.exceptions.CommandSyntaxException; 7 | import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; 8 | import com.mojang.brigadier.suggestion.Suggestions; 9 | import com.mojang.brigadier.suggestion.SuggestionsBuilder; 10 | import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; 11 | import net.minecraft.text.Text; 12 | import net.minecraft.util.math.Direction; 13 | import yan.lx.bedrockminer.BedrockMinerLang; 14 | 15 | import java.util.ArrayList; 16 | import java.util.concurrent.CompletableFuture; 17 | 18 | public class DirectionListArgumentType implements ArgumentType { 19 | private static final DynamicCommandExceptionType INVALID_STRING_EXCEPTION = new DynamicCommandExceptionType(input -> Text.literal(BedrockMinerLang.EXCEPTION_INVALID_STRING.getString().replace("%input%", input.toString()))); 20 | 21 | public static Direction getDirection(CommandContext context, String name) { 22 | return context.getArgument(name, Direction.class); 23 | } 24 | 25 | 26 | public Direction[] parse(StringReader reader) throws CommandSyntaxException { 27 | var list = new ArrayList(); 28 | while (reader.canRead()) { 29 | if (reader.peek() == ',') { 30 | reader.skip(); 31 | continue; 32 | } 33 | var i = reader.getCursor(); 34 | while (reader.peek() != ',') { 35 | reader.skip(); 36 | } 37 | var string = reader.getString().substring(i, reader.getCursor()); 38 | Direction facing = null; 39 | for (Direction direction : Direction.values()) { 40 | if (string.equalsIgnoreCase(direction.asString())) { 41 | facing = direction; 42 | } 43 | } 44 | if (facing == null) { 45 | reader.setCursor(i); 46 | throw INVALID_STRING_EXCEPTION.create(string); 47 | } else { 48 | list.add(facing); 49 | } 50 | } 51 | return list.toArray(Direction[]::new); 52 | } 53 | 54 | 55 | public CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder) { 56 | StringReader reader = new StringReader(builder.getInput()); 57 | reader.setCursor(builder.getStart()); 58 | var i = reader.getCursor(); 59 | while (reader.canRead()) { 60 | reader.skip(); 61 | } 62 | var string = reader.getString().substring(i, reader.getCursor()); 63 | for (Direction direction : Direction.values()) { 64 | if (direction.asString().contains(string)) { 65 | builder.suggest(direction.asString()); 66 | } 67 | } 68 | return builder.buildFuture(); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/config/Config.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.config; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.GsonBuilder; 5 | import net.fabricmc.loader.api.FabricLoader; 6 | import net.minecraft.block.Blocks; 7 | import yan.lx.bedrockminer.BedrockMinerMod; 8 | import yan.lx.bedrockminer.utils.BlockUtils; 9 | 10 | import java.io.*; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | public class Config { 15 | public static final File file = new File(FabricLoader.getInstance().getConfigDir().toFile(), "bedrockminer.json"); 16 | public static final Config INSTANCE = Config.load(); 17 | public boolean disable = false; 18 | public boolean debug = false; 19 | public boolean vertical = true; 20 | public boolean horizontal = true; 21 | public int taskLimit = 1; 22 | public List blockWhitelist = getDefaultBlockWhitelist(); 23 | public List blockBlacklist = new ArrayList<>(); 24 | public transient List blockBlacklistServer = getDefaultBlockBlacklistServer(); 25 | 26 | public static List getDefaultBlockWhitelist() { 27 | var list = new ArrayList(); 28 | list.add(BlockUtils.getId(Blocks.BEDROCK)); // 基岩 29 | // list.add(BlockUtils.getId(Blocks.END_PORTAL)); // 末地传送门 30 | // list.add(BlockUtils.getId(Blocks.END_PORTAL_FRAME)); // 末地传送门-框架 31 | // list.add(BlockUtils.getId(Blocks.END_GATEWAY)); // 末地折跃门 32 | return list; 33 | } 34 | 35 | public static List getDefaultBlockBlacklistServer() { 36 | // 默认方块黑名单 (用于限制的服务器, 与自定义黑名单分离) 37 | var list = new ArrayList(); 38 | list.add(BlockUtils.getId(Blocks.BARRIER)); // 屏障 39 | list.add(BlockUtils.getId(Blocks.COMMAND_BLOCK)); // 普通命令方块 40 | list.add(BlockUtils.getId(Blocks.CHAIN_COMMAND_BLOCK)); // 连锁型命令方块 41 | list.add(BlockUtils.getId(Blocks.REPEATING_COMMAND_BLOCK)); // 循环型命令方块 42 | list.add(BlockUtils.getId(Blocks.STRUCTURE_VOID)); // 结构空位 43 | list.add(BlockUtils.getId(Blocks.STRUCTURE_BLOCK)); // 结构方块 44 | list.add(BlockUtils.getId(Blocks.JIGSAW)); // 拼图方块 45 | return list; 46 | } 47 | 48 | public static Config load() { 49 | Config config = null; 50 | Gson gson = new Gson(); 51 | try (Reader reader = new FileReader(file)) { 52 | config = gson.fromJson(reader, Config.class); 53 | BedrockMinerMod.LOGGER.info("已成功加载配置文件"); 54 | } catch (Exception e) { 55 | if (file.exists()) { 56 | if (file.delete()) { 57 | BedrockMinerMod.LOGGER.info("无法加载配置,已成功删除配置文件"); 58 | } else { 59 | BedrockMinerMod.LOGGER.info("无法加载配置,删除配置文件失败"); 60 | } 61 | } else { 62 | BedrockMinerMod.LOGGER.info("找不到配置文件"); 63 | } 64 | } 65 | if (config == null) { 66 | BedrockMinerMod.LOGGER.info("使用默认配置"); 67 | config = new Config(); 68 | save(); 69 | } 70 | return config; 71 | } 72 | 73 | public static void save() { 74 | Gson gson = new GsonBuilder().setPrettyPrinting().create(); 75 | try (FileWriter writer = new FileWriter(file)) { 76 | gson.toJson(INSTANCE, writer); 77 | } catch (IOException e) { 78 | BedrockMinerMod.LOGGER.info("无法保存配置文件"); 79 | e.printStackTrace(); 80 | } 81 | } 82 | 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/task/TaskModifyLookHandle.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.task; 2 | 3 | import net.minecraft.client.MinecraftClient; 4 | import net.minecraft.client.network.ClientPlayNetworkHandler; 5 | import net.minecraft.client.network.ClientPlayerEntity; 6 | import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; 7 | import net.minecraft.util.math.Direction; 8 | import org.jetbrains.annotations.Nullable; 9 | 10 | public class TaskModifyLookHandle { 11 | private static boolean modifyYaw = false; 12 | private static boolean modifyPitch = false; 13 | private static float yaw = 0F; 14 | private static float pitch = 0F; 15 | private static int ticks = 0; 16 | private static @Nullable TaskHandler taskHandler = null; 17 | 18 | public static float onModifyLookYaw(float yaw) { 19 | return modifyYaw ? TaskModifyLookHandle.yaw : yaw; 20 | } 21 | 22 | public static float onModifyLookPitch(float pitch) { 23 | return modifyPitch ? TaskModifyLookHandle.pitch : pitch; 24 | } 25 | 26 | private static PlayerMoveC2SPacket getLookAndOnGroundPacket(ClientPlayerEntity player) { 27 | var yaw = modifyYaw ? TaskModifyLookHandle.yaw : player.getYaw(); 28 | var pitch = modifyPitch ? TaskModifyLookHandle.pitch : player.getPitch(); 29 | return new PlayerMoveC2SPacket.LookAndOnGround(yaw, pitch, player.isOnGround(), player.horizontalCollision); 30 | } 31 | 32 | public static void set(float yaw, float pitch) { 33 | TaskModifyLookHandle.modifyYaw = true; 34 | TaskModifyLookHandle.yaw = yaw; 35 | TaskModifyLookHandle.modifyPitch = true; 36 | TaskModifyLookHandle.pitch = pitch; 37 | } 38 | 39 | public static void set(Direction facing, TaskHandler handler) { 40 | taskHandler = handler; 41 | MinecraftClient client = MinecraftClient.getInstance(); 42 | ClientPlayerEntity player = client.player; 43 | ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); 44 | float yaw = switch (facing) { 45 | case SOUTH -> 180F; 46 | case EAST -> 90F; 47 | case NORTH -> 0F; 48 | case WEST -> -90F; 49 | default -> player == null ? 0F : player.getYaw(); 50 | }; 51 | float pitch = switch (facing) { 52 | case UP -> 90F; 53 | case DOWN -> -90F; 54 | default -> 0F; 55 | }; 56 | set(yaw, pitch); 57 | if (networkHandler != null && player != null) { 58 | networkHandler.sendPacket(getLookAndOnGroundPacket(player)); 59 | } 60 | } 61 | 62 | public static void reset() { 63 | modifyYaw = false; 64 | yaw = 0F; 65 | modifyPitch = false; 66 | pitch = 0F; 67 | taskHandler = null; 68 | // 发送一个还原视角的数据包 69 | MinecraftClient client = MinecraftClient.getInstance(); 70 | ClientPlayerEntity player = client.player; 71 | ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); 72 | if (networkHandler != null && player != null) { 73 | networkHandler.sendPacket(getLookAndOnGroundPacket(player)); 74 | } 75 | } 76 | 77 | 78 | public static void onTick() { 79 | // 自动重置视角 80 | if (isModify()){ 81 | if (ticks++ > 20) { 82 | ticks = 0; 83 | reset(); 84 | } 85 | } 86 | } 87 | 88 | public static boolean isModify() { 89 | return modifyYaw || modifyPitch; 90 | } 91 | 92 | public static @Nullable TaskHandler getTaskHandler() { 93 | return taskHandler; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/utils/BlockPlacerUtils.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.utils; 2 | 3 | import net.minecraft.client.MinecraftClient; 4 | import net.minecraft.item.*; 5 | import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; 6 | import net.minecraft.server.network.ServerPlayNetworkHandler; 7 | import net.minecraft.util.Hand; 8 | import net.minecraft.util.hit.BlockHitResult; 9 | import net.minecraft.util.math.BlockPos; 10 | import net.minecraft.util.math.Direction; 11 | import net.minecraft.util.math.MathHelper; 12 | import net.minecraft.util.math.Vec3d; 13 | import org.jetbrains.annotations.Nullable; 14 | import yan.lx.bedrockminer.Debug; 15 | 16 | public class BlockPlacerUtils { 17 | public static final double MAX_BREAK_SQUARED_DISTANCE = MathHelper.square(6.0); 18 | /** 19 | * 活塞放置 20 | * 21 | * @param blockPos 活塞放置坐标 22 | * @param facing 活塞放置方向 23 | * @param items 使用的物品 24 | */ 25 | public static void placement(BlockPos blockPos, Direction facing, @Nullable Item... items) { 26 | if (blockPos == null || facing == null) return; 27 | var client = MinecraftClient.getInstance(); 28 | var world = client.world; 29 | var player = client.player; 30 | var networkHandler = client.getNetworkHandler(); 31 | var interactionManager = client.interactionManager; 32 | if (world == null || player == null || networkHandler == null || interactionManager == null) return; 33 | if (!world.getBlockState(blockPos).isReplaceable()) return; 34 | var yaw = switch (facing) { 35 | case SOUTH -> 180F; 36 | case EAST -> 90F; 37 | case NORTH -> 0F; 38 | case WEST -> -90F; 39 | default -> player.getYaw(); 40 | }; 41 | var pitch = switch (facing) { 42 | case UP -> 90F; 43 | case DOWN -> -90F; 44 | default -> 0F; 45 | }; 46 | // 模拟选中位置(凭空放置) 47 | var blockCenterPos = Vec3d.ofCenter(blockPos); 48 | var hitPos = blockPos.offset(facing.getOpposite()); 49 | var hitVec3d = hitPos.toCenterPos().offset(facing, 0.5F); // 放置面中心坐标 50 | var hitResult = new BlockHitResult(hitVec3d, facing, blockPos, false); 51 | var distance = player.getEyePos().squaredDistanceTo(blockCenterPos); 52 | if (distance > MAX_BREAK_SQUARED_DISTANCE) { 53 | Debug.info("玩家位置离目标方块位置超过限制%s, 当前距离目标方块:%s", MAX_BREAK_SQUARED_DISTANCE, distance); 54 | return; 55 | } 56 | var spacing = hitVec3d.subtract(blockCenterPos); // 选中放置面与目标方块中心位置的间距 57 | var maxRange = 1.0000001D; 58 | if (!(Math.abs(spacing.getX()) < maxRange && Math.abs(spacing.getY()) < maxRange && Math.abs(spacing.getZ()) < maxRange)) { 59 | Debug.info("选中放置面与目标方块中心位置的间距超过限制%s!%s, %s", maxRange, blockPos.toShortString(), hitVec3d); 60 | return; 61 | } 62 | if (items != null) { 63 | InventoryManagerUtils.switchToItem(items); 64 | } 65 | // 发送修改视角数据包 66 | networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(yaw, pitch, player.isOnGround(), player.horizontalCollision)); 67 | // 发送交互方块数据包 68 | interactionManager.interactBlock(player, Hand.MAIN_HAND, hitResult); 69 | } 70 | 71 | public static void placement(BlockPos blockPos, Direction facing) { 72 | placement(blockPos, facing, (Item) null); 73 | } 74 | 75 | public static void simpleBlockPlacement(BlockPos blockPos) { 76 | simpleBlockPlacement(blockPos, (Item) null); 77 | } 78 | 79 | public static void simpleBlockPlacement(BlockPos blockPos, @Nullable Item... items) { 80 | placement(blockPos, Direction.UP, items); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/command/argument/BlockNameArgument.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.command.argument; 2 | 3 | import com.mojang.brigadier.StringReader; 4 | import com.mojang.brigadier.arguments.ArgumentType; 5 | import com.mojang.brigadier.context.CommandContext; 6 | import com.mojang.brigadier.exceptions.CommandSyntaxException; 7 | import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; 8 | import com.mojang.brigadier.suggestion.Suggestions; 9 | import com.mojang.brigadier.suggestion.SuggestionsBuilder; 10 | import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; 11 | import net.minecraft.block.Block; 12 | import net.minecraft.registry.Registries; 13 | import net.minecraft.text.Text; 14 | import net.minecraft.util.Identifier; 15 | import org.jetbrains.annotations.Nullable; 16 | import yan.lx.bedrockminer.BedrockMinerLang; 17 | import yan.lx.bedrockminer.utils.BlockUtils; 18 | 19 | import java.util.Arrays; 20 | import java.util.Collection; 21 | import java.util.concurrent.CompletableFuture; 22 | import java.util.function.Function; 23 | 24 | public class BlockNameArgument implements ArgumentType { 25 | private static final DynamicCommandExceptionType INVALID_STRING_EXCEPTION = new DynamicCommandExceptionType(input 26 | -> Text.literal(BedrockMinerLang.EXCEPTION_INVALID_STRING.getString().replace("%input%", input.toString()))); 27 | private static final Collection EXAMPLES = Arrays.asList("Stone", "Bedrock", "石头", "基岩"); 28 | @Nullable 29 | private Function filter; 30 | 31 | 32 | public static Block getBlock(CommandContext context, String name) { 33 | return context.getArgument(name, Block.class); 34 | } 35 | 36 | public Block parse(StringReader reader) throws CommandSyntaxException { 37 | var i = reader.getCursor(); 38 | while (reader.canRead()) { 39 | reader.skip(); 40 | } 41 | // 获取用户输入的字符串内容 42 | var string = reader.getString().substring(i, reader.getCursor()); 43 | // 检查方块注册表中是否存在该名称 44 | var optionalBlock = Registries.BLOCK.stream().filter(block -> block.getName().getString().equals(string)).findFirst(); 45 | if (optionalBlock.isEmpty()) { 46 | reader.setCursor(i); 47 | throw INVALID_STRING_EXCEPTION.create(string); 48 | } 49 | // 已获取到方块信息 50 | var block = optionalBlock.get(); 51 | // 检查过滤器 52 | if (filter != null && !filter.apply(BlockUtils.getIdentifier(block))) { 53 | reader.setCursor(i); 54 | throw INVALID_STRING_EXCEPTION.create(string); 55 | } 56 | return block; 57 | } 58 | 59 | 60 | public CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder) { 61 | StringReader reader = new StringReader(builder.getInput()); 62 | reader.setCursor(builder.getStart()); 63 | // 读取标识符 64 | var i = reader.getCursor(); 65 | while (reader.canRead()) { 66 | reader.skip(); 67 | } 68 | // 获取用户输入的字符串内容 69 | var string = reader.getString().substring(i, reader.getCursor()); 70 | // 检查方块注册表中是否存在该名称 71 | Registries.BLOCK.forEach(block -> { 72 | if (block.getName().getString().contains(string)) { 73 | if (filter != null && filter.apply(BlockUtils.getIdentifier(block))) { 74 | // 添加建议列表 75 | builder.suggest(block.getName().getString()); 76 | } 77 | } 78 | }); 79 | return builder.buildFuture(); 80 | } 81 | 82 | public Collection getExamples() { 83 | return EXAMPLES; 84 | } 85 | 86 | public BlockNameArgument setFilter(Function filter) { 87 | this.filter = filter; 88 | return this; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/command/argument/BlockIdentifierArgument.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.command.argument; 2 | 3 | import com.mojang.brigadier.StringReader; 4 | import com.mojang.brigadier.arguments.ArgumentType; 5 | import com.mojang.brigadier.context.CommandContext; 6 | import com.mojang.brigadier.exceptions.CommandSyntaxException; 7 | import com.mojang.brigadier.suggestion.Suggestions; 8 | import com.mojang.brigadier.suggestion.SuggestionsBuilder; 9 | import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; 10 | import net.minecraft.block.Block; 11 | import net.minecraft.registry.Registries; 12 | import net.minecraft.util.Identifier; 13 | import org.jetbrains.annotations.Nullable; 14 | import yan.lx.bedrockminer.utils.BlockUtils; 15 | 16 | import java.util.Arrays; 17 | import java.util.Collection; 18 | import java.util.concurrent.CompletableFuture; 19 | import java.util.function.Function; 20 | 21 | import static net.minecraft.command.argument.BlockArgumentParser.INVALID_BLOCK_ID_EXCEPTION; 22 | 23 | public class BlockIdentifierArgument implements ArgumentType { 24 | private static final Collection EXAMPLES = Arrays.asList("stone", "minecraft:stone"); 25 | @Nullable 26 | private Function filter; 27 | 28 | public static Block getBlock(CommandContext context, String name) { 29 | return context.getArgument(name, Block.class); 30 | } 31 | 32 | public Block parse(StringReader reader) throws CommandSyntaxException { 33 | var i = reader.getCursor(); 34 | while (reader.canRead() && isCharValid(reader.peek())) { 35 | reader.skip(); 36 | } 37 | // 获取用户输入的字符串内容 38 | var string = reader.getString().substring(i, reader.getCursor()); 39 | // 检查方块注册表中是否存在该名称 40 | var blockId = Identifier.of(string); 41 | var optionalBlock = Registries.BLOCK.stream().filter(block -> BlockUtils.getIdentifier(block).equals(blockId)).findFirst(); 42 | if (optionalBlock.isEmpty()) { 43 | reader.setCursor(i); 44 | throw INVALID_BLOCK_ID_EXCEPTION.create(string); 45 | } 46 | // 已获取到方块信息 47 | var block = optionalBlock.get(); 48 | // 检查过滤器 49 | if (filter != null && !filter.apply(BlockUtils.getIdentifier(block))) { 50 | reader.setCursor(i); 51 | throw INVALID_BLOCK_ID_EXCEPTION.create(string); 52 | } 53 | return block; 54 | } 55 | 56 | 57 | public CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder) { 58 | var reader = new StringReader(builder.getInput()); 59 | reader.setCursor(builder.getStart()); 60 | // 读取标识符 61 | var i = reader.getCursor(); 62 | while (reader.canRead() && isCharValid(reader.peek())) { 63 | reader.skip(); 64 | } 65 | // 获取用户输入的字符串内容 66 | var string = reader.getString().substring(i, reader.getCursor()); 67 | // 检查方块注册表中是否存在该名称 68 | Registries.BLOCK.forEach(block -> { 69 | var identifier = BlockUtils.getIdentifier(block); 70 | var namespace = identifier.getNamespace(); 71 | var path = identifier.getPath(); 72 | if (namespace.contains(string) || path.contains(string)) { 73 | if (filter != null && filter.apply(identifier)) { 74 | // 添加建议列表 75 | builder.suggest(BlockUtils.getId(block)); 76 | } 77 | } 78 | }); 79 | return builder.buildFuture(); 80 | } 81 | 82 | public Collection getExamples() { 83 | return EXAMPLES; 84 | } 85 | 86 | public BlockIdentifierArgument setFilter(Function filter) { 87 | this.filter = filter; 88 | return this; 89 | } 90 | 91 | public static boolean isCharValid(char c) { 92 | return c >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c == '_' || c == ':' || c == '/' || c == '.' || c == '-'; 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/command/TaskCommand.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.command; 2 | 3 | import com.mojang.brigadier.arguments.BoolArgumentType; 4 | import com.mojang.brigadier.arguments.IntegerArgumentType; 5 | import com.mojang.brigadier.builder.LiteralArgumentBuilder; 6 | import com.mojang.brigadier.context.CommandContext; 7 | import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; 8 | import net.minecraft.client.MinecraftClient; 9 | import net.minecraft.command.CommandRegistryAccess; 10 | import net.minecraft.text.Text; 11 | import net.minecraft.util.math.Direction; 12 | import yan.lx.bedrockminer.BedrockMinerLang; 13 | import yan.lx.bedrockminer.command.argument.BlockPosArgumentType; 14 | import yan.lx.bedrockminer.config.Config; 15 | import yan.lx.bedrockminer.task.TaskManager; 16 | import yan.lx.bedrockminer.utils.MessageUtils; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; 22 | import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; 23 | 24 | public class TaskCommand extends BaseCommand { 25 | 26 | @Override 27 | public String getName() { 28 | return "task"; 29 | } 30 | 31 | @Override 32 | public void build(LiteralArgumentBuilder builder, CommandRegistryAccess registryAccess) { 33 | builder 34 | .then(literal("vertical") 35 | .then(argument("bool", BoolArgumentType.bool()).executes(context -> { 36 | Config.INSTANCE.vertical = BoolArgumentType.getBool(context, "bool"); 37 | MessageUtils.addMessage(Text.translatable(String.valueOf(Config.INSTANCE.vertical))); 38 | Config.save(); 39 | return 0; 40 | }))) 41 | .then(literal("horizontal") 42 | .then(argument("bool", BoolArgumentType.bool()).executes(context -> { 43 | Config.INSTANCE.horizontal = BoolArgumentType.getBool(context, "bool"); 44 | MessageUtils.addMessage(Text.translatable(String.valueOf(Config.INSTANCE.horizontal))); 45 | Config.save(); 46 | return 0; 47 | }))) 48 | .then(literal("add") 49 | .then(argument("blockPos", BlockPosArgumentType.blockPos()) 50 | .executes(this::add) 51 | // .then(argument("blockPos2", BlockPosArgumentType.blockPos()).executes(this::selection)))) 52 | )) 53 | .then(literal("clear").executes(this::clear)); 54 | // 55 | // .then(literal("limit") 56 | // .then(argument("limit", IntegerArgumentType.integer(1, 5)) 57 | // .executes(this::toggleSwitch))); 58 | } 59 | 60 | private int selection(CommandContext context) { 61 | var blockPos1 = BlockPosArgumentType.getBlockPos(context, "blockPos"); 62 | var blockPos2 = BlockPosArgumentType.getBlockPos(context, "blockPos"); 63 | return 0; 64 | } 65 | 66 | private Text getModeText(boolean mode, Direction... directions) { 67 | List list = new ArrayList<>(); 68 | for (Direction direction : directions) { 69 | list.add(direction.asString()); 70 | } 71 | return Text.literal(String.format("%s: %s", String.join(", ", list), mode)); 72 | } 73 | 74 | 75 | private int add(CommandContext context) { 76 | var blockPos = BlockPosArgumentType.getBlockPos(context, "blockPos"); 77 | var client = MinecraftClient.getInstance(); 78 | var world = client.world; 79 | if (world != null) { 80 | var blockState = world.getBlockState(blockPos); 81 | var block = blockState.getBlock(); 82 | TaskManager.addTask(block, blockPos, world); 83 | } 84 | return 0; 85 | } 86 | 87 | private int clear(CommandContext context) { 88 | TaskManager.clearTask(); 89 | return 0; 90 | } 91 | 92 | private int toggleSwitch(CommandContext context) { 93 | var config = Config.INSTANCE; 94 | var limit = IntegerArgumentType.getInteger(context, "limit"); 95 | if (config.taskLimit != limit) { 96 | config.taskLimit = limit; 97 | Config.save(); 98 | } 99 | var msg = BedrockMinerLang.COMMAND_TASK_LIMIT.getString().replace("%limit%", String.valueOf(limit)); 100 | MessageUtils.addMessage(Text.translatable(msg)); 101 | return 0; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/Test.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer; 2 | 3 | import com.mojang.brigadier.builder.LiteralArgumentBuilder; 4 | import com.mojang.brigadier.context.CommandContext; 5 | import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; 6 | import net.minecraft.block.Blocks; 7 | import net.minecraft.client.MinecraftClient; 8 | import net.minecraft.client.network.ClientPlayNetworkHandler; 9 | import net.minecraft.client.network.ClientPlayerEntity; 10 | import net.minecraft.client.network.ClientPlayerInteractionManager; 11 | import net.minecraft.entity.player.PlayerInventory; 12 | import net.minecraft.item.Items; 13 | import net.minecraft.network.ClientConnection; 14 | import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket; 15 | import net.minecraft.server.MinecraftServer; 16 | import net.minecraft.server.network.ServerPlayerEntity; 17 | import net.minecraft.util.ActionResult; 18 | import net.minecraft.util.Hand; 19 | import net.minecraft.util.hit.BlockHitResult; 20 | import net.minecraft.util.hit.HitResult; 21 | import net.minecraft.util.math.BlockPos; 22 | import net.minecraft.util.math.Direction; 23 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 24 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; 25 | import yan.lx.bedrockminer.command.argument.BlockPosArgumentType; 26 | import yan.lx.bedrockminer.utils.BlockBreakerUtils; 27 | import yan.lx.bedrockminer.utils.BlockPlacerUtils; 28 | 29 | import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; 30 | import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; 31 | import static net.minecraft.block.Block.sideCoversSmallSquare; 32 | 33 | public class Test { 34 | 35 | public static void register(LiteralArgumentBuilder root) { 36 | root.then(literal("test").executes(Test::onCommandExecute) 37 | .then(argument("blockPos", BlockPosArgumentType.blockPos()).executes(Test::onBlockPos))); 38 | } 39 | 40 | private static int onBlockPos(CommandContext context) { 41 | var blockPos = BlockPosArgumentType.getBlockPos(context, "blockPos"); 42 | BlockPlacerUtils.placement(blockPos.up(), Direction.NORTH); 43 | return 0; 44 | } 45 | 46 | public static int onCommandExecute(CommandContext context) { 47 | var client = MinecraftClient.getInstance(); 48 | var world = client.world; 49 | var player = client.player; 50 | var hitResult = client.crosshairTarget; 51 | var interactionManager = client.interactionManager; 52 | ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); 53 | if (world == null || player == null || hitResult == null || networkHandler == null) return 0; 54 | if (hitResult.getType() == HitResult.Type.BLOCK) { 55 | var blockHitResult = (BlockHitResult) hitResult; 56 | var blockPos = blockHitResult.getBlockPos(); 57 | var blockState = world.getBlockState(blockPos); 58 | var block = blockState.getBlock(); 59 | BlockBreakerUtils.simpleBreakBlock(blockPos); 60 | // Debug.info(world.getWorldBorder().getMaxRadius()); 61 | } 62 | 63 | //BlockPlacerUtils.placement(new BlockPos(8, -60, 8), Direction.NORTH, Items.REDSTONE_TORCH); 64 | // var itemStack = player.getMainHandStack(); 65 | // var registry = world.getRegistryManager().get(RegistryKeys.BLOCK); 66 | // var cachedBlockPosition = new CachedBlockPosition(world, blockPos, false); 67 | // Debug.info(); 68 | // Debug.info("[canPlaceOn]" + itemStack.canPlaceOn(registry, cachedBlockPosition)); 69 | // Debug.info("[canDestroy]" + itemStack.canDestroy(registry, cachedBlockPosition)); 70 | 71 | return 0; 72 | } 73 | 74 | 75 | public static void onInteractBlock(ClientPlayerEntity player, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable cir) { 76 | var pos = hitResult.getPos(); 77 | var side = hitResult.getSide(); 78 | var blockPos = hitResult.getBlockPos(); 79 | var insideBlock = hitResult.isInsideBlock(); 80 | // Debug.info("%s, %s, %s, %s, %s", hand, pos, side, blockPos, insideBlock); 81 | } 82 | 83 | public static void onTick(ClientConnection connection, MinecraftServer server, ServerPlayerEntity player) { 84 | // Debug.info("%s, %s", player.getYaw(), player.getPitch()); 85 | } 86 | 87 | public static void onPlayerInteractBlock(ServerPlayerEntity player, PlayerInteractBlockC2SPacket packet, CallbackInfo ci) { 88 | var hitResult = packet.getBlockHitResult(); 89 | var hand = packet.getHand(); 90 | var sequence = packet.getSequence(); 91 | var pos = hitResult.getPos(); 92 | var side = hitResult.getSide(); 93 | var blockPos = hitResult.getBlockPos(); 94 | var insideBlock = hitResult.isInsideBlock(); 95 | Debug.info("%s, %s", player.getYaw(), player.getPitch()); 96 | Debug.info("%s, %s, %s, %s, %s, %s", sequence, hand, pos, side, blockPos, insideBlock); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/utils/CheckingEnvironmentUtils.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.utils; 2 | 3 | import net.minecraft.block.Block; 4 | import net.minecraft.block.Blocks; 5 | import net.minecraft.client.MinecraftClient; 6 | import net.minecraft.client.world.ClientWorld; 7 | import net.minecraft.entity.ItemEntity; 8 | import net.minecraft.item.ItemPlacementContext; 9 | import net.minecraft.util.Hand; 10 | import net.minecraft.util.hit.BlockHitResult; 11 | import net.minecraft.util.math.BlockPos; 12 | import net.minecraft.util.math.Direction; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | import static net.minecraft.block.Block.sideCoversSmallSquare; 18 | 19 | public class CheckingEnvironmentUtils { 20 | 21 | /*** 找到附近的平地放置红石火把 22 | * @param world 客户端世界 23 | * @param pistonBlockPos 活塞位置 24 | * @return 可以直接放置红石火把的位置 25 | */ 26 | public static List findNearbyFlatBlockToPlaceRedstoneTorch(ClientWorld world, BlockPos pistonBlockPos) { 27 | var list = new ArrayList(); 28 | for (Direction direction : Direction.Type.HORIZONTAL) { 29 | var blockPos = pistonBlockPos.offset(direction); 30 | var blockState = world.getBlockState(blockPos); 31 | // 检查火把下的方块是否可以放置 32 | if (!sideCoversSmallSquare(world, blockPos.down(), Direction.UP)) { 33 | continue; 34 | } 35 | if (blockState.isReplaceable() || blockState.isOf(Blocks.REDSTONE_TORCH)) { 36 | list.add(blockPos); 37 | } 38 | } 39 | return list; 40 | } 41 | 42 | /** 43 | * 查找可能放置粘液块的位置 44 | */ 45 | public static List findPossibleSlimeBlockPos(ClientWorld world, BlockPos pistonBlockPos) { 46 | var list = new ArrayList(); 47 | for (Direction direction : Direction.Type.HORIZONTAL) { 48 | BlockPos redTorchPos = pistonBlockPos.offset(direction); 49 | BlockPos BaseBlockPos = redTorchPos.down(); 50 | if (!world.getBlockState(redTorchPos).isReplaceable() || !world.getBlockState(BaseBlockPos).isReplaceable()) { 51 | continue; 52 | } 53 | list.add(BaseBlockPos); 54 | } 55 | return list; 56 | } 57 | 58 | public static boolean has2BlocksOfPlaceToPlacePiston(ClientWorld world, BlockPos blockPos) { 59 | BlockPos pos1 = blockPos.up(); // 活塞位置 60 | BlockPos pos2 = blockPos.up().up(); // 活塞臂位置 61 | // 获取硬度, 打掉0硬度值的方块 62 | var blockState1 = world.getBlockState(pos1); 63 | if (!blockState1.isAir() && blockState1.getBlock().getHardness() < 45f) { 64 | BlockBreakerUtils.simpleBreakBlock(pos1); 65 | } 66 | var blockState2 = world.getBlockState(pos1); 67 | if (!blockState2.isAir() && blockState2.getBlock().getHardness() < 45f) { 68 | BlockBreakerUtils.simpleBreakBlock(pos2); 69 | } 70 | // 实体碰撞箱 71 | boolean b = true; 72 | var state = Blocks.PISTON.getDefaultState(); 73 | var shape = state.getCollisionShape(world, pos1); 74 | if (!shape.isEmpty()) { 75 | for (var entity : world.getEntities()) { 76 | // 过滤掉落物实体 77 | if (entity instanceof ItemEntity) { 78 | continue; 79 | } 80 | if (entity.collidesWithStateAtPos(pos1, state)) { 81 | b = false; 82 | } 83 | } 84 | } 85 | // 判断活塞位置和活塞臂位置是否可以放置 86 | return world.getBlockState(pos1).isReplaceable() && world.getBlockState(pos2).isReplaceable() && b; 87 | } 88 | 89 | public static List findNearbyRedstoneTorch(ClientWorld world, BlockPos pistonBlockPos) { 90 | List list = new ArrayList<>(); 91 | for (Direction direction : Direction.Type.HORIZONTAL) { 92 | BlockPos pos = pistonBlockPos.offset(direction); 93 | Block block = world.getBlockState(pos).getBlock(); 94 | if (block == Blocks.REDSTONE_TORCH || block == Blocks.REDSTONE_WALL_TORCH) { 95 | list.add(pos); 96 | } 97 | } 98 | return list; 99 | } 100 | 101 | public static boolean canPlace(BlockPos blockPos, Block block, Direction direction) { 102 | var player = MinecraftClient.getInstance().player; 103 | var world = MinecraftClient.getInstance().world; 104 | if (player != null && world != null) { 105 | // 放置检测 106 | var item = block.asItem(); 107 | var context = new ItemPlacementContext(player, Hand.MAIN_HAND, item.getDefaultStack(), new BlockHitResult(blockPos.toCenterPos(), direction, blockPos, false)); 108 | // 实体碰撞箱 109 | boolean b = true; 110 | var state = block.getDefaultState(); 111 | var shape = state.getCollisionShape(world, blockPos); 112 | if (!shape.isEmpty()) { 113 | for (var entity : world.getEntities()) { 114 | // 过滤掉落物实体 115 | if (entity instanceof ItemEntity) { 116 | continue; 117 | } 118 | // 检查实体是否在目标位置内 119 | if (entity.collidesWithStateAtPos(blockPos, state)) { 120 | b = false; 121 | } 122 | } 123 | } 124 | return context.canPlace() && b; 125 | } 126 | return false; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/command/BlockNameCommand.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.command; 2 | 3 | import com.mojang.brigadier.builder.LiteralArgumentBuilder; 4 | import com.mojang.brigadier.context.CommandContext; 5 | import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; 6 | import net.minecraft.block.Block; 7 | import net.minecraft.command.CommandRegistryAccess; 8 | import net.minecraft.registry.Registries; 9 | import net.minecraft.text.Text; 10 | import net.minecraft.util.Identifier; 11 | import yan.lx.bedrockminer.BedrockMinerLang; 12 | import yan.lx.bedrockminer.command.argument.BlockNameArgument; 13 | import yan.lx.bedrockminer.config.Config; 14 | import yan.lx.bedrockminer.utils.BlockUtils; 15 | import yan.lx.bedrockminer.utils.MessageUtils; 16 | 17 | import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; 18 | import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; 19 | 20 | public class BlockNameCommand extends BaseCommand { 21 | @Override 22 | public String getName() { 23 | return "blockName"; 24 | } 25 | 26 | @Override 27 | public void build(LiteralArgumentBuilder builder, CommandRegistryAccess registryAccess) { 28 | builder.then(literal("whitelist") 29 | .then(literal("add") 30 | .then(argument("block", new BlockNameArgument().setFilter(this::filterWhitelist)) 31 | .executes(context -> add(context, true)) 32 | ) 33 | ) 34 | .then(literal("remove") 35 | .then(argument("block", new BlockNameArgument().setFilter(this::showWhitelist)) 36 | .executes(context -> remove(context, true)) 37 | ) 38 | )) 39 | .then(literal("blacklist") 40 | .then(literal("add") 41 | .then(argument("block", new BlockNameArgument().setFilter(this::filterBlacklist)) 42 | .executes(context -> add(context, false)) 43 | ) 44 | ) 45 | .then(literal("remove") 46 | .then(argument("block", new BlockNameArgument().setFilter(this::showBlacklist)) 47 | .executes(context -> remove(context, false)) 48 | ) 49 | ) 50 | ); 51 | } 52 | 53 | private int add(CommandContext context, boolean whitelist) { 54 | var block = BlockNameArgument.getBlock(context, "block"); 55 | var config = Config.INSTANCE; 56 | var id = BlockUtils.getId(block); 57 | if (whitelist && !config.blockWhitelist.contains(id)) { 58 | config.blockWhitelist.add(id); 59 | Config.save(); 60 | sendChat(BedrockMinerLang.COMMAND_BLOCK_WHITELIST_ADD, block); 61 | } else if (!config.blockBlacklist.contains(id)) { 62 | config.blockBlacklist.add(id); 63 | Config.save(); 64 | sendChat(BedrockMinerLang.COMMAND_BLOCK_BLACKLIST_ADD, block); 65 | } 66 | return 0; 67 | } 68 | 69 | private int remove(CommandContext context, boolean whitelist) { 70 | var block = BlockNameArgument.getBlock(context, "block"); 71 | var config = Config.INSTANCE; 72 | var id = BlockUtils.getId(block); 73 | if (whitelist && config.blockWhitelist.contains(id)) { 74 | config.blockWhitelist.remove(id); 75 | Config.save(); 76 | sendChat(BedrockMinerLang.COMMAND_BLOCK_WHITELIST_REMOVE, block); 77 | } else if (config.blockBlacklist.contains(id)) { 78 | config.blockBlacklist.remove(id); 79 | Config.save(); 80 | sendChat(BedrockMinerLang.COMMAND_BLOCK_BLACKLIST_REMOVE, block); 81 | } 82 | return 0; 83 | } 84 | 85 | private boolean isFilterBlock(Identifier blockId) { 86 | var block = Registries.BLOCK.get(blockId); 87 | // 过滤空气和可替换方块 88 | return block.getDefaultState().isAir() || block.getDefaultState().isReplaceable(); 89 | } 90 | 91 | private Boolean showWhitelist(Identifier blockId) { 92 | var config = Config.INSTANCE; 93 | for (var whitelist : config.blockWhitelist) { 94 | if (blockId.toString().equals(whitelist)) { 95 | return true; 96 | } 97 | } 98 | return false; 99 | } 100 | 101 | private Boolean filterWhitelist(Identifier blockId) { 102 | if (isFilterBlock(blockId)) { 103 | return false; 104 | } 105 | var config = Config.INSTANCE; 106 | for (var whitelist : config.blockWhitelist) { 107 | if (blockId.toString().equals(whitelist)) { 108 | return false; 109 | } 110 | } 111 | return true; 112 | } 113 | 114 | private Boolean showBlacklist(Identifier blockId) { 115 | var config = Config.INSTANCE; 116 | for (var whitelist : config.blockBlacklist) { 117 | if (blockId.toString().equals(whitelist)) { 118 | return true; 119 | } 120 | } 121 | return false; 122 | } 123 | 124 | private Boolean filterBlacklist(Identifier blockId) { 125 | if (isFilterBlock(blockId)) { 126 | return false; 127 | } 128 | var config = Config.INSTANCE; 129 | for (var whitelist : config.blockBlacklist) { 130 | if (blockId.toString().equals(whitelist)) { 131 | return false; 132 | } 133 | } 134 | return true; 135 | } 136 | 137 | private void sendChat(Text text, Block block) { 138 | var msg = text.getString().replace("%blockName%", block.getName().getString()); 139 | MessageUtils.addMessage(Text.translatable(msg)); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/command/BlockCommand.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.command; 2 | 3 | import com.mojang.brigadier.builder.LiteralArgumentBuilder; 4 | import com.mojang.brigadier.context.CommandContext; 5 | import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; 6 | import net.minecraft.block.Block; 7 | import net.minecraft.command.CommandRegistryAccess; 8 | import net.minecraft.registry.Registries; 9 | import net.minecraft.text.Text; 10 | import net.minecraft.util.Identifier; 11 | import yan.lx.bedrockminer.BedrockMinerLang; 12 | import yan.lx.bedrockminer.command.argument.BlockIdentifierArgument; 13 | import yan.lx.bedrockminer.command.argument.BlockNameArgument; 14 | import yan.lx.bedrockminer.config.Config; 15 | import yan.lx.bedrockminer.utils.BlockUtils; 16 | import yan.lx.bedrockminer.utils.MessageUtils; 17 | 18 | import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.*; 19 | 20 | public class BlockCommand extends BaseCommand { 21 | @Override 22 | public String getName() { 23 | return "block"; 24 | } 25 | 26 | @Override 27 | public void build(LiteralArgumentBuilder builder, CommandRegistryAccess registryAccess) { 28 | builder.then(literal("whitelist") 29 | .then(literal("add") 30 | .then(argument("block", new BlockIdentifierArgument().setFilter(this::filterWhitelist)) 31 | .executes(this::addWhitelist) 32 | ) 33 | ) 34 | .then(literal("remove") 35 | .then(argument("block", new BlockIdentifierArgument().setFilter(this::showWhitelist)) 36 | .executes(this::removeWhitelist) 37 | ) 38 | )) 39 | .then(literal("blacklist") 40 | .then(literal("add") 41 | .then(argument("block", new BlockIdentifierArgument().setFilter(this::filterBlacklist)) 42 | .executes(this::addBlacklist) 43 | ) 44 | ) 45 | .then(literal("remove") 46 | .then(argument("block", new BlockIdentifierArgument().setFilter(this::showBlacklist)) 47 | .executes(this::removeBlacklist) 48 | ) 49 | ) 50 | ); 51 | } 52 | 53 | private boolean isFilterBlock(Identifier blockId) { 54 | var block = Registries.BLOCK.get(blockId); 55 | // 过滤空气和可替换方块 56 | return block.getDefaultState().isAir() || block.getDefaultState().isReplaceable(); 57 | } 58 | 59 | private Boolean showWhitelist(Identifier blockId) { 60 | var config = Config.INSTANCE; 61 | for (var whitelist : config.blockWhitelist) { 62 | if (blockId.toString().equals(whitelist)) { 63 | return true; 64 | } 65 | } 66 | return false; 67 | } 68 | 69 | private Boolean filterWhitelist(Identifier blockId) { 70 | if (isFilterBlock(blockId)) { 71 | return false; 72 | } 73 | var config = Config.INSTANCE; 74 | for (var whitelist : config.blockWhitelist) { 75 | if (blockId.toString().equals(whitelist)) { 76 | return false; 77 | } 78 | } 79 | return true; 80 | } 81 | 82 | private Boolean showBlacklist(Identifier blockId) { 83 | var config = Config.INSTANCE; 84 | for (var whitelist : config.blockBlacklist) { 85 | if (blockId.toString().equals(whitelist)) { 86 | return true; 87 | } 88 | } 89 | return false; 90 | } 91 | 92 | private Boolean filterBlacklist(Identifier blockId) { 93 | if (isFilterBlock(blockId)) { 94 | return false; 95 | } 96 | var config = Config.INSTANCE; 97 | for (var whitelist : config.blockBlacklist) { 98 | if (blockId.toString().equals(whitelist)) { 99 | return false; 100 | } 101 | } 102 | return true; 103 | } 104 | 105 | private int addWhitelist(CommandContext context) { 106 | var block = BlockNameArgument.getBlock(context, "block"); 107 | var config = Config.INSTANCE; 108 | var id = BlockUtils.getId(block); 109 | if (!config.blockWhitelist.contains(id)) { 110 | config.blockWhitelist.add(id); 111 | Config.save(); 112 | sendChat(BedrockMinerLang.COMMAND_BLOCK_WHITELIST_ADD, block); 113 | } 114 | return 0; 115 | } 116 | 117 | private int removeWhitelist(CommandContext context) { 118 | var block = BlockNameArgument.getBlock(context, "block"); 119 | var config = Config.INSTANCE; 120 | var id = BlockUtils.getId(block); 121 | if (config.blockWhitelist.contains(id)) { 122 | config.blockWhitelist.remove(id); 123 | Config.save(); 124 | sendChat(BedrockMinerLang.COMMAND_BLOCK_WHITELIST_REMOVE, block); 125 | } 126 | return 0; 127 | } 128 | 129 | private int addBlacklist(CommandContext context) { 130 | var block = BlockNameArgument.getBlock(context, "block"); 131 | var config = Config.INSTANCE; 132 | var id = BlockUtils.getId(block); 133 | if (!config.blockBlacklist.contains(id)) { 134 | config.blockBlacklist.add(id); 135 | Config.save(); 136 | sendChat(BedrockMinerLang.COMMAND_BLOCK_BLACKLIST_ADD, block); 137 | } 138 | return 0; 139 | } 140 | 141 | private int removeBlacklist(CommandContext context) { 142 | var block = BlockIdentifierArgument.getBlock(context, "block"); 143 | var config = Config.INSTANCE; 144 | var id = BlockUtils.getId(block); 145 | if (config.blockBlacklist.contains(id)) { 146 | config.blockBlacklist.remove(id); 147 | Config.save(); 148 | sendChat(BedrockMinerLang.COMMAND_BLOCK_BLACKLIST_REMOVE, block); 149 | } 150 | return 0; 151 | } 152 | 153 | private void sendChat(Text text, Block block) { 154 | var msg = text.getString().replace("%blockName%", block.getName().getString()); 155 | MessageUtils.addMessage(Text.translatable(msg)); 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/task/TaskSeekSchemeTools.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.task; 2 | 3 | import net.minecraft.block.Block; 4 | import net.minecraft.block.BlockState; 5 | import net.minecraft.block.Blocks; 6 | import net.minecraft.client.world.ClientWorld; 7 | import net.minecraft.util.math.BlockPos; 8 | import net.minecraft.util.math.Direction; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | /** 14 | * 任务方案查找器 15 | */ 16 | public class TaskSeekSchemeTools { 17 | public static Direction[] directions = new Direction[]{Direction.UP, Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST}; 18 | 19 | /** 20 | * 查找所有可能放置情况(假设性的,未检查游戏中的环境) 21 | */ 22 | public static TaskSeekSchemeInfo[] findAllPossible(BlockPos targetPos, ClientWorld world) { 23 | List schemes = new ArrayList<>(); 24 | for (Direction direction : directions) { 25 | TaskSeekBlockInfo[] pistons = findPistonPossible(direction, targetPos); 26 | for (TaskSeekBlockInfo piston : pistons) { 27 | TaskSeekBlockInfo[] redstoneTorches = findRedstoneTorchPossible(piston); 28 | for (TaskSeekBlockInfo redstoneTorch : redstoneTorches) { 29 | TaskSeekBlockInfo slimeBlock = findSlimeBlockPossible(redstoneTorch); 30 | schemes.add(new TaskSeekSchemeInfo(direction, piston, redstoneTorch, slimeBlock)); 31 | } 32 | } 33 | } 34 | // 重新排序 35 | schemes.sort((o1, o2) -> { 36 | int cr = 0; 37 | int a = o1.piston.level - o2.piston.level; 38 | if (a != 0) { 39 | cr = (a > 0) ? 3 : -1; 40 | } else { 41 | a = o1.redstoneTorch.level - o2.redstoneTorch.level; 42 | if (a != 0) { 43 | cr = (a > 0) ? 2 : -2; 44 | } else { 45 | a = o1.slimeBlock.level - o2.slimeBlock.level; 46 | if (a != 0) { 47 | cr = (a > 0) ? 1 : -3; 48 | } 49 | } 50 | } 51 | return cr; 52 | }); 53 | return schemes.toArray(TaskSeekSchemeInfo[]::new); 54 | } 55 | 56 | private static TaskSeekBlockInfo[] findPistonPossible(Direction direction, BlockPos targetPos) { 57 | List list = new ArrayList<>(); 58 | BlockPos pos = targetPos.offset(direction); 59 | for (Direction facing : Direction.values()) { 60 | // 过滤朝着目标方块的方向 61 | if (direction == facing.getOpposite()) continue; 62 | int level = switch (facing) { 63 | case UP -> 0; 64 | case DOWN -> 1; 65 | case NORTH -> 2; 66 | case SOUTH -> 3; 67 | case WEST -> 4; 68 | case EAST -> 5; 69 | }; 70 | list.add(new TaskSeekBlockInfo(pos, facing, level)); 71 | } 72 | return list.toArray(TaskSeekBlockInfo[]::new); 73 | } 74 | 75 | private static TaskSeekBlockInfo[] findRedstoneTorchPossible(TaskSeekBlockInfo pistonInfo) { 76 | List list = new ArrayList<>(); 77 | for (Direction direction : Direction.values()) { 78 | // 过滤与活塞臂退出的位置 79 | if (direction == pistonInfo.facing) continue; 80 | // 红石火把的方向集合, 因为红石火把没有倒着放, 所以去掉了他 81 | List facings = List.of(Direction.UP, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST); 82 | BlockPos pos = pistonInfo.pos.offset(direction); 83 | // 活塞底部位置, 并且过滤活塞伸出方向位置 84 | for (Direction facing : facings) { 85 | if (direction == facing) continue; 86 | // 方案在上活塞底下是目标方块, 所以过滤 87 | if (direction == Direction.UP) continue; 88 | // 活塞朝下, 那么活塞下面就被活塞臂占位, 所以过滤 89 | if (pistonInfo.facing == Direction.DOWN) continue; 90 | int level = switch (facing) { 91 | case UP -> 0; 92 | case NORTH -> 1; 93 | case SOUTH -> 2; 94 | case WEST -> 3; 95 | case EAST -> 4; 96 | default -> throw new IllegalStateException("Unexpected value: " + facing); 97 | }; 98 | list.add(new TaskSeekBlockInfo(pos, facing, level)); 99 | } 100 | // 常规位置 101 | for (Direction facing : facings) { 102 | // 过滤活塞测方向 103 | if (direction == facing) continue; 104 | // 过滤垂直方向 105 | if (direction.getAxis().isVertical()) continue; 106 | // 过滤红石火把附在活塞面上位置 107 | if (facing == pistonInfo.facing) continue; 108 | int level = switch (facing) { 109 | case UP -> 0; 110 | case NORTH -> 1; 111 | case SOUTH -> 2; 112 | case WEST -> 3; 113 | case EAST -> 4; 114 | default -> throw new IllegalStateException("Unexpected value: " + facing); 115 | }; 116 | list.add(new TaskSeekBlockInfo(pos, facing, level)); 117 | list.add(new TaskSeekBlockInfo(pos.up(), facing, level)); 118 | 119 | } 120 | 121 | 122 | } 123 | return list.toArray(TaskSeekBlockInfo[]::new); 124 | } 125 | 126 | private static TaskSeekBlockInfo findSlimeBlockPossible(TaskSeekBlockInfo redstoneTorchInfo) { 127 | BlockPos pos = redstoneTorchInfo.pos; 128 | Direction facing = redstoneTorchInfo.facing; 129 | return new TaskSeekBlockInfo(pos.offset(facing.getOpposite()), facing, facing == Direction.UP ? 0 : 1); 130 | } 131 | 132 | /** 133 | * 查找活塞附近的火把 134 | */ 135 | public static BlockPos[] findPistonNearbyRedstoneTorch(BlockPos pistonPos, ClientWorld world) { 136 | List list = new ArrayList<>(); 137 | // 查找活塞2格范围内的红石火把, 之所以是2格, 是为了避免强充能方块边上被激活 138 | int range = 2; 139 | for (Direction direction : Direction.values()) { 140 | for (int i = 0; i < range; i++) { 141 | BlockPos pos = pistonPos.offset(direction, i); 142 | BlockState blockState = world.getBlockState(pos); 143 | if (blockState.isOf(Blocks.REDSTONE_TORCH) || blockState.isOf(Blocks.REDSTONE_WALL_TORCH)) { 144 | list.add(pos); 145 | } 146 | } 147 | } 148 | return list.toArray(BlockPos[]::new); 149 | } 150 | 151 | } 152 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/command/argument/BlockPosArgumentType.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.command.argument; 2 | 3 | import com.mojang.brigadier.StringReader; 4 | import com.mojang.brigadier.arguments.ArgumentType; 5 | import com.mojang.brigadier.context.CommandContext; 6 | import com.mojang.brigadier.exceptions.CommandSyntaxException; 7 | import com.mojang.brigadier.suggestion.Suggestions; 8 | import com.mojang.brigadier.suggestion.SuggestionsBuilder; 9 | import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; 10 | import net.minecraft.client.MinecraftClient; 11 | import net.minecraft.command.argument.Vec3ArgumentType; 12 | import net.minecraft.util.hit.BlockHitResult; 13 | import net.minecraft.util.hit.HitResult; 14 | import net.minecraft.util.math.BlockPos; 15 | 16 | import java.util.Arrays; 17 | import java.util.Collection; 18 | import java.util.concurrent.CompletableFuture; 19 | 20 | public class BlockPosArgumentType implements ArgumentType { 21 | private static final Collection EXAMPLES = Arrays.asList("0 0 0", "~ ~ ~"); 22 | 23 | public static BlockPosArgumentType blockPos() { 24 | return new BlockPosArgumentType(); 25 | } 26 | 27 | public static BlockPos getBlockPos(CommandContext context, String name) { 28 | return context.getArgument(name, BlockPos.class); 29 | } 30 | 31 | @Override 32 | public BlockPos parse(StringReader reader) throws CommandSyntaxException { 33 | var i = reader.getCursor(); 34 | if (reader.canRead()) { 35 | int x = parseCoordinate(reader, 0); 36 | if (reader.canRead()) { 37 | int y = parseCoordinate(reader, 1); 38 | if (reader.canRead()) { 39 | int z = parseCoordinate(reader, 2); 40 | return new BlockPos(x, y, z); 41 | } 42 | } 43 | } 44 | reader.setCursor(i); 45 | throw Vec3ArgumentType.INCOMPLETE_EXCEPTION.createWithContext(reader); 46 | } 47 | 48 | @Override 49 | public CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder) { 50 | var remaining = builder.getRemaining(); 51 | var reader = new StringReader(remaining); 52 | var xString = (String) null; 53 | var yString = (String) null; 54 | var zString = (String) null; 55 | if (reader.canRead() && (reader.peek() == '~' || isAllowedInteger(reader.peek()))) { 56 | var cursor = reader.getCursor(); 57 | while (reader.canRead() && reader.peek() != ' ') { 58 | reader.skip(); 59 | } 60 | xString = reader.getString().substring(cursor, reader.getCursor()); 61 | } 62 | reader.skipWhitespace(); 63 | if (reader.canRead() && (reader.peek() == '~' || isAllowedInteger(reader.peek()))) { 64 | var cursor = reader.getCursor(); 65 | while (reader.canRead() && reader.peek() != ' ') { 66 | reader.skip(); 67 | } 68 | yString = reader.getString().substring(cursor, reader.getCursor()); 69 | } 70 | reader.skipWhitespace(); 71 | if (reader.canRead() && (reader.peek() == '~' || isAllowedInteger(reader.peek()))) { 72 | var cursor = reader.getCursor(); 73 | while (reader.canRead() && reader.peek() != ' ') { 74 | reader.skip(); 75 | } 76 | zString = reader.getString().substring(cursor, reader.getCursor()); 77 | } 78 | 79 | var hitResult = MinecraftClient.getInstance().crosshairTarget; 80 | if (hitResult != null && hitResult.getType() == HitResult.Type.BLOCK) { 81 | var blockHitResult = (BlockHitResult) hitResult; 82 | var blockPos = blockHitResult.getBlockPos(); 83 | if (xString == null && yString == null && zString == null) { 84 | builder.suggest(blockPos.getX()); 85 | builder.suggest(String.format("%s %s", blockPos.getX(), blockPos.getY())); 86 | builder.suggest(String.format("%s %s %s", blockPos.getX(), blockPos.getY(), blockPos.getZ())); 87 | } 88 | if (xString != null && yString == null && zString == null) { 89 | builder.suggest(String.format("%s %s", xString, blockPos.getY())); 90 | builder.suggest(String.format("%s %s %s", xString, blockPos.getY(), blockPos.getZ())); 91 | } 92 | if (xString != null && yString != null && zString == null) { 93 | builder.suggest(String.format("%s %s %s", xString, yString, blockPos.getZ())); 94 | } 95 | } else { 96 | if (xString == null && yString == null && zString == null) { 97 | builder.suggest("~"); 98 | builder.suggest("~ ~"); 99 | builder.suggest("~ ~ ~"); 100 | } 101 | if (xString != null && yString == null && zString == null) { 102 | builder.suggest(String.format("%s ~", xString)); 103 | builder.suggest(String.format("%s ~ ~", xString)); 104 | } 105 | if (xString != null && yString != null && zString == null) { 106 | builder.suggest(String.format("%s %s ~", xString, yString)); 107 | } 108 | } 109 | return builder.buildFuture(); 110 | } 111 | 112 | private int parseCoordinate(StringReader reader, int type) throws CommandSyntaxException { 113 | reader.skipWhitespace(); 114 | var i = reader.getCursor(); 115 | if (reader.canRead() && reader.peek() != ' ') { 116 | if (reader.peek() == '~') { 117 | reader.skip(); 118 | // 偏移量 119 | var offset = 0; 120 | if (reader.canRead() && isAllowedInteger(reader.peek())) { 121 | offset = reader.readInt(); 122 | } 123 | // 玩家位置 124 | var player = MinecraftClient.getInstance().player; 125 | if (type == 0) { 126 | return (player == null ? 0 : player.getBlockX()) + offset; 127 | } else if (type == 1) { 128 | return (player == null ? 0 : player.getBlockY()) + offset; 129 | } else if (type == 2) { 130 | return (player == null ? 0 : player.getBlockZ()) + offset; 131 | } 132 | return 0; 133 | 134 | } else if (isAllowedInteger(reader.peek())) { 135 | return reader.readInt(); 136 | } 137 | } 138 | reader.setCursor(i); 139 | throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerInvalidInt().create(reader.getRemaining()); 140 | } 141 | 142 | public static boolean isAllowedInteger(final char c) { 143 | return c >= '0' && c <= '9' || c == '-'; 144 | } 145 | 146 | @Override 147 | public Collection getExamples() { 148 | return EXAMPLES; 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/task/TaskManager.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.task; 2 | 3 | import net.minecraft.block.Block; 4 | import net.minecraft.client.MinecraftClient; 5 | import net.minecraft.client.world.ClientWorld; 6 | import net.minecraft.item.Items; 7 | import net.minecraft.text.Text; 8 | import net.minecraft.util.math.BlockPos; 9 | import yan.lx.bedrockminer.BedrockMinerLang; 10 | import yan.lx.bedrockminer.config.Config; 11 | import yan.lx.bedrockminer.utils.BlockUtils; 12 | import yan.lx.bedrockminer.utils.InventoryManagerUtils; 13 | import yan.lx.bedrockminer.utils.MessageUtils; 14 | 15 | import java.util.ArrayList; 16 | import java.util.LinkedList; 17 | import java.util.List; 18 | 19 | public class TaskManager { 20 | private static final List selectionInfos = new ArrayList<>(); 21 | private static final List handleTasks = new LinkedList<>(); 22 | private static boolean working = false; 23 | 24 | public static void switchOnOff(Block block) { 25 | if (isDisabled()) return; 26 | if (checkIsAllowBlock(block)) { 27 | if (working) { 28 | clearTask(); 29 | setWorking(false); 30 | } else { 31 | var client = MinecraftClient.getInstance(); 32 | // 检查玩家是否为创造 33 | if (client.interactionManager != null && client.interactionManager.getCurrentGameMode().isCreative()) { 34 | MessageUtils.addMessage(BedrockMinerLang.FAIL_MISSING_SURVIVAL); 35 | return; 36 | } 37 | setWorking(true); 38 | // 检查是否在服务器 39 | if (!client.isInSingleplayer()) { 40 | MessageUtils.addMessage(BedrockMinerLang.WARN_MULTIPLAYER); 41 | } 42 | } 43 | } 44 | } 45 | 46 | public static void addTask(Block block, BlockPos pos, ClientWorld world) { 47 | if (isDisabled()) return; 48 | if (!working) return; 49 | var interactionManager = MinecraftClient.getInstance().interactionManager; 50 | if (interactionManager != null) { 51 | if (reverseCheckInventoryItemConditionsAllow()) return; 52 | // 仅生存执行 53 | if (interactionManager.getCurrentGameMode().isSurvivalLike()) { 54 | if (checkIsAllowBlock(block)) { 55 | for (var targetBlock : handleTasks) { 56 | // 检查重复任务 57 | if (targetBlock.pos.getManhattanDistance(pos) == 0) { 58 | return; 59 | } 60 | } 61 | handleTasks.add(new TaskHandler(world, world.getBlockState(pos).getBlock(), pos)); 62 | } 63 | } 64 | } 65 | } 66 | 67 | public static void clearTask() { 68 | if (TaskModifyLookHandle.isModify()) { 69 | TaskModifyLookHandle.reset(); 70 | } 71 | handleTasks.clear(); 72 | MessageUtils.addMessage(BedrockMinerLang.COMMAND_TASK_CLEAR); 73 | } 74 | 75 | public static void tick() { 76 | if (isDisabled()) return; 77 | if (!working) return; 78 | var minecraftClient = MinecraftClient.getInstance(); 79 | var world = minecraftClient.world; 80 | var player = minecraftClient.player; 81 | var interactionManager = minecraftClient.interactionManager; 82 | if (world == null || player == null || interactionManager == null) return; 83 | if (handleTasks.isEmpty()) return; 84 | if (interactionManager.getCurrentGameMode().isCreative()) return; // 检查玩家模式 85 | if (reverseCheckInventoryItemConditionsAllow()) return; // 检查物品条件 86 | // 使用迭代器, 安全删除列表 87 | var range = 4; 88 | for (int y = -range; y < range + 1; y++) { 89 | for (int x = -range; x < range + 1; x++) { 90 | for (int z = -range; z < range + 1; z++) { 91 | BlockPos blockPos = player.getBlockPos().add(new BlockPos(x, y, z)); 92 | // 普通模式 93 | var iterator = handleTasks.iterator(); 94 | while (iterator.hasNext()) { 95 | var handler = iterator.next(); 96 | // 检查是否有其他任务正在修改视角且不是那个任务 97 | if (TaskModifyLookHandle.isModify() && TaskModifyLookHandle.getTaskHandler() != handler) { 98 | continue; 99 | } 100 | // 检查正在执行的目标位置是否与任务坐标一致 101 | if (blockPos.equals(handler.pos)) { 102 | continue; 103 | } 104 | // 玩家切换世界,距离目标方块太远时,删除缓存任务 105 | if (handler.world != world) { 106 | iterator.remove(); 107 | continue; 108 | } 109 | // 判断玩家与方块距离是否在处理范围内 110 | handler.tick(); 111 | if (handler.isComplete()) { 112 | iterator.remove(); 113 | } 114 | return; 115 | 116 | } 117 | } 118 | } 119 | } 120 | 121 | 122 | } 123 | 124 | public static boolean checkIsAllowBlock(Block block) { 125 | var minecraftClient = MinecraftClient.getInstance(); 126 | var config = Config.INSTANCE; 127 | // 方块黑名单检查(服务器) 128 | if (!minecraftClient.isInSingleplayer()) { 129 | for (var defaultBlockBlack : config.blockBlacklistServer) { 130 | if (BlockUtils.getId(block).equals(defaultBlockBlack)) { 131 | return false; 132 | } 133 | } 134 | } 135 | // 方块黑名单检查(用户自定义) 136 | for (var blockBlack : config.blockBlacklist) { 137 | if (BlockUtils.getId(block).equals(blockBlack)) { 138 | return false; 139 | } 140 | } 141 | // 方块白名单检查(用户自定义) 142 | for (var blockBlack : config.blockWhitelist) { 143 | if (BlockUtils.getId(block).equals(blockBlack)) { 144 | return true; 145 | } 146 | } 147 | return false; 148 | } 149 | 150 | public static boolean reverseCheckInventoryItemConditionsAllow() { 151 | var client = MinecraftClient.getInstance(); 152 | var msg = (Text) null; 153 | if (client.interactionManager != null && !client.interactionManager.getCurrentGameMode().isSurvivalLike()) { 154 | msg = BedrockMinerLang.FAIL_MISSING_SURVIVAL; 155 | } 156 | if (InventoryManagerUtils.getInventoryItemCount(Items.PISTON) < 2) { 157 | msg = BedrockMinerLang.FAIL_MISSING_PISTON; 158 | } 159 | if (InventoryManagerUtils.getInventoryItemCount(Items.REDSTONE_TORCH) < 1) { 160 | msg = BedrockMinerLang.FAIL_MISSING_REDSTONETORCH; 161 | } 162 | if (InventoryManagerUtils.getInventoryItemCount(Items.SLIME_BLOCK) < 1) { 163 | msg = BedrockMinerLang.FAIL_MISSING_SLIME; 164 | } 165 | if (!InventoryManagerUtils.canInstantlyMinePiston()) { 166 | msg = BedrockMinerLang.FAIL_MISSING_INSTANTMINE; 167 | } 168 | if (msg != null) { 169 | MessageUtils.setOverlayMessage(msg); 170 | return true; 171 | } 172 | return false; 173 | } 174 | 175 | public static boolean isWorking() { 176 | return working; 177 | } 178 | 179 | public static void setWorking(boolean working) { 180 | if (working) { 181 | MessageUtils.addMessage(BedrockMinerLang.TOGGLE_ON); 182 | } else { 183 | MessageUtils.addMessage(BedrockMinerLang.TOGGLE_OFF); 184 | } 185 | TaskManager.working = working; 186 | } 187 | 188 | private static boolean isDisabled() { 189 | return Config.INSTANCE.disable; 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/utils/InventoryManagerUtils.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.utils; 2 | 3 | import net.minecraft.block.Block; 4 | import net.minecraft.block.BlockState; 5 | import net.minecraft.block.Blocks; 6 | import net.minecraft.client.MinecraftClient; 7 | import net.minecraft.client.network.ClientPlayNetworkHandler; 8 | import net.minecraft.client.network.ClientPlayerEntity; 9 | import net.minecraft.client.network.ClientPlayerInteractionManager; 10 | import net.minecraft.enchantment.EnchantmentHelper; 11 | import net.minecraft.enchantment.Enchantments; 12 | import net.minecraft.entity.attribute.EntityAttributes; 13 | import net.minecraft.entity.effect.StatusEffectInstance; 14 | import net.minecraft.entity.effect.StatusEffectUtil; 15 | import net.minecraft.entity.effect.StatusEffects; 16 | import net.minecraft.entity.player.PlayerInventory; 17 | import net.minecraft.item.Item; 18 | import net.minecraft.item.ItemStack; 19 | import net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket; 20 | import net.minecraft.registry.tag.FluidTags; 21 | import net.minecraft.util.math.BlockPos; 22 | import java.util.Objects; 23 | 24 | 25 | public class InventoryManagerUtils { 26 | 27 | public static void autoSwitch() { 28 | var player = MinecraftClient.getInstance().player; 29 | if (player == null) { 30 | return; 31 | } 32 | var playerInventory = player.getInventory(); 33 | // 选取最优工具 34 | float lastTime = -1; 35 | int lastSlot = -1; 36 | for (int i = 0; i < playerInventory.size(); i++) { 37 | var itemStack = playerInventory.getStack(i); 38 | // 检查耐久是否发起警告(剩余耐久<=检查值) 39 | if (InventoryManagerUtils.isItemDamageWarning(itemStack, 5)) { 40 | continue; 41 | } 42 | // 选取最快工具 43 | float blockBreakingTotalTime = InventoryManagerUtils.getBlockBreakingTotalTime(Blocks.PISTON.getDefaultState(), itemStack); 44 | 45 | if (blockBreakingTotalTime != -1) { 46 | if (lastTime == -1 || lastTime > blockBreakingTotalTime) { 47 | lastTime = blockBreakingTotalTime; 48 | lastSlot = i; 49 | } 50 | } 51 | } 52 | if (lastSlot != -1) { 53 | InventoryManagerUtils.switchToSlot(lastSlot); 54 | } 55 | } 56 | 57 | public static void switchToSlot(int slot) { 58 | MinecraftClient client = MinecraftClient.getInstance(); 59 | ClientPlayerEntity player = client.player; 60 | ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); 61 | ClientPlayerInteractionManager interactionManager = client.interactionManager; 62 | if (slot <= -1 || player == null || networkHandler == null || interactionManager == null) { 63 | return; 64 | } 65 | PlayerInventory playerInventory = player.getInventory(); 66 | // 背包中没有指定的物品 67 | if (PlayerInventory.isValidHotbarIndex(slot)) { 68 | playerInventory.setSelectedSlot(slot); 69 | } else { 70 | interactionManager.pickItemFromBlock(BlockPos.fromLong(slot), true); 71 | } 72 | networkHandler.sendPacket(new UpdateSelectedSlotC2SPacket(playerInventory.getSelectedSlot())); // 发送更新手持物品的数据包 73 | 74 | } 75 | 76 | public static void switchToItem(int minDamage, Item... items) { 77 | MinecraftClient client = MinecraftClient.getInstance(); 78 | ClientPlayerEntity player = client.player; 79 | ClientPlayerInteractionManager interactionManager = client.interactionManager; 80 | ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); 81 | if (player == null || interactionManager == null || networkHandler == null) { 82 | return; 83 | } 84 | PlayerInventory playerInventory = player.getInventory(); 85 | 86 | // 遍历主背包 87 | for (int i = 0; i < playerInventory.size(); i++) { 88 | ItemStack stack = playerInventory.getStack(i); 89 | if (stack.isEmpty()) { 90 | continue; 91 | } 92 | for (Item item : items) { 93 | if (stack.isOf(item)) { 94 | // 检查耐久是否发起警告(剩余耐久<=检查值) 95 | if (minDamage > 0 && InventoryManagerUtils.isItemDamageWarning(stack, minDamage)) { 96 | continue; 97 | } 98 | switchToSlot(i); 99 | return; 100 | } 101 | } 102 | } 103 | } 104 | 105 | 106 | public static void switchToItem(Item... items) { 107 | switchToItem(-1, items); 108 | } 109 | 110 | /** 111 | * 判断物品的耐久度是否小于等于给定的最小值 112 | * 113 | * @param itemStack 要检查耐久度的物品堆栈 114 | * @param minDamage 最小的剩余耐久度 115 | * @return 如果物品的剩余耐久度小于等于最小值则返回true,否则返回false 116 | */ 117 | public static boolean isItemDamageWarning(ItemStack itemStack, int minDamage) { 118 | int damageMax = itemStack.getMaxDamage(); // 获取物品的最大耐久度 119 | if (damageMax > 0) { 120 | int damage = itemStack.getDamage(); // 获取物品的已使用耐久度 121 | int damageSurplus = damageMax - damage; // 计算物品的剩余耐久度 122 | return damageSurplus <= minDamage; // 如果剩余耐久度小于等于给定的最小值,则返回true 123 | } 124 | return false; // 如果物品没有耐久度,则返回false 125 | } 126 | 127 | /** 128 | * 判断玩家是否可以瞬间破坏活塞方块 129 | * 130 | * @return 如果可以瞬间破坏活塞方块则返回true,否则返回false 131 | */ 132 | public static boolean canInstantlyMinePiston() { 133 | var client = MinecraftClient.getInstance(); 134 | var player = client.player; 135 | if (player == null) return false; 136 | var playerInventory = player.getInventory(); 137 | for (int i = 0; i < playerInventory.size(); i++) { 138 | if (isInstantBreakingBlock(Blocks.PISTON.getDefaultState(), playerInventory.getStack(i))) { 139 | return true; 140 | } 141 | } 142 | return false; 143 | } 144 | 145 | /** 146 | * 是否可以瞬间破坏方块 147 | * 148 | * @param blockState 要破坏的方块状态 149 | * @param itemStack 使用工具/物品破坏方块 150 | * @return true为可以瞬间破坏 151 | */ 152 | public static boolean isInstantBreakingBlock(BlockState blockState, ItemStack itemStack) { 153 | float hardness = blockState.getBlock().getHardness(); // 当前方块硬度 154 | if (hardness < 0) return false; // 无硬度(如基岩无法破坏) 155 | float speed = getBlockBreakingSpeed(blockState, itemStack); // 当前破坏速度 156 | return speed > (hardness * 30); 157 | } 158 | 159 | /** 160 | * 获取方块破坏所需的总时间 161 | * 162 | * @param blockState 要破坏的方块状态 163 | * @param itemStack 使用工具/物品破坏方块 164 | * @return 当前物品破坏该方块所需的时间 (单位为秒) 165 | */ 166 | public static float getBlockBreakingTotalTime(BlockState blockState, ItemStack itemStack) { 167 | var hardness = blockState.getBlock().getHardness(); // 当前方块硬度 168 | if (hardness < 0) return -1; 169 | var speed = getBlockBreakingSpeed(blockState, itemStack); // 当前工具的破坏速度系数 170 | return (float) ((hardness * 1.5) / speed); 171 | } 172 | 173 | /** 174 | * 获取当前物品能够破坏指定方块的破坏速度. 175 | * 176 | * @param blockState 要破坏的方块状态 177 | * @param itemStack 使用工具/物品破坏方块 178 | * @return 当前物品破坏该方块所需的时间(单位为 tick) 179 | */ 180 | private static float getBlockBreakingSpeed(BlockState blockState, ItemStack itemStack) { 181 | var client = MinecraftClient.getInstance(); 182 | var player = client.player; 183 | if (player == null) return 0; 184 | 185 | var toolSpeed = itemStack.getMiningSpeedMultiplier(blockState); // 当前物品的破坏系数速度 186 | // Debug.info("[1]" + toolSpeed); 187 | 188 | // 根据工具的"效率"附魔增加破坏速度 189 | if (toolSpeed > 1.0F) { 190 | // 获取itemStack的附魔集合 191 | for (var enchantment : itemStack.getEnchantments().getEnchantments()) { 192 | var enchantmentKey = enchantment.getKey(); 193 | if (enchantmentKey.isPresent()) { 194 | // 获取效率附魔等级 195 | if (enchantmentKey.get() == Enchantments.EFFICIENCY) { 196 | int toolLevel = EnchantmentHelper.getLevel(enchantment, itemStack); 197 | if (toolLevel > 0 && !itemStack.isEmpty()) { 198 | toolSpeed += (float) (toolLevel * toolLevel + 1); 199 | } 200 | } 201 | } 202 | } 203 | // Debug.info("[2]" + toolSpeed); 204 | } 205 | 206 | // 根据玩家"急迫"状态效果增加破坏速度 207 | if (StatusEffectUtil.hasHaste(player)) { 208 | toolSpeed *= 1.0F + (float) (StatusEffectUtil.getHasteAmplifier(player) + 1) * 0.2F; 209 | } 210 | 211 | // 根据玩家"挖掘疲劳"状态效果减缓破坏速度 212 | if (player.hasStatusEffect(StatusEffects.MINING_FATIGUE)) { 213 | float g = switch (Objects.requireNonNull(player.getStatusEffect(StatusEffects.MINING_FATIGUE)).getAmplifier()) { 214 | case 0 -> 0.3F; 215 | case 1 -> 0.09F; 216 | case 2 -> 0.0027F; 217 | default -> 8.1E-4F; 218 | }; 219 | toolSpeed *= g; 220 | } 221 | 222 | 223 | // 如果玩家在水中并且没有"水下速掘"附魔,则减缓破坏速度 224 | toolSpeed *= (float) player.getAttributeValue(EntityAttributes.BLOCK_BREAK_SPEED); 225 | if (player.isSubmergedIn(FluidTags.WATER)) { 226 | toolSpeed *= (float) Objects.requireNonNull(player.getAttributeInstance(EntityAttributes.SUBMERGED_MINING_SPEED)).getValue(); 227 | } 228 | 229 | // 如果玩家不在地面上,则减缓破坏速度 230 | if (!player.isOnGround()) { 231 | toolSpeed /= 5.0F; 232 | } 233 | // Debug.info("[3]" + toolSpeed); 234 | return toolSpeed; 235 | } 236 | 237 | /*** 获取背包物品数量 ***/ 238 | public static int getInventoryItemCount(Item item) { 239 | var client = MinecraftClient.getInstance(); 240 | var player = client.player; 241 | if (player == null) return 0; 242 | var playerInventory = player.getInventory(); 243 | return playerInventory.count(item); 244 | } 245 | } 246 | -------------------------------------------------------------------------------- /src/main/java/yan/lx/bedrockminer/task/TaskHandler.java: -------------------------------------------------------------------------------- 1 | package yan.lx.bedrockminer.task; 2 | 3 | import com.google.common.collect.Queues; 4 | import net.minecraft.block.*; 5 | import net.minecraft.client.MinecraftClient; 6 | import net.minecraft.client.world.ClientWorld; 7 | import net.minecraft.item.Items; 8 | import net.minecraft.text.Text; 9 | import net.minecraft.util.math.BlockPos; 10 | import net.minecraft.util.math.Direction; 11 | import net.minecraft.world.World; 12 | import org.jetbrains.annotations.Nullable; 13 | import yan.lx.bedrockminer.BedrockMinerLang; 14 | import yan.lx.bedrockminer.Debug; 15 | import yan.lx.bedrockminer.config.Config; 16 | import yan.lx.bedrockminer.utils.*; 17 | 18 | import java.util.Queue; 19 | 20 | import static net.minecraft.block.Block.sideCoversSmallSquare; 21 | 22 | public class TaskHandler { 23 | public final ClientWorld world; 24 | public final Block block; 25 | public final BlockPos pos; 26 | 27 | private TaskState state; 28 | private @Nullable TaskState nextState; 29 | 30 | public final TaskSeekSchemeInfo[] taskSchemes; 31 | public @Nullable Direction direction; 32 | public @Nullable TaskSeekBlockInfo piston; 33 | public @Nullable TaskSeekBlockInfo redstoneTorch; 34 | public @Nullable TaskSeekBlockInfo slimeBlock; 35 | public final Queue recycledQueue; 36 | 37 | 38 | public boolean executeModify; 39 | private int ticks; 40 | private int ticksTotalMax; 41 | private int ticksTimeoutMax; 42 | private int tickWaitMax; 43 | 44 | public int retryCount; 45 | public int retryCountMax; 46 | public boolean executed; 47 | public boolean recycled; 48 | public int recycledCount; 49 | public boolean timeout; 50 | 51 | 52 | public TaskHandler(ClientWorld world, Block block, BlockPos pos) { 53 | this.debug("[构造函数] 开始\r\n"); 54 | 55 | this.world = world; 56 | this.block = block; 57 | this.pos = pos; 58 | this.state = TaskState.INITIALIZE; 59 | this.taskSchemes = TaskSeekSchemeTools.findAllPossible(pos, world); 60 | this.recycledQueue = Queues.newConcurrentLinkedQueue(); 61 | 62 | this.retryCount = 0; 63 | this.retryCountMax = 1; 64 | 65 | this.init(); 66 | this.debug("[构造函数] 结束\r\n"); 67 | } 68 | 69 | 70 | private void setWait(@Nullable TaskState nextState, int tickWaitMax) { 71 | this.nextState = nextState; 72 | this.tickWaitMax = Math.max(tickWaitMax, 1); 73 | this.state = TaskState.WAIT_CUSTOM; 74 | } 75 | 76 | private void setModifyLook(TaskSeekBlockInfo blockInfo) { 77 | if (blockInfo != null) { 78 | setModifyLook(blockInfo.facing); 79 | blockInfo.modify = true; 80 | } 81 | } 82 | 83 | private void setModifyLook(Direction facing) { 84 | TaskModifyLookHandle.set(facing, this); 85 | } 86 | 87 | private void resetModifyLook() { 88 | TaskModifyLookHandle.reset(); 89 | } 90 | 91 | public void tick() { 92 | this.tick(false); 93 | } 94 | 95 | private void tickInternal() { 96 | this.tick(true); 97 | } 98 | 99 | private void tick(boolean internalCallbacks) { 100 | if (internalCallbacks) { 101 | debug("内部调用开始"); 102 | } else { 103 | debug("开始"); 104 | } 105 | if (this.state == TaskState.COMPLETE) { 106 | return; 107 | } 108 | if (this.ticks > this.ticksTotalMax) { 109 | this.state = TaskState.COMPLETE; 110 | } 111 | if (!this.timeout && this.ticks > this.ticksTimeoutMax) { 112 | this.timeout = true; 113 | this.state = TaskState.TIMEOUT; 114 | } 115 | 116 | switch (this.state) { 117 | case INITIALIZE -> this.init(); 118 | case WAIT_GAME_UPDATE -> this.updateStates(); 119 | case WAIT_CUSTOM -> this.waitCustom(); 120 | case FIND_PISTON -> this.findPiston(); 121 | case FIND_REDSTONE_TORCH -> this.findRedstoneTorch(); 122 | case FIND_SLIME_BLOCK -> this.findSlimeBlock(); 123 | case PLACE_PISTON -> this.placePiston(); 124 | case PLACE_REDSTONE_TORCH -> this.placeRedstoneTorch(); 125 | case PLACE_SLIME_BLOCK -> this.placeSlimeBlock(); 126 | case EXECUTE -> this.execute(); 127 | case TIMEOUT -> this.timeout(); 128 | case FAIL -> this.fail(); 129 | case RECYCLED_ITEMS -> this.recycledItems(); 130 | case COMPLETE -> complete(); 131 | } 132 | 133 | if (internalCallbacks) { 134 | debug("内部调用结束"); 135 | } else { 136 | debug("结束\r\n"); 137 | ++ticks; 138 | } 139 | } 140 | 141 | private void placeSlimeBlock() { 142 | if (slimeBlock == null) { 143 | findPiston(); 144 | return; 145 | } 146 | if (slimeBlock.isNeedModify() && !slimeBlock.modify) { 147 | setModifyLook(slimeBlock); 148 | return; 149 | } 150 | BlockPlacerUtils.placement(slimeBlock.pos, slimeBlock.facing, Items.SLIME_BLOCK); 151 | addRecycled(slimeBlock.pos); 152 | setWait(TaskState.WAIT_GAME_UPDATE, 1); 153 | resetModifyLook(); 154 | } 155 | 156 | private void placeRedstoneTorch() { 157 | if (redstoneTorch == null) { 158 | findPiston(); 159 | } 160 | if (redstoneTorch.isNeedModify() && !redstoneTorch.modify) { 161 | setModifyLook(redstoneTorch); 162 | return; 163 | } 164 | BlockPlacerUtils.placement(redstoneTorch.pos, redstoneTorch.facing, Items.REDSTONE_TORCH); 165 | addRecycled(redstoneTorch.pos); 166 | setWait(TaskState.WAIT_GAME_UPDATE, 3); 167 | resetModifyLook(); 168 | } 169 | 170 | private void placePiston() { 171 | if (piston == null) { 172 | findPiston(); 173 | } 174 | if (piston.isNeedModify() && !piston.modify) { 175 | setModifyLook(piston); 176 | return; 177 | } 178 | BlockPlacerUtils.placement(piston.pos, piston.facing, Items.PISTON); 179 | addRecycled(piston.pos); 180 | setWait(TaskState.WAIT_GAME_UPDATE, 1); 181 | resetModifyLook(); 182 | } 183 | 184 | private void findSlimeBlock() { 185 | if (slimeBlock == null || !(world.getBlockState(slimeBlock.pos).isReplaceable() 186 | || sideCoversSmallSquare(world, slimeBlock.pos, slimeBlock.facing))) { 187 | for (TaskSeekSchemeInfo taskSchemeInfo : taskSchemes) { 188 | if (taskSchemeInfo.piston.equals(piston)) { 189 | TaskSeekBlockInfo piston = taskSchemeInfo.piston; 190 | if (taskSchemeInfo.redstoneTorch.equals(redstoneTorch)) { 191 | TaskSeekBlockInfo redstoneTorch = taskSchemeInfo.redstoneTorch; 192 | TaskSeekBlockInfo slimeBlock = taskSchemeInfo.slimeBlock; 193 | if (World.isValid(piston.pos) && World.isValid(redstoneTorch.pos) && World.isValid(slimeBlock.pos)) { 194 | BlockState pistonState = world.getBlockState(piston.pos); 195 | BlockState pistonHeadState = world.getBlockState(piston.pos.offset(piston.facing)); 196 | // 检查活塞位置 197 | if (!(pistonState.isReplaceable() && pistonHeadState.isReplaceable())) { 198 | if (!(pistonState.getBlock() instanceof PistonBlock)) { 199 | continue; 200 | } 201 | } 202 | // 预检查, 避免无法放置导致失败 203 | BlockState redstoneTorchState = world.getBlockState(redstoneTorch.pos); 204 | if (!redstoneTorchState.isReplaceable()) { 205 | if (!(redstoneTorchState.getBlock() instanceof RedstoneTorchBlock)) { 206 | continue; 207 | } 208 | } 209 | // 预检查, 避免无法放置导致失败 210 | if (!(world.getBlockState(slimeBlock.pos).isReplaceable() || sideCoversSmallSquare(world, slimeBlock.pos, slimeBlock.facing))) { 211 | continue; 212 | } 213 | if (!CheckingEnvironmentUtils.canPlace(slimeBlock.pos, Blocks.SLIME_BLOCK, slimeBlock.facing)) { 214 | continue; 215 | } 216 | if (slimeBlock.facing.getAxis().isHorizontal()) { 217 | if (!Config.INSTANCE.horizontal) { 218 | continue; 219 | } 220 | } 221 | if (slimeBlock.facing.getAxis().isVertical()) { 222 | if (!Config.INSTANCE.vertical) { 223 | continue; 224 | } 225 | } 226 | this.slimeBlock = slimeBlock; 227 | break; 228 | } 229 | } 230 | } 231 | } 232 | } 233 | if (this.slimeBlock == null) { 234 | // state = TaskState.FAIL; 235 | MessageUtils.setOverlayMessage(Text.literal(BedrockMinerLang.HANDLE_SEEK.getString().replace("%BlockPos%", pos.toShortString()))); 236 | } else { 237 | state = TaskState.WAIT_GAME_UPDATE; 238 | } 239 | } 240 | 241 | private void findRedstoneTorch() { 242 | if (redstoneTorch == null || !(world.getBlockState(redstoneTorch.pos).isReplaceable() || sideCoversSmallSquare(world, redstoneTorch.pos, redstoneTorch.facing))) { 243 | for (TaskSeekSchemeInfo taskSchemeInfo : taskSchemes) { 244 | if (taskSchemeInfo.piston.equals(piston)) { 245 | TaskSeekBlockInfo piston = taskSchemeInfo.piston; 246 | TaskSeekBlockInfo redstoneTorch = taskSchemeInfo.redstoneTorch; 247 | TaskSeekBlockInfo slimeBlock = taskSchemeInfo.slimeBlock; 248 | if (World.isValid(piston.pos) && World.isValid(redstoneTorch.pos) && World.isValid(slimeBlock.pos)) { 249 | BlockState pistonState = world.getBlockState(piston.pos); 250 | BlockState pistonHeadState = world.getBlockState(piston.pos.offset(piston.facing)); 251 | // 检查活塞位置 252 | if (!(pistonState.isReplaceable() && pistonHeadState.isReplaceable())) { 253 | if (!(pistonState.getBlock() instanceof PistonBlock)) { 254 | continue; 255 | } 256 | } 257 | // 预检查, 避免无法放置导致失败 258 | BlockState redstoneTorchState = world.getBlockState(redstoneTorch.pos); 259 | if (!redstoneTorchState.isReplaceable()) { 260 | if (!(redstoneTorchState.getBlock() instanceof RedstoneTorchBlock)) { 261 | continue; 262 | } 263 | } 264 | if (!(world.getBlockState(slimeBlock.pos).isReplaceable() || sideCoversSmallSquare(world, slimeBlock.pos, slimeBlock.facing))) { 265 | continue; 266 | } 267 | if (!CheckingEnvironmentUtils.canPlace(slimeBlock.pos, Blocks.SLIME_BLOCK, slimeBlock.facing)) { 268 | continue; 269 | } 270 | if (redstoneTorch.facing.getAxis().isHorizontal()) { 271 | if (!Config.INSTANCE.horizontal) { 272 | continue; 273 | } 274 | } 275 | if (redstoneTorch.facing.getAxis().isVertical()) { 276 | if (!Config.INSTANCE.vertical) { 277 | continue; 278 | } 279 | } 280 | this.redstoneTorch = redstoneTorch; 281 | this.slimeBlock = null; 282 | break; 283 | } 284 | } 285 | } 286 | } 287 | if (this.redstoneTorch == null) { 288 | // state = TaskState.FAIL; 289 | MessageUtils.setOverlayMessage(Text.literal(BedrockMinerLang.HANDLE_SEEK.getString().replace("%BlockPos%", pos.toShortString()))); 290 | } else { 291 | state = TaskState.WAIT_GAME_UPDATE; 292 | } 293 | } 294 | 295 | private void findPiston() { 296 | if (this.piston == null) { 297 | for (TaskSeekSchemeInfo taskSchemeInfo : taskSchemes) { 298 | Direction direction = taskSchemeInfo.direction; 299 | TaskSeekBlockInfo piston = taskSchemeInfo.piston; 300 | TaskSeekBlockInfo redstoneTorch = taskSchemeInfo.redstoneTorch; 301 | TaskSeekBlockInfo slimeBlock = taskSchemeInfo.slimeBlock; 302 | if (direction.getAxis().isHorizontal()) { 303 | if (!Config.INSTANCE.horizontal) { 304 | continue; 305 | } 306 | } 307 | if (direction.getAxis().isVertical()) { 308 | if (!Config.INSTANCE.vertical) { 309 | continue; 310 | } 311 | } 312 | if (World.isValid(piston.pos) && World.isValid(redstoneTorch.pos) && World.isValid(slimeBlock.pos)) { 313 | BlockState pistonState = world.getBlockState(piston.pos); 314 | BlockState pistonHeadState = world.getBlockState(piston.pos.offset(piston.facing)); 315 | // 检查活塞位置 316 | if (!(pistonState.isReplaceable() && pistonHeadState.isReplaceable())) { 317 | if (!(pistonState.getBlock() instanceof PistonBlock)) { 318 | continue; 319 | } 320 | } 321 | // 预检查, 避免无法放置导致失败 322 | BlockState redstoneTorchState = world.getBlockState(redstoneTorch.pos); 323 | if (!redstoneTorchState.isReplaceable()) { 324 | if (!(redstoneTorchState.getBlock() instanceof RedstoneTorchBlock)) { 325 | continue; 326 | } 327 | } 328 | // 预检查, 避免无法放置导致失败 329 | if (!(world.getBlockState(slimeBlock.pos).isReplaceable() || sideCoversSmallSquare(world, slimeBlock.pos, slimeBlock.facing))) { 330 | continue; 331 | } 332 | if (!CheckingEnvironmentUtils.canPlace(slimeBlock.pos, Blocks.SLIME_BLOCK, slimeBlock.facing)) { 333 | continue; 334 | } 335 | if (piston.facing.getAxis().isHorizontal()) { 336 | if (!Config.INSTANCE.horizontal) { 337 | continue; 338 | } 339 | } 340 | if (piston.facing.getAxis().isVertical()) { 341 | if (!Config.INSTANCE.vertical) { 342 | continue; 343 | } 344 | } 345 | this.direction = direction; 346 | this.piston = piston; 347 | this.redstoneTorch = null; 348 | this.slimeBlock = null; 349 | break; 350 | } 351 | } 352 | } 353 | if (this.piston == null) { 354 | // state = TaskState.FAIL; 355 | MessageUtils.setOverlayMessage(Text.literal(BedrockMinerLang.HANDLE_SEEK.getString().replace("%BlockPos%", pos.toShortString()))); 356 | } else { 357 | state = TaskState.WAIT_GAME_UPDATE; 358 | } 359 | } 360 | 361 | private void complete() { 362 | debug("任务已完成"); 363 | } 364 | 365 | private void recycledItems() { 366 | if (!recycled) recycled = true; 367 | var player = MinecraftClient.getInstance().player; 368 | if (!recycledQueue.isEmpty() && player != null) { 369 | var blockPos = recycledQueue.peek(); 370 | BlockBreakerUtils.simpleBreakBlock(blockPos); 371 | if (world.getBlockState(blockPos).calcBlockBreakingDelta(player, world, blockPos) < 1F) { 372 | InventoryManagerUtils.autoSwitch(); 373 | return; 374 | } 375 | if (world.getBlockState(blockPos).isReplaceable()) { 376 | recycledQueue.remove(blockPos); 377 | } 378 | return; 379 | } 380 | // else if (world.getBlockState(pos).isOf(block)) { 381 | // if (retryCount < retryCountMax - 1) { 382 | // state = TaskState.INITIALIZE; 383 | // retryCount += 1; 384 | // return; 385 | // } 386 | // } 387 | state = TaskState.COMPLETE; 388 | } 389 | 390 | private void fail() { 391 | state = TaskState.RECYCLED_ITEMS; 392 | } 393 | 394 | private void timeout() { 395 | state = TaskState.FAIL; 396 | } 397 | 398 | private void execute() { 399 | var player = MinecraftClient.getInstance().player; 400 | if (executed || player == null || direction == null || piston == null || redstoneTorch == null || slimeBlock == null) { 401 | return; 402 | } 403 | if (!executeModify && direction.getAxis().isHorizontal()) { 404 | setModifyLook(direction.getOpposite()); 405 | executeModify = true; 406 | return; 407 | } else { 408 | if (world.getBlockState(piston.pos).calcBlockBreakingDelta(player, world, piston.pos) < 1F) { 409 | InventoryManagerUtils.autoSwitch(); 410 | setWait(TaskState.EXECUTE, 3); 411 | return; 412 | } 413 | // 打掉附近红石火把 414 | BlockPos[] nearbyRedstoneTorch = TaskSeekSchemeTools.findPistonNearbyRedstoneTorch(piston.pos, world); 415 | for (BlockPos pos : nearbyRedstoneTorch) { 416 | if (world.getBlockState(pos).getBlock() instanceof RedstoneTorchBlock) { 417 | BlockBreakerUtils.simpleBreakBlock(pos); 418 | } 419 | } 420 | if (world.getBlockState(redstoneTorch.pos).getBlock() instanceof RedstoneTorchBlock) { 421 | BlockBreakerUtils.simpleBreakBlock(redstoneTorch.pos); 422 | } 423 | BlockBreakerUtils.simpleBreakBlock(piston.pos); 424 | BlockPlacerUtils.placement(piston.pos, direction.getOpposite(), Items.PISTON); 425 | addRecycled(piston.pos); 426 | if (executeModify) { 427 | resetModifyLook(); 428 | } 429 | executed = true; 430 | } 431 | setWait(TaskState.WAIT_GAME_UPDATE, 4); 432 | } 433 | 434 | private void waitCustom() { 435 | if (--this.tickWaitMax <= 0) { 436 | this.state = this.nextState == null ? TaskState.WAIT_GAME_UPDATE : this.nextState; 437 | this.tickWaitMax = 0; 438 | debug("等待已结束, 状态设置为: %s", this.state); 439 | } else { 440 | ++this.ticksTotalMax; 441 | ++this.ticksTimeoutMax; 442 | debug("剩余等待TICK: %s", tickWaitMax); 443 | } 444 | 445 | // tickWait = 0; 446 | // var playerListEntry = networkHandler.getPlayerListEntry(player.getUuid()); 447 | // if (playerListEntry != null) { 448 | // int latency = playerListEntry.getLatency(); 449 | // tickWait += latency / 50; 450 | // } 451 | // if (waitCount > (tickWait + waitCountDelta)) { 452 | // if (nextState != null) { 453 | // state = nextState; 454 | // nextState = null; 455 | // } 456 | // waitCount = 0; 457 | // waitCountDelta = 0; 458 | // } else { 459 | // waitCount += 1; 460 | // } 461 | } 462 | 463 | private void updateStates() { 464 | if (this.piston != null && this.world.getBlockState(this.piston.pos).isOf(Blocks.MOVING_PISTON)) { 465 | debugUpdateStates("活塞正在移动"); 466 | return; 467 | } 468 | if (!this.world.getBlockState(pos).isOf(block)) { 469 | state = TaskState.RECYCLED_ITEMS; 470 | debugUpdateStates("目标不存在"); 471 | return; 472 | } 473 | if (!this.executed) { 474 | debugUpdateStates("任务未执行过"); 475 | 476 | // 获取放置位置 477 | if (this.piston == null) { 478 | this.debugUpdateStates("活塞未获取,准备查找合适的位置"); 479 | this.state = TaskState.FIND_PISTON; 480 | this.tickInternal(); // 查找算法,不需要独占TICK执行 481 | return; 482 | } 483 | 484 | if (this.redstoneTorch == null) { 485 | this.debugUpdateStates("红石火把未获取,准备查找合适的位置"); 486 | this.state = TaskState.FIND_REDSTONE_TORCH; 487 | this.tickInternal(); // 查找算法,不需要独占TICK执行 488 | return; 489 | } 490 | if (this.slimeBlock == null) { 491 | this.debugUpdateStates("红石火把底座未获取,准备查找合适的位置"); 492 | this.state = TaskState.FIND_SLIME_BLOCK; 493 | this.tickInternal(); // 查找算法,不需要独占TICK执行 494 | return; 495 | } 496 | 497 | if (this.world.getBlockState(this.piston.pos).isReplaceable()) { 498 | this.debugUpdateStates("[%s] 活塞未放置且该位置可放置物品,设置放置状态", this.piston.pos.toShortString()); 499 | this.state = TaskState.PLACE_PISTON; 500 | return; 501 | } else if (!(this.world.getBlockState(this.piston.pos).getBlock() instanceof PistonBlock)) { 502 | this.findPiston(); 503 | return; 504 | } 505 | 506 | 507 | if (this.world.getBlockState(this.slimeBlock.pos).isReplaceable()) { 508 | this.state = TaskState.PLACE_SLIME_BLOCK; 509 | return; 510 | } else if (!Block.sideCoversSmallSquare(world, slimeBlock.pos, slimeBlock.facing)) { 511 | this.findRedstoneTorch(); 512 | return; 513 | } 514 | 515 | if (world.getBlockState(redstoneTorch.pos).isReplaceable()) { 516 | state = TaskState.PLACE_REDSTONE_TORCH; 517 | return; 518 | } else if (!(world.getBlockState(redstoneTorch.pos).getBlock() instanceof RedstoneTorchBlock)) { 519 | this.findRedstoneTorch(); 520 | return; 521 | } 522 | 523 | if (this.world.getBlockState(this.piston.pos).getBlock() instanceof PistonBlock) { 524 | if (this.world.getBlockState(this.piston.pos).contains(PistonBlock.EXTENDED)) { 525 | if (this.world.getBlockState(this.piston.pos).get(PistonBlock.EXTENDED)) { 526 | this.state = TaskState.EXECUTE; 527 | } 528 | } 529 | } 530 | } 531 | } 532 | 533 | private void init() { 534 | this.state = TaskState.WAIT_GAME_UPDATE; 535 | this.nextState = null; 536 | this.ticks = 0; 537 | this.ticksTotalMax = 100; 538 | this.ticksTimeoutMax = 30; 539 | this.tickWaitMax = 0; 540 | 541 | this.direction = null; 542 | this.piston = null; 543 | this.redstoneTorch = null; 544 | this.slimeBlock = null; 545 | 546 | this.recycledQueue.clear(); 547 | this.executed = false; 548 | this.recycled = false; 549 | this.recycledCount = 0; 550 | this.timeout = false; 551 | 552 | this.tickInternal(); 553 | } 554 | 555 | private void debug(String var1, Object... var2) { 556 | Debug.info("[{}] [{}] [{}] {}", retryCount, ticks, state, String.format(var1, var2)); 557 | } 558 | 559 | private void debugUpdateStates(String var1, Object... var2) { 560 | Debug.info("[{}] [{}] [{}] [状态更新] {}", retryCount, ticks, state, String.format(var1, var2)); 561 | } 562 | 563 | private void addRecycled(BlockPos pos) { 564 | if (!recycledQueue.contains(pos)) { 565 | recycledQueue.add(pos); 566 | } 567 | } 568 | 569 | public boolean isComplete() { 570 | return state == TaskState.COMPLETE; 571 | } 572 | } 573 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | TaskState the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------