Skip to content

Commit

Permalink
updated to 1.21.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bunnyi116 committed Jun 19, 2024
1 parent 8c9262c commit 53dc40a
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 125 deletions.
122 changes: 64 additions & 58 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,91 +1,97 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'maven-publish'
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'maven-publish'
}

version = "${project.minecraft_version}-${project.mod_version}"
group = project.maven_group

repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
}

loom {
accessWidenerPath = file("src/main/resources/bedrock-miner.accesswidener")
accessWidenerPath = file("src/main/resources/bedrock-miner.accesswidener")
}

dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
}

processResources {
inputs.property("version", project.version)
inputs.property("minecraft_version", project.property("minecraft_version"))
inputs.property("loader_version", project.property("loader_version"))
inputs.property("version", project.version)
inputs.property("minecraft_version", project.property("minecraft_version"))
inputs.property("loader_version", project.property("loader_version"))
inputs.property("java_version", project.property("java_version"))

filteringCharset "UTF-8"
filesMatching("fabric.mod.json") {
expand([
"version" : project.version,
"minecraft_version": project.property("minecraft_version"),
"loader_version" : project.property("loader_version")
])
}
filteringCharset "UTF-8"
filesMatching("fabric.mod.json") {
expand([
"version" : project.version,
"minecraft_version" : project.property("minecraft_version"),
"loader_version" : project.property("loader_version"),
"java_version" : project.property("java_version")
])
}
}
// 从1.12(17w13a)开始,运行Minecraft的最低要求是Java 8。
// 从1.17(21w19a)开始,运行Minecraft的最低要求是Java 16。
// 从1.18(1.18-pre2)开始,运行Minecraft的最低要求是Java 17。
// 从1.20.5(24w14a)开始,运行Minecraft的最低要求是Java 21,且操作系统要求为64位。

def targetJavaVersion = 21
def targetJavaVersion = project.java_version as Integer
tasks.withType(JavaCompile).configureEach {
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
// If Javadoc is generated, this must be specified in that task too.
it.options.encoding = "UTF-8"
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
it.options.release = targetJavaVersion
}
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
// If Javadoc is generated, this must be specified in that task too.
it.options.encoding = "UTF-8"
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
it.options.release = targetJavaVersion
}
}

java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
archivesBaseName = project.archives_base_name
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
archivesBaseName = project.archives_base_name
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}

jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}" }
}
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}" }
}
}

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
publications {
mavenJava(MavenPublication) {
from components.java
}
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
25 changes: 20 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,35 @@ org.gradle.parallel=true
mod_version=1.2.21
maven_group=yan.lx.bedrockMiner
archives_base_name=bedrock-miner
java_version=21

# Fabric Properties
# check these on https://fabricmc.net/develop/
# Dependencies
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.1
minecraft_version=1.21
yarn_mappings=1.21+build.2
loader_version=0.15.11

# Fabric API
fabric_version=0.97.8+1.20.6
fabric_version=0.100.3+1.21

## Loom image source
# Loom image source
#loom_libraries_base=https://bmclapi2.bangbang93.com/maven/
#loom_resources_base=https://bmclapi2.bangbang93.com/assets/
#loom_version_manifests=https://bmclapi2.bangbang93.com/mc/game/version_manifest.json
#loom_experimental_versions=https://maven.fabricmc.net/net/minecraft/experimental_versions.json
#loom_fabric_repository=https://repository.hanbings.io/proxy/
#loom_fabric_repository=https://repository.hanbings.io/proxy/

# Proxy
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=10809
systemProp.http.nonProxyHosts=10.*|localhost

systemProp.socks.proxyHost=localhost
systemProp.socks.proxyPort=10808
systemProp.socks.nonProxyHosts=10.*|localhost

#systemProp.https.proxyHost=127.0.0.1
#systemProp.https.proxyPort=1081
#systemProp.https.nonProxyHosts=10.*|localhost

2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https://services.gradle.org/distributions/gradle-8.8-bin.zip
# distributionUrl=https://mirrors.cloud.tencent.com/gradle/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/yan/lx/bedrockminer/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ public static int onCommandExecute(CommandContext<FabricClientCommandSource> con
// Debug.info(world.getWorldBorder().getMaxRadius());
}

PlayerInventory playerInventory = player.getInventory();
// 遍历主背包
for (int i = 0; i < playerInventory.main.size(); i++) {
BedrockMinerMod.LOGGER.info("[" + i + "] " + playerInventory.main.get(i).getName().getString());
}
//BlockPlacerUtils.placement(new BlockPos(8, -60, 8), Direction.NORTH, Items.REDSTONE_TORCH);
// var itemStack = player.getMainHandStack();
// var registry = world.getRegistryManager().get(RegistryKeys.BLOCK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Block parse(StringReader reader) throws CommandSyntaxException {
// 获取用户输入的字符串内容
var string = reader.getString().substring(i, reader.getCursor());
// 检查方块注册表中是否存在该名称
var blockId = new Identifier(string);
var blockId = Identifier.of(string);
var optionalBlock = Registries.BLOCK.stream().filter(block -> BlockUtils.getIdentifier(block).equals(blockId)).findFirst();
if (optionalBlock.isEmpty()) {
reader.setCursor(i);
Expand Down
27 changes: 15 additions & 12 deletions src/main/java/yan/lx/bedrockminer/task/TaskHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import yan.lx.bedrockminer.BedrockMinerLang;
import yan.lx.bedrockminer.Debug;
import yan.lx.bedrockminer.config.Config;
import yan.lx.bedrockminer.utils.BlockBreakerUtils;
import yan.lx.bedrockminer.utils.BlockPlacerUtils;
import yan.lx.bedrockminer.utils.CheckingEnvironmentUtils;
import yan.lx.bedrockminer.utils.MessageUtils;
import yan.lx.bedrockminer.utils.*;

import java.util.List;
import java.util.Queue;
Expand Down Expand Up @@ -244,6 +241,12 @@ private boolean onHandleStatus() {
executeModify = true;
return false;
} else {
var mainHandStack = player.getInventory().getMainHandStack();
if (InventoryManagerUtils.getBlockBreakingTotalTime(world.getBlockState(piston.pos), mainHandStack) > 1) {
InventoryManagerUtils.autoSwitch();
setWait(TaskState.EXECUTE, 1);
return false;
}
// 打掉附近红石火把
BlockPos[] nearbyRedstoneTorch = TaskSeekSchemeTools.findPistonNearbyRedstoneTorch(piston.pos, world);
for (BlockPos pos : nearbyRedstoneTorch) {
Expand Down Expand Up @@ -336,12 +339,12 @@ private boolean findPiston() {
TaskSeekBlockInfo redstoneTorch = taskSchemeInfo.redstoneTorch;
TaskSeekBlockInfo slimeBlock = taskSchemeInfo.slimeBlock;
if (direction.getAxis().isHorizontal()) {
if (!Config.INSTANCE.horizontal){
if (!Config.INSTANCE.horizontal) {
continue;
}
}
if (direction.getAxis().isVertical()) {
if (!Config.INSTANCE.vertical){
if (!Config.INSTANCE.vertical) {
continue;
}
}
Expand Down Expand Up @@ -372,12 +375,12 @@ private boolean findPiston() {
continue;
}
if (piston.facing.getAxis().isHorizontal()) {
if (!Config.INSTANCE.horizontal){
if (!Config.INSTANCE.horizontal) {
continue;
}
}
if (piston.facing.getAxis().isVertical()) {
if (!Config.INSTANCE.vertical){
if (!Config.INSTANCE.vertical) {
continue;
}
}
Expand Down Expand Up @@ -432,12 +435,12 @@ private boolean findRedstoneTorch() {
continue;
}
if (redstoneTorch.facing.getAxis().isHorizontal()) {
if (!Config.INSTANCE.horizontal){
if (!Config.INSTANCE.horizontal) {
continue;
}
}
if (redstoneTorch.facing.getAxis().isVertical()) {
if (!Config.INSTANCE.vertical){
if (!Config.INSTANCE.vertical) {
continue;
}
}
Expand Down Expand Up @@ -494,12 +497,12 @@ private boolean findSlimeBlock() {
continue;
}
if (slimeBlock.facing.getAxis().isHorizontal()) {
if (!Config.INSTANCE.horizontal){
if (!Config.INSTANCE.horizontal) {
continue;
}
}
if (slimeBlock.facing.getAxis().isVertical()) {
if (!Config.INSTANCE.vertical){
if (!Config.INSTANCE.vertical) {
continue;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/yan/lx/bedrockminer/task/TaskManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static void tick() {
if (handler.isSucceed()) {
iterator.remove();
}
break;
return;

}
}
Expand Down
32 changes: 7 additions & 25 deletions src/main/java/yan/lx/bedrockminer/utils/BlockBreakerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import org.jetbrains.annotations.Nullable;
import yan.lx.bedrockminer.BedrockMinerMod;
import yan.lx.bedrockminer.Debug;

Expand All @@ -30,32 +31,13 @@ public static boolean breakBlock(BlockPos blockPos, Direction direction) {
if (world.getBlockState(blockPos).isReplaceable()) return true;
if (world.getBlockState(blockPos).getBlock().getHardness() < 0) return false;

// 选取最优工具
float lastTime = -1;
int lastSlot = -1;
for (int i = 0; i < playerInventory.size(); i++) {
var itemStack = playerInventory.getStack(i);
// 检查耐久是否发起警告(剩余耐久<=检查值)
if (InventoryManagerUtils.isItemDamageWarning(itemStack, 5)) {
continue;
}
// 选取最快工具
float blockBreakingTotalTime = InventoryManagerUtils.getBlockBreakingTotalTime(world.getBlockState(blockPos), itemStack);
if (blockBreakingTotalTime != -1) {
if (lastTime == -1 || lastTime > blockBreakingTotalTime) {
lastTime = blockBreakingTotalTime;
lastSlot = i;
}
}
InventoryManagerUtils.autoSwitch();

}
if (lastSlot != -1) {
InventoryManagerUtils.switchToSlot(lastSlot);
}
// 更新方块正在破坏进程
if (interactionManager.updateBlockBreakingProgress(blockPos, direction)) {
client.particleManager.addBlockBreakingParticles(blockPos, direction);
}
interactionManager.attackBlock(blockPos, direction);
// // 更新方块正在破坏进程
// if (interactionManager.updateBlockBreakingProgress(blockPos, direction)) {
// client.particleManager.addBlockBreakingParticles(blockPos, direction);
// }
// 检查是否已经成功
return world.getBlockState(blockPos).isReplaceable();
}
Expand Down
Loading

0 comments on commit 53dc40a

Please sign in to comment.