Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
72 changes: 16 additions & 56 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
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 {

// global state
public static Boolean disableNormalItemUse = false;
public static boolean isAccurateBlockPlacementEnabled = true;

private static FabricKeyBinding keyBinding;
private static KeyBinding keyBinding;

private static boolean wasAccurateBlockPlacementToggleKeyPressed = false;

Expand All @@ -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;
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -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());
Expand All @@ -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;
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
],

"depends": {
"fabricloader": ">=0.4.0",
"fabric": "*"
"fabricloader": ">=0.14.21",
"fabric": "*",
"minecraft": ">=1.20"
}
}