Skip to content

Commit

Permalink
Fix mistakes
Browse files Browse the repository at this point in the history
It should not pick block if not required
  • Loading branch information
aria1th authored Aug 3, 2022
1 parent 775f454 commit 93b8f82
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package io.github.eatmyvenom.litematicin.mixin.Litematica;

import io.github.eatmyvenom.litematicin.utils.BedrockBreaker;
import io.github.eatmyvenom.litematicin.utils.FakeAccurateBlockPlacement;
import io.github.eatmyvenom.litematicin.utils.ItemInputs;
import io.github.eatmyvenom.litematicin.utils.Printer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
Expand All @@ -16,14 +19,22 @@


@Mixin(MinecraftClient.class)
public class MinecraftClientMixin {
public abstract class MinecraftClientMixin {
@Shadow
public HitResult crosshairTarget;

@Shadow
@Nullable
public ClientWorld world;

@Shadow
@Nullable
public abstract ClientPlayNetworkHandler getNetworkHandler();

@Shadow
@Nullable
public ClientPlayerEntity player;

// On join a new world/server
@Inject(at = @At("HEAD"), method = "joinWorld")
public void joinWorld(ClientWorld world, CallbackInfo ci) {
Expand All @@ -34,6 +45,7 @@ public void joinWorld(ClientWorld world, CallbackInfo ci) {
@Inject(at = @At("HEAD"), method = "tick")
public void onPrinterTickCount(CallbackInfo info) {
BedrockBreaker.tick();
FakeAccurateBlockPlacement.tick(this.getNetworkHandler(), this.player);
}

@Inject(at = @At("HEAD"), method = "doItemUse")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//see https://github.com/senseiwells/EssentialClient/blob/1.19.x/src/main/java/me/senseiwells/essentialclient/feature/BetterAccurateBlockPlacement.java

import io.github.eatmyvenom.litematicin.LitematicaMixinMod;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.block.*;
import net.minecraft.block.enums.BlockHalf;
import net.minecraft.block.enums.WallMountLocation;
Expand Down Expand Up @@ -54,16 +53,6 @@ public static boolean isHandling() {
return requestedTicks >= 0;
}

// should be called every client tick.
static {
ClientTickEvents.END_CLIENT_TICK.register(FakeAccurateBlockPlacement::endtick);
ClientTickEvents.START_CLIENT_TICK.register(FakeAccurateBlockPlacement::starttick);
}

public static boolean getShouldModify() {
return true;
}

public static boolean canHandleOther() {
return currentHandling == null || currentHandling == Items.AIR;
}
Expand All @@ -78,15 +67,10 @@ public static boolean canHandleOther(Item item) {
return currentHandling == item;
}

public static void starttick(MinecraftClient minecraftClient) {
blockPlacedInTick = 0;
}

//I can implement anti-anti cheat, because anti cheats are just checking rotations being too accurate / fast, just interpolating is enough...
//But I won't. Just follow server rules :shrug:
public static void endtick(MinecraftClient minecraftClient) {
ClientPlayNetworkHandler clientPlayNetworkHandler = minecraftClient.getNetworkHandler();
ClientPlayerEntity playerEntity = minecraftClient.player;
public static void tick(ClientPlayNetworkHandler clientPlayNetworkHandler, ClientPlayerEntity playerEntity) {
tickElapsed = 0;
if (playerEntity == null || clientPlayNetworkHandler == null) {
requestedTicks = -3;
Expand All @@ -112,6 +96,7 @@ public static void endtick(MinecraftClient minecraftClient) {
previousFakeYaw = playerEntity.getYaw();
}
requestedTicks = requestedTicks - 1;
blockPlacedInTick = 0;
}

public static void emptyWaitingQueue() {
Expand Down Expand Up @@ -445,7 +430,7 @@ private static boolean placeBlock(BlockPos pos, BlockState blockState) {
appliedHitVec = Vec3d.ofCenter(pos); //follows player looking
}
BlockHitResult blockHitResult = new BlockHitResult(appliedHitVec, side, pos, true);
if (Printer.doSchematicWorldPickBlock(minecraftClient, blockState) && blockState.getBlock().asItem() == currentHandling) {
if (blockState.getBlock().asItem() == currentHandling && Printer.doSchematicWorldPickBlock(minecraftClient, blockState)) {
MessageHolder.sendDebugMessage(player, "Placing " + blockState.getBlock().getTranslationKey() + " at " + pos.toShortString() + " facing : " + fi.dy.masa.malilib.util.BlockUtils.getFirstPropertyFacingValue(blockState));
MessageHolder.sendDebugMessage(player, "Player facing is set to : " + fakeDirection + " Yaw : " + fakeYaw + " Pitch : " + fakePitch + " ticks : " + requestedTicks + " for pos " + pos.toShortString());
interactionManager.interactBlock(player, Hand.MAIN_HAND, blockHitResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ public static ActionResult doPrinterAction(MinecraftClient mc) {
}

if (clickTimes > 0) {
cacheEasyPlacePosition(pos, true, 600);
cacheEasyPlacePosition(pos, true, 3600);
}

} //can place vanilla
Expand Down Expand Up @@ -2039,13 +2039,11 @@ public static boolean isPositionCached(BlockPos pos, boolean useClicked) {
positionCache.remove(i);
--i;
} else if (val.getPos().equals(pos)) {

// Item placement and "using"/"clicking" (changing delay for repeaters) are
// diffferent
if (!useClicked || val.hasClicked) {
cached = true;
}

// Keep checking and removing old entries if there are a fair amount
if (positionCache.size() < 16) {
break;
Expand Down

0 comments on commit 93b8f82

Please sign in to comment.