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 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 diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 4e56769..0000000 --- a/build.gradle +++ /dev/null @@ -1,99 +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 { url "https://maven.terraformersmc.com/releases/" } - maven { url 'https://maven.wispforest.io/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}" - annotationProcessor modImplementation("io.wispforest:owo-lib:${project.owo_version}") - include "io.wispforest:owo-sentinel:${project.owo_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 5763f71..24b7093 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,18 +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 +mod_version=0.3.0 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 -# 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 +yacl_version=3.7.1+1.21.6-fabric +modmenu_version=15.0.0 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 deleted file mode 100644 index 634023a..0000000 --- a/src/main/java/moe/sebiann/qol27/client/CarpetSafety.java +++ /dev/null @@ -1,63 +0,0 @@ -package moe.sebiann.qol27.client; - -import moe.sebiann.qol27.config.QoL27Config; -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 java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - - -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 (!world.isClient) return ActionResult.PASS; - - ItemStack heldItem = player.getStackInHand(hand); - if (!CARPET_ITEMS.contains(heldItem.getItem())) return ActionResult.PASS; - - BlockPos pos = hitResult.getBlockPos(); - BlockState state = world.getBlockState(pos); - - if (config.sneakOverridesCarpetPlacing() && player.isSneaking()) { - return ActionResult.PASS; - } else if (state.getBlock() instanceof CarpetBlock) { - return ActionResult.FAIL; - } else { - return ActionResult.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/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 bc319dd..0000000 --- a/src/main/java/moe/sebiann/qol27/client/QoL27Client.java +++ /dev/null @@ -1,25 +0,0 @@ -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); - - @Override - public void onInitializeClient() { - NoSilkDetection.initialize(); - WoodStrippingDetection.initialize(); - CarpetSafety.initialize(); - - LOGGER.info("{} initialized!", MOD_ID); - } - - public static QoL27Config getConfig() { - return CONFIG; - } -} 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/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 a5667e2..0000000 --- a/src/main/java/moe/sebiann/qol27/client/WoodStrippingDetection.java +++ /dev/null @@ -1,48 +0,0 @@ -package moe.sebiann.qol27.client; - -import moe.sebiann.qol27.config.QoL27Config; -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; - - -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 (!world.isClient) return ActionResult.PASS; - - ItemStack heldItem = player.getStackInHand(hand); - if (!(heldItem.getItem() instanceof AxeItem)) return ActionResult.PASS; - - BlockPos pos = hitResult.getBlockPos(); - BlockState state = world.getBlockState(pos); - - if (config.sneakOverridesStripping() && player.isSneaking()) { - // If the player is sneaking, we allow the action regardless of enchantments - return ActionResult.PASS; - } else if (isStrippableWood(state.getBlock())) { - return ActionResult.FAIL; - } else { - return ActionResult.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 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/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.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 a049291..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" ], @@ -17,16 +17,16 @@ "icon": "assets/qol27/icon.png", "environment": "client", "entrypoints": { - "client": ["moe.sebiann.qol27.client.QoL27Client"] + "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}", - "owo": "*" - }, - "injectors": { - "defaultRequire": 1 + "minecraft": "${minecraft_version}" } } \ No newline at end of file