diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 34c78a66..00000000 --- a/build.gradle +++ /dev/null @@ -1,208 +0,0 @@ -plugins { - id 'fabric-loom' version '1.11-SNAPSHOT' - id 'maven-publish' - id "me.modmuss50.mod-publish-plugin" version "1.1.0" -} - -version = project.mod_version + "+" + stonecutter.current.version -group = project.maven_group - -base { - archivesName = project.archives_base_name -} - -loom { - splitEnvironmentSourceSets() - - mods { - redstonetools { - sourceSet sourceSets.main - sourceSet sourceSets.client - } - } -} - -stonecutter { - swaps["mouse_clicked_params"] = eval(current.version, "<1.21.10") ? "double mouseX, double mouseY, int button" : "Click click, boolean doubleClick" // mouseClicked - swaps["mouse_clicked_args"] = eval(current.version, "<1.21.10") ? "mouseX, mouseY, button" : "click, doubleClick" - swaps["on_mouse_clicked_args"] = eval(current.version, "<1.21.10") ? "(int) mouseX, (int) mouseY, button" : "click, doubleClick" // onMouseClicked - swaps["dragged_released_params"] = eval(current.version, "<1.21.10") ? "double mouseX, double mouseY, int button" : "Click click" // mouseDragged, mouseReleased - swaps["dragged_released_args"] = eval(current.version, "<1.21.10") ? "mouseX, mouseY, button" : "click" - swaps["on_released_args"] = eval(current.version, "<1.21.10") ? "(int) mouseX, (int) mouseY, button" : "click" // onMouseReleased - swaps["keyinput_params"] = eval(current.version, "<1.21.10") ? "int keyCode, int scanCode, int modifiers" : "KeyInput input" // keyPressed, keyReleased - swaps["keyinput_args"] = eval(current.version, "<1.21.10") ? "keyCode, scanCode, modifiers" : "input" - swaps["charinput_params"] = eval(current.version, "<1.21.10") ? "char chr, int modifiers" : "CharInput input" // charTyped - swaps["charinput_args"] = eval(current.version, "<1.21.10") ? "chr, modifiers" : "input" - swaps["click_and_inputs_imports"] = eval(current.version, "<1.21.10") ? "" : - "//\nimport net.minecraft.client.gui.Click;\nimport net.minecraft.client.input.KeyInput;\nimport net.minecraft.client.input.CharInput;" - - swaps["get_x"] = eval(current.version, "<1.21.10") ? "x" : "getX()" - swaps["get_y"] = eval(current.version, "<1.21.10") ? "y" : "getY()" - swaps["get_width"] = eval(current.version, "<1.21.10") ? "entryWidth" : "getWidth()" -} - -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. - - maven { url "https://maven.shedaniel.me/" } - maven { url "https://maven.terraformersmc.com/releases/" } - maven { url 'https://masa.dy.fi/maven' } - exclusiveContent { - forRepository { - maven { - name = "Modrinth" - url = "https://api.modrinth.com/maven" - } - } - filter { - includeGroup "maven.modrinth" - } - } - maven { - name = "WorldEdit Maven" - url = "https://maven.enginehub.org/repo/" - } - maven { - name = "JitPack" - url = "https://jitpack.io" - } -} - -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}") - - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}") - - // Worldedit API - modImplementation("com.sk89q.worldedit:worldedit-fabric-mc${project.worldedit_version}") - // MaLiLib - modApi "maven.modrinth:malilib:${project.malilib_version}" -} - -loom { - decompilerOptions.named("vineflower") { - options.put("mark-corresponding-synthetics", "1") // Adds names to lambdas - useful for mixins - } - - runConfigs.configureEach { - ideConfigGenerated(true) -// vmArgs("-Dmixin.debug.export=true") // Exports transformed classes for debugging - runDir = "../../run" // Shares the run directory between versions - } -} - -processResources { - inputs.property "version", project.version - inputs.property "minecraft_version", project.minecraft_version - inputs.property "minecraft_version_out", project.minecraft_version_out - inputs.property "malilib_version", project.minecraft_version_out - inputs.property "loader_version", project.loader_version - filteringCharset "UTF-8" - - filesMatching("fabric.mod.json") { - expand( - "version": project.version, - "minecraft_version": project.minecraft_version, - "minecraft_version_out": project.minecraft_version_out, - "malilib_version": project.minecraft_version_out, - "loader_version": project.loader_version - ) - } -} - -tasks.register("collectFile") { - group = "build" - mustRunAfter("build") - - doLast { -// println "build/libs/${project.archives_base_name}-${project.mod_version}+${project.minecraft_version}.jar" - copy { - from file("build/libs/${project.archives_base_name}-${project.mod_version}+${project.minecraft_version}.jar") - into rootProject.file("build/libs") - } - } -} - -tasks.register("buildAndCollect") { - group = "build" - dependsOn(tasks.named("build"), tasks.named("collectFile")) -} - -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" - it.options.release.set(21) -} - -java { - toolchain.languageVersion = JavaLanguageVersion.of(21) - // 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. - } -} - -publishMods { - file = remapJar.archiveFile - type = STABLE - modLoaders.add("fabric") - - changelog = "" - displayName = "${project.mod_version}" - - if (providers.environmentVariable("RELEASE_MODRINTH").getOrElse("false").toBoolean()) { - modrinth { - accessToken = providers.environmentVariable("MODRINTH_TOKEN") - projectId = "9ySQVrz2" - minecraftVersions.add(project.minecraft_version) - - requires("fabric-api") - requires("malilib") - optional("worldedit") - } - } - - - if (providers.environmentVariable("RELEASE_GITHUB").getOrElse("false").toBoolean()) { - github { - accessToken = providers.environmentVariable("GITHUB_TOKEN") - - parent rootProject.tasks.named("publishGithub") - } - } -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..7bb44be8 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,169 @@ +plugins { + id("fabric-loom") version "1.15-SNAPSHOT" + id("maven-publish") + id("me.modmuss50.mod-publish-plugin") version "1.1.0" +} + +version = "${project.property("mod_version")}+${stonecutter.current.version}" +group = project.property("maven_group")!! + +base { + archivesName.set(project.property("archives_base_name") as String) +} + +loom { + splitEnvironmentSourceSets() + + mods { + create("redstonetools", Action { + sourceSet(sourceSets.main.get()) + sourceSet("client") + }) + } +} + +stonecutter { + swaps["mouse_clicked_params"] = if (current.parsed < "1.21.10") "double mouseX, double mouseY, int button" else "Click click, boolean doubleClick" // mouseClicked + swaps["mouse_clicked_args"] = if (current.parsed < "1.21.10") "mouseX, mouseY, button" else "click, doubleClick" + swaps["on_mouse_clicked_args"] = if (current.parsed < "1.21.10") "(int) mouseX, (int) mouseY, button" else "click, doubleClick" // onMouseClicked + swaps["dragged_released_params"] = if (current.parsed < "1.21.10") "double mouseX, double mouseY, int button" else "Click click" // mouseDragged, mouseReleased + swaps["dragged_released_args"] = if (current.parsed < "1.21.10") "mouseX, mouseY, button" else "click" + swaps["on_released_args"] = if (current.parsed < "1.21.10") "(int) mouseX, (int) mouseY, button" else "click" // onMouseReleased + swaps["keyinput_params"] = if (current.parsed < "1.21.10") "int keyCode, int scanCode, int modifiers" else "KeyInput input" // keyPressed, keyReleased + swaps["keyinput_args"] = if (current.parsed < "1.21.10") "keyCode, scanCode, modifiers" else "input" + swaps["charinput_params"] = if (current.parsed < "1.21.10") "char chr, int modifiers" else "CharInput input" // charTyped + swaps["charinput_args"] = if (current.parsed < "1.21.10") "chr, modifiers" else "input" + swaps["click_and_inputs_imports"] = if (current.parsed < "1.21.10") "" else + "//\nimport net.minecraft.client.gui.Click;\nimport net.minecraft.client.input.KeyInput;\nimport net.minecraft.client.input.CharInput;" + +} + +repositories { + exclusiveContent { + forRepository { + maven { + name = "Modrinth" + url = uri("https://api.modrinth.com/maven") + } + } + filter { + includeGroup("maven.modrinth") + } + } + maven { + name = "WorldEdit Maven" + url = uri("https://maven.enginehub.org/repo/") + } +} + +dependencies { + minecraft("com.mojang:minecraft:${project.property("minecraft_version")}") + mappings("net.fabricmc:yarn:${project.property("yarn_mappings")}:v2") + modImplementation("net.fabricmc:fabric-loader:${project.property("loader_version")}") + modImplementation("net.fabricmc.fabric-api:fabric-api:${project.property("fabric_version")}") + modImplementation("com.sk89q.worldedit:worldedit-fabric-mc${project.property("worldedit_version")}") + modApi("maven.modrinth:malilib:${project.property("malilib_version")}") +} + +loom { + decompilerOptions.named("vineflower") { + options.put("mark-corresponding-synthetics", "1") + } + + runConfigs.configureEach { + ideConfigGenerated(true) + runDir = "../../run" + } +} + +tasks.processResources { + val properties = mapOf( + "version" to project.version, + "minecraft_version" to project.property("minecraft_version"), + "minecraft_version_out" to project.property("minecraft_version_out"), + "malilib_version" to project.property("minecraft_version_out"), + "loader_version" to project.property("loader_version") + ) + properties.forEach { inputs.property(it.key, it.value) } + filteringCharset = "UTF-8" + + filesMatching("fabric.mod.json") { + expand(properties) + } +} + +tasks.register("collectFile") { + group = "build" + mustRunAfter("build") + + doLast { + copy { + from( + file( + "build/libs/${project.property("archives_base_name")}-${project.property("mod_version")}+${project.property("minecraft_version")}.jar" + ) + ) + into(rootProject.file("build/libs")) + } + } +} + +tasks.register("buildAndCollect") { + group = "build" + dependsOn(tasks.named("build"), tasks.named("collectFile")) +} + +tasks.withType().configureEach { + options.encoding = "UTF-8" + options.release = 21 +} + +java { + toolchain.languageVersion = JavaLanguageVersion.of(21) + withSourcesJar() +} + +tasks.jar { + from("LICENSE") { + rename { "${it}_${project.property("archives_base_name")}" } + } +} + +publishing { + publications { + create("mavenJava") { + artifactId = project.property("archives_base_name") as String + from(components["java"]) + } + } + repositories { + } +} + +publishMods { + file.set(tasks.remapJar.get().archiveFile) + type.set(STABLE) + modLoaders.add("fabric") + + changelog.set("") + displayName.set(project.property("mod_version") as String) + + if (providers.environmentVariable("RELEASE_MODRINTH").orNull?.toBoolean() ?: false) { + modrinth { + accessToken.set(providers.environmentVariable("MODRINTH_TOKEN")) + projectId.set("9ySQVrz2") + minecraftVersions.add(project.property("minecraft_version") as String) + + requires("fabric-api") + requires("malilib") + optional("worldedit") + } + } + + if (providers.environmentVariable("RELEASE_GITHUB").orNull?.toBoolean() ?: false) { + github { + accessToken.set(providers.environmentVariable("GITHUB_TOKEN")) + parent(rootProject.tasks.named("publishGithub")) + } + } +} diff --git a/gradle.properties b/gradle.properties index ffd81e64..4b9d37cd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,5 +5,5 @@ org.gradle.parallel=true maven_group = tools.redstone archives_base_name = redstonetools -loader_version=0.17.3 -mod_version = v3.1.5 +loader_version=0.18.4 +mod_version = 3.2.0 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d706aba6..23449a2b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 910cb56d..00000000 --- a/settings.gradle +++ /dev/null @@ -1,33 +0,0 @@ -pluginManagement { - repositories { - mavenCentral() - gradlePluginPortal() - - maven {url = "https://maven.fabricmc.net/"} - maven { - name = "KikuGie Snapshots" - url = "https://maven.kikugie.dev/snapshots" - } - } -} - -plugins { - id "dev.kikugie.stonecutter" version "0.7.10" -} - -rootProject.name = "redstonetools-mod" - -include "1.21.4" -include "1.21.5" -include "1.21.8" -include "1.21.10" - -stonecutter { - kotlinController = false - centralScript = "build.gradle" - - create(rootProject) { - versions "1.21.4", "1.21.5", "1.21.8", "1.21.10" - vcsVersion = "1.21.10" - } -} diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 00000000..b144a456 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,35 @@ +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + + maven { + url = uri("https://maven.fabricmc.net/") + } + maven { + name = "KikuGie Snapshots" + url = uri("https://maven.kikugie.dev/snapshots") + } + } +} + +plugins { + id("dev.kikugie.stonecutter") version "0.8.3" +} + +rootProject.name = "redstonetools-mod" + +include("1.21.4") +include("1.21.5") +include("1.21.8") +include("1.21.10") +include("1.21.11") + +stonecutter { + centralScript = "build.gradle.kts" + + create(rootProject) { + versions("1.21.4", "1.21.5", "1.21.8", "1.21.10", "1.21.11") + vcsVersion = "1.21.11" + } +} diff --git a/src/client/java/tools/redstone/redstonetools/ClientCommands.java b/src/client/java/tools/redstone/redstonetools/ClientCommands.java index 01b4eba6..4409ba68 100644 --- a/src/client/java/tools/redstone/redstonetools/ClientCommands.java +++ b/src/client/java/tools/redstone/redstonetools/ClientCommands.java @@ -3,12 +3,26 @@ import com.mojang.brigadier.CommandDispatcher; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.command.CommandRegistryAccess; +//? if >=1.21.11 { +import net.minecraft.command.DefaultPermissions; +import net.minecraft.command.permission.PermissionCheck; +import net.minecraft.server.command.CommandManager; +//?} import tools.redstone.redstonetools.features.commands.*; import tools.redstone.redstonetools.features.toggleable.AirPlaceFeature; import tools.redstone.redstonetools.features.toggleable.BigDustFeature; import tools.redstone.redstonetools.utils.DependencyLookup; +import java.util.function.Predicate; + public class ClientCommands { + public static final Predicate PERMISSION_LEVEL_2 = + //? if <=1.21.10 { + /*source -> source.getPlayer().hasPermissionLevel(2); + *///?} else { + CommandManager.requirePermissionLevel(new PermissionCheck.Require(DefaultPermissions.GAMEMASTERS)); + //?} + public static void registerCommands(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { if (!DependencyLookup.REDSTONE_TOOLS_SERVER_PRESENT) { BaseConvertClient.INSTANCE.registerCommand(dispatcher, registryAccess); diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/GiveMeClient.java b/src/client/java/tools/redstone/redstonetools/features/commands/GiveMeClient.java index 0b5ced2a..1931aea9 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/GiveMeClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/GiveMeClient.java @@ -7,6 +7,7 @@ import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.ItemStackArgument; import net.minecraft.command.argument.ItemStackArgumentType; +import tools.redstone.redstonetools.ClientCommands; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; @@ -20,7 +21,7 @@ protected GiveMeClient() { public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { dispatcher.register( literal("g") - .requires(source -> source.getPlayer().hasPermissionLevel(2)) + .requires(ClientCommands.PERMISSION_LEVEL_2) .then(argument("item", ItemStackArgumentType.itemStack(registryAccess)) .executes(context -> this.execute( context, diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/QuickTpClient.java b/src/client/java/tools/redstone/redstonetools/features/commands/QuickTpClient.java index 8fb7ea31..01e3b7b0 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/QuickTpClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/QuickTpClient.java @@ -5,6 +5,7 @@ import com.mojang.brigadier.context.CommandContext; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.command.CommandRegistryAccess; +import tools.redstone.redstonetools.ClientCommands; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; @@ -18,7 +19,7 @@ protected QuickTpClient() { public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { dispatcher.register( literal("quicktp") - .requires(source -> source.getPlayer().hasPermissionLevel(2)) + .requires(ClientCommands.PERMISSION_LEVEL_2) .executes(context -> this.execute( context, 50.0f)) diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/ReachClient.java b/src/client/java/tools/redstone/redstonetools/features/commands/ReachClient.java index 7f273701..eabafcb0 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/ReachClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/ReachClient.java @@ -8,6 +8,7 @@ import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.entity.attribute.EntityAttributes; +import tools.redstone.redstonetools.ClientCommands; public class ReachClient { @@ -18,7 +19,7 @@ protected ReachClient() { public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { dispatcher.register(ClientCommandManager.literal("reach") - .requires(source -> source.getPlayer().hasPermissionLevel(2)) + .requires(ClientCommands.PERMISSION_LEVEL_2) .then(ClientCommandManager.argument("reach", FloatArgumentType.floatArg(0.0f)) .executes(context -> execute(context, true, true)) ) diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java index 67002720..d662e258 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java @@ -3,16 +3,21 @@ import com.mojang.brigadier.CommandDispatcher; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; //? if <1.21.10 { -/*import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; +/*import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; *///?} else { import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderContext; import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderEvents; import net.minecraft.client.render.state.OutlineRenderState; //?} +//? if <=1.21.10 { +/*import net.minecraft.client.render.RenderLayer; +*///?} else { +import net.minecraft.client.render.RenderLayers; +//?} import net.minecraft.block.BlockState; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.Camera; -import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.VertexConsumer; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.entity.EquipmentSlot; @@ -20,17 +25,20 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; +import net.minecraft.util.BlockRotation; import net.minecraft.util.Colors; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import tools.redstone.redstonetools.ClientCommands; import tools.redstone.redstonetools.malilib.config.Configs; import tools.redstone.redstonetools.mixin.features.WorldRendererInvoker; -import tools.redstone.redstonetools.utils.BlockUtils; import tools.redstone.redstonetools.utils.ItemUtils; import tools.redstone.redstonetools.utils.RaycastUtils; +import java.util.function.BiConsumer; + import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; public class AirPlaceFeature extends ClientToggleableFeature { @@ -41,8 +49,8 @@ protected AirPlaceFeature() { } public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { - dispatcher.register(literal("airplace") - .requires(source -> source.getPlayer().hasPermissionLevel(2)) + dispatcher.register(literal("airplace") + .requires(ClientCommands.PERMISSION_LEVEL_2) .executes(this::toggle)); } @@ -75,117 +83,90 @@ public static BlockHitResult findAirPlaceBlockHit(PlayerEntity playerEntity) { } { - //? if <1.21.10 { - /*// register ghost block renderer - WorldRenderEvents.BEFORE_BLOCK_OUTLINE.register((context, blockOutlineContext) -> { + + BiConsumer listener = (context, crosshairTarget) -> { if (!isEnabled()) - return true; + return; if (!Configs.General.AIRPLACE_SHOW_OUTLINE.getBooleanValue()) - return true; + return; MinecraftClient client = MinecraftClient.getInstance(); if (client.player == null || client.interactionManager == null) - return true; - if (blockOutlineContext == null) - return true; - if (blockOutlineContext.getType() != HitResult.Type.MISS) - return true; + return; + if (crosshairTarget == null) + return; + if (crosshairTarget.getType() != HitResult.Type.MISS) + return; if (!canAirPlace(client.player)) - return true; + return; BlockHitResult hitResult = findAirPlaceBlockHit(client.player); BlockPos blockPos = hitResult.getBlockPos(); + if (!client.world.getBlockState(blockPos).isAir()) + return; + if (blockPos.getY() > 319 || blockPos.getY() < -64) - return true; + return; - BlockState blockState = ItemUtils.getUseState(client.player, - client.player.getMainHandStack(), - reach); + BlockState blockState = ItemUtils.getUseState(client.player, client.player.getMainHandStack(), reach); if (AutoRotateClient.isEnabled.getBooleanValue()) { - blockState = BlockUtils.rotate(blockState); + blockState = blockState.rotate(BlockRotation.CLOCKWISE_180); } if (blockState == null) - return true; + return; - /^ render block outline ^/ + /* render block outline */ Camera camera = client.gameRenderer.getCamera(); - Vec3d camPos = camera.getPos(); - - VertexConsumer consumer = context.consumers().getBuffer(RenderLayer.getLines()); + Vec3d camPos = camera + //? if <=1.21.10 { + /*.getPos(); + *///?} else { + .getCameraPos(); + //?} + + VertexConsumer consumer = context.consumers().getBuffer( + //? if <=1.21.10 { + /*RenderLayer.getLines() + *///?} else { + RenderLayers.lines() + //?} + ); - ((WorldRendererInvoker) (context.worldRenderer())).invokeDrawBlockOutline( - context.matrixStack(), - consumer, - client.player, - camPos.x, camPos.y, camPos.z, + //? if <1.21.10 { + /*((WorldRendererInvoker) context.worldRenderer()).invokeDrawBlockOutline( + context.matrixStack(), + consumer, + client.player, + camPos.x, camPos.y, camPos.z, + blockPos, + blockState, + Colors.BLACK + ); + *///?} else { + ((WorldRendererInvoker) context.worldRenderer()).invokeDrawBlockOutline( + context.matrices(), + consumer, + camPos.x, camPos.y, camPos.z, + new OutlineRenderState( blockPos, - blockState, - Colors.BLACK + false, + false, + blockState.getOutlineShape(client.world, blockPos) + ), + Colors.BLACK/*? if >=1.21.11 {*/, client.getWindow().getMinimumLineWidth()/*?}*/ ); + //?} + }; + //? if <1.21.10 { + /*WorldRenderEvents.BEFORE_BLOCK_OUTLINE.register((context, hitResult) -> { + listener.accept(context, hitResult); return true; }); *///?} else { - WorldRenderEvents.END_MAIN.register(new WorldRenderEvents.EndMain() { - @Override - public void endMain(WorldRenderContext context) { - if (!AirPlaceFeature.this.isEnabled()) - return; - if (!Configs.General.AIRPLACE_SHOW_OUTLINE.getBooleanValue()) - return; - - MinecraftClient client = MinecraftClient.getInstance(); - if (client.player == null || client.interactionManager == null) - return; - if (MinecraftClient.getInstance().crosshairTarget == null) - return; - if (MinecraftClient.getInstance().crosshairTarget.getType() != HitResult.Type.MISS) - return; - - if (!canAirPlace(client.player)) - return; - - BlockHitResult hitResult = findAirPlaceBlockHit(client.player); - BlockPos blockPos = hitResult.getBlockPos(); - if (MinecraftClient.getInstance().world == null) - return; - if (!MinecraftClient.getInstance().world.getBlockState(blockPos).isAir()) - return; - - if (blockPos.getY() > 319 || blockPos.getY() < -64) - return; - - BlockState blockState = ItemUtils.getUseState(client.player, - client.player.getMainHandStack(), - reach); - if (AutoRotateClient.isEnabled.getBooleanValue()) { - blockState = BlockUtils.rotate(blockState); - } - if (blockState == null) - return; - - Camera camera = client.gameRenderer.getCamera(); - Vec3d camPos = camera.getPos(); - - VertexConsumer consumer = context.consumers().getBuffer(RenderLayer.getLines()); - - ((WorldRendererInvoker) (context.worldRenderer())).invokeDrawBlockOutline( - context.matrices(), - consumer, - camPos.x, camPos.y, camPos.z, - new OutlineRenderState( - blockPos, - false, - false, - blockState.getOutlineShape(MinecraftClient.getInstance().world, blockPos) - ), - Colors.BLACK - ); - } - }); + WorldRenderEvents.END_MAIN.register(context -> listener.accept(context, MinecraftClient.getInstance().crosshairTarget)); //?} } - } diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoDustClient.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoDustClient.java index 9234ce9a..325617a4 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoDustClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoDustClient.java @@ -3,6 +3,7 @@ import fi.dy.masa.malilib.config.options.ConfigBoolean; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.minecraft.client.MinecraftClient; import tools.redstone.redstonetools.malilib.config.Configs; import tools.redstone.redstonetools.packets.SetFeatureEnabledPayload; @@ -16,8 +17,10 @@ public static void registerHandler() { }); isEnabled.setValueChangeCallback((t) -> { - SetFeatureEnabledPayload payload = new SetFeatureEnabledPayload("AutoDust", t.getBooleanValue()); - ClientPlayNetworking.send(payload); + if (MinecraftClient.getInstance().getNetworkHandler() != null) { + SetFeatureEnabledPayload payload = new SetFeatureEnabledPayload("AutoDust", t.getBooleanValue()); + ClientPlayNetworking.send(payload); + } }); } } diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoRotateClient.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoRotateClient.java index 45ed73ba..2c16e036 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoRotateClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoRotateClient.java @@ -3,6 +3,7 @@ import fi.dy.masa.malilib.config.options.ConfigBoolean; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.minecraft.client.MinecraftClient; import tools.redstone.redstonetools.malilib.config.Configs; import tools.redstone.redstonetools.packets.SetFeatureEnabledPayload; @@ -16,9 +17,10 @@ public static void registerHandler() { }); isEnabled.setValueChangeCallback((t) -> { - System.out.println(t.getBooleanValue()); - SetFeatureEnabledPayload payload = new SetFeatureEnabledPayload("AutoRotate", t.getBooleanValue()); - ClientPlayNetworking.send(payload); + if (MinecraftClient.getInstance().getNetworkHandler() != null) { + SetFeatureEnabledPayload payload = new SetFeatureEnabledPayload("AutoRotate", t.getBooleanValue()); + ClientPlayNetworking.send(payload); + } }); } } diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/ClickContainerClient.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/ClickContainerClient.java index 6b968785..4dd3a67c 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/ClickContainerClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/ClickContainerClient.java @@ -3,6 +3,7 @@ import fi.dy.masa.malilib.config.options.ConfigBoolean; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.minecraft.client.MinecraftClient; import tools.redstone.redstonetools.malilib.config.Configs; import tools.redstone.redstonetools.packets.SetFeatureEnabledPayload; @@ -16,9 +17,10 @@ public static void registerHandler() { }); isEnabled.setValueChangeCallback((t) -> { - System.out.println(t.getBooleanValue()); - SetFeatureEnabledPayload payload = new SetFeatureEnabledPayload("ClickContainers", t.getBooleanValue()); - ClientPlayNetworking.send(payload); + if (MinecraftClient.getInstance().getNetworkHandler() != null) { + SetFeatureEnabledPayload payload = new SetFeatureEnabledPayload("ClickContainers", t.getBooleanValue()); + ClientPlayNetworking.send(payload); + } }); } } diff --git a/src/client/java/tools/redstone/redstonetools/macros/actions/CommandAction.java b/src/client/java/tools/redstone/redstonetools/macros/actions/CommandAction.java index 27f6c9f6..92a0f628 100644 --- a/src/client/java/tools/redstone/redstonetools/macros/actions/CommandAction.java +++ b/src/client/java/tools/redstone/redstonetools/macros/actions/CommandAction.java @@ -1,8 +1,10 @@ package tools.redstone.redstonetools.macros.actions; +import com.mojang.serialization.Codec; import net.minecraft.client.MinecraftClient; public class CommandAction extends Action { + public static final Codec CODEC = Codec.STRING.xmap(CommandAction::new, action -> action.command); public String command; public CommandAction(String command) { diff --git a/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java b/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java index 9447c802..6042a882 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java @@ -2,12 +2,15 @@ import fi.dy.masa.malilib.config.IConfigBoolean; import fi.dy.masa.malilib.config.options.ConfigBoolean; +import fi.dy.masa.malilib.event.InputEventHandler; import fi.dy.masa.malilib.gui.GuiBase; import fi.dy.masa.malilib.gui.GuiKeybindSettings; import fi.dy.masa.malilib.gui.button.ConfigButtonBoolean; import fi.dy.masa.malilib.gui.button.ConfigButtonKeybind; import fi.dy.masa.malilib.gui.widgets.WidgetKeybindSettings; -import net.minecraft.client.MinecraftClient; +//? if >=1.21.11 { +import fi.dy.masa.malilib.render.GuiContext; +//?} import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; @@ -27,21 +30,20 @@ public class GuiMacroEditor extends Screen { public final MacroBase macro; - private final GuiMacroManager parent; - private CommandListWidget commandList; + private final GuiMacroManager macroManager; + public CommandListWidget commandList; private ConfigButtonKeybind buttonKeybind; private ConfigButtonBoolean buttonEnabled; private ConfigButtonBoolean buttonMuted; private WidgetKeybindSettings widgetAdvancedKeybindSettings; - private IConfigBoolean configBoolean; - private IConfigBoolean configBoolean2; + private IConfigBoolean enabledConfigBoolean; + private IConfigBoolean mutedConfigBoolean; public TextFieldWidget nameWidget; private float errorCountDown; - public GuiMacroEditor(Text title, MacroBase macro, GuiMacroManager parent) { + public GuiMacroEditor(Text title, MacroBase macro, GuiMacroManager macroManager) { super(title); - this.parent = parent; - this.client = MinecraftClient.getInstance(); + this.macroManager = macroManager; this.macro = macro; } @@ -56,11 +58,16 @@ public void render(DrawContext context, int mouseX, int mouseY, float deltaTicks buttonEnabled.render(mouseX, mouseY, buttonEnabled.isMouseOver(mouseX, mouseY), context); buttonMuted.render(mouseX, mouseY, buttonMuted.isMouseOver(mouseX, mouseY), context); widgetAdvancedKeybindSettings.render(mouseX, mouseY, widgetAdvancedKeybindSettings.isMouseOver(mouseX, mouseY), context); - *///?} else { - buttonKeybind.render(context, mouseX, mouseY, buttonKeybind.isMouseOver(mouseX, mouseY)); + *///?} else if <=1.21.10 { + /*buttonKeybind.render(context, mouseX, mouseY, buttonKeybind.isMouseOver(mouseX, mouseY)); buttonEnabled.render(context, mouseX, mouseY, buttonEnabled.isMouseOver(mouseX, mouseY)); buttonMuted.render(context, mouseX, mouseY, buttonMuted.isMouseOver(mouseX, mouseY)); widgetAdvancedKeybindSettings.render(context, mouseX, mouseY, widgetAdvancedKeybindSettings.isMouseOver(mouseX, mouseY)); + *///?} else { + buttonKeybind.render(GuiContext.fromGuiGraphics(context), mouseX, mouseY, buttonKeybind.isMouseOver(mouseX, mouseY)); + buttonEnabled.render(GuiContext.fromGuiGraphics(context), mouseX, mouseY, buttonEnabled.isMouseOver(mouseX, mouseY)); + buttonMuted.render(GuiContext.fromGuiGraphics(context), mouseX, mouseY, buttonMuted.isMouseOver(mouseX, mouseY)); + widgetAdvancedKeybindSettings.render(GuiContext.fromGuiGraphics(context), mouseX, mouseY, widgetAdvancedKeybindSettings.isMouseOver(mouseX, mouseY)); //?} if (errorCountDown > 0.0f) { context.drawText(this.textRenderer, "Name already exists!", mouseX, mouseY - 10, 0xFFFFFFFF, true); @@ -78,19 +85,19 @@ protected void init() { minMaxLayouts.add(new GuiUtils.MinMaxLayout(-1, -1, -1, -1)); // name widget minMaxLayouts.add(new GuiUtils.MinMaxLayout(-1, -1, -1, -1)); // mute List layouts = GuiUtils.betterGetWidgetLayout(minMaxLayouts, 10, this.width, true, 50, this.height - 52, 20); - GuiUtils.Layout ncLayout = layouts.get(0); - GuiUtils.Layout bkLayout = layouts.get(1); - GuiUtils.Layout akoLayout = layouts.get(2); - GuiUtils.Layout beLayout = layouts.get(3); - GuiUtils.Layout nwLayout = layouts.get(4); - GuiUtils.Layout bmLayout = layouts.get(5); + GuiUtils.Layout addCommandLayout = layouts.get(0); + GuiUtils.Layout buttonKeybindLayout = layouts.get(1); + GuiUtils.Layout keybindSettingsLayout = layouts.get(2); + GuiUtils.Layout buttonEnabledLayout = layouts.get(3); + GuiUtils.Layout nameWidgetLayout = layouts.get(4); + GuiUtils.Layout buttonMutedLayout = layouts.get(5); this.commandList = this.addDrawableChild( new CommandListWidget(this, this.client, this.width, this.height - 75, 0, 36, this.macro)); this.addDrawableChild(ButtonWidget.builder(Text.of("Add command"), button -> this.commandList.addEntry()) - .dimensions(ncLayout.x(), ncLayout.y(), ncLayout.width(), ncLayout.height()) + .dimensions(addCommandLayout.x(), addCommandLayout.y(), addCommandLayout.width(), addCommandLayout.height()) .build()); - this.widgetAdvancedKeybindSettings = new WidgetKeybindSettings(akoLayout.x(), akoLayout.y(), akoLayout.width(), akoLayout.height(), macro.hotkey.getKeybind(), "", null, null) { + this.widgetAdvancedKeybindSettings = new WidgetKeybindSettings(keybindSettingsLayout.x(), keybindSettingsLayout.y(), keybindSettingsLayout.width(), keybindSettingsLayout.height(), macro.hotkey.getKeybind(), "", null, null) { @Override protected boolean onMouseClickedImpl(/*? if >=1.21.10 {*/Click click, boolean doubleClick/*?} else {*//*int mouseX, int mouseY, int button*//*?}*/) { //? if >=1.21.10 { @@ -102,7 +109,7 @@ protected boolean onMouseClickedImpl(/*? if >=1.21.10 {*/Click click, boolean do } else return super.onMouseClickedImpl(/*? if >=1.21.10 {*/click, doubleClick/*?} else {*//*mouseX, mouseY, button*//*?}*/); } }; - this.buttonKeybind = new ConfigButtonKeybind(bkLayout.x(), bkLayout.y(), bkLayout.width(), bkLayout.height(), macro.hotkey.getKeybind(), null) { + this.buttonKeybind = new ConfigButtonKeybind(buttonKeybindLayout.x(), buttonKeybindLayout.y(), buttonKeybindLayout.width(), buttonKeybindLayout.height(), macro.hotkey.getKeybind(), null) { @Override public boolean onMouseClicked(/*? if >=1.21.10 {*/Click click, boolean doubleClick/*?} else {*//*int mouseX, int mouseY, int button*//*?}*/) { if (!this.isMouseOver(/*? if >=1.21.10 {*/(int) click.x(), (int) click.y()/*?} else {*//*mouseX, mouseY*//*?}*/)) { @@ -118,29 +125,27 @@ public void onClearSelection() { super.onClearSelection(); } }; - this.configBoolean = new ConfigBoolean("", true, ""); - this.configBoolean.setBooleanValue(this.macro.isEnabled()); - this.configBoolean2 = new ConfigBoolean("", true, ""); - this.configBoolean2.setBooleanValue(this.macro.muted); - final String beName = "Enabled: "; - final String bmName = "Muted: "; - this.buttonEnabled = new ConfigButtonBoolean(beLayout.x(), beLayout.y(), beLayout.width(), beLayout.height(), this.configBoolean) { + this.enabledConfigBoolean = new ConfigBoolean("", true, ""); + this.enabledConfigBoolean.setBooleanValue(this.macro.isEnabled()); + this.mutedConfigBoolean = new ConfigBoolean("", true, ""); + this.mutedConfigBoolean.setBooleanValue(this.macro.muted); + this.buttonEnabled = new ConfigButtonBoolean(buttonEnabledLayout.x(), buttonEnabledLayout.y(), buttonEnabledLayout.width(), buttonEnabledLayout.height(), this.enabledConfigBoolean) { @Override public void updateDisplayString() { super.updateDisplayString(); - this.displayString = beName + this.displayString; + this.displayString = "Enabled: " + this.displayString; } }; - this.buttonMuted = new ConfigButtonBoolean(bmLayout.x(), bmLayout.y(), bmLayout.width(), bmLayout.height(), this.configBoolean2) { + this.buttonMuted = new ConfigButtonBoolean(buttonMutedLayout.x(), buttonMutedLayout.y(), buttonMutedLayout.width(), buttonMutedLayout.height(), this.mutedConfigBoolean) { @Override public void updateDisplayString() { super.updateDisplayString(); - this.displayString = bmName + this.displayString; + this.displayString = "Muted: " + this.displayString; } }; - this.nameWidget = addDrawableChild(new TextFieldWidget(this.textRenderer, nwLayout.width(), nwLayout.height(), Text.of(""))); + this.nameWidget = addDrawableChild(new TextFieldWidget(this.textRenderer, nameWidgetLayout.width(), nameWidgetLayout.height(), Text.of(""))); this.nameWidget.setText(macro.getName()); - this.nameWidget.setPosition(nwLayout.x(), nwLayout.y()); + this.nameWidget.setPosition(nameWidgetLayout.x(), nameWidgetLayout.y()); } @Override @@ -148,6 +153,7 @@ public boolean keyPressed(/*$ keyinput_params {*/KeyInput input/*$}*/) { //? if >=1.21.10 { int keyCode = input.key(); //?} + if (this.commandList.keyPressed(/*$ keyinput_args {*/input/*$}*/)) return true; buttonEnabled.onKeyTyped(/*$ keyinput_args {*/input/*$}*/); buttonMuted.onKeyTyped(/*$ keyinput_args {*/input/*$}*/); widgetAdvancedKeybindSettings.onKeyTyped(/*$ keyinput_args {*/input/*$}*/); @@ -157,10 +163,7 @@ public boolean keyPressed(/*$ keyinput_params {*/KeyInput input/*$}*/) { buttonKeybind.onClearSelection(); return true; } - if (this.commandList.keyPressed(/*$ keyinput_args {*/input/*$}*/)) - return true; - else - return super.keyPressed(/*$ keyinput_args {*/input/*$}*/); + return super.keyPressed(/*$ keyinput_args {*/input/*$}*/); } @Override @@ -170,48 +173,36 @@ public void mouseMoved(double mouseX, double mouseY) { @Override public boolean mouseClicked(/*$ mouse_clicked_params {*/Click click, boolean doubleClick/*$}*/) { - if (buttonKeybind.onMouseClicked(/*$ on_mouse_clicked_args {*/click, doubleClick/*$}*/)) { + if (super.mouseClicked(/*$ mouse_clicked_args {*/click, doubleClick/*$}*/)) return true; + boolean buttonKeybindClicked = buttonKeybind.onMouseClicked(/*$ on_mouse_clicked_args {*/click, doubleClick/*$}*/); + boolean buttonEnabledClicked = buttonEnabled.onMouseClicked(/*$ on_mouse_clicked_args {*/click, doubleClick/*$}*/); + boolean buttonMutedClicked = buttonMuted.onMouseClicked(/*$ on_mouse_clicked_args {*/click, doubleClick/*$}*/); + boolean widgetAdvancedKeybindSettingsClicked = widgetAdvancedKeybindSettings.onMouseClicked(/*$ on_mouse_clicked_args {*/click, doubleClick/*$}*/); + boolean commandListClicked = commandList.mouseClicked(/*$ mouse_clicked_args {*/click, doubleClick/*$}*/); + if (buttonKeybindClicked || buttonEnabledClicked || buttonMutedClicked || widgetAdvancedKeybindSettingsClicked || commandListClicked) { if (this.getFocused() != null) { - this.getFocused().setFocused(false); + this.setFocused(null); } return true; } - else if (buttonEnabled.onMouseClicked(/*$ on_mouse_clicked_args {*/click, doubleClick/*$}*/)) { - if (this.getFocused() != null) { - this.getFocused().setFocused(false); - } - return true; - } - else if (buttonMuted.onMouseClicked(/*$ on_mouse_clicked_args {*/click, doubleClick/*$}*/)) { - if (this.getFocused() != null) { - this.getFocused().setFocused(false); - } - return true; - } - else if (widgetAdvancedKeybindSettings.onMouseClicked(/*$ on_mouse_clicked_args {*/click, doubleClick/*$}*/)) { - if (this.getFocused() != null) { - this.getFocused().setFocused(false); - } - return true; - } - else if (super.mouseClicked(/*$ mouse_clicked_args {*/click, doubleClick/*$}*/)) return true; - else return commandList.mouseClicked(/*$ mouse_clicked_args {*/click, doubleClick/*$}*/); + return false; } @Override public boolean mouseReleased(/*$ dragged_released_params {*/Click click/*$}*/) { + if (super.mouseReleased(/*$ dragged_released_args {*/click/*$}*/)) return true; + if (commandList.mouseReleased(/*$ dragged_released_args {*/click/*$}*/)) return true; buttonKeybind.onMouseReleased(/*$ on_released_args {*/click/*$}*/); buttonEnabled.onMouseReleased(/*$ on_released_args {*/click/*$}*/); buttonMuted.onMouseReleased(/*$ on_released_args {*/click/*$}*/); widgetAdvancedKeybindSettings.onMouseReleased(/*$ on_released_args {*/click/*$}*/); - if (commandList.mouseReleased(/*$ dragged_released_args {*/click/*$}*/)) return true; - else return super.mouseReleased(/*$ dragged_released_args {*/click/*$}*/); + return false; } @Override public boolean mouseDragged(/*$ dragged_released_params {*/Click click/*$}*/, double deltaX, double deltaY) { if (commandList.mouseDragged(/*$ dragged_released_args {*/click/*$}*/, deltaX, deltaY)) return true; - else return super.mouseDragged(/*$ dragged_released_args {*/click/*$}*/, deltaX, deltaY); + return super.mouseDragged(/*$ dragged_released_args {*/click/*$}*/, deltaX, deltaY); } @Override @@ -274,12 +265,13 @@ public void close() { } this.macro.actions.clear(); this.commandList.children().forEach(t -> this.macro.actions.add(t.command)); - this.macro.setEnabled(this.configBoolean.getBooleanValue()); - this.macro.muted = this.configBoolean2.getBooleanValue(); + this.macro.setEnabled(this.enabledConfigBoolean.getBooleanValue()); + this.macro.muted = this.mutedConfigBoolean.getBooleanValue(); this.macro.setName(this.nameWidget.getText()); MacroManager.saveChanges(); + InputEventHandler.getKeybindManager().updateUsedKeys(); assert client != null; - parent.initGui(); - GuiBase.openGui(parent); + macroManager.initGui(); + GuiBase.openGui(macroManager); } } diff --git a/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroManager.java b/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroManager.java index 055daa25..d58a0e2d 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroManager.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroManager.java @@ -6,6 +6,7 @@ import fi.dy.masa.malilib.gui.button.ButtonGeneric; import fi.dy.masa.malilib.gui.button.IButtonActionListener; import fi.dy.masa.malilib.gui.interfaces.ISelectionListener; +import fi.dy.masa.malilib.hotkeys.KeybindSettings; import net.minecraft.client.gui.DrawContext; import org.jetbrains.annotations.Nullable; import tools.redstone.redstonetools.malilib.config.MacroManager; @@ -30,11 +31,7 @@ public GuiMacroManager() { @Override public void render(DrawContext drawContext, int mouseX, int mouseY, float partialTicks) { if (this.client != null && this.client.world == null) this.renderPanoramaBackground(drawContext, partialTicks); - //? if <=1.21.5 { - /*this.applyBlur(); - *///?} else { - this.applyBlur(drawContext); - //?} + this.applyBlur(/*? if >1.21.5 {*/drawContext/*?}*/); super.render(drawContext, mouseX, mouseY, partialTicks); } @@ -54,7 +51,11 @@ public void initGui() { super.initGui(); - this.clearWidgets(); + //? if <=1.21.10 { + /*this.clearWidgets(); + *///?} else { + this.clearChildren(); + //?} this.clearButtons(); this.createTabButtons(); this.getListWidget().refreshEntries(); @@ -94,7 +95,7 @@ protected void createTabButtons() { this.addButton(addMacroButton, (btn, mbtn) -> { String string = "macro "; string += MacroManager.getAllMacros().size(); - MacroManager.addMacroToTop(new MacroBase(string, "", new ArrayList<>())); + MacroManager.addMacroToTop(new MacroBase(string, "", KeybindSettings.PRESS_ALLOWEXTRA, new ArrayList<>())); MacroManager.saveChanges(); this.getListWidget().refreshEntries(); }); diff --git a/src/client/java/tools/redstone/redstonetools/malilib/config/Configs.java b/src/client/java/tools/redstone/redstonetools/malilib/config/Configs.java index 61ef5af4..634b73e8 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/config/Configs.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/config/Configs.java @@ -9,7 +9,6 @@ import fi.dy.masa.malilib.util.JsonUtils; import net.minecraft.client.MinecraftClient; import tools.redstone.redstonetools.RedstoneTools; -import tools.redstone.redstonetools.features.toggleable.AutoDustClient; import java.io.File; import java.util.ArrayList; @@ -104,11 +103,7 @@ public static class General { ); public static int getHeightInPixels() { - try { - return BIGDUST_HEIGHT_IN_PIXELS.getIntegerValue(); - } catch (Exception ignored) { - return 1; - } + return BIGDUST_HEIGHT_IN_PIXELS.getIntegerValue(); } } diff --git a/src/client/java/tools/redstone/redstonetools/malilib/config/MacroManager.java b/src/client/java/tools/redstone/redstonetools/malilib/config/MacroManager.java index a9aaf0c8..fe3a6341 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/config/MacroManager.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/config/MacroManager.java @@ -2,15 +2,16 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.google.gson.reflect.TypeToken; -import net.minecraft.client.MinecraftClient; +import com.google.gson.JsonElement; +import com.mojang.serialization.JsonOps; +import fi.dy.masa.malilib.hotkeys.KeybindSettings; +import net.fabricmc.loader.api.FabricLoader; import tools.redstone.redstonetools.macros.actions.CommandAction; import tools.redstone.redstonetools.malilib.widget.macro.MacroBase; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; -import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -22,8 +23,7 @@ public class MacroManager { private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); public static boolean shouldMute; - private static final Path MACROS_FILE_PATH = MinecraftClient.getInstance().runDirectory.toPath() - .resolve("config") + private static final Path MACROS_FILE_PATH = FabricLoader.getInstance().getConfigDir() .resolve("redstonetools") .resolve("macros.json"); private static List macros = new ArrayList<>(); @@ -32,27 +32,14 @@ public static List getAllMacros() { return macros; } - - private static final Type MACRO_LIST_TYPE = new TypeToken>() { - }.getType(); - public static void saveChanges() { - List macroStructure = new ArrayList<>(); - for (MacroBase macro : macros) { - macroStructure.add(new MacroStructure( - macro.getName(), - macro.hotkey.getKeybind().getStringValue(), - macro.isEnabled(), - macro.muted, - macro.actions - )); - } + JsonElement jsonElement = MacroBase.CODEC.listOf().encodeStart(JsonOps.INSTANCE, macros).getOrThrow(); try { if (MACROS_FILE_PATH.getParent() != null) Files.createDirectories(MACROS_FILE_PATH.getParent()); Path tmp = MACROS_FILE_PATH.resolveSibling(MACROS_FILE_PATH.getFileName().toString() + ".tmp"); try (BufferedWriter writer = Files.newBufferedWriter(tmp, StandardCharsets.UTF_8)) { - GSON.toJson(macroStructure, MACRO_LIST_TYPE, writer); + GSON.toJson(jsonElement, writer); } Files.move(tmp, MACROS_FILE_PATH, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE); } catch (IOException ignored) { @@ -65,22 +52,13 @@ public static void loadMacros() { return; } try (BufferedReader reader = Files.newBufferedReader(MACROS_FILE_PATH, StandardCharsets.UTF_8)) { - List list = GSON.fromJson(reader, MACRO_LIST_TYPE); - if (list == null) { + List macrosFromFile = MacroBase.CODEC.listOf().parse(JsonOps.INSTANCE, GSON.fromJson(reader, JsonElement.class)).result().orElse(null); + if (macrosFromFile == null) { macros = getDefaultMacros(); return; } - for (MacroStructure macro : list) { - macros.add(new MacroBase( - macro.name, - macro.key, - macro.actions, - macro.enabled, - macro.muted - )); - } - } catch ( - IOException ignored) { + macros.addAll(macrosFromFile); + } catch (IOException ignored) { macros = getDefaultMacros(); } } @@ -135,7 +113,7 @@ public static MacroBase createCommandMacro(String name, String[] commands) { actions[i] = new CommandAction(commands[i]); } - return new MacroBase(name, "", List.of(actions)); + return new MacroBase(name, "", KeybindSettings.PRESS_ALLOWEXTRA, List.of(actions)); } public static void removeMacro(MacroBase macro) { @@ -149,13 +127,4 @@ public static void addMacroToTop(MacroBase macroBase) { macros.addFirst(macroBase); } - record MacroStructure( - String name, - String key, - boolean enabled, - boolean muted, - List actions - ) { - - } } diff --git a/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandEditScreen.java b/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandEditScreen.java deleted file mode 100644 index 6bf6df3a..00000000 --- a/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandEditScreen.java +++ /dev/null @@ -1,110 +0,0 @@ -package tools.redstone.redstonetools.malilib.widget.action; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.ChatInputSuggestor; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.widget.TextFieldWidget; -/*$ click_and_inputs_imports {*/// -import net.minecraft.client.gui.Click; -import net.minecraft.client.input.KeyInput; -import net.minecraft.client.input.CharInput;/*$}*/ -import net.minecraft.client.util.InputUtil; -import net.minecraft.text.Text; -import tools.redstone.redstonetools.malilib.GuiMacroEditor; - -public class CommandEditScreen extends Screen { - - private final TextFieldWidget commandField; - private final ChatInputSuggestor commandSuggester; - private boolean changed = false; - public final GuiMacroEditor parent; - - public CommandEditScreen(GuiMacroEditor parent, TextFieldWidget commandField) { - super(Text.of("")); - this.parent = parent; - this.commandField = commandField; - this.commandField.setMaxLength(256); - client = MinecraftClient.getInstance(); - this.commandSuggester = new ChatInputSuggestor(client, this, commandField, client.textRenderer, false, false, commandField.getY() - 20, 5, false, -805306368) { - @Override - public void refresh() { - if (client == null) return; - if (client.getNetworkHandler() == null) return; - super.refresh(); - } - }; - - commandField.setChangedListener((s) -> changed = true); - commandSuggester.setWindowActive(true); - commandSuggester.refresh(); - } - - @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { - parent.render(context, mouseX, mouseY, delta); - commandField.render(context, mouseX, mouseY, delta); - - commandSuggester.render(context, mouseX, mouseY); - if (changed) { - commandSuggester.refresh(); - changed = false; - } - } - - @Override - public void resize(MinecraftClient client, int width, int height) { - parent.resize(client, width, height); - } - - @Override - public void close() { - this.client.setScreen(parent); - commandField.setFocused(false); - commandField.setChangedListener(null); - commandSuggester.setWindowActive(false); - commandSuggester.refresh(); - } - - @Override - public boolean mouseClicked(/*$ mouse_clicked_params {*/Click click, boolean doubleClick/*$}*/) { - if (!commandField.mouseClicked(/*$ mouse_clicked_args {*/click, doubleClick/*$}*/)) { - if (!commandSuggester.mouseClicked(/*? if >=1.21.10 {*/click/*?} else {*//*mouseX, mouseY, button*//*?}*/)) { - close(); - } else { - commandField.setFocused(true); - } - return false; - } - return super.mouseClicked(/*$ mouse_clicked_args {*/click, doubleClick/*$}*/); - } - - @Override - public boolean mouseScrolled(double mouseX, double mouseY, double amount, double horizontalAmount) { - return commandSuggester.mouseScrolled(amount); - } - - @Override - public boolean charTyped(/*$ charinput_params {*/CharInput input/*$}*/) { - return commandField.charTyped(/*$ charinput_args {*/input/*$}*/); - } - - @Override - public boolean keyPressed(/*$ keyinput_params {*/KeyInput input/*$}*/) { - //? if >=1.21.10 { - int keyCode = input.key(); - //?} - if (keyCode == InputUtil.GLFW_KEY_ESCAPE || keyCode == InputUtil.GLFW_KEY_ENTER || keyCode == InputUtil.GLFW_KEY_KP_ENTER) { - close(); - return true; - } - commandSuggester.keyPressed(/*$ keyinput_args {*/input/*$}*/); - - return commandField.keyPressed(/*$ keyinput_args {*/input/*$}*/); - } - - @Override - public boolean keyReleased(/*$ keyinput_params {*/KeyInput input/*$}*/) { - return commandField.keyReleased(/*$ keyinput_args {*/input/*$}*/); - } -} diff --git a/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java b/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java index 543415f4..fa94792a 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java @@ -2,8 +2,16 @@ import fi.dy.masa.malilib.gui.button.ButtonBase; import fi.dy.masa.malilib.gui.button.ButtonGeneric; +//? if >=1.21.11 { +import fi.dy.masa.malilib.render.GuiContext; +//?} import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.ScreenRect; +import net.minecraft.client.gui.navigation.GuiNavigation; +import net.minecraft.client.gui.navigation.GuiNavigationPath; +import net.minecraft.client.gui.navigation.NavigationAxis; +import net.minecraft.client.gui.navigation.NavigationDirection; import net.minecraft.client.gui.screen.ChatInputSuggestor; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; import net.minecraft.client.gui.widget.EntryListWidget; @@ -12,216 +20,265 @@ import net.minecraft.client.gui.Click; import net.minecraft.client.input.KeyInput; import net.minecraft.client.input.CharInput;/*$}*/ +import net.minecraft.client.util.math.Rect2i; import net.minecraft.text.Text; +import org.jetbrains.annotations.Nullable; import tools.redstone.redstonetools.macros.actions.CommandAction; import tools.redstone.redstonetools.malilib.GuiMacroEditor; import tools.redstone.redstonetools.malilib.widget.macro.MacroBase; +import tools.redstone.redstonetools.mixin.features.ChatInputSuggestorAccessor; +import tools.redstone.redstonetools.mixin.features.SuggestionWindowAccessor; +//? if >=1.21.10 { +import tools.redstone.redstonetools.mixin.features.TextFieldWidgetAccessor; +//?} + public class CommandListWidget extends EntryListWidget { private final GuiMacroEditor parent; + @Nullable + private ChatInputSuggestor commandSuggester; private final MacroBase macro; public CommandListWidget(GuiMacroEditor parent, MinecraftClient mc, int width, int height, int y, int itemHeight, MacroBase macro) { super(mc, width, height, y, itemHeight); this.parent = parent; this.macro = macro; - this.macro.actions.forEach((t) -> this.addEntry(new CommandEntry(t, this))); - } - - @Override - protected void clearEntries() { - this.children().clear(); - super.clearEntries(); + for (CommandAction commandAction : this.macro.actions) { + CommandEntry entry = new CommandEntry(commandAction); + this.addEntry(entry); + this.setSelected(entry); + } + this.recalculateAllActionsPositions(); + this.setSelected(null); } @Override - public int getRowWidth() { - return this.width - 50; - } - - public void addEntry() { - this.macro.actions.addFirst(new CommandAction("")); - this.addEntryToTop(new CommandEntry(this.macro.actions.getFirst(), this)); - this.centerScrollOn(this.getFirst()); - } + public void setSelected(@Nullable CommandListWidget.CommandEntry entry) { + if (this.getSelectedOrNull() != null) { + this.getSelectedOrNull().commandWidget.setSuggestion(null); + } + super.setSelected(entry); + if (entry == null) { + this.commandSuggester = null; + return; + } + //? if >=1.21.10 + ((TextFieldWidgetAccessor) entry.commandWidget).getFormatters().clear(); + this.commandSuggester = new ChatInputSuggestor( + client, + this.parent, + entry.commandWidget, + client.textRenderer, + false, + false, + 0, + 10, + false, + 0xD0000000 + ) { + @Override + public void refresh() { + if (client == null) return; + if (client.getNetworkHandler() == null) return; + super.refresh(); + } - //? if >=1.21.10 { - private CommandEntry getFirst() { - return this.children().getFirst(); + @Override + public void renderMessages(DrawContext context) { + //? if >=1.21.8 { + context.getMatrices().pushMatrix(); + //?} else + /*context.getMatrices().push();*/ + var x = 0; + var y = entry.commandWidget.getY() + 20 - 72; + context.getMatrices().translate(x, y/*? if <1.21.8 {*//*, 0*//*?}*/); + super.renderMessages(context); + //? if >=1.21.8 { + context.getMatrices().popMatrix(); + //?} else + /*context.getMatrices().pop();*/ + } + }; + this.commandSuggester.setWindowActive(true); + this.commandSuggester.refresh(); } - //?} - - CommandEntry previousSelected = this.getSelectedOrNull(); @Override - public void renderWidget(DrawContext context, int mouseX, int mouseY, float deltaTicks) { - if (this.isSelected()) { - if (this.getSelectedOrNull() != null) { - this.getSelectedOrNull().setFocused(true); - if (previousSelected != null) - this.previousSelected.setFocused(false); - } - } else { - if (this.getSelectedOrNull() != null) - this.getSelectedOrNull().setFocused(false); - if (this.previousSelected != null) - this.previousSelected.setFocused(false); - this.setSelected(null); + public void setScrollY(double scrollY) { + super.setScrollY(scrollY); + recalculateAllActionsPositions(); + if (this.commandSuggester != null && this.getSelectedOrNull() != null) { + ChatInputSuggestor.SuggestionWindow window = ((ChatInputSuggestorAccessor) this.commandSuggester).getWindow(); + if (window == null) return; + Rect2i area = ((SuggestionWindowAccessor) window).getArea(); + area.setY(this.getSelectedOrNull().commandWidget.getY() + 23); } - this.previousSelected = this.getSelectedOrNull(); - super.renderWidget(context, mouseX, mouseY, deltaTicks); } @Override - protected void appendClickableNarrations(NarrationMessageBuilder builder) { - - } + public @Nullable GuiNavigationPath getNavigationPath(GuiNavigation navigation) { + if (this.getEntryCount() == 0) { + return null; + } + if (!this.isFocused()) { + return GuiNavigationPath.of(this); + } + if (!(navigation instanceof GuiNavigation.Arrow(NavigationDirection navigationDirection))) { + return super.getNavigationPath(navigation); + } + if (navigationDirection.getAxis() == NavigationAxis.HORIZONTAL) { + return GuiNavigationPath.of(this.getSelectedOrNull(), this); + } - @Override - public void mouseMoved(double mouseX, double mouseY) { - if (this.getSelectedOrNull() != null) { - this.getSelectedOrNull().mouseMoved(mouseX, mouseY); + CommandEntry neighboringEntry = this.getNeighboringEntry(navigationDirection); + if (neighboringEntry == null) { + return GuiNavigationPath.of(this.getSelectedOrNull(), this); } - super.mouseMoved(mouseX, mouseY); + + return GuiNavigationPath.of(neighboringEntry, this); } @Override public boolean mouseClicked(/*$ mouse_clicked_params {*/Click click, boolean doubleClick/*$}*/) { - if (this.getSelectedOrNull() != null) { - this.getSelectedOrNull().mouseClicked(/*$ mouse_clicked_args {*/click, doubleClick/*$}*/); - } + if (this.commandSuggester != null && this.commandSuggester.mouseClicked(/*? if <1.21.10 {*//*mouseX, mouseY, button*//*?} else {*/click/*?}*/)) return true; return super.mouseClicked(/*$ mouse_clicked_args {*/click, doubleClick/*$}*/); } @Override - public boolean mouseReleased(/*$ dragged_released_params {*/Click click/*$}*/) { - if (this.getSelectedOrNull() != null) { - return this.getSelectedOrNull().mouseReleased(/*$ dragged_released_args {*/click/*$}*/); - } - return super.mouseReleased(/*$ dragged_released_args {*/click/*$}*/); + public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { + if (this.commandSuggester != null && this.commandSuggester.mouseScrolled(verticalAmount)) return true; + return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); } @Override - public boolean mouseDragged(/*$ dragged_released_params {*/Click click/*$}*/, double deltaX, double deltaY) { - if (this.getSelectedOrNull() != null) { - return this.getSelectedOrNull().mouseDragged(/*$ dragged_released_args {*/click/*$}*/, deltaX, deltaY); - } - return super.mouseDragged(/*$ dragged_released_args {*/click/*$}*/, deltaX, deltaY); + public boolean keyPressed(/*$ keyinput_params {*/KeyInput input/*$}*/) { + if (this.commandSuggester != null && this.commandSuggester.keyPressed(/*$ keyinput_args {*/input/*$}*/)) return true; + return super.keyPressed(/*$ keyinput_args {*/input/*$}*/); } @Override - public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { - if (this.getSelectedOrNull() != null) { - return this.getSelectedOrNull().mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); + protected void renderList(DrawContext context, int mouseX, int mouseY, float deltaTicks) { + super.renderList(context, mouseX, mouseY, deltaTicks); + if (this.commandSuggester != null) { + this.commandSuggester.render(context, mouseX, mouseY); } - return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); } @Override - public boolean keyPressed(/*$ keyinput_params {*/KeyInput input/*$}*/) { - if (this.getSelectedOrNull() != null) { - return this.getSelectedOrNull().keyPressed(/*$ keyinput_args {*/input/*$}*/); - } - return super.keyPressed(/*$ keyinput_args {*/input/*$}*/); + //? if >=1.21.10 { + protected boolean isEntrySelectionAllowed() { + //?} else { + /*protected boolean isSelectedEntry(int index) { + *///?} + return false; } + @Override - public boolean keyReleased(/*$ keyinput_params {*/KeyInput input/*$}*/) { - if (this.getSelectedOrNull() != null) { - return this.getSelectedOrNull().keyReleased(/*$ keyinput_args {*/input/*$}*/); + public int getRowWidth() { + return this.width - 50; + } + + public void addEntry() { + this.macro.actions.addFirst(new CommandAction("")); + CommandEntry entry = new CommandEntry(this.macro.actions.getFirst()); + this.addEntryToTop(entry); + this.centerScrollOn(this.getFirst()); + recalculateAllActionsPositions(); + if (this.commandSuggester != null) { + this.commandSuggester.refresh(); } - return super.keyReleased(/*$ keyinput_args {*/input/*$}*/); } - @Override - public boolean charTyped(/*$ charinput_params {*/CharInput input/*$}*/) { - if (this.getSelectedOrNull() != null) { - return this.getSelectedOrNull().charTyped(/*$ charinput_args {*/input/*$}*/); + private void recalculateAllActionsPositions() { + int i = this.getY() - (int) this.getScrollY(); + + for (CommandEntry entry : this.children()) { + entry.removeButton.setY(i + 6); + entry.commandWidget.setY(i + 3); + i += this.itemHeight; } - return super.charTyped(/*$ charinput_args {*/input/*$}*/); } + //? if >=1.21.10 { + private CommandEntry getFirst() { + return this.children().getFirst(); + } + //?} + @Override - public boolean isMouseOver(double mouseX, double mouseY) { - if (this.getSelectedOrNull() != null) { - return this.getSelectedOrNull().isMouseOver(mouseX, mouseY); - } - return super.isMouseOver(mouseX, mouseY); + protected void appendClickableNarrations(NarrationMessageBuilder builder) { + } - public static class CommandEntry extends EntryListWidget.Entry { + public class CommandEntry extends Entry { public final CommandAction command; - public final TextFieldWidget commandWidget; - private final CommandListWidget parent; - private boolean isFirst = true; - private ButtonBase removeButton = new ButtonGeneric(0, 0, 0, 0, "Remove"); + private TextFieldWidget commandWidget; + private ButtonBase removeButton; - public CommandEntry(CommandAction command, CommandListWidget parent) { - this.parent = parent; + public CommandEntry(CommandAction command) { this.command = command; - this.commandWidget = new TextFieldWidget(MinecraftClient.getInstance().textRenderer, 250, 50, Text.of("")); - this.commandWidget.setMaxLength(256); - this.commandWidget.setText(command.command); - var commandSuggester = new ChatInputSuggestor(MinecraftClient.getInstance(), this.parent.parent, this.commandWidget, MinecraftClient.getInstance().textRenderer, false, false, 0, 7, false, Integer.MIN_VALUE) { - @Override - public void refresh() { - if (parent.client == null) return; - if (parent.client.getNetworkHandler() == null) return; - super.refresh(); - } - }; - commandSuggester.setWindowActive(true); - commandSuggester.refresh(); + this.commandWidget = new TextFieldWidget(MinecraftClient.getInstance().textRenderer, CommandListWidget.this.getX() + 4 + 25, 0, CommandListWidget.this.getRowWidth() - 100, 26, Text.of("")); + commandWidget.setMaxLength(256); + commandWidget.setText(command.command); + commandWidget.setChangedListener(this::onCommandChanged); + + this.removeButton = new ButtonGeneric(0, 0, -1, 20, "Remove"); + this.removeButton.setX(CommandListWidget.this.getX() + CommandListWidget.this.getRowWidth() - this.removeButton.getWidth() - 10 + 25); + this.removeButton.setActionListener((button, mouseButton) -> { + CommandListWidget.this.macro.actions.remove(CommandListWidget.this.children().indexOf(this)); + CommandListWidget.this.removeEntryWithoutScrolling(this); + recalculateAllActionsPositions(); + }); } - @Override - public void render(DrawContext context, /*? if <1.21.10 {*/ /*int index, int y, int x, int entryWidth, int entryHeight, *//*?}*/ int mouseX, int mouseY, boolean hovered, float tickProgress) { - if (isFirst) { - isFirst = false; - this.removeButton = new ButtonGeneric(/*$ get_x {*/getX()/*$}*/ + /*$ get_width {*/getWidth()/*$}*/, /*$ get_y {*/getY()/*$}*/, -1, 20, "Remove"); - this.removeButton.setActionListener((t, g) -> { - this.parent.macro.actions.remove(this.parent.children().indexOf(this)); - this.parent.removeEntry(this); - }); - this.removeButton.setX(removeButton.getX() - (removeButton.getWidth() + 10)); - } - removeButton.setY(/*$ get_y {*/getY()/*$}*/ + 6); - - if (this.isFocused()) { - this.parent.parent.macro.setName(this.parent.parent.nameWidget.getText()); - MinecraftClient.getInstance().setScreen(new CommandEditScreen(parent.parent, this.commandWidget)); - this.parent.setSelected(null); + private void onCommandChanged(String text) { + command.command = text; + if (CommandListWidget.this.commandSuggester != null) { + CommandListWidget.this.commandSuggester.refresh(); } + } - commandWidget.setFocused(this.isFocused()); - commandWidget.setPosition(/*$ get_x {*/getX()/*$}*/ + 4, /*$ get_y {*/getY()/*$}*/ + 3); - commandWidget.setWidth(/*$ get_width {*/getWidth()/*$}*/ - 100); - commandWidget.setHeight(26); + @Override + public void render(DrawContext context, /*? if <1.21.10 {*/ /*int index, int argY, int argX, int entryWidth, int entryHeight, *//*?}*/ int mouseX, int mouseY, boolean hovered, float tickProgress) { commandWidget.render(context, mouseX, mouseY, tickProgress); //? if <=1.21.5 { /*removeButton.render(mouseX, mouseY, removeButton.isMouseOver(), context); + *///?} else if <=1.21.10 { + /*removeButton.render(context, mouseX, mouseY, removeButton.isMouseOver()); *///?} else { - removeButton.render(context, mouseX, mouseY, removeButton.isMouseOver()); + GuiContext guiContext = GuiContext.fromGuiGraphics(context); + ScreenRect last = context.scissorStack.peekLast(); + if (last != null) { + guiContext.pushScissor(last); + } + removeButton.render(guiContext, mouseX, mouseY, removeButton.isMouseOver()); //?} + } - command.command = commandWidget.getText(); + @Override + public void setFocused(boolean focused) { + super.setFocused(focused); + commandWidget.setFocused(focused); } @Override public void mouseMoved(double mouseX, double mouseY) { - commandWidget.mouseMoved(mouseX, mouseY); super.mouseMoved(mouseX, mouseY); + commandWidget.mouseMoved(mouseX, mouseY); } @Override public boolean mouseClicked(/*$ mouse_clicked_params {*/Click click, boolean doubleClick/*$}*/) { if (commandWidget.mouseClicked(/*$ mouse_clicked_args {*/click, doubleClick/*$}*/)) return true; - else return removeButton.onMouseClicked(/*$ on_mouse_clicked_args {*/click, doubleClick/*$}*/); + if (removeButton.onMouseClicked(/*$ on_mouse_clicked_args {*/click, doubleClick/*$}*/)) return true; + return false; } @Override public boolean mouseReleased(/*$ dragged_released_params {*/Click click/*$}*/) { + removeButton.onMouseReleased(/*$ on_released_args {*/click/*$}*/); return commandWidget.mouseReleased(/*$ dragged_released_args {*/click/*$}*/); } @@ -232,12 +289,18 @@ public boolean mouseDragged(/*$ dragged_released_params {*/Click click/*$}*/, do @Override public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { - return commandWidget.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); + if (commandWidget.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount)) return true; + var x = /*? if <1.21.10 {*//*(int)*//*?}*/mouseX; + var y = /*? if <1.21.10 {*//*(int)*//*?}*/mouseY; + if (removeButton.onMouseScrolled(x, y, horizontalAmount, verticalAmount)) return true; + return false; } @Override public boolean keyPressed(/*$ keyinput_params {*/KeyInput input/*$}*/) { - return commandWidget.keyPressed(/*$ keyinput_args {*/input/*$}*/); + if (commandWidget.keyPressed(/*$ keyinput_args {*/input/*$}*/)) return true; + if (removeButton.onKeyTyped(/*$ keyinput_args {*/input/*$}*/)) return true; + return false; } @Override @@ -247,12 +310,16 @@ public boolean keyReleased(/*$ keyinput_params {*/KeyInput input/*$}*/) { @Override public boolean charTyped(/*$ charinput_params {*/CharInput input/*$}*/) { - return commandWidget.charTyped(/*$ charinput_args {*/input/*$}*/); + if (commandWidget.charTyped(/*$ charinput_args {*/input/*$}*/)) return true; + if (removeButton.onCharTyped(/*$ charinput_args {*/input/*$}*/)) return true; + return false; } @Override public boolean isMouseOver(double mouseX, double mouseY) { - return commandWidget.isMouseOver(mouseX, mouseY); + if (commandWidget.isMouseOver(mouseX, mouseY)) return true; + if (removeButton.isMouseOver((int) mouseX, (int) mouseY)) return true; + return false; } } } diff --git a/src/client/java/tools/redstone/redstonetools/malilib/widget/macro/MacroBase.java b/src/client/java/tools/redstone/redstonetools/malilib/widget/macro/MacroBase.java index d2ff46c1..aeb92f97 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/widget/macro/MacroBase.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/widget/macro/MacroBase.java @@ -1,5 +1,12 @@ package tools.redstone.redstonetools.malilib.widget.macro; +import com.google.gson.JsonElement; +import com.mojang.datafixers.util.Pair; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.DynamicOps; +import com.mojang.serialization.JsonOps; +import com.mojang.serialization.codecs.RecordCodecBuilder; import fi.dy.masa.malilib.config.options.ConfigHotkey; import fi.dy.masa.malilib.event.InputEventHandler; import fi.dy.masa.malilib.hotkeys.KeybindSettings; @@ -10,10 +17,33 @@ import tools.redstone.redstonetools.malilib.KeybindHandler; import tools.redstone.redstonetools.malilib.config.MacroManager; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; public class MacroBase { + private static final Codec KEYBIND_SETTINGS_CODEC = new Codec<>() { + @Override + public DataResult encode(KeybindSettings keybindSettings, DynamicOps dynamicOps, T t) { + return DataResult.success(JsonOps.INSTANCE.convertTo(dynamicOps, keybindSettings.toJson())); + } + + @Override + public DataResult> decode(DynamicOps dynamicOps, T t) { + JsonElement jsonElement = dynamicOps.convertTo(JsonOps.INSTANCE, t); + KeybindSettings keybindSettings1 = !jsonElement.isJsonObject() ? KeybindSettings.PRESS_ALLOWEXTRA : KeybindSettings.fromJson(jsonElement.getAsJsonObject()); + return DataResult.success(Pair.of(keybindSettings1, dynamicOps.empty())); + } + }; + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.STRING.optionalFieldOf("name", "").forGetter(macro -> macro.name), + Codec.STRING.optionalFieldOf("keybind", "").forGetter(macro -> macro.hotkey.getStringValue()), + KEYBIND_SETTINGS_CODEC.optionalFieldOf("keybindSettings", KeybindSettings.PRESS_ALLOWEXTRA).forGetter(macro -> macro.hotkey.getKeybind().getSettings()), + CommandAction.CODEC.listOf().optionalFieldOf("actions", List.of()).forGetter(macro -> macro.actions), + Codec.BOOL.optionalFieldOf("enabled", true).forGetter(macro -> macro.enabled), + Codec.BOOL.optionalFieldOf("muted", false).forGetter(macro -> macro.muted) + ).apply(instance, MacroBase::new)); + public ConfigHotkey hotkey; public boolean muted; protected String name; @@ -21,13 +51,13 @@ public class MacroBase { public KeybindHandler handler; public List actions; - public MacroBase(String name, String keybind, List actions) { - this(name, keybind, actions, true, false); + public MacroBase(String name, String keybind, KeybindSettings keybindSettings, List actions) { + this(name, keybind, keybindSettings, actions, true, false); } - public MacroBase(String name, String keybind, List actions, boolean enabled, boolean muted) { - this.actions = new java.util.ArrayList<>(actions); - this.hotkey = new ConfigHotkey("Hotkey", keybind, KeybindSettings.PRESS_ALLOWEXTRA, "Pressing this hotkey will activate the macro"); + public MacroBase(String name, String keybind, KeybindSettings keybindSettings, List actions, boolean enabled, boolean muted) { + this.actions = new ArrayList<>(actions); + this.hotkey = new ConfigHotkey("Hotkey", keybind, keybindSettings, "Pressing this hotkey will activate the macro"); this.hotkey.getKeybind().setCallback((t, g) -> { this.run(); return true; diff --git a/src/client/java/tools/redstone/redstonetools/malilib/widget/macro/WidgetMacroEntry.java b/src/client/java/tools/redstone/redstonetools/malilib/widget/macro/WidgetMacroEntry.java index b54e3b7d..93532369 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/widget/macro/WidgetMacroEntry.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/widget/macro/WidgetMacroEntry.java @@ -8,13 +8,17 @@ import fi.dy.masa.malilib.gui.widgets.WidgetListEntryBase; import fi.dy.masa.malilib.render.RenderUtils; import fi.dy.masa.malilib.util.StringUtils; -import net.minecraft.client.gui.DrawContext; import net.minecraft.text.Text; import tools.redstone.redstonetools.malilib.GuiMacroEditor; import tools.redstone.redstonetools.malilib.config.MacroManager; //? if >=1.21.10 { import net.minecraft.client.gui.Click; //?} +//? if <=1.21.10 { +/*import net.minecraft.client.gui.DrawContext; +*///?} else { +import fi.dy.masa.malilib.render.GuiContext; +//?} public class WidgetMacroEntry extends WidgetListEntryBase { private final WidgetListMacros parent; @@ -37,7 +41,7 @@ public boolean canSelectAt(Click click) { //? if >=1.21.8 { @Override - public void render(DrawContext context, int mouseX, int mouseY, boolean selected) { + public void render(/*? if <=1.21.10 {*//*DrawContext*//*?} else {*/GuiContext/*?}*/ context, int mouseX, int mouseY, boolean selected) { if (selected || this.isMouseOver(mouseX, mouseY)) { RenderUtils.drawRect(context, this.x, this.y, this.width, this.height, 0x70FFFFFF); } else if (this.isOdd) { @@ -51,7 +55,7 @@ public void render(DrawContext context, int mouseX, int mouseY, boolean selected } @Override - public void postRenderHovered(DrawContext context, int mouseX, int mouseY, boolean selected) { + public void postRenderHovered(/*? if <=1.21.10 {*//*DrawContext*//*?} else {*/GuiContext/*?}*/ context, int mouseX, int mouseY, boolean selected) { super.postRenderHovered(context, mouseX, mouseY, selected); } //?} else { diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/AutoRotateClientMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/features/AutoRotateClientMixin.java index 6ecffeaa..37c42ec8 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/AutoRotateClientMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/AutoRotateClientMixin.java @@ -5,11 +5,11 @@ import net.minecraft.block.BlockState; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemPlacementContext; +import net.minecraft.util.BlockRotation; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import tools.redstone.redstonetools.features.toggleable.AutoRotateClient; -import tools.redstone.redstonetools.utils.BlockUtils; @Mixin(BlockItem.class) public abstract class AutoRotateClientMixin { @@ -22,7 +22,7 @@ private BlockState changeRotation(BlockState original, @Local(argsOnly = true) I || original == null) return original; BlockState backup = original; - original = BlockUtils.rotate(original); + original = original.rotate(BlockRotation.CLOCKWISE_180); if (this.canPlace(context, original)) return original; diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggesterMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggesterMixin.java deleted file mode 100644 index 1b322fab..00000000 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggesterMixin.java +++ /dev/null @@ -1,40 +0,0 @@ -package tools.redstone.redstonetools.mixin.features; - -import net.minecraft.client.gui.screen.ChatInputSuggestor; -import net.minecraft.client.gui.widget.TextFieldWidget; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import tools.redstone.redstonetools.malilib.config.Configs; -import tools.redstone.redstonetools.utils.StringUtils; - -import static tools.redstone.redstonetools.utils.StringUtils.unmodifiedCommand; - -@Mixin(ChatInputSuggestor.class) -public class ChatInputSuggesterMixin { - @Final - @Shadow - TextFieldWidget textField; - - @Unique - private boolean shouldReturn = false; - - @Inject(method = "refresh", at = @At("HEAD")) - private void meowww(CallbackInfo ci) { - shouldReturn = !Configs.ClientData.ENABLE_MATH_VARIABLES.getBooleanValue() || StringUtils.insertVariablesAndMath(textField.getText()).length() < textField.getText().length(); - if (shouldReturn) return; - unmodifiedCommand.add(textField.getText()); - ((TextFieldAccessor)textField).setText2(StringUtils.insertVariablesAndMath(textField.getText())); - } - - @Inject(method = "refresh", at = @At("RETURN")) - private void mrawww(CallbackInfo ci) { - if (shouldReturn) return; - ((TextFieldAccessor)textField).setText2(unmodifiedCommand.getLast()); - unmodifiedCommand.removeLast(); - } -} diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggestorAccessor.java b/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggestorAccessor.java index a07568c0..1781166e 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggestorAccessor.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggestorAccessor.java @@ -2,6 +2,7 @@ import net.minecraft.client.gui.screen.ChatInputSuggestor; import net.minecraft.client.gui.widget.TextFieldWidget; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; @@ -9,4 +10,7 @@ public interface ChatInputSuggestorAccessor { @Accessor TextFieldWidget getTextField(); + + @Accessor + @Nullable ChatInputSuggestor.SuggestionWindow getWindow(); } \ No newline at end of file diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggestorMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggestorMixin.java new file mode 100644 index 00000000..cef8814b --- /dev/null +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggestorMixin.java @@ -0,0 +1,48 @@ +package tools.redstone.redstonetools.mixin.features; + +import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import net.minecraft.client.gui.screen.ChatInputSuggestor; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.widget.TextFieldWidget; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArg; +import tools.redstone.redstonetools.malilib.GuiMacroEditor; +import tools.redstone.redstonetools.malilib.config.Configs; +import tools.redstone.redstonetools.utils.StringUtils; + +@Mixin(ChatInputSuggestor.class) +public class ChatInputSuggestorMixin { + @Final + @Shadow + TextFieldWidget textField; + + @Shadow + @Final + private Screen owner; + + @WrapMethod(method = "refresh") + private void makeMethodSeeReplacedVariables(Operation original) { + boolean shouldReturn = !Configs.ClientData.ENABLE_MATH_VARIABLES.getBooleanValue() || StringUtils.insertVariablesAndMath(textField.getText()).length() < textField.getText().length(); + if (shouldReturn) return; + String originalCommand = textField.getText(); + ((TextFieldWidgetAccessor) textField).setTextDirectly(StringUtils.insertVariablesAndMath(textField.getText())); + original.call(); + ((TextFieldWidgetAccessor) textField).setTextDirectly(originalCommand); + } + + @ModifyArg( + method = "show", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/ChatInputSuggestor$SuggestionWindow;(Lnet/minecraft/client/gui/screen/ChatInputSuggestor;IIILjava/util/List;Z)V"), + index = 2 + ) + private int modifyY(int y) { + if (this.owner instanceof GuiMacroEditor) { + return textField.getY() + 20; + } + return y; + } +} diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowAccessor.java b/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowAccessor.java new file mode 100644 index 00000000..cc23100d --- /dev/null +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowAccessor.java @@ -0,0 +1,12 @@ +package tools.redstone.redstonetools.mixin.features; + +import net.minecraft.client.gui.screen.ChatInputSuggestor; +import net.minecraft.client.util.math.Rect2i; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(ChatInputSuggestor.SuggestionWindow.class) +public interface SuggestionWindowAccessor { + @Accessor + Rect2i getArea(); +} diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowMixin.java index 97e4a4a8..48c27ab6 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/SuggestionWindowMixin.java @@ -1,14 +1,12 @@ package tools.redstone.redstonetools.mixin.features; +import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import net.minecraft.client.gui.screen.ChatInputSuggestor; import net.minecraft.client.gui.widget.TextFieldWidget; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import tools.redstone.redstonetools.utils.StringUtils; @Mixin(ChatInputSuggestor.SuggestionWindow.class) @@ -17,17 +15,11 @@ public class SuggestionWindowMixin { @Final ChatInputSuggestor field_21615; - @Unique - private static String beforeComplete; - - @Inject(method = "complete", at = @At("HEAD")) - private void mroeww(CallbackInfo ci) { - beforeComplete = ((ChatInputSuggestorAccessor) this.field_21615).getTextField().getText(); - } - - @Inject(method = "complete", at = @At("RETURN")) - private void mrawww(CallbackInfo ci) { + @WrapMethod(method = "complete") + private void expandVariablesToo(Operation original) { TextFieldWidget textField = ((ChatInputSuggestorAccessor) this.field_21615).getTextField(); + String beforeComplete = textField.getText(); + original.call(); if (StringUtils.expand(beforeComplete, textField.getText()).equals(textField.getText())) return; textField.setText(StringUtils.expand(beforeComplete, textField.getText())); } diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/TextFieldAccessor.java b/src/client/java/tools/redstone/redstonetools/mixin/features/TextFieldWidgetAccessor.java similarity index 53% rename from src/client/java/tools/redstone/redstonetools/mixin/features/TextFieldAccessor.java rename to src/client/java/tools/redstone/redstonetools/mixin/features/TextFieldWidgetAccessor.java index f896e340..86ab4098 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/TextFieldAccessor.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/TextFieldWidgetAccessor.java @@ -4,8 +4,15 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; +import java.util.List; + @Mixin(TextFieldWidget.class) -public interface TextFieldAccessor { - @Accessor(value = "text") - void setText2(String s); +public interface TextFieldWidgetAccessor { + @Accessor("text") + void setTextDirectly(String s); + + //? if >=1.21.10 { + @Accessor + List getFormatters(); + //?} } diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/WorldRendererInvoker.java b/src/client/java/tools/redstone/redstonetools/mixin/features/WorldRendererInvoker.java index 3e6d2672..e4f55bc0 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/WorldRendererInvoker.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/WorldRendererInvoker.java @@ -4,7 +4,7 @@ /*import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; -/^^/*///?} else { +*///?} else { import net.minecraft.client.render.state.OutlineRenderState; //?} import net.minecraft.client.render.VertexConsumer; @@ -15,12 +15,12 @@ @Mixin(WorldRenderer.class) public interface WorldRendererInvoker { - //? if <1.21.10 { - /*@Invoker - void invokeDrawBlockOutline(MatrixStack matrices, VertexConsumer vertexConsumer, Entity entity, double cameraX, double cameraY, double cameraZ, BlockPos pos, BlockState state, int color); - *///?} else { - @Invoker - void invokeDrawBlockOutline(MatrixStack matrices, VertexConsumer vertexConsumer, double x, double y, double z, OutlineRenderState state, int i); + //? if <=1.21.8 { + /*void invokeDrawBlockOutline(MatrixStack matrices, VertexConsumer vertexConsumer, Entity entity, double cameraX, double cameraY, double cameraZ, BlockPos pos, BlockState state, int color); + *///?} else if <=1.21.10 { + /*void invokeDrawBlockOutline(MatrixStack matrices, VertexConsumer vertexConsumer, double x, double y, double z, OutlineRenderState state, int color); + *///?} else { + void invokeDrawBlockOutline(MatrixStack matrices, VertexConsumer vertexConsumer, double x, double y, double z, OutlineRenderState state, int color, float lineWidth); //?} } \ No newline at end of file diff --git a/src/client/java/tools/redstone/redstonetools/utils/MathUtils.java b/src/client/java/tools/redstone/redstonetools/utils/MathUtils.java index f325b810..2419cf61 100644 --- a/src/client/java/tools/redstone/redstonetools/utils/MathUtils.java +++ b/src/client/java/tools/redstone/redstonetools/utils/MathUtils.java @@ -30,7 +30,6 @@ private static String reduceMathExpression(String[] components) { if (components[0].equals("(")) { components = removeAt(components, 0); for (int i = 0; i < components.length; i++) { - System.out.println(Arrays.toString(components)); if (components[i].equals("(")) { components = ArrayUtils.addAll(Arrays.copyOfRange(components, 0, i), reduceMathExpression(Arrays.copyOfRange(components, i+1, components.length))); i = 0; diff --git a/src/client/java/tools/redstone/redstonetools/utils/StringUtils.java b/src/client/java/tools/redstone/redstonetools/utils/StringUtils.java index 049c99df..63bf0272 100644 --- a/src/client/java/tools/redstone/redstonetools/utils/StringUtils.java +++ b/src/client/java/tools/redstone/redstonetools/utils/StringUtils.java @@ -2,9 +2,7 @@ import tools.redstone.redstonetools.features.commands.ClientDataFeature; -import java.util.ArrayList; import java.util.HashSet; -import java.util.List; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -12,8 +10,6 @@ import static tools.redstone.redstonetools.malilib.config.Configs.ClientData.*; public class StringUtils { - public static List unmodifiedCommand = new ArrayList<>(); - public static String insertVariablesAndMath(String command) { int counter = 0; String prevCommand = ""; @@ -61,46 +57,46 @@ public static String insertVariablesAndMath(String command) { return command; } - public static String expand (String shortStr, String expandedString){ - Pattern tokenPattern = Pattern.compile("'([^']*)'"); - Pattern quotedValuePattern = Pattern.compile("^'([^']*)'$"); - Matcher tokenMatcher = tokenPattern.matcher(shortStr); - - String result = expandedString; - - while (tokenMatcher.find()) { - String tokenWithQuotes = tokenMatcher.group(0); - String key = tokenMatcher.group(1); - - Set seen = new HashSet<>(); - String currentKey = key; - String resolved; - - while (true) { - if (!seen.add(currentKey)) { - resolved = null; - break; - } - String val = ClientDataFeature.INSTANCE.variables.get(currentKey); - if (val == null) { - resolved = null; - break; - } - Matcher qm = quotedValuePattern.matcher(val); - if (qm.matches()) { - currentKey = qm.group(1); - } else { - resolved = val; - break; - } - } + public static String expand(String shortStr, String expandedString) { + Pattern tokenPattern = Pattern.compile("'([^']*)'"); + Pattern quotedValuePattern = Pattern.compile("^'([^']*)'$"); + Matcher tokenMatcher = tokenPattern.matcher(shortStr); + + String result = expandedString; + + while (tokenMatcher.find()) { + String tokenWithQuotes = tokenMatcher.group(0); + String key = tokenMatcher.group(1); + + Set seen = new HashSet<>(); + String currentKey = key; + String resolved; - if (resolved == null || resolved.isEmpty()) { - continue; + while (true) { + if (!seen.add(currentKey)) { + resolved = null; + break; + } + String val = ClientDataFeature.INSTANCE.variables.get(currentKey); + if (val == null) { + resolved = null; + break; + } + Matcher qm = quotedValuePattern.matcher(val); + if (qm.matches()) { + currentKey = qm.group(1); + } else { + resolved = val; + break; } - result = result.replaceFirst(Pattern.quote(resolved), Matcher.quoteReplacement(tokenWithQuotes)); } - return result; + if (resolved == null || resolved.isEmpty()) { + continue; + } + result = result.replaceFirst(Pattern.quote(resolved), Matcher.quoteReplacement(tokenWithQuotes)); } + + return result; } +} diff --git a/src/client/resources/redstonetools.client.mixins.json b/src/client/resources/redstonetools.client.mixins.json index 8ee654fd..5f71a0b2 100644 --- a/src/client/resources/redstonetools.client.mixins.json +++ b/src/client/resources/redstonetools.client.mixins.json @@ -21,13 +21,14 @@ "features.AirPlaceClientMixin", "features.AutoRotateClientMixin", "features.ChatHudMixin", - "features.ChatInputSuggesterMixin", "features.ChatInputSuggestorAccessor", + "features.ChatInputSuggestorMixin", "features.ClientPlayNetworkHandlerMixin", "features.CommandSourceMixin", "features.ItemBindItemStackMixin", + "features.SuggestionWindowAccessor", "features.SuggestionWindowMixin", - "features.TextFieldAccessor", + "features.TextFieldWidgetAccessor", "features.WorldRendererInvoker", "macros.AddMacroButtonMixin", "macros.InitializeMacroManagerMixin" diff --git a/src/main/java/tools/redstone/redstonetools/Commands.java b/src/main/java/tools/redstone/redstonetools/Commands.java index e48f652c..ad716163 100644 --- a/src/main/java/tools/redstone/redstonetools/Commands.java +++ b/src/main/java/tools/redstone/redstonetools/Commands.java @@ -1,11 +1,26 @@ package tools.redstone.redstonetools; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +//? if >=1.21.11 { +import net.minecraft.command.DefaultPermissions; +import net.minecraft.command.permission.PermissionCheck; +import net.minecraft.server.command.CommandManager; +//?} +import net.minecraft.server.command.ServerCommandSource; import tools.redstone.redstonetools.features.commands.*; import tools.redstone.redstonetools.features.toggleable.*; import tools.redstone.redstonetools.utils.DependencyLookup; +import java.util.function.Predicate; + public class Commands { + public static final Predicate PERMISSION_LEVEL_2 = + //? if <=1.21.10 { + /*source -> source.hasPermissionLevel(2); + *///?} else { + CommandManager.requirePermissionLevel(new PermissionCheck.Require(DefaultPermissions.GAMEMASTERS)); + //?} + public static void registerCommands() { CommandRegistrationCallback.EVENT.register((commandDispatcher, commandRegistryAccess, registrationEnvironment) -> { if (DependencyLookup.WORLDEDIT_PRESENT) { diff --git a/src/main/java/tools/redstone/redstonetools/RedstoneToolsGameRules.java b/src/main/java/tools/redstone/redstonetools/RedstoneToolsGameRules.java index a2e7ac70..6ebe460c 100644 --- a/src/main/java/tools/redstone/redstonetools/RedstoneToolsGameRules.java +++ b/src/main/java/tools/redstone/redstonetools/RedstoneToolsGameRules.java @@ -1,6 +1,7 @@ package tools.redstone.redstonetools; -import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory; +//? if <=1.21.10 { +/*import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory; import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry; import net.minecraft.world.GameRules; @@ -19,3 +20,61 @@ public static void register() { // } } } +*///?} else { +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.serialization.Codec; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.resource.featuretoggle.FeatureSet; +import net.minecraft.util.Identifier; +import net.minecraft.world.rule.*; + +import java.util.function.ToIntFunction; + +public class RedstoneToolsGameRules { + private RedstoneToolsGameRules() { + } + + public static GameRule DO_CONTAINER_DROPS; +// public static GameRule DO_BLOCK_UPDATES_AFTER_EDIT; + + public static void register() { + DO_CONTAINER_DROPS = registerBooleanRule("do_container_drops", GameRuleCategory.DROPS, true); + +// if (DependencyLookup.WORLDEDIT_PRESENT) { +// DO_BLOCK_UPDATES_AFTER_EDIT = registerBooleanRule("doBlockUpdatesAfterEdit", GameRuleCategory.UPDATES, false); +// } + } + + private static GameRule registerBooleanRule(String name, GameRuleCategory category, boolean defaultValue) { + return registerRule( + name, + category, + GameRuleType.BOOL, + BoolArgumentType.bool(), + Codec.BOOL, + defaultValue, + FeatureSet.empty(), + GameRuleVisitor::visitBoolean, + value -> value ? 1 : 0 + ); + } + + private static GameRule registerRule( + String name, + GameRuleCategory category, + GameRuleType type, + ArgumentType argumentType, + Codec codec, + T defaultValue, + FeatureSet requiredFeatures, + net.minecraft.world.rule.GameRules.Acceptor acceptor, + ToIntFunction commandResultSupplier + ) { + return Registry.register( + Registries.GAME_RULE, Identifier.of(RedstoneTools.MOD_ID, name), new GameRule<>(category, type, argumentType, acceptor, codec, commandResultSupplier, defaultValue, requiredFeatures) + ); + } +} +//?} diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/BinaryBlockReadFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/BinaryBlockReadFeature.java index a1cd45b4..b41879d8 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/BinaryBlockReadFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/BinaryBlockReadFeature.java @@ -18,6 +18,7 @@ import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; import net.minecraft.util.math.BlockPos; +import tools.redstone.redstonetools.Commands; import tools.redstone.redstonetools.utils.WorldEditUtils; import static net.minecraft.server.command.CommandManager.argument; @@ -32,7 +33,7 @@ protected BinaryBlockReadFeature() { public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { dispatcher.register( literal("/read") - .requires(source -> source.hasPermissionLevel(2)) + .requires(Commands.PERMISSION_LEVEL_2) .executes(getCommandForArgumentCount(0)) .then(argument("offset", IntegerArgumentType.integer(1)) .executes(getCommandForArgumentCount(1)) diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java index ac9fa9be..128b1080 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java @@ -20,6 +20,7 @@ import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; import org.jetbrains.annotations.Nullable; +import tools.redstone.redstonetools.Commands; import tools.redstone.redstonetools.utils.*; import static net.minecraft.server.command.CommandManager.argument; @@ -33,7 +34,7 @@ protected ColorCodeFeature() { public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { dispatcher.register(literal("/colorcode") - .requires(source -> source.hasPermissionLevel(2)) + .requires(Commands.PERMISSION_LEVEL_2) .then(argument("color", StringArgumentType.string()).suggests(ArgumentUtils.BLOCK_COLOR_SUGGESTION_PROVIDER) .executes(this::execute) .then(argument("onlyColor", StringArgumentType.string()).suggests(ArgumentUtils.BLOCK_COLOR_SUGGESTION_PROVIDER) diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/ColoredFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/ColoredFeature.java index ef4a1243..4ba854f1 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/ColoredFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/ColoredFeature.java @@ -8,6 +8,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; +import tools.redstone.redstonetools.Commands; import tools.redstone.redstonetools.utils.ArgumentUtils; import tools.redstone.redstonetools.utils.BlockColor; import tools.redstone.redstonetools.utils.BlockInfo; @@ -21,19 +22,21 @@ protected ColoredFeature() { } public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { - dispatcher.register(CommandManager.literal("colored") - .requires(source -> source.hasPermissionLevel(2)) - .executes(this::execute) - .then(CommandManager.argument("blockType", StringArgumentType.string()).suggests(ArgumentUtils.COLORED_BLOCK_TYPE_SUGGESTION_PROVIDER) - .executes(this::execute))); + dispatcher.register(CommandManager.literal("colored") + .requires(Commands.PERMISSION_LEVEL_2) + .executes(this::execute) + .then(CommandManager.argument("blockType", StringArgumentType.string()).suggests(ArgumentUtils.COLORED_BLOCK_TYPE_SUGGESTION_PROVIDER) + .executes(this::execute))); } public static ColoredBlockType blockType; + @Override protected boolean requiresBlock() { return false; } + @Override protected ItemStack getItemStack(CommandContext context, @Nullable BlockInfo blockInfo) { var color = blockInfo == null ? BlockColor.WHITE diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/CopyStateFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/CopyStateFeature.java index 47834893..5deb1c4b 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/CopyStateFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/CopyStateFeature.java @@ -12,6 +12,7 @@ import net.minecraft.server.command.ServerCommandSource; import net.minecraft.state.property.Property; import net.minecraft.text.Text; +import tools.redstone.redstonetools.Commands; import tools.redstone.redstonetools.mixin.AbstractBlockMixin; import tools.redstone.redstonetools.mixin.features.ServerPlayNetworkHandlerAccessor; import tools.redstone.redstonetools.utils.BlockInfo; @@ -27,7 +28,7 @@ protected CopyStateFeature() { } public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { - dispatcher.register(CommandManager.literal("copystate").requires(source -> source.hasPermissionLevel(2)).executes(this::execute)); + dispatcher.register(CommandManager.literal("copystate").requires(Commands.PERMISSION_LEVEL_2).executes(this::execute)); } @Override diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java index cd8dc50e..f0b733c4 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/GiveMeFeature.java @@ -11,6 +11,7 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; +import tools.redstone.redstonetools.Commands; import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; @@ -24,7 +25,7 @@ protected GiveMeFeature() { public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { dispatcher.register( literal("g") - .requires(source -> source.hasPermissionLevel(2)) + .requires(Commands.PERMISSION_LEVEL_2) .then(argument("item", ItemStackArgumentType.itemStack(registryAccess)) .executes(context -> this.execute( context, diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/ItemBindFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/ItemBindFeature.java index 365ea5aa..55f4e7f3 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/ItemBindFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/ItemBindFeature.java @@ -11,6 +11,7 @@ import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; +import tools.redstone.redstonetools.Commands; import tools.redstone.redstonetools.utils.ItemUtils; import java.util.ArrayList; @@ -26,7 +27,7 @@ protected ItemBindFeature() { public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { dispatcher.register(literal("itembind") - .requires(source -> source.hasPermissionLevel(2)) + .requires(Commands.PERMISSION_LEVEL_2) .executes(this::execute) .then(literal("reset") .executes(ItemBindFeature::executeReset))); diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/ItemComponentsFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/ItemComponentsFeature.java index ae739662..e23b7b9c 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/ItemComponentsFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/ItemComponentsFeature.java @@ -22,6 +22,7 @@ import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; +import tools.redstone.redstonetools.Commands; import java.util.Objects; @@ -36,7 +37,7 @@ protected ItemComponentsFeature() { public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { dispatcher.register( CommandManager.literal("components") - .requires(source -> source.hasPermissionLevel(2)) + .requires(Commands.PERMISSION_LEVEL_2) .executes(context -> components(Objects.requireNonNull(context.getSource().getPlayer()).getMainHandStack(), context.getSource())) .then(CommandManager.argument("target", EntityArgumentType.player()) .executes(context -> components(EntityArgumentType.getPlayer(context, "target").getMainHandStack(), context.getSource())) diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java index 74f216b3..ad73011c 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java @@ -16,6 +16,7 @@ import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; +import tools.redstone.redstonetools.Commands; import tools.redstone.redstonetools.utils.WorldEditUtils; import java.util.ArrayList; @@ -32,7 +33,7 @@ protected MinSelectionFeature() { public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { dispatcher.register(literal("/minsel") - .requires(source -> source.hasPermissionLevel(2)) + .requires(Commands.PERMISSION_LEVEL_2) .executes(this::execute)); } @@ -52,8 +53,10 @@ protected int execute(CommandContext context) throws Comman assert BlockTypes.AIR != null; boolean isEmpty = true; for (BlockVector3 point : selection) { - if (!selectionWorld.getBlock(point).equals(BlockTypes.AIR.getDefaultState())) + if (selectionWorld.getBlock(point).getBlockType() != BlockTypes.AIR) { isEmpty = false; + break; + } } if (isEmpty) { @@ -75,21 +78,14 @@ private void minimiseSelection(World selectionWorld, Region selection) var faces = getFaces(selection); var finished = true; - for (CuboidRegion face : faces) { - var isOnlyAir = true; - + faceLoop: for (CuboidRegion face : faces) { for (BlockVector3 point : face) { assert BlockTypes.AIR != null; - if (selectionWorld.getBlock(point).getBlockType().getDefaultState() != BlockTypes.AIR - .getDefaultState()) { - isOnlyAir = false; - break; + if (selectionWorld.getBlock(point).getBlockType() != BlockTypes.AIR) { + continue faceLoop; } } - if (!isOnlyAir) - continue; - var difference = selection.getCenter().subtract(face.getCenter()); difference = difference.normalize(); diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/QuickTpFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/QuickTpFeature.java index 6cbcce47..5db5f72f 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/QuickTpFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/QuickTpFeature.java @@ -8,12 +8,14 @@ import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.Vec3d; +import tools.redstone.redstonetools.Commands; import tools.redstone.redstonetools.utils.PositionUtils; import tools.redstone.redstonetools.utils.RaycastUtils; @@ -31,7 +33,7 @@ protected QuickTpFeature() { public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { dispatcher.register(literal("quicktp") - .requires(source -> source.hasPermissionLevel(2)) + .requires(Commands.PERMISSION_LEVEL_2) .executes(this::parseArguments) .then(argument("distance", DoubleArgumentType.doubleArg()) .executes(this::parseArguments) @@ -103,7 +105,7 @@ protected static void execute(CommandContext context, doubl player.requestTeleport(targetPosition.x, targetPosition.y, targetPosition.z); if (resetVelocity) player.setVelocity(Vec3d.ZERO); player.fallDistance = 0; - player.velocityModified = true; // guh + player.networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(player)); } finally { quicktpingForPlayer.remove(player); } diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java index 0eca49a5..b3d24f92 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java @@ -24,6 +24,7 @@ import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; import org.jetbrains.annotations.Nullable; +import tools.redstone.redstonetools.Commands; import tools.redstone.redstonetools.utils.ArgumentUtils; import tools.redstone.redstonetools.utils.DirectionArgument; @@ -43,7 +44,7 @@ protected RStackFeature() { public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { dispatcher.register( literal("/rstack") - .requires(source -> source.hasPermissionLevel(2)) + .requires(Commands.PERMISSION_LEVEL_2) .executes(getCommandForArgumentCount(0)) .then(argument("count", IntegerArgumentType.integer()) .executes(getCommandForArgumentCount(1)) diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/ReachFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/ReachFeature.java index ce1e3b0e..07a2a168 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/ReachFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/ReachFeature.java @@ -7,6 +7,7 @@ import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; +import tools.redstone.redstonetools.Commands; public class ReachFeature { public static final ReachFeature INSTANCE = new ReachFeature(); @@ -16,7 +17,7 @@ protected ReachFeature() { public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { dispatcher.register(CommandManager.literal("reach") - .requires(source -> source.hasPermissionLevel(2)) + .requires(Commands.PERMISSION_LEVEL_2) .then(CommandManager.argument("reach", FloatArgumentType.floatArg(0.0f)) .executes(context -> execute(context, true, true)) ) diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/SignalStrengthBlockFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/SignalStrengthBlockFeature.java index 6431a91c..c8e7fb09 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/SignalStrengthBlockFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/SignalStrengthBlockFeature.java @@ -11,6 +11,7 @@ import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; +import tools.redstone.redstonetools.Commands; import tools.redstone.redstonetools.utils.ArgumentUtils; import tools.redstone.redstonetools.utils.SignalBlock; @@ -29,7 +30,7 @@ protected SignalStrengthBlockFeature() { public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { dispatcher.register(literal("ssb") - .requires(source -> source.hasPermissionLevel(2)) + .requires(Commands.PERMISSION_LEVEL_2) .executes(this::parseArguments) .then(argument("signalStrength", IntegerArgumentType.integer()) .executes(this::parseArguments) diff --git a/src/main/java/tools/redstone/redstonetools/features/toggleable/ClickContainerFeature.java b/src/main/java/tools/redstone/redstonetools/features/toggleable/ClickContainerFeature.java index b90fcd40..d828ee2f 100644 --- a/src/main/java/tools/redstone/redstonetools/features/toggleable/ClickContainerFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/toggleable/ClickContainerFeature.java @@ -2,6 +2,7 @@ import com.mojang.brigadier.CommandDispatcher; 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.command.CommandRegistryAccess; @@ -16,6 +17,7 @@ import net.minecraft.util.ActionResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import tools.redstone.redstonetools.RedstoneTools; import static net.minecraft.server.command.CommandManager.literal; @@ -34,8 +36,7 @@ protected ClickContainerFeature() { if (!ClickContainerFeature.INSTANCE.isEnabled((ServerPlayerEntity) player)) return ActionResult.PASS; ItemStack stack = player.getStackInHand(hand); - if (!stack.isEmpty() || - stack.getItem() instanceof BlockItem) return ActionResult.PASS; + if (!stack.isEmpty() || stack.getItem() instanceof BlockItem) return ActionResult.PASS; BlockPos pos = hitResult.getBlockPos(); BlockState state = world.getBlockState(pos); @@ -67,13 +68,13 @@ protected ClickContainerFeature() { }); } - public static void handleIntLevelProperty(World world, BlockPos pos, BlockState state, IntProperty prop, net.minecraft.block.Block resetBlock, ServerPlayerEntity player) { + public static void handleIntLevelProperty(World world, BlockPos pos, BlockState state, IntProperty prop, Block resetBlock, ServerPlayerEntity player) { if (prop == null) return; Integer current; try { current = state.get(prop); } catch (Exception e) { - System.err.println("[ClickContainerFeature] Failed to read property " + prop.getName() + " for block " + state.getBlock() + " at " + pos + ": " + e); + RedstoneTools.LOGGER.error("[ClickContainerFeature] Failed to read property " + prop.getName() + " for block " + state.getBlock() + " at " + pos + ": " + e); return; } if (current == null) return; @@ -92,7 +93,7 @@ public static void handleIntLevelProperty(World world, BlockPos pos, BlockState } public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) { - dispatcher.register(literal("clickcontainers").executes(this::toggle)); + dispatcher.register(literal("clickcontainers").executes(this::toggle)); } @Override diff --git a/src/main/java/tools/redstone/redstonetools/mixin/features/AutoRotateMixin.java b/src/main/java/tools/redstone/redstonetools/mixin/features/AutoRotateMixin.java index 42317d6d..c998360f 100644 --- a/src/main/java/tools/redstone/redstonetools/mixin/features/AutoRotateMixin.java +++ b/src/main/java/tools/redstone/redstonetools/mixin/features/AutoRotateMixin.java @@ -7,11 +7,11 @@ import net.minecraft.item.ItemPlacementContext; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.BlockRotation; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import tools.redstone.redstonetools.features.toggleable.AutoRotateFeature; -import tools.redstone.redstonetools.utils.BlockUtils; @Mixin(BlockItem.class) public abstract class AutoRotateMixin { @@ -32,7 +32,7 @@ private BlockState changeRotation(BlockState original, @Local(argsOnly = true) I if (original == null) return null; BlockState backup = original; - original = BlockUtils.rotate(original); + original = original.rotate(BlockRotation.CLOCKWISE_180); if (this.canPlace(context, original)) return original; diff --git a/src/main/java/tools/redstone/redstonetools/mixin/gamerules/DoContainerDropsMixin.java b/src/main/java/tools/redstone/redstonetools/mixin/gamerules/DoContainerDropsMixin.java index 6485bcae..0235bf23 100644 --- a/src/main/java/tools/redstone/redstonetools/mixin/gamerules/DoContainerDropsMixin.java +++ b/src/main/java/tools/redstone/redstonetools/mixin/gamerules/DoContainerDropsMixin.java @@ -11,11 +11,15 @@ import tools.redstone.redstonetools.RedstoneToolsGameRules; @Mixin(ItemScatterer.class) -public class DoContainerDropsMixin { +public abstract class DoContainerDropsMixin { @Inject(method = "spawn(Lnet/minecraft/world/World;DDDLnet/minecraft/item/ItemStack;)V", at = @At("HEAD"), cancellable = true) private static void preventSpawning(World world, double x, double y, double z, ItemStack stack, CallbackInfo ci) { if (world instanceof ServerWorld serverWorld) { - if (!serverWorld.getGameRules().getBoolean(RedstoneToolsGameRules.DO_CONTAINER_DROPS)) ci.cancel(); + //? if <=1.21.10 { + /*if (!serverWorld.getGameRules().getBoolean(RedstoneToolsGameRules.DO_CONTAINER_DROPS)) ci.cancel(); + *///?} else { + if (!serverWorld.getGameRules().getValue(RedstoneToolsGameRules.DO_CONTAINER_DROPS)) ci.cancel(); + //?} } } } diff --git a/src/main/java/tools/redstone/redstonetools/utils/BlockUtils.java b/src/main/java/tools/redstone/redstonetools/utils/BlockUtils.java deleted file mode 100644 index 7f9dc7f9..00000000 --- a/src/main/java/tools/redstone/redstonetools/utils/BlockUtils.java +++ /dev/null @@ -1,20 +0,0 @@ -package tools.redstone.redstonetools.utils; - -import net.minecraft.block.BlockState; -import net.minecraft.state.property.Properties; -import net.minecraft.util.math.Direction; - -public class BlockUtils { - public static BlockState rotate(BlockState original) { - if (original.contains(Properties.FACING)) - original = original.with(Properties.FACING, original.get(Properties.FACING).getOpposite()); - - if (original.contains(Properties.HORIZONTAL_FACING)) - original = original.with(Properties.HORIZONTAL_FACING, original.get(Properties.HORIZONTAL_FACING).getOpposite()); - - if (original.contains(Properties.HOPPER_FACING)) - if (original.get(Properties.HOPPER_FACING).getOpposite() != Direction.UP) - original = original.with(Properties.HOPPER_FACING, original.get(Properties.HOPPER_FACING).getOpposite()); - return original; - } -} diff --git a/src/main/java/tools/redstone/redstonetools/utils/ItemUtils.java b/src/main/java/tools/redstone/redstonetools/utils/ItemUtils.java index 80758106..d2f8b4b4 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/ItemUtils.java +++ b/src/main/java/tools/redstone/redstonetools/utils/ItemUtils.java @@ -62,7 +62,6 @@ public static void removeCommand(ItemStack stack) { data.remove("command"); stack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(data)); } - System.out.println(stack); } private static NbtCompound getCustomData(ItemStack stack) { diff --git a/src/main/java/tools/redstone/redstonetools/utils/PlayerUtils.java b/src/main/java/tools/redstone/redstonetools/utils/PlayerUtils.java index fd47bef8..888c081e 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/PlayerUtils.java +++ b/src/main/java/tools/redstone/redstonetools/utils/PlayerUtils.java @@ -1,7 +1,6 @@ package tools.redstone.redstonetools.utils; import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.world.World; public class PlayerUtils { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index dc2bc400..9feb17dd 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -35,9 +35,9 @@ } ], "depends": { - "fabricloader": ">=${loader_version}", - "fabric": "*", - "minecraft": ">=1.21.4 <=1.21.10" + "fabricloader": ">=0.18.1", + "fabric-api": "*", + "minecraft": ">=1.21.4 <=1.21.11" }, "recommends": { "worldedit": "*", diff --git a/stonecutter.gradle b/stonecutter.gradle deleted file mode 100644 index 2035f022..00000000 --- a/stonecutter.gradle +++ /dev/null @@ -1,32 +0,0 @@ -plugins { - id "dev.kikugie.stonecutter" - id "me.modmuss50.mod-publish-plugin" version "1.1.0" -} -stonecutter.active "1.21.10" - -version = project.mod_version + "+" + stonecutter.current.version - -publishMods { - if (providers.environmentVariable("RELEASE_MODRINTH").getOrElse("false").toBoolean()) { - if (!providers.environmentVariable("MODRINTH_TOKEN").isPresent() || providers.environmentVariable("MODRINTH_TOKEN").get() == "") { - throw new GradleException('Missing MODRINTH_TOKEN') - } - } - - if (providers.environmentVariable("RELEASE_GITHUB").getOrElse("false").toBoolean()) { - if (!providers.environmentVariable("GITHUB_TOKEN").isPresent() || providers.environmentVariable("GITHUB_TOKEN").get() == "") { - throw new GradleException('Missing GITHUB_TOKEN') - } - - github { - accessToken = providers.environmentVariable("GITHUB_TOKEN") - repository = providers.environmentVariable("GITHUB_REPO") - commitish = "main" - changelog = "" - type = STABLE - tagName = "${project.mod_version}" - displayName = "Redstone Tools ${rootProject.mod_version}" - allowEmptyFiles = true - } - } -} \ No newline at end of file diff --git a/stonecutter.gradle.kts b/stonecutter.gradle.kts new file mode 100644 index 00000000..28337031 --- /dev/null +++ b/stonecutter.gradle.kts @@ -0,0 +1,34 @@ +plugins { + id("dev.kikugie.stonecutter") + id("me.modmuss50.mod-publish-plugin") version "1.1.0" +} +stonecutter.active("1.21.11") + +version = "${project.property("mod_version")}+${stonecutter.current?.version}" + +publishMods { + if (providers.environmentVariable("RELEASE_MODRINTH").orNull?.toBoolean() ?: false) { + val modrinthToken = providers.environmentVariable("MODRINTH_TOKEN") + if (!modrinthToken.isPresent || modrinthToken.get() == "") { + throw GradleException("Missing MODRINTH_TOKEN") + } + } + + if (providers.environmentVariable("RELEASE_GITHUB").orNull?.toBoolean() ?: false) { + val githubToken = providers.environmentVariable("GITHUB_TOKEN") + if (!githubToken.isPresent || githubToken.get() == "") { + throw GradleException("Missing GITHUB_TOKEN") + } + + github { + accessToken = githubToken + repository = providers.environmentVariable("GITHUB_REPO") + commitish = "main" + changelog = "" + type = STABLE + tagName = "${rootProject.property("mod_version")}" + displayName = "Redstone Tools ${rootProject.property("mod_version")}" + allowEmptyFiles = true + } + } +} \ No newline at end of file diff --git a/versions/1.21.10/gradle.properties b/versions/1.21.10/gradle.properties index 6eb23355..d1c86d30 100644 --- a/versions/1.21.10/gradle.properties +++ b/versions/1.21.10/gradle.properties @@ -1,7 +1,7 @@ minecraft_version=1.21.10 minecraft_version_out=1.21.10 -yarn_mappings=1.21.10+build.2 +yarn_mappings=1.21.10+build.3 -fabric_version=0.138.0+1.21.10 -malilib_version=0.26.3 -worldedit_version=1.21.10:7.3.17 +fabric_version=0.138.4+1.21.10 +malilib_version=0.26.8 +worldedit_version=1.21.10:7.4.0-SNAPSHOT diff --git a/versions/1.21.11/gradle.properties b/versions/1.21.11/gradle.properties new file mode 100644 index 00000000..decf2eb2 --- /dev/null +++ b/versions/1.21.11/gradle.properties @@ -0,0 +1,7 @@ +minecraft_version=1.21.11 +minecraft_version_out=1.21.11 +yarn_mappings=1.21.11+build.4 + +fabric_version=0.141.2+1.21.11 +malilib_version=0.27.5 +worldedit_version=1.21.11:7.4.0-SNAPSHOT diff --git a/versions/1.21.4/gradle.properties b/versions/1.21.4/gradle.properties index 6304cc55..a2f00f22 100644 --- a/versions/1.21.4/gradle.properties +++ b/versions/1.21.4/gradle.properties @@ -3,5 +3,5 @@ minecraft_version_out=1.21.4 yarn_mappings=1.21.4+build.8 fabric_version=0.119.4+1.21.4 -malilib_version=0.23.4 +malilib_version=0.23.5 worldedit_version=1.21.4:7.3.11 diff --git a/versions/1.21.5/gradle.properties b/versions/1.21.5/gradle.properties index 07e27ac1..419d70b9 100644 --- a/versions/1.21.5/gradle.properties +++ b/versions/1.21.5/gradle.properties @@ -3,5 +3,5 @@ minecraft_version_out=1.21.5 yarn_mappings=1.21.5+build.1 fabric_version=0.128.2+1.21.5 -malilib_version=0.24.2 +malilib_version=0.24.3 worldedit_version=1.21.5:7.3.14 \ No newline at end of file diff --git a/versions/1.21.8/gradle.properties b/versions/1.21.8/gradle.properties index f92a8366..199c289e 100644 --- a/versions/1.21.8/gradle.properties +++ b/versions/1.21.8/gradle.properties @@ -2,6 +2,6 @@ minecraft_version=1.21.8 minecraft_version_out=1.21.8 yarn_mappings=1.21.8+build.1 -fabric_version=0.136.0+1.21.8 -malilib_version=0.25.5 +fabric_version=0.136.1+1.21.8 +malilib_version=0.25.7 worldedit_version=1.21.7:7.3.16