diff --git a/README.md b/README.md index 14293f0..b75299c 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,7 @@ A simple fabric mod for minecraft which causes players to place a blocks based on what they are looking at rather than a timer. See https://minecraft.curseforge.com/projects/accurate-block-placement for releases. + +# Wyne10's note + +The latest version of this mod on github is 1.14.2 and the latest version on curseforge is 1.19.3. Author made some updates but didn't upload them to github, so i had to update 1.14.2 version to 1.20. It looks like in this version you have to hold shift button to make mod work, so keep that in mind! diff --git a/build.gradle b/build.gradle index a4d3b80..76e02b5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,80 +1,40 @@ plugins { - id 'fabric-loom' version '0.2.2-SNAPSHOT' - id 'maven-publish' + id 'fabric-loom' version '1.2-SNAPSHOT' } -sourceCompatibility = JavaVersion.VERSION_1_8 -targetCompatibility = JavaVersion.VERSION_1_8 - -archivesBaseName = project.archives_base_name version = project.mod_version group = project.maven_group -minecraft { -} - dependencies { - //to change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings "net.fabricmc:yarn:${project.yarn_mappings}" - modCompile "net.fabricmc:fabric-loader:${project.loader_version}" - - // Fabric API. This is technically optional, but you probably want it anyway. - modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - - // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. - // You may need to force-disable transitiveness on them. + modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" } processResources { inputs.property "version", project.version + filteringCharset "UTF-8" - from(sourceSets.main.resources.srcDirs) { - include "fabric.mod.json" + filesMatching("fabric.mod.json") { expand "version": project.version } - - from(sourceSets.main.resources.srcDirs) { - exclude "fabric.mod.json" - } } -// 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 -tasks.withType(JavaCompile) { - options.encoding = "UTF-8" +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" + it.options.release = 17 } -// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task -// if it is present. -// If you remove this task, sources will not be generated. -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = "sources" - from sourceSets.main.allSource +java { + archivesBaseName = project.archives_base_name + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + withSourcesJar() } jar { - from "LICENSE" -} - -// configure the maven publication -publishing { - publications { - mavenJava(MavenPublication) { - // add all the jars that should be included when publishing to maven - artifact(jar) { - builtBy remapJar - } - artifact(sourcesJar) { - builtBy remapSourcesJar - } - } + from("LICENSE") { + rename { "${it}_${project.archivesBaseName}" } } - - // select the repositories you want to publish to - repositories { - // uncomment to publish to the local maven - // mavenLocal() - } -} +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index c23a5c5..556c492 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,9 +3,9 @@ org.gradle.jvmargs=-Xmx3G # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=1.14.2 - yarn_mappings=1.14.2+build.1 - loader_version=0.4.8+build.154 + minecraft_version=1.20 + yarn_mappings=1.20+build.1 + loader_version=0.14.21 # Mod Properties mod_version = 1.0.3 @@ -14,4 +14,4 @@ org.gradle.jvmargs=-Xmx3G # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric - fabric_version=0.3.0+build.170 + fabric_version=0.83.0+1.20 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 290541c..fae0804 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/net/clayborn/accurateblockplacement/AccurateBlockPlacementMod.java b/src/main/java/net/clayborn/accurateblockplacement/AccurateBlockPlacementMod.java index 1e2742a..9fc23e7 100644 --- a/src/main/java/net/clayborn/accurateblockplacement/AccurateBlockPlacementMod.java +++ b/src/main/java/net/clayborn/accurateblockplacement/AccurateBlockPlacementMod.java @@ -1,18 +1,17 @@ package net.clayborn.accurateblockplacement; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.minecraft.text.MutableText; +import net.minecraft.text.Style; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; import org.lwjgl.glfw.GLFW; import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; -import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry; -import net.fabricmc.fabric.api.event.client.ClientTickCallback; -import net.minecraft.ChatFormat; +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.option.KeyBinding; import net.minecraft.client.util.InputUtil; -import net.minecraft.network.chat.ChatMessageType; -import net.minecraft.network.chat.Style; -import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.util.Identifier; public class AccurateBlockPlacementMod implements ModInitializer { @@ -20,7 +19,7 @@ public class AccurateBlockPlacementMod implements ModInitializer { public static Boolean disableNormalItemUse = false; public static boolean isAccurateBlockPlacementEnabled = true; - private static FabricKeyBinding keyBinding; + private static KeyBinding keyBinding; private static boolean wasAccurateBlockPlacementToggleKeyPressed = false; @@ -29,17 +28,14 @@ public class AccurateBlockPlacementMod implements ModInitializer { @Override public void onInitialize() { - keyBinding = FabricKeyBinding.Builder.create( - new Identifier("accurateblockplacement", "togglevanillaplacement"), + keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding( + "key.accurateblockplacement.togglevanillaplacement", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_UNKNOWN, KEY_CATEGORY_NAME - ).build(); - - KeyBindingRegistry.INSTANCE.addCategory(KEY_CATEGORY_NAME); - KeyBindingRegistry.INSTANCE.register(keyBinding); + )); - ClientTickCallback.EVENT.register(e -> + ClientTickEvents.END_CLIENT_TICK.register(e -> { MinecraftClient client = MinecraftClient.getInstance(); if (client == null || client.inGameHud == null) return; @@ -50,17 +46,17 @@ public void onInitialize() { { isAccurateBlockPlacementEnabled = !isAccurateBlockPlacementEnabled; - TranslatableComponent message = null; + MutableText message = null; if (isAccurateBlockPlacementEnabled) { - message = new TranslatableComponent("net.clayborn.accurateblockplacement.modplacementmodemessage"); + message = Text.translatable("net.clayborn.accurateblockplacement.modplacementmodemessage"); } else { - message = new TranslatableComponent("net.clayborn.accurateblockplacement.vanillaplacementmodemessage"); + message = Text.translatable("net.clayborn.accurateblockplacement.vanillaplacementmodemessage"); } - message.setStyle((new Style()).setColor(ChatFormat.DARK_AQUA)); + message.setStyle( Style.EMPTY.withColor(Formatting.DARK_AQUA)); - client.inGameHud.addChatMessage(ChatMessageType.SYSTEM, message); + client.inGameHud.getChatHud().addMessage(message); } wasAccurateBlockPlacementToggleKeyPressed = true; } else { diff --git a/src/main/java/net/clayborn/accurateblockplacement/mixin/GameRendererMixin.java b/src/main/java/net/clayborn/accurateblockplacement/mixin/GameRendererMixin.java index a03fe05..ab02160 100644 --- a/src/main/java/net/clayborn/accurateblockplacement/mixin/GameRendererMixin.java +++ b/src/main/java/net/clayborn/accurateblockplacement/mixin/GameRendererMixin.java @@ -3,6 +3,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; +import net.minecraft.util.hit.HitResult; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -23,7 +24,6 @@ import net.minecraft.item.ItemUsageContext; import net.minecraft.util.Hand; 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 net.minecraft.world.World; @@ -206,14 +206,14 @@ private void onUpdateTargetedEntityComplete(CallbackInfo info) { MinecraftClient client = MinecraftClient.getInstance(); // safety checks - if (client == null || client.options == null || client.options.keyUse == null || client.hitResult == null - || client.player == null || client.world == null || client.mouse == null || client.window == null) { + if (client == null || client.options == null || client.options.useKey == null || client.crosshairTarget == null + || client.player == null || client.world == null || client.mouse == null || client.getWindow() == null) { return; } // will be set to true only if needed AccurateBlockPlacementMod.disableNormalItemUse = false; - IKeyBindingAccessor keyUseAccessor = (IKeyBindingAccessor) (Object) client.options.keyUse; + IKeyBindingAccessor keyUseAccessor = (IKeyBindingAccessor) (Object) client.options.useKey; Boolean freshKeyPress = keyUseAccessor.accurateblockplacement_GetTimesPressed() > 0; Item currentItem = getItemInUse(client); @@ -230,9 +230,9 @@ private void onUpdateTargetedEntityComplete(CallbackInfo info) { autoRepeatWaitingOnCooldown = true; backFillList.clear(); - if (client.window.getWidth() > 0 && client.window.getHeight() > 0) { - lastFreshPressMouseRatio = new Vec3d(client.mouse.getX() / client.window.getWidth(), - client.mouse.getY() / client.window.getHeight(), 0); + if (client.getWindow().getWidth() > 0 && client.getWindow().getHeight() > 0) { + lastFreshPressMouseRatio = new Vec3d(client.mouse.getX() / client.getWindow().getWidth(), + client.mouse.getY() / client.getWindow().getHeight(), 0); } else { lastFreshPressMouseRatio = null; } @@ -257,10 +257,10 @@ private void onUpdateTargetedEntityComplete(CallbackInfo info) { return; // if we aren't looking a block (so we can place), let vanilla take over - if (client.hitResult.getType() != HitResult.Type.BLOCK) + if (client.crosshairTarget.getType() != HitResult.Type.BLOCK) return; - BlockHitResult blockHitResult = (BlockHitResult) client.hitResult; + BlockHitResult blockHitResult = (BlockHitResult) client.crosshairTarget; BlockPos blockHitPos = blockHitResult.getBlockPos(); Boolean isTargetBlockActivatable = doesBlockHaveOverriddenActivateMethod( client.world.getBlockState(blockHitPos).getBlock()); @@ -273,7 +273,7 @@ private void onUpdateTargetedEntityComplete(CallbackInfo info) { // are they holding the use key and is the item to use a block? // also is the the SAME item we started with if we are in repeat mode? // note: check both freshKey and current state in cause of shitty frame rates - if ((freshKeyPress || client.options.keyUse.isPressed())) { + if ((freshKeyPress || client.options.useKey.isPressed())) { // it's a block!! it's go time! AccurateBlockPlacementMod.disableNormalItemUse = true; @@ -290,20 +290,20 @@ private void onUpdateTargetedEntityComplete(CallbackInfo info) { if (lastPlacedBlockPos != null && lastPlayerPlacedBlockPos != null) { facingAxisPlayerPos = client.player.getPos() - .getComponentAlongAxis(targetPlacement.getFacing().getAxis()); + .getComponentAlongAxis(targetPlacement.getSide().getAxis()); facingAxisPlayerLastPos = lastPlayerPlacedBlockPos - .getComponentAlongAxis(targetPlacement.getFacing().getAxis()); - facingAxisLastPlacedPos = new Vec3d(lastPlacedBlockPos) - .getComponentAlongAxis(targetPlacement.getFacing().getAxis()); + .getComponentAlongAxis(targetPlacement.getSide().getAxis()); + facingAxisLastPlacedPos = Vec3d.of(lastPlacedBlockPos) + .getComponentAlongAxis(targetPlacement.getSide().getAxis()); } IMinecraftClientAccessor clientAccessor = (IMinecraftClientAccessor) client; Vec3d currentMouseRatio = null; - if (client.window.getWidth() > 0 && client.window.getHeight() > 0) { - currentMouseRatio = new Vec3d(client.mouse.getX() / client.window.getWidth(), - client.mouse.getY() / client.window.getHeight(), 0); + if (client.getWindow().getWidth() > 0 && client.getWindow().getHeight() > 0) { + currentMouseRatio = new Vec3d(client.mouse.getX() / client.getWindow().getWidth(), + client.mouse.getY() / client.getWindow().getHeight(), 0); } // Condition: @@ -339,19 +339,19 @@ private void onUpdateTargetedEntityComplete(CallbackInfo info) { if (autoRepeatWaitingOnCooldown && !freshKeyPress) { autoRepeatWaitingOnCooldown = false; - HitResult currentHitResult = client.hitResult; + HitResult currentHitResult = client.crosshairTarget; // try to place the backlog for (HitResult prevHitResult : backFillList) { - client.hitResult = prevHitResult; + client.crosshairTarget = prevHitResult; // use item clientAccessor.accurateblockplacement_DoItemUseBypassDisable(); } backFillList.clear(); - client.hitResult = currentHitResult; + client.crosshairTarget = currentHitResult; } // always run at least once if we reach here @@ -361,7 +361,7 @@ private void onUpdateTargetedEntityComplete(CallbackInfo info) { // in case they manage to push the button multiple times per frame // note: we already subtracted one from the press count earlier so the total // should be the same - while (runOnceFlag || client.options.keyUse.wasPressed()) { + while (runOnceFlag || client.options.useKey.wasPressed()) { // use item clientAccessor.accurateblockplacement_DoItemUseBypassDisable(); @@ -375,11 +375,11 @@ private void onUpdateTargetedEntityComplete(CallbackInfo info) { } else { // prevent slow rounding error from eventually moving the player out of range Vec3d summedLastPlayerPos = lastPlayerPlacedBlockPos - .add(new Vec3d(targetPlacement.getFacing().getVector())); + .add(Vec3d.of(targetPlacement.getSide().getVector())); Vec3d newLastPlayerPlacedPos = null; - switch (targetPlacement.getFacing().getAxis()) { + switch (targetPlacement.getSide().getAxis()) { case X: newLastPlayerPlacedPos = new Vec3d(summedLastPlayerPos.x, client.player.getPos().y, client.player.getPos().z); @@ -406,7 +406,7 @@ private void onUpdateTargetedEntityComplete(CallbackInfo info) { else if (isPlacementTargetFresh) { // populate the backfill list just in case - backFillList.add(client.hitResult); + backFillList.add(client.crosshairTarget); } } diff --git a/src/main/java/net/clayborn/accurateblockplacement/mixin/KeyBindingMixin.java b/src/main/java/net/clayborn/accurateblockplacement/mixin/KeyBindingMixin.java index 93f8393..32766d6 100644 --- a/src/main/java/net/clayborn/accurateblockplacement/mixin/KeyBindingMixin.java +++ b/src/main/java/net/clayborn/accurateblockplacement/mixin/KeyBindingMixin.java @@ -4,7 +4,7 @@ import org.spongepowered.asm.mixin.Shadow; import net.clayborn.accurateblockplacement.IKeyBindingAccessor; -import net.minecraft.client.options.KeyBinding; +import net.minecraft.client.option.KeyBinding; @Mixin(KeyBinding.class) public abstract class KeyBindingMixin implements IKeyBindingAccessor { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 9635696..fc8c0fc 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -30,7 +30,8 @@ ], "depends": { - "fabricloader": ">=0.4.0", - "fabric": "*" + "fabricloader": ">=0.14.21", + "fabric": "*", + "minecraft": ">=1.20" } }