From da71f49ac29a36a64ff1720d7818b20dc969684c Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 26 Sep 2025 09:03:10 +0200 Subject: [PATCH 1/5] Trying stuff out Signed-off-by: Sebastian --- build.gradle | 14 +++++--- gradle.properties | 5 ++- .../moe/sebiann/qol27/client/QoL27Client.java | 6 ---- .../java/moe/sebiann/qol27/config/Config.java | 34 +++++++++++++++++++ .../moe/sebiann/qol27/config/Config27.java | 25 -------------- .../qol27/config/ModMenuIntegration.java | 17 ++++++++++ src/main/resources/fabric.mod.json | 5 +-- 7 files changed, 66 insertions(+), 40 deletions(-) create mode 100644 src/main/java/moe/sebiann/qol27/config/Config.java delete mode 100644 src/main/java/moe/sebiann/qol27/config/Config27.java create mode 100644 src/main/java/moe/sebiann/qol27/config/ModMenuIntegration.java diff --git a/build.gradle b/build.gradle index 4e56769..b57bfae 100644 --- a/build.gradle +++ b/build.gradle @@ -24,8 +24,14 @@ loom { repositories { mavenCentral() maven { url "https://maven.shedaniel.me/" } - maven { url "https://maven.terraformersmc.com/releases/" } - maven { url 'https://maven.wispforest.io/releases/' } + maven { + name = "Terraformers" + url = "https://maven.terraformersmc.com/" + } + maven { + name 'Xander Maven' + url 'https://maven.isxander.dev/releases' + } } dependencies { @@ -34,8 +40,8 @@ dependencies { mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - annotationProcessor modImplementation("io.wispforest:owo-lib:${project.owo_version}") - include "io.wispforest:owo-sentinel:${project.owo_version}" + modImplementation("com.terraformersmc:modmenu:${project.modmenu_version}") + modImplementation "dev.isxander:yet-another-config-lib:${project.yacl_version}" } processResources { diff --git a/gradle.properties b/gradle.properties index 5763f71..54a1472 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,6 @@ archives_base_name=qol27 # Dependencies # check this on https://modmuss50.me/fabric.html fabric_version=0.133.0+1.21.8 -# https://maven.wispforest.io/io/wispforest/owo-lib/ -owo_version=0.12.21+1.21.6 # Extras -modmenu_version=14.0.0-beta.3 \ No newline at end of file +modmenu_version=15.0.0 +yacl_version=3.7.1+1.21.6-fabric \ No newline at end of file diff --git a/src/main/java/moe/sebiann/qol27/client/QoL27Client.java b/src/main/java/moe/sebiann/qol27/client/QoL27Client.java index bc319dd..c31f8b2 100644 --- a/src/main/java/moe/sebiann/qol27/client/QoL27Client.java +++ b/src/main/java/moe/sebiann/qol27/client/QoL27Client.java @@ -1,12 +1,10 @@ package moe.sebiann.qol27.client; -import moe.sebiann.qol27.config.QoL27Config; import net.fabricmc.api.ClientModInitializer; import org.slf4j.LoggerFactory; import org.slf4j.Logger; public class QoL27Client implements ClientModInitializer { - public static final QoL27Config CONFIG = QoL27Config.createAndLoad(); public static final String MOD_ID = "QoL27Client"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); @@ -18,8 +16,4 @@ public void onInitializeClient() { LOGGER.info("{} initialized!", MOD_ID); } - - public static QoL27Config getConfig() { - return CONFIG; - } } diff --git a/src/main/java/moe/sebiann/qol27/config/Config.java b/src/main/java/moe/sebiann/qol27/config/Config.java new file mode 100644 index 0000000..078386d --- /dev/null +++ b/src/main/java/moe/sebiann/qol27/config/Config.java @@ -0,0 +1,34 @@ +package moe.sebiann.qol27.config; + +import dev.isxander.yacl3.config.v2.api.ConfigClassHandler; +import dev.isxander.yacl3.config.v2.api.SerialEntry; +import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder; +import net.fabricmc.loader.api.FabricLoader; + +public class Config { + public static ConfigClassHandler HANDLER = ConfigClassHandler.createBuilder(Config.class) + .id(new ResourceLocation("qol27", "config")) + .serializer(config -> GsonConfigSerializerBuilder.create(config) + .setPath(FabricLoader.getInstance().getConfigDir().resolve("my_mod.json5")) + .setJson5(true) + .build()) + .build(); + + @SerialEntry + public boolean noSilkDetectionEnabled = true; + + @SerialEntry + public boolean sneakOverridesDetection = true; + + @SerialEntry + public boolean noStrippingEnabled = true; + + @SerialEntry + public boolean sneakOverridesStripping = true; + + @SerialEntry + public boolean noCarpetsOnCarpetsEnabled = true; + + @SerialEntry + public boolean sneakOverridesCarpetPlacing = true; +} diff --git a/src/main/java/moe/sebiann/qol27/config/Config27.java b/src/main/java/moe/sebiann/qol27/config/Config27.java deleted file mode 100644 index 81da1cd..0000000 --- a/src/main/java/moe/sebiann/qol27/config/Config27.java +++ /dev/null @@ -1,25 +0,0 @@ -package moe.sebiann.qol27.config; - -import io.wispforest.owo.config.annotation.Config; -import io.wispforest.owo.config.annotation.Modmenu; -import io.wispforest.owo.config.annotation.SectionHeader; - -@Modmenu(modId = "qol27") -@Config(name = "qol27-config", wrapperName = "QoL27Config") -public class Config27 { - @SectionHeader("noSilkTouchDetection") - public boolean noSilkDetectionEnabled = true; - public boolean sneakOverridesDetection = true; - - @SectionHeader("woodStrippingDetection") - public boolean noStrippingEnabled = true; - public boolean sneakOverridesStripping = true; - - // @SectionHeader("saveCoordsOnLogout") - // public boolean saveCoordsOnLogout = true; - - @SectionHeader("noCarpetsOnCarpets") - public boolean noCarpetsOnCarpetsEnabled = true; - public boolean sneakOverridesCarpetPlacing = true; - -} diff --git a/src/main/java/moe/sebiann/qol27/config/ModMenuIntegration.java b/src/main/java/moe/sebiann/qol27/config/ModMenuIntegration.java new file mode 100644 index 0000000..cb4a378 --- /dev/null +++ b/src/main/java/moe/sebiann/qol27/config/ModMenuIntegration.java @@ -0,0 +1,17 @@ +package moe.sebiann.qol27.config; + +import com.terraformersmc.modmenu.api.ConfigScreenFactory; +import com.terraformersmc.modmenu.api.ModMenuApi; +import dev.isxander.yacl3.api.YetAnotherConfigLib; +import net.minecraft.text.Text; + +public class ModMenuIntegration implements ModMenuApi { + @Override + public ConfigScreenFactory getModConfigScreenFactory() { + return parentScreen -> YetAnotherConfigLib.createBuilder() + .title("test") + .save(() -> System.out.println("Config saved")) + .build() + .generateScreen(parentScreen); + } +} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index a049291..53dd7e2 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -17,14 +17,15 @@ "icon": "assets/qol27/icon.png", "environment": "client", "entrypoints": { - "client": ["moe.sebiann.qol27.client.QoL27Client"] + "client": ["moe.sebiann.qol27.client.QoL27Client"], + "modmenu": ["moe.sebiann.qol27.config.ModMenuIntegration" ] }, "mixins": [], "depends": { "fabricloader": ">=${loader_version}", "fabric": "*", "minecraft": "${minecraft_version}", - "owo": "*" + "yet_another_config_lib_v3": ">=${yacl_version}" }, "injectors": { "defaultRequire": 1 From 262762620cf8a4ae31460df834fd22b8ceb00b55 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 26 Sep 2025 22:08:45 +0200 Subject: [PATCH 2/5] IDK lets go Signed-off-by: Sebastian --- build.gradle | 105 -------------- build.gradle.kts | 106 ++++++++++++++ gradle.properties | 8 +- src/main/java/moe/sebiann/qol27/QoL27.kt | 16 ++ .../sebiann/qol27/client/CarpetSafety.java | 38 +++-- .../sebiann/qol27/client/NoSilkDetection.java | 47 ------ .../sebiann/qol27/client/NoSilkDetection.kt | 83 +++++++++++ .../moe/sebiann/qol27/client/QoL27Client.java | 19 --- .../moe/sebiann/qol27/client/QoL27Client.kt | 20 +++ .../qol27/client/WoodStrippingDetection.java | 33 ++--- .../java/moe/sebiann/qol27/config/Config.java | 34 ----- .../java/moe/sebiann/qol27/config/Config.kt | 137 ++++++++++++++++++ .../qol27/config/ModMenuIntegration.java | 17 --- .../qol27/config/ModMenuIntegration.kt | 11 ++ .../java/moe/sebiann/qol27/utils/Resources.kt | 8 + .../resources/assets/qol27/lang/en_us.json | 33 +++-- src/main/resources/fabric.mod.json | 13 +- 17 files changed, 446 insertions(+), 282 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts create mode 100644 src/main/java/moe/sebiann/qol27/QoL27.kt delete mode 100644 src/main/java/moe/sebiann/qol27/client/NoSilkDetection.java create mode 100644 src/main/java/moe/sebiann/qol27/client/NoSilkDetection.kt delete mode 100644 src/main/java/moe/sebiann/qol27/client/QoL27Client.java create mode 100644 src/main/java/moe/sebiann/qol27/client/QoL27Client.kt delete mode 100644 src/main/java/moe/sebiann/qol27/config/Config.java create mode 100644 src/main/java/moe/sebiann/qol27/config/Config.kt delete mode 100644 src/main/java/moe/sebiann/qol27/config/ModMenuIntegration.java create mode 100644 src/main/java/moe/sebiann/qol27/config/ModMenuIntegration.kt create mode 100644 src/main/java/moe/sebiann/qol27/utils/Resources.kt diff --git a/build.gradle b/build.gradle deleted file mode 100644 index b57bfae..0000000 --- a/build.gradle +++ /dev/null @@ -1,105 +0,0 @@ -plugins { - id 'fabric-loom' version '1.11-SNAPSHOT' - id 'maven-publish' -} - -version = project.mod_version -group = project.maven_group - -base { - archivesName = project.archives_base_name -} - -loom { - splitEnvironmentSourceSets() - - mods { - "qol27" { - sourceSet sourceSets.main - sourceSet sourceSets.client - } - } -} - -repositories { - mavenCentral() - maven { url "https://maven.shedaniel.me/" } - maven { - name = "Terraformers" - url = "https://maven.terraformersmc.com/" - } - maven { - name 'Xander Maven' - url 'https://maven.isxander.dev/releases' - } -} - -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}" - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modImplementation("com.terraformersmc:modmenu:${project.modmenu_version}") - modImplementation "dev.isxander:yet-another-config-lib:${project.yacl_version}" -} - -processResources { - inputs.property "version", project.version - inputs.property "minecraft_version", project.minecraft_version - inputs.property "loader_version", project.loader_version - filteringCharset "UTF-8" - - filesMatching("fabric.mod.json") { - expand "version": project.version, - "minecraft_version": project.minecraft_version, - "loader_version": project.loader_version - } -} - -def targetJavaVersion = 21 -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.set(targetJavaVersion) - } -} - -java { - def javaVersion = JavaVersion.toVersion(targetJavaVersion) - if (JavaVersion.current() < javaVersion) { - toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) - } - // 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}" } - } -} - -// configure the maven publication -publishing { - publications { - create("mavenJava", MavenPublication) { - artifactId = project.archives_base_name - 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. - } -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..1f71b4a --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,106 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + kotlin("jvm") version "2.2.0" + id("fabric-loom") version "1.11-SNAPSHOT" + kotlin("plugin.serialization") version "2.0.20" + id("maven-publish") +} + +version = project.property("mod_version") as String +group = project.property("maven_group") as String + +base { + archivesName.set(project.property("archives_base_name") as String) +} + +val targetJavaVersion = 21 +java { + toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) + // 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() +} + +repositories { + mavenCentral() + maven("https://maven.isxander.dev/releases") { + name = "Xander Maven" + } + maven("https://maven.terraformersmc.com/") { + name = "Terraformers" + } + exclusiveContent { + forRepository { + maven("https://api.modrinth.com/maven") { + name = "Modrinth" + } + } + filter { + includeGroup("maven.modrinth") + } + } +} + +dependencies { + minecraft("com.mojang:minecraft:${project.property("minecraft_version")}") + mappings(loom.officialMojangMappings()) +// mappings("net.fabricmc:yarn:${project.property("yarn_mappings")}:v2") + modImplementation("net.fabricmc:fabric-loader:${project.property("loader_version")}") + modImplementation("net.fabricmc:fabric-language-kotlin:${project.property("kotlin_loader_version")}") + + modImplementation("net.fabricmc.fabric-api:fabric-api:${project.property("fabric_version")}") + modImplementation("dev.isxander:yet-another-config-lib:${project.property("yacl_version")}") + modImplementation("com.terraformersmc:modmenu:${project.property("modmenu_version")}") + + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1") + compileOnlyApi("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.9.0-RC.2") +} + +tasks.processResources { + inputs.property("version", project.version) + inputs.property("minecraft_version", project.property("minecraft_version")) + inputs.property("loader_version", project.property("loader_version")) + filteringCharset = "UTF-8" + + filesMatching("fabric.mod.json") { + expand( + "version" to project.version, + "minecraft_version" to project.property("minecraft_version"), + "loader_version" to project.property("loader_version"), + "kotlin_loader_version" to project.property("kotlin_loader_version") + ) + } +} + +tasks.withType().configureEach { + options.encoding = "UTF-8" + options.release.set(targetJavaVersion) +} + +tasks.withType().configureEach { + compilerOptions.jvmTarget.set(JvmTarget.fromTarget(targetJavaVersion.toString())) +} + +tasks.jar { + from("LICENSE") { + rename { "${it}_${project.base.archivesName}" } + } +} + +publishing { + publications { + create("mavenJava") { + groupId = project.property("maven_group") as String + artifactId = project.property("archives_base_name") as String + version = version + from(components["java"]) + } + } + repositories { + // Add repositories to publish to here. + } +} + diff --git a/gradle.properties b/gradle.properties index 54a1472..aa7393f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,17 +1,17 @@ # Done to increase the memory available to gradle. -org.gradle.jvmargs=-Xmx4G +org.gradle.jvmargs=-Xmx2G # Fabric Properties # check these on https://modmuss50.me/fabric.html minecraft_version=1.21.8 yarn_mappings=1.21.8+build.1 loader_version=0.17.2 +kotlin_loader_version=1.13.4+kotlin.2.2.0 # Mod Properties mod_version=0.2.4 maven_group=moe.sebiann -archives_base_name=qol27 +archives_base_name=Qol27 # Dependencies # check this on https://modmuss50.me/fabric.html fabric_version=0.133.0+1.21.8 -# Extras +yacl_version=3.7.1+1.21.6-fabric modmenu_version=15.0.0 -yacl_version=3.7.1+1.21.6-fabric \ No newline at end of file diff --git a/src/main/java/moe/sebiann/qol27/QoL27.kt b/src/main/java/moe/sebiann/qol27/QoL27.kt new file mode 100644 index 0000000..3cdea88 --- /dev/null +++ b/src/main/java/moe/sebiann/qol27/QoL27.kt @@ -0,0 +1,16 @@ +package moe.sebiann.qol27 + +import moe.sebiann.qol27.config.Config +import net.fabricmc.api.ModInitializer +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +class QoL27 : ModInitializer{ + companion object { + val LOGGER: Logger = LoggerFactory.getLogger(this.toString()) + } + override fun onInitialize() { + LOGGER.info("[Qol27] Initializing Client...") + Config.init() + } +} \ No newline at end of file diff --git a/src/main/java/moe/sebiann/qol27/client/CarpetSafety.java b/src/main/java/moe/sebiann/qol27/client/CarpetSafety.java index 634023a..85ff5f8 100644 --- a/src/main/java/moe/sebiann/qol27/client/CarpetSafety.java +++ b/src/main/java/moe/sebiann/qol27/client/CarpetSafety.java @@ -1,15 +1,15 @@ package moe.sebiann.qol27.client; -import moe.sebiann.qol27.config.QoL27Config; +import moe.sebiann.qol27.config.Config; import net.fabricmc.fabric.api.event.player.UseBlockCallback; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.CarpetBlock; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ActionResult; -import net.minecraft.util.math.BlockPos; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.CarpetBlock; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.InteractionResult; +import net.minecraft.core.BlockPos; import java.util.Set; import java.util.stream.Collectors; @@ -18,26 +18,24 @@ public class CarpetSafety { public static void initialize() { - QoL27Config config = QoL27Client.getConfig(); - UseBlockCallback.EVENT.register((player, world, hand, hitResult) -> { - if (!config.noCarpetsOnCarpetsEnabled()) { - return ActionResult.PASS; + if (!Config.Carpets.INSTANCE.getEnabled()) { + return InteractionResult.PASS; } - if (!world.isClient) return ActionResult.PASS; + if (!world.isClientSide) return InteractionResult.PASS; - ItemStack heldItem = player.getStackInHand(hand); - if (!CARPET_ITEMS.contains(heldItem.getItem())) return ActionResult.PASS; + ItemStack heldItem = player.getItemInHand(hand); + if (!CARPET_ITEMS.contains(heldItem.getItem())) return InteractionResult.PASS; BlockPos pos = hitResult.getBlockPos(); BlockState state = world.getBlockState(pos); - if (config.sneakOverridesCarpetPlacing() && player.isSneaking()) { - return ActionResult.PASS; + if (Config.Carpets.INSTANCE.getSneakOverrides() && player.isShiftKeyDown()) { + return InteractionResult.PASS; } else if (state.getBlock() instanceof CarpetBlock) { - return ActionResult.FAIL; + return InteractionResult.FAIL; } else { - return ActionResult.PASS; + return InteractionResult.PASS; } }); } diff --git a/src/main/java/moe/sebiann/qol27/client/NoSilkDetection.java b/src/main/java/moe/sebiann/qol27/client/NoSilkDetection.java deleted file mode 100644 index 3f97c2c..0000000 --- a/src/main/java/moe/sebiann/qol27/client/NoSilkDetection.java +++ /dev/null @@ -1,47 +0,0 @@ -package moe.sebiann.qol27.client; - -import moe.sebiann.qol27.config.QoL27Config; -import net.fabricmc.fabric.api.event.player.AttackBlockCallback; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.registry.entry.RegistryEntry; -import net.minecraft.util.ActionResult; - -import java.util.Set; - -public class NoSilkDetection { - public static void initialize() { - QoL27Config config = QoL27Client.getConfig(); - - AttackBlockCallback.EVENT.register((player, world, hand, pos, direction) -> { - if (!config.noSilkDetectionEnabled()) { - return ActionResult.PASS; - } - BlockState state = world.getBlockState(pos); - if (state.getBlock() == Blocks.ENDER_CHEST) { - ItemStack itemStack = player.getInventory().getSelectedStack(); - Item item = itemStack.getItem(); - boolean isPickaxe = item == Items.DIAMOND_PICKAXE - || item == Items.NETHERITE_PICKAXE; - Set> enchantments = itemStack.getEnchantments().getEnchantments(); - boolean hasNoSilkTouch = enchantments.stream().noneMatch(enchantmentRegistryEntry -> enchantmentRegistryEntry.getKey().get().getValue().getPath().equalsIgnoreCase("silk_touch")); - - if (config.sneakOverridesDetection() && player.isSneaking()) { - // If the player is sneaking, we allow the action regardless of enchantments - return ActionResult.PASS; - } else if (isPickaxe && hasNoSilkTouch) { - return ActionResult.FAIL; - } else { - return ActionResult.PASS; - } - } else { - return ActionResult.PASS; - } - }); - - } -} diff --git a/src/main/java/moe/sebiann/qol27/client/NoSilkDetection.kt b/src/main/java/moe/sebiann/qol27/client/NoSilkDetection.kt new file mode 100644 index 0000000..7ace764 --- /dev/null +++ b/src/main/java/moe/sebiann/qol27/client/NoSilkDetection.kt @@ -0,0 +1,83 @@ +package moe.sebiann.qol27.client + +import moe.sebiann.qol27.config.Config +import net.fabricmc.fabric.api.event.player.AttackBlockCallback +import net.minecraft.world.InteractionResult +import net.minecraft.world.item.ItemStack +import net.minecraft.world.level.block.Block +import net.minecraft.world.level.block.Blocks + +object NoSilkDetection { + fun initialize() { + AttackBlockCallback.EVENT.register { player, world, hand, pos, direction -> + val blockState = world.getBlockState(pos) + val block = blockState.block + val heldItem: ItemStack = player.mainHandItem + val enchantments = heldItem.enchantments.toString() + + if (Config.SilkTouch.sneakOverrides && player.isShiftKeyDown) { + InteractionResult.PASS + } + // Check for Ender Chest + else if (block == Blocks.ENDER_CHEST && Config.SilkTouch.enderchest) { + if (enchantments.contains("silk_touch")) { + InteractionResult.PASS + } else { + InteractionResult.FAIL + } + } + // Check for Glass blocks (separate condition) + else if (isGlassBlock(block) && Config.SilkTouch.glass) { + if (enchantments.contains("silk_touch")) { + InteractionResult.PASS + } else { + InteractionResult.FAIL + } + } + else { + // Allow normal behavior for other blocks + InteractionResult.PASS + } + } + } + + private fun isGlassBlock(block: Block): Boolean { + return block == Blocks.GLASS || + block == Blocks.TINTED_GLASS || + // Regular stained glass blocks + block == Blocks.WHITE_STAINED_GLASS || + block == Blocks.ORANGE_STAINED_GLASS || + block == Blocks.MAGENTA_STAINED_GLASS || + block == Blocks.LIGHT_BLUE_STAINED_GLASS || + block == Blocks.YELLOW_STAINED_GLASS || + block == Blocks.LIME_STAINED_GLASS || + block == Blocks.PINK_STAINED_GLASS || + block == Blocks.GRAY_STAINED_GLASS || + block == Blocks.LIGHT_GRAY_STAINED_GLASS || + block == Blocks.CYAN_STAINED_GLASS || + block == Blocks.PURPLE_STAINED_GLASS || + block == Blocks.BLUE_STAINED_GLASS || + block == Blocks.BROWN_STAINED_GLASS || + block == Blocks.GREEN_STAINED_GLASS || + block == Blocks.RED_STAINED_GLASS || + block == Blocks.BLACK_STAINED_GLASS || + // Glass panes + block == Blocks.GLASS_PANE || + block == Blocks.WHITE_STAINED_GLASS_PANE || + block == Blocks.ORANGE_STAINED_GLASS_PANE || + block == Blocks.MAGENTA_STAINED_GLASS_PANE || + block == Blocks.LIGHT_BLUE_STAINED_GLASS_PANE || + block == Blocks.YELLOW_STAINED_GLASS_PANE || + block == Blocks.LIME_STAINED_GLASS_PANE || + block == Blocks.PINK_STAINED_GLASS_PANE || + block == Blocks.GRAY_STAINED_GLASS_PANE || + block == Blocks.LIGHT_GRAY_STAINED_GLASS_PANE || + block == Blocks.CYAN_STAINED_GLASS_PANE || + block == Blocks.PURPLE_STAINED_GLASS_PANE || + block == Blocks.BLUE_STAINED_GLASS_PANE || + block == Blocks.BROWN_STAINED_GLASS_PANE || + block == Blocks.GREEN_STAINED_GLASS_PANE || + block == Blocks.RED_STAINED_GLASS_PANE || + block == Blocks.BLACK_STAINED_GLASS_PANE + } +} diff --git a/src/main/java/moe/sebiann/qol27/client/QoL27Client.java b/src/main/java/moe/sebiann/qol27/client/QoL27Client.java deleted file mode 100644 index c31f8b2..0000000 --- a/src/main/java/moe/sebiann/qol27/client/QoL27Client.java +++ /dev/null @@ -1,19 +0,0 @@ -package moe.sebiann.qol27.client; - -import net.fabricmc.api.ClientModInitializer; -import org.slf4j.LoggerFactory; -import org.slf4j.Logger; - -public class QoL27Client implements ClientModInitializer { - public static final String MOD_ID = "QoL27Client"; - public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); - - @Override - public void onInitializeClient() { - NoSilkDetection.initialize(); - WoodStrippingDetection.initialize(); - CarpetSafety.initialize(); - - LOGGER.info("{} initialized!", MOD_ID); - } -} diff --git a/src/main/java/moe/sebiann/qol27/client/QoL27Client.kt b/src/main/java/moe/sebiann/qol27/client/QoL27Client.kt new file mode 100644 index 0000000..48df2e3 --- /dev/null +++ b/src/main/java/moe/sebiann/qol27/client/QoL27Client.kt @@ -0,0 +1,20 @@ +package moe.sebiann.qol27.client + +import net.fabricmc.api.ClientModInitializer +import org.slf4j.Logger +import org.slf4j.LoggerFactory + +class QoL27Client : ClientModInitializer { + override fun onInitializeClient() { + NoSilkDetection.initialize(); + WoodStrippingDetection.initialize() + CarpetSafety.initialize() + + LOGGER.info("{} initialized!", MOD_ID) + } + + companion object { + const val MOD_ID: String = "QoL27Client" + val LOGGER: Logger = LoggerFactory.getLogger(MOD_ID) + } +} \ No newline at end of file diff --git a/src/main/java/moe/sebiann/qol27/client/WoodStrippingDetection.java b/src/main/java/moe/sebiann/qol27/client/WoodStrippingDetection.java index a5667e2..18624ec 100644 --- a/src/main/java/moe/sebiann/qol27/client/WoodStrippingDetection.java +++ b/src/main/java/moe/sebiann/qol27/client/WoodStrippingDetection.java @@ -1,38 +1,37 @@ package moe.sebiann.qol27.client; -import moe.sebiann.qol27.config.QoL27Config; +import moe.sebiann.qol27.config.Config; import net.fabricmc.fabric.api.event.player.UseBlockCallback; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.item.*; -import net.minecraft.util.ActionResult; -import net.minecraft.util.math.BlockPos; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.item.*; +import net.minecraft.world.InteractionResult; +import net.minecraft.core.BlockPos; public class WoodStrippingDetection { public static void initialize() { - QoL27Config config = QoL27Client.getConfig(); UseBlockCallback.EVENT.register((player, world, hand, hitResult) -> { - if (!config.noStrippingEnabled()) { - return ActionResult.PASS; + if (!Config.WoodStripping.INSTANCE.getEnabled()) { + return InteractionResult.PASS; } - if (!world.isClient) return ActionResult.PASS; + if (!world.isClientSide) return InteractionResult.PASS; - ItemStack heldItem = player.getStackInHand(hand); - if (!(heldItem.getItem() instanceof AxeItem)) return ActionResult.PASS; + ItemStack heldItem = player.getItemInHand(hand); + if (!(heldItem.getItem() instanceof AxeItem)) return InteractionResult.PASS; BlockPos pos = hitResult.getBlockPos(); BlockState state = world.getBlockState(pos); - if (config.sneakOverridesStripping() && player.isSneaking()) { + if (Config.WoodStripping.INSTANCE.getSneakOverrides() && player.isShiftKeyDown()) { // If the player is sneaking, we allow the action regardless of enchantments - return ActionResult.PASS; + return InteractionResult.PASS; } else if (isStrippableWood(state.getBlock())) { - return ActionResult.FAIL; + return InteractionResult.FAIL; } else { - return ActionResult.PASS; + return InteractionResult.PASS; } }); } diff --git a/src/main/java/moe/sebiann/qol27/config/Config.java b/src/main/java/moe/sebiann/qol27/config/Config.java deleted file mode 100644 index 078386d..0000000 --- a/src/main/java/moe/sebiann/qol27/config/Config.java +++ /dev/null @@ -1,34 +0,0 @@ -package moe.sebiann.qol27.config; - -import dev.isxander.yacl3.config.v2.api.ConfigClassHandler; -import dev.isxander.yacl3.config.v2.api.SerialEntry; -import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder; -import net.fabricmc.loader.api.FabricLoader; - -public class Config { - public static ConfigClassHandler HANDLER = ConfigClassHandler.createBuilder(Config.class) - .id(new ResourceLocation("qol27", "config")) - .serializer(config -> GsonConfigSerializerBuilder.create(config) - .setPath(FabricLoader.getInstance().getConfigDir().resolve("my_mod.json5")) - .setJson5(true) - .build()) - .build(); - - @SerialEntry - public boolean noSilkDetectionEnabled = true; - - @SerialEntry - public boolean sneakOverridesDetection = true; - - @SerialEntry - public boolean noStrippingEnabled = true; - - @SerialEntry - public boolean sneakOverridesStripping = true; - - @SerialEntry - public boolean noCarpetsOnCarpetsEnabled = true; - - @SerialEntry - public boolean sneakOverridesCarpetPlacing = true; -} diff --git a/src/main/java/moe/sebiann/qol27/config/Config.kt b/src/main/java/moe/sebiann/qol27/config/Config.kt new file mode 100644 index 0000000..02e0ccd --- /dev/null +++ b/src/main/java/moe/sebiann/qol27/config/Config.kt @@ -0,0 +1,137 @@ +package moe.sebiann.qol27.config + +import moe.sebiann.qol27.utils.Resources +import dev.isxander.yacl3.api.OptionDescription +import dev.isxander.yacl3.config.v2.api.ConfigClassHandler +import dev.isxander.yacl3.config.v2.api.SerialEntry +import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder +import dev.isxander.yacl3.dsl.* +import net.fabricmc.loader.api.FabricLoader +import net.minecraft.client.gui.screens.Screen +import net.minecraft.network.chat.Component + +class Config { + @SerialEntry + var silkTouchDetectionEnderchest: Boolean = true + @SerialEntry + var silkTouchDetectionGlass: Boolean = true + @SerialEntry + var silkTouchSneakOverrides: Boolean = true + + @SerialEntry + var woodStrippingDetection: Boolean = true + @SerialEntry + var woodStrippingSneakOverrides: Boolean = true + + @SerialEntry + var carpetsCantPlaceOnCarpets: Boolean = true + @SerialEntry + var carpetsSneakOverrides: Boolean = true + + object SilkTouch { + val enderchest: Boolean + get() = handler.instance().silkTouchDetectionEnderchest + val glass: Boolean + get() = handler.instance().silkTouchDetectionGlass + val sneakOverrides: Boolean + get() = handler.instance().silkTouchSneakOverrides + } + + object WoodStripping { + val enabled: Boolean + get() = handler.instance().woodStrippingDetection + val sneakOverrides: Boolean + get() = handler.instance().woodStrippingSneakOverrides + } + + object Carpets { + val enabled: Boolean + get() = handler.instance().carpetsCantPlaceOnCarpets + val sneakOverrides: Boolean + get() = handler.instance().carpetsSneakOverrides + } + + companion object { + val handler: ConfigClassHandler by lazy { + ConfigClassHandler.createBuilder(Config::class.java).id(Resources.qol27("config")).serializer { config -> + GsonConfigSerializerBuilder.create(config) + .setPath(FabricLoader.getInstance().configDir.resolve("qol27.json")).build() + }.build() + } + + fun init() { + handler.load() + } + + fun getScreen(parentScreen: Screen?): Screen = YetAnotherConfigLib("qol27") { + title(Component.translatable("config.qol27.name")) + save { + handler.save() + } + + categories.register("qol27") { + name(Component.translatable("config.qol27.name")) + + groups.register("silk_touch") { + name(Component.translatable("config.qol27.silk_touch.name")) + description(OptionDescription.of(Component.translatable("config.qol27.silk_touch.description"))) + + options.register("silk_touch_detection_enderchest") { + name(Component.translatable("config.qol27.silk_touch.enderchest.name")) + description(OptionDescription.of(Component.translatable("config.qol27.silk_touch.enderchest.description"))) + binding(handler.instance()::silkTouchDetectionEnderchest, true) + controller(tickBox()) + } + options.register("silk_touch_detection_glass") { + name(Component.translatable("config.qol27.silk_touch.glass.name")) + description(OptionDescription.of(Component.translatable("config.qol27.silk_touch.glass.description"))) + binding(handler.instance()::silkTouchDetectionGlass, true) + controller(tickBox()) + } + options.register("silk_touch_sneak_overrides") { + name(Component.translatable("config.qol27.silk_touch.sneak_overrides.name")) + description(OptionDescription.of(Component.translatable("config.qol27.silk_touch.sneak_overrides.description"))) + binding(handler.instance()::silkTouchSneakOverrides, true) + controller(tickBox()) + } + } + + groups.register("wood_stripping") { + name(Component.translatable("config.qol27.wood_stripping.name")) + description(OptionDescription.of(Component.translatable("config.qol27.wood_stripping.description"))) + + options.register("wood_stripping_detection_enabled") { + name(Component.translatable("config.qol27.wood_stripping.enabled.name")) + description(OptionDescription.of(Component.translatable("config.qol27.wood_stripping.enabled.description"))) + binding(handler.instance()::woodStrippingDetection, true) + controller(tickBox()) + } + options.register("wood_stripping_sneak_overrides") { + name(Component.translatable("config.qol27.wood_stripping.sneak_overrides.name")) + description(OptionDescription.of(Component.translatable("config.qol27.wood_stripping.sneak_overrides.description"))) + binding(handler.instance()::woodStrippingSneakOverrides, true) + controller(tickBox()) + } + } + + groups.register("carpets") { + name(Component.translatable("config.qol27.carpets.name")) + description(OptionDescription.of(Component.translatable("config.qol27.carpets.description"))) + + options.register("carpets_enabled") { + name(Component.translatable("config.qol27.carpets.enabled.name")) + description(OptionDescription.of(Component.translatable("config.qol27.carpets.enabled.description"))) + binding(handler.instance()::carpetsCantPlaceOnCarpets, true) + controller(tickBox()) + } + options.register("carpets_sneak_overrides") { + name(Component.translatable("config.qol27.carpets.sneak_overrides.name")) + description(OptionDescription.of(Component.translatable("config.qol27.carpets.sneak_overrides.description"))) + binding(handler.instance()::carpetsSneakOverrides, true) + controller(tickBox()) + } + } + } + }.generateScreen(parentScreen) + } +} \ No newline at end of file diff --git a/src/main/java/moe/sebiann/qol27/config/ModMenuIntegration.java b/src/main/java/moe/sebiann/qol27/config/ModMenuIntegration.java deleted file mode 100644 index cb4a378..0000000 --- a/src/main/java/moe/sebiann/qol27/config/ModMenuIntegration.java +++ /dev/null @@ -1,17 +0,0 @@ -package moe.sebiann.qol27.config; - -import com.terraformersmc.modmenu.api.ConfigScreenFactory; -import com.terraformersmc.modmenu.api.ModMenuApi; -import dev.isxander.yacl3.api.YetAnotherConfigLib; -import net.minecraft.text.Text; - -public class ModMenuIntegration implements ModMenuApi { - @Override - public ConfigScreenFactory getModConfigScreenFactory() { - return parentScreen -> YetAnotherConfigLib.createBuilder() - .title("test") - .save(() -> System.out.println("Config saved")) - .build() - .generateScreen(parentScreen); - } -} \ No newline at end of file diff --git a/src/main/java/moe/sebiann/qol27/config/ModMenuIntegration.kt b/src/main/java/moe/sebiann/qol27/config/ModMenuIntegration.kt new file mode 100644 index 0000000..696f7c1 --- /dev/null +++ b/src/main/java/moe/sebiann/qol27/config/ModMenuIntegration.kt @@ -0,0 +1,11 @@ +package moe.sebiann.qol27.config + +import com.terraformersmc.modmenu.api.ConfigScreenFactory +import com.terraformersmc.modmenu.api.ModMenuApi +import net.minecraft.client.gui.screens.Screen + +class ModMenuIntegration : ModMenuApi { + override fun getModConfigScreenFactory(): ConfigScreenFactory { + return ConfigScreenFactory(Config.Companion::getScreen) + } +} \ No newline at end of file diff --git a/src/main/java/moe/sebiann/qol27/utils/Resources.kt b/src/main/java/moe/sebiann/qol27/utils/Resources.kt new file mode 100644 index 0000000..46f4e44 --- /dev/null +++ b/src/main/java/moe/sebiann/qol27/utils/Resources.kt @@ -0,0 +1,8 @@ +package moe.sebiann.qol27.utils + +import net.minecraft.resources.ResourceLocation + +object Resources { + fun qol27(path: String): ResourceLocation = ResourceLocation.fromNamespaceAndPath("qol27", path) + fun minecraft(path: String): ResourceLocation = ResourceLocation.withDefaultNamespace(path) +} \ No newline at end of file diff --git a/src/main/resources/assets/qol27/lang/en_us.json b/src/main/resources/assets/qol27/lang/en_us.json index afc2abf..9d437a6 100644 --- a/src/main/resources/assets/qol27/lang/en_us.json +++ b/src/main/resources/assets/qol27/lang/en_us.json @@ -1,14 +1,23 @@ { - "text.config.qol27-config.title":"QOL27 Config", - "text.config.qol27-config.section.noSilkTouchDetection":"No Silk Touch Detection", - "text.config.qol27-config.option.noSilkDetectionEnabled":"No Silk Touch Detection", - "text.config.qol27-config.option.sneakOverridesDetection":"Sneak Overrides Detection", - "text.config.qol27-config.section.woodStrippingDetection":"Wood Stripping Detection", - "text.config.qol27-config.option.noStrippingEnabled":"No Stripping Detection Enabled", - "text.config.qol27-config.option.sneakOverridesStripping":"Sneak Overrides Stripping", - "text.config.qol27-config.section.saveCoordsOnLogout":"Save Coordinates on Logout", - "text.config.qol27-config.option.saveCoordsOnLogout":"Save Coordinates on Logout", - "text.config.qol27-config.section.noCarpetsOnCarpets":"No Carpets on Carpets", - "text.config.qol27-config.option.noCarpetsOnCarpetsEnabled":"No Carpets on Carpets Enabled", - "text.config.qol27-config.option.sneakOverridesCarpetPlacing":"Sneak Overrides Carpet Placing" + "config.qol27.name":"QoL27 Config", + "config.qol27.silk_touch.name":"Silk Touch Detection", + "config.qol27.silk_touch.description":"Blocks breaking certain blocks without silk touch.", + "config.qol27.silk_touch.enderchest.name":"Block Enderchest", + "config.qol27.silk_touch.enderchest.description":"Blocks breaking enderchests without silk touch.", + "config.qol27.silk_touch.glass.name":"Block Glass", + "config.qol27.silk_touch.glass.description":"Blocks breaking glass without silk touch.", + "config.qol27.silk_touch.sneak_overrides.name":"Sneak Overrides it", + "config.qol27.silk_touch.sneak_overrides.description":"Sneaking overrides the silk touch requirement.", + "config.qol27.wood_stripping.name":"Wood Stripping", + "config.qol27.wood_stripping.description":"Blocks stripping wood", + "config.qol27.wood_stripping.enabled.name":"Enabled", + "config.qol27.wood_stripping.enabled.description":"Blocks stripping wood in general", + "config.qol27.wood_stripping.sneak_overrides.name":"Sneak Overrides it", + "config.qol27.wood_stripping.sneak_overrides.description":"Sneaking allows wood stripping.", + "config.qol27.carpets.name":"Carpets on Carpets", + "config.qol27.carpets.description":"Blocks placing carpets on carpets", + "config.qol27.carpets.enabled.name":"Enabled", + "config.qol27.carpets.enabled.description":"You cannot place carpets on carpets", + "config.qol27.carpets.sneak_overrides.name":"Sneak Overrides it", + "config.qol27.carpets.sneak_overrides.description":"Sneaking allows placing carpets on carpets." } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 53dd7e2..b620345 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -2,8 +2,8 @@ "schemaVersion": 1, "id": "qol27", "version": "${version}", - "name": "QoL 27", - "description": "Multiple Quality of Life improvements for Minecraft 1.21.7", + "name": "QoL27", + "description": "Multiple Quality of Life improvements for Minecraft 1.21.8", "authors": [ "Sebiann" ], @@ -18,16 +18,15 @@ "environment": "client", "entrypoints": { "client": ["moe.sebiann.qol27.client.QoL27Client"], + "main": ["moe.sebiann.qol27.QoL27"], "modmenu": ["moe.sebiann.qol27.config.ModMenuIntegration" ] }, "mixins": [], "depends": { + "yet_another_config_lib_v3": ">=3.7.1+1.21.5-fabric", "fabricloader": ">=${loader_version}", + "fabric-language-kotlin": ">=${kotlin_loader_version}", "fabric": "*", - "minecraft": "${minecraft_version}", - "yet_another_config_lib_v3": ">=${yacl_version}" - }, - "injectors": { - "defaultRequire": 1 + "minecraft": "${minecraft_version}" } } \ No newline at end of file From cda943406aebf82e8adba63dc92a559a18b089fc Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 27 Sep 2025 22:25:55 +0200 Subject: [PATCH 3/5] Finish 0.3.0 Signed-off-by: Sebastian --- gradle.properties | 2 +- .../sebiann/qol27/client/CarpetSafety.java | 61 ------------------- .../moe/sebiann/qol27/client/CarpetSafety.kt | 59 ++++++++++++++++++ .../sebiann/qol27/client/SaveCoordinates.java | 4 -- .../sebiann/qol27/client/SaveCoordinates.kt | 4 ++ .../qol27/client/WoodStrippingDetection.java | 47 -------------- .../qol27/client/WoodStrippingDetection.kt | 49 +++++++++++++++ 7 files changed, 113 insertions(+), 113 deletions(-) delete mode 100644 src/main/java/moe/sebiann/qol27/client/CarpetSafety.java create mode 100644 src/main/java/moe/sebiann/qol27/client/CarpetSafety.kt delete mode 100644 src/main/java/moe/sebiann/qol27/client/SaveCoordinates.java create mode 100644 src/main/java/moe/sebiann/qol27/client/SaveCoordinates.kt delete mode 100644 src/main/java/moe/sebiann/qol27/client/WoodStrippingDetection.java create mode 100644 src/main/java/moe/sebiann/qol27/client/WoodStrippingDetection.kt diff --git a/gradle.properties b/gradle.properties index aa7393f..24b7093 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ yarn_mappings=1.21.8+build.1 loader_version=0.17.2 kotlin_loader_version=1.13.4+kotlin.2.2.0 # Mod Properties -mod_version=0.2.4 +mod_version=0.3.0 maven_group=moe.sebiann archives_base_name=Qol27 # Dependencies diff --git a/src/main/java/moe/sebiann/qol27/client/CarpetSafety.java b/src/main/java/moe/sebiann/qol27/client/CarpetSafety.java deleted file mode 100644 index 85ff5f8..0000000 --- a/src/main/java/moe/sebiann/qol27/client/CarpetSafety.java +++ /dev/null @@ -1,61 +0,0 @@ -package moe.sebiann.qol27.client; - -import moe.sebiann.qol27.config.Config; -import net.fabricmc.fabric.api.event.player.UseBlockCallback; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.CarpetBlock; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.InteractionResult; -import net.minecraft.core.BlockPos; - -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - - -public class CarpetSafety { - public static void initialize() { - UseBlockCallback.EVENT.register((player, world, hand, hitResult) -> { - if (!Config.Carpets.INSTANCE.getEnabled()) { - return InteractionResult.PASS; - } - if (!world.isClientSide) return InteractionResult.PASS; - - ItemStack heldItem = player.getItemInHand(hand); - if (!CARPET_ITEMS.contains(heldItem.getItem())) return InteractionResult.PASS; - - BlockPos pos = hitResult.getBlockPos(); - BlockState state = world.getBlockState(pos); - - if (Config.Carpets.INSTANCE.getSneakOverrides() && player.isShiftKeyDown()) { - return InteractionResult.PASS; - } else if (state.getBlock() instanceof CarpetBlock) { - return InteractionResult.FAIL; - } else { - return InteractionResult.PASS; - } - }); - } - - private static final Set CARPET_ITEMS = Stream.of( - Blocks.WHITE_CARPET, - Blocks.LIGHT_GRAY_CARPET, - Blocks.GRAY_CARPET, - Blocks.BLACK_CARPET, - Blocks.BROWN_CARPET, - Blocks.ORANGE_CARPET, - Blocks.MAGENTA_CARPET, - Blocks.LIGHT_BLUE_CARPET, - Blocks.YELLOW_CARPET, - Blocks.LIME_CARPET, - Blocks.PINK_CARPET, - Blocks.CYAN_CARPET, - Blocks.PURPLE_CARPET, - Blocks.BLUE_CARPET, - Blocks.GREEN_CARPET, - Blocks.RED_CARPET - ).map(Block::asItem).collect(Collectors.toSet()); -} diff --git a/src/main/java/moe/sebiann/qol27/client/CarpetSafety.kt b/src/main/java/moe/sebiann/qol27/client/CarpetSafety.kt new file mode 100644 index 0000000..18051bf --- /dev/null +++ b/src/main/java/moe/sebiann/qol27/client/CarpetSafety.kt @@ -0,0 +1,59 @@ +package moe.sebiann.qol27.client + +import moe.sebiann.qol27.config.Config.Carpets.enabled +import moe.sebiann.qol27.config.Config.Carpets.sneakOverrides +import net.fabricmc.fabric.api.event.player.UseBlockCallback +import net.minecraft.world.InteractionHand +import net.minecraft.world.InteractionResult +import net.minecraft.world.entity.player.Player +import net.minecraft.world.item.Item +import net.minecraft.world.level.Level +import net.minecraft.world.level.block.Block +import net.minecraft.world.level.block.Blocks +import net.minecraft.world.level.block.CarpetBlock +import net.minecraft.world.phys.BlockHitResult +import java.util.stream.Collectors +import java.util.stream.Stream + +object CarpetSafety { + fun initialize() { + UseBlockCallback.EVENT.register(UseBlockCallback { player: Player?, world: Level?, hand: InteractionHand?, hitResult: BlockHitResult? -> + if (!enabled) { + InteractionResult.PASS + } + if (!world!!.isClientSide) InteractionResult.PASS + + val heldItem = player!!.getItemInHand(hand) + if (!CARPET_ITEMS.contains(heldItem.item)) InteractionResult.PASS + + val pos = hitResult!!.blockPos + val state = world.getBlockState(pos) + if (sneakOverrides && player.isShiftKeyDown) { + InteractionResult.PASS + } else if (state.block is CarpetBlock) { + InteractionResult.FAIL + } else { + InteractionResult.PASS + } + }) + } + + private val CARPET_ITEMS: MutableSet = Stream.of( + Blocks.WHITE_CARPET, + Blocks.LIGHT_GRAY_CARPET, + Blocks.GRAY_CARPET, + Blocks.BLACK_CARPET, + Blocks.BROWN_CARPET, + Blocks.ORANGE_CARPET, + Blocks.MAGENTA_CARPET, + Blocks.LIGHT_BLUE_CARPET, + Blocks.YELLOW_CARPET, + Blocks.LIME_CARPET, + Blocks.PINK_CARPET, + Blocks.CYAN_CARPET, + Blocks.PURPLE_CARPET, + Blocks.BLUE_CARPET, + Blocks.GREEN_CARPET, + Blocks.RED_CARPET + ).map { obj: Block? -> obj!!.asItem() }.collect(Collectors.toSet()) +} \ No newline at end of file diff --git a/src/main/java/moe/sebiann/qol27/client/SaveCoordinates.java b/src/main/java/moe/sebiann/qol27/client/SaveCoordinates.java deleted file mode 100644 index 77d0e91..0000000 --- a/src/main/java/moe/sebiann/qol27/client/SaveCoordinates.java +++ /dev/null @@ -1,4 +0,0 @@ -package moe.sebiann.qol27.client; - -public class SaveCoordinates { -} diff --git a/src/main/java/moe/sebiann/qol27/client/SaveCoordinates.kt b/src/main/java/moe/sebiann/qol27/client/SaveCoordinates.kt new file mode 100644 index 0000000..7ca1527 --- /dev/null +++ b/src/main/java/moe/sebiann/qol27/client/SaveCoordinates.kt @@ -0,0 +1,4 @@ +package moe.sebiann.qol27.client + +class SaveCoordinates { +} \ No newline at end of file diff --git a/src/main/java/moe/sebiann/qol27/client/WoodStrippingDetection.java b/src/main/java/moe/sebiann/qol27/client/WoodStrippingDetection.java deleted file mode 100644 index 18624ec..0000000 --- a/src/main/java/moe/sebiann/qol27/client/WoodStrippingDetection.java +++ /dev/null @@ -1,47 +0,0 @@ -package moe.sebiann.qol27.client; - -import moe.sebiann.qol27.config.Config; -import net.fabricmc.fabric.api.event.player.UseBlockCallback; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.item.*; -import net.minecraft.world.InteractionResult; -import net.minecraft.core.BlockPos; - - -public class WoodStrippingDetection { - public static void initialize() { - - UseBlockCallback.EVENT.register((player, world, hand, hitResult) -> { - if (!Config.WoodStripping.INSTANCE.getEnabled()) { - return InteractionResult.PASS; - } - if (!world.isClientSide) return InteractionResult.PASS; - - ItemStack heldItem = player.getItemInHand(hand); - if (!(heldItem.getItem() instanceof AxeItem)) return InteractionResult.PASS; - - BlockPos pos = hitResult.getBlockPos(); - BlockState state = world.getBlockState(pos); - - if (Config.WoodStripping.INSTANCE.getSneakOverrides() && player.isShiftKeyDown()) { - // If the player is sneaking, we allow the action regardless of enchantments - return InteractionResult.PASS; - } else if (isStrippableWood(state.getBlock())) { - return InteractionResult.FAIL; - } else { - return InteractionResult.PASS; - } - }); - } - - private static boolean isStrippableWood(Block block) { - return block == Blocks.OAK_LOG || block == Blocks.SPRUCE_LOG || block == Blocks.BIRCH_LOG || - block == Blocks.JUNGLE_LOG || block == Blocks.ACACIA_LOG || block == Blocks.DARK_OAK_LOG || - block == Blocks.MANGROVE_LOG || block == Blocks.OAK_WOOD || block == Blocks.SPRUCE_WOOD || - block == Blocks.BIRCH_WOOD || block == Blocks.JUNGLE_WOOD || block == Blocks.ACACIA_WOOD || - block == Blocks.DARK_OAK_WOOD || block == Blocks.MANGROVE_WOOD || block == Blocks.CRIMSON_STEM || - block == Blocks.WARPED_STEM || block == Blocks.CHERRY_LOG || block == Blocks.CHERRY_WOOD; - } -} diff --git a/src/main/java/moe/sebiann/qol27/client/WoodStrippingDetection.kt b/src/main/java/moe/sebiann/qol27/client/WoodStrippingDetection.kt new file mode 100644 index 0000000..94346b9 --- /dev/null +++ b/src/main/java/moe/sebiann/qol27/client/WoodStrippingDetection.kt @@ -0,0 +1,49 @@ +package moe.sebiann.qol27.client + +import moe.sebiann.qol27.config.Config.WoodStripping.enabled +import moe.sebiann.qol27.config.Config.WoodStripping.sneakOverrides +import net.fabricmc.fabric.api.event.player.UseBlockCallback +import net.minecraft.world.InteractionHand +import net.minecraft.world.InteractionResult +import net.minecraft.world.entity.player.Player +import net.minecraft.world.item.AxeItem +import net.minecraft.world.level.Level +import net.minecraft.world.level.block.Block +import net.minecraft.world.level.block.Blocks +import net.minecraft.world.phys.BlockHitResult + +object WoodStrippingDetection { + fun initialize() { + UseBlockCallback.EVENT.register(UseBlockCallback { player: Player?, world: Level?, hand: InteractionHand?, hitResult: BlockHitResult? -> + if (!enabled) { + InteractionResult.PASS + } + if (!world!!.isClientSide) InteractionResult.PASS + + val heldItem = player!!.getItemInHand(hand) + if (heldItem.item !is AxeItem) InteractionResult.PASS + + val pos = hitResult!!.blockPos + val state = world.getBlockState(pos) + if (sneakOverrides && player.isShiftKeyDown) { + // If the player is sneaking, we allow the action regardless of enchantments + InteractionResult.PASS + } else if (isStrippableWood(state.block)) { + InteractionResult.FAIL + } else { + InteractionResult.PASS + } + }) + } + +private fun isStrippableWood(block: Block?): Boolean { + val strippableBlocks = setOf( + Blocks.OAK_LOG, Blocks.SPRUCE_LOG, Blocks.BIRCH_LOG, Blocks.JUNGLE_LOG, + Blocks.ACACIA_LOG, Blocks.DARK_OAK_LOG, Blocks.MANGROVE_LOG, Blocks.CHERRY_LOG, + Blocks.OAK_WOOD, Blocks.SPRUCE_WOOD, Blocks.BIRCH_WOOD, Blocks.JUNGLE_WOOD, + Blocks.ACACIA_WOOD, Blocks.DARK_OAK_WOOD, Blocks.MANGROVE_WOOD, Blocks.CHERRY_WOOD, + Blocks.CRIMSON_STEM, Blocks.WARPED_STEM + ) + return block in strippableBlocks + } +} \ No newline at end of file From 1a13bd10dd4e3716931f0ff078e4e246fd827eaf Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 27 Sep 2025 22:35:50 +0200 Subject: [PATCH 4/5] Finally deleted this Signed-off-by: Sebastian --- .github/workflows/Validate-Build.yml | 32 ---------------------------- 1 file changed, 32 deletions(-) delete mode 100644 .github/workflows/Validate-Build.yml diff --git a/.github/workflows/Validate-Build.yml b/.github/workflows/Validate-Build.yml deleted file mode 100644 index 1ad6f66..0000000 --- a/.github/workflows/Validate-Build.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Validate Build - -on: - # Trigger when a pull request is opened or reopened - pull_request: - types: - - opened - - reopened - # Trigger when a code review is submitted - pull_request_review: - types: - - submitted - # Allow manual runs - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - permissions: - contents: read - - steps: - - uses: actions/checkout@v3 - - - name: Set up JDK 21 - uses: actions/setup-java@v3 - with: - java-version: '21' - distribution: 'temurin' - - - name: Build with Gradle - run: gradle build From ace94a66835bd9ccc501d70eecfef67acaf07c61 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 27 Sep 2025 22:38:01 +0200 Subject: [PATCH 5/5] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9550c35..50a95ec 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # QoL 27 Currently the main features are: -- it blocking you from mining an enderchest without silktouch except if you sneak (configurable) +- it blocking you from mining an enderchest and glass without silktouch except if you sneak (configurable) - it blocking you from stripping wood except if you sneak (configurable) +- it blocking you from placing carpets ontop of carpets except if you sneak (configurable) ## Contributing