diff --git a/build.gradle b/build.gradle index a4d3b80..93ce263 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '0.2.2-SNAPSHOT' + id 'fabric-loom' version '0.2.6-SNAPSHOT' id 'maven-publish' } @@ -16,14 +16,11 @@ 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}" + mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" 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. } processResources { diff --git a/gradle.properties b/gradle.properties index c23a5c5..f8295e3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,17 +1,12 @@ # Done to increase the memory available to gradle. 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.15.2 +yarn_mappings=1.15.2+build.14 +loader_version=0.7.8+build.184 # Mod Properties - mod_version = 1.0.3 - maven_group = net.clayborn - archives_base_name = accurate-block-placement - +mod_version=1.0.4 +maven_group=net.clayborn +archives_base_name=accurate-block-placement # 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.4.32+build.292-1.15 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 290541c..8422670 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-6.2-all.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..068c5d0 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 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.minecraft.client.MinecraftClient; 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.network.MessageType; +import net.minecraft.text.Style; +import net.minecraft.text.TranslatableText; +import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; +import org.lwjgl.glfw.GLFW; public class AccurateBlockPlacementMod implements ModInitializer { @@ -50,17 +49,17 @@ public void onInitialize() { { isAccurateBlockPlacementEnabled = !isAccurateBlockPlacementEnabled; - TranslatableComponent message = null; + TranslatableText message = null; if (isAccurateBlockPlacementEnabled) { - message = new TranslatableComponent("net.clayborn.accurateblockplacement.modplacementmodemessage"); + message = new TranslatableText("net.clayborn.accurateblockplacement.modplacementmodemessage"); } else { - message = new TranslatableComponent("net.clayborn.accurateblockplacement.vanillaplacementmodemessage"); + message = new TranslatableText("net.clayborn.accurateblockplacement.vanillaplacementmodemessage"); } - message.setStyle((new Style()).setColor(ChatFormat.DARK_AQUA)); + message.setStyle((new Style()).setColor(Formatting.DARK_AQUA)); - client.inGameHud.addChatMessage(ChatMessageType.SYSTEM, message); + client.inGameHud.addChatMessage(MessageType.SYSTEM, message); } wasAccurateBlockPlacementToggleKeyPressed = true; } else { @@ -68,4 +67,4 @@ public void onInitialize() { } }); } -} \ No newline at end of file +} diff --git a/src/main/java/net/clayborn/accurateblockplacement/mixin/GameRendererMixin.java b/src/main/java/net/clayborn/accurateblockplacement/mixin/GameRendererMixin.java index a03fe05..4ee75c9 100644 --- a/src/main/java/net/clayborn/accurateblockplacement/mixin/GameRendererMixin.java +++ b/src/main/java/net/clayborn/accurateblockplacement/mixin/GameRendererMixin.java @@ -1,13 +1,5 @@ package net.clayborn.accurateblockplacement.mixin; -import java.lang.reflect.Method; -import java.util.ArrayList; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - import net.clayborn.accurateblockplacement.AccurateBlockPlacementMod; import net.clayborn.accurateblockplacement.IKeyBindingAccessor; import net.clayborn.accurateblockplacement.IMinecraftClientAccessor; @@ -16,17 +8,20 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.GameRenderer; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemUsageContext; +import net.minecraft.item.*; 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; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.lang.reflect.Method; +import java.util.ArrayList; @Mixin(GameRenderer.class) public abstract class GameRendererMixin { @@ -206,15 +201,15 @@ 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.keyUse == 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; - Boolean freshKeyPress = keyUseAccessor.accurateblockplacement_GetTimesPressed() > 0; + boolean freshKeyPress = keyUseAccessor.accurateblockplacement_GetTimesPressed() > 0; Item currentItem = getItemInUse(client); @@ -230,9 +225,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; } @@ -249,7 +244,7 @@ private void onUpdateTargetedEntityComplete(CallbackInfo info) { if (!(currentItem instanceof BlockItem)) return; - Boolean isItemUsable = currentItem.isFood() || doesItemHaveOverriddenUseMethod(currentItem) + boolean isItemUsable = currentItem.isFood() || doesItemHaveOverriddenUseMethod(currentItem) || doesItemHaveOverriddenUseOnBlockMethod(currentItem); // if the item we are holding is activatable, let vanilla take over @@ -257,10 +252,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()); @@ -290,20 +285,20 @@ private void onUpdateTargetedEntityComplete(CallbackInfo info) { if (lastPlacedBlockPos != null && lastPlayerPlacedBlockPos != null) { facingAxisPlayerPos = client.player.getPos() - .getComponentAlongAxis(targetPlacement.getFacing().getAxis()); + .getComponentAlongAxis(targetPlacement.getPlayerFacing().getAxis()); facingAxisPlayerLastPos = lastPlayerPlacedBlockPos - .getComponentAlongAxis(targetPlacement.getFacing().getAxis()); + .getComponentAlongAxis(targetPlacement.getPlayerFacing().getAxis()); facingAxisLastPlacedPos = new Vec3d(lastPlacedBlockPos) - .getComponentAlongAxis(targetPlacement.getFacing().getAxis()); + .getComponentAlongAxis(targetPlacement.getPlayerFacing().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: @@ -312,7 +307,7 @@ private void onUpdateTargetedEntityComplete(CallbackInfo info) { // [ we have no 'place' history or the 'place' history isn't a match ] ] OR // [ we have 'place' history, it is a match, the player is building toward // themselves and has moved one block backwards] ] - Boolean isPlacementTargetFresh = ((lastSeenBlockPos == null || !lastSeenBlockPos.equals(blockHitPos)) + boolean isPlacementTargetFresh = ((lastSeenBlockPos == null || !lastSeenBlockPos.equals(blockHitPos)) && (lastPlacedBlockPos == null || !lastPlacedBlockPos.equals(blockHitPos))) || (lastPlacedBlockPos != null && lastPlayerPlacedBlockPos != null && lastPlacedBlockPos.equals(blockHitPos) @@ -320,10 +315,10 @@ private void onUpdateTargetedEntityComplete(CallbackInfo info) { && Math.abs(facingAxisPlayerLastPos - facingAxisLastPlacedPos) < Math .abs(facingAxisPlayerPos - facingAxisLastPlacedPos))); - Boolean hasMouseMoved = (currentMouseRatio != null && lastFreshPressMouseRatio != null + boolean hasMouseMoved = (currentMouseRatio != null && lastFreshPressMouseRatio != null && lastFreshPressMouseRatio.distanceTo(currentMouseRatio) >= 0.1); - Boolean isOnCooldown = autoRepeatWaitingOnCooldown + boolean isOnCooldown = autoRepeatWaitingOnCooldown && clientAccessor.accurateblockplacement_GetItemUseCooldown() > 0 && !hasMouseMoved; // if [ we are still holding the same block we starting pressing 'use' with] AND @@ -339,24 +334,24 @@ 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 // if this isn't a freshkey press, turn on the run once flag - Boolean runOnceFlag = !freshKeyPress; + boolean runOnceFlag = !freshKeyPress; // 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 @@ -375,11 +370,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(new Vec3d(targetPlacement.getPlayerFacing().getVector())); Vec3d newLastPlayerPlacedPos = null; - switch (targetPlacement.getFacing().getAxis()) { + switch (targetPlacement.getPlayerFacing().getAxis()) { case X: newLastPlayerPlacedPos = new Vec3d(summedLastPlayerPos.x, client.player.getPos().y, client.player.getPos().z); @@ -406,7 +401,7 @@ private void onUpdateTargetedEntityComplete(CallbackInfo info) { else if (isPlacementTargetFresh) { // populate the backfill list just in case - backFillList.add(client.hitResult); + backFillList.add(client.crosshairTarget); } }