Skip to content

Commit

Permalink
Merge branch 'merge-placement-and-click' into printing
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksilassila committed Mar 21, 2022
2 parents 85229de + a5169ff commit 81b1d02
Show file tree
Hide file tree
Showing 12 changed files with 891 additions and 596 deletions.
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version=1.18.1
yarn_mappings=1.18.1+build.14
loader_version=0.12.12
minecraft_version=1.18.2
yarn_mappings=1.18.2+build.2
loader_version=0.13.3

# Mod Properties
mod_version = 2.2
maven_group = net.fabricmc
archives_base_name = litematica-printer

malilib_version = 1.18.0:0.10.0-dev.26
litematica_fileid=3545947
malilib_version = 1.18.2:0.12.0
litematica_fileid=3692244
litematica_projectid=308892

# Dependencies
fabric_version=0.45.0+1.18
fabric_version=0.48.0+1.18.2
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class LitematicaMixinMod implements ModInitializer {
public static final ConfigBoolean PRINT_MODE = new ConfigBoolean("printingMode", false, "Autobuild / print loaded selection.\nBe aware that some servers and anticheat plugins do not allow printing.");
public static final ConfigBoolean REPLACE_FLUIDS = new ConfigBoolean("replaceFluids", false, "Whether or not fluid source blocks should be replaced by the printer.");
public static final ConfigBoolean STRIP_LOGS = new ConfigBoolean("stripLogs", false, "Whether or not the printer should use normal logs if stripped\nversions are not available and then strip them with an axe.");
public static boolean shouldPrintInAir = PRINT_IN_AIR.getBooleanValue();

public static ImmutableList<IConfigBase> getConfigList() {
List<IConfigBase> list = new java.util.ArrayList<>(Configs.Generic.OPTIONS);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package me.aleksilassila.litematica.printer.interfaces;

import me.aleksilassila.litematica.printer.mixin.PlayerMoveC2SPacketAccessor;
import me.aleksilassila.litematica.printer.printer.PlacementGuide;
import me.aleksilassila.litematica.printer.printer.Printer;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.MappingResolver;
import net.minecraft.block.*;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.player.PlayerAbilities;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.network.Packet;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.util.math.Direction;
Expand All @@ -19,6 +24,15 @@
* be the only file that has to be changed in every printer branch.
*/
public class Implementation {
public static final Item[] HOES = {Items.DIAMOND_HOE, Items.IRON_HOE, Items.GOLDEN_HOE,
Items.NETHERITE_HOE, Items.STONE_HOE, Items.WOODEN_HOE};

public static final Item[] SHOVELS = {Items.DIAMOND_SHOVEL, Items.IRON_SHOVEL, Items.GOLDEN_SHOVEL,
Items.NETHERITE_SHOVEL, Items.STONE_SHOVEL, Items.WOODEN_SHOVEL};

public static final Item[] AXES = {Items.DIAMOND_AXE, Items.IRON_AXE, Items.GOLDEN_AXE,
Items.NETHERITE_AXE, Items.STONE_AXE, Items.WOODEN_AXE};

public static PlayerInventory getInventory(ClientPlayerEntity playerEntity) {
return playerEntity.getInventory();
}
Expand Down Expand Up @@ -50,11 +64,11 @@ public static boolean isLookAndMovePacket(Packet<?> packet) {
return packet instanceof PlayerMoveC2SPacket.Full;
}

public static Packet<?> getFixedLookPacket(ClientPlayerEntity playerEntity, Packet<?> packet) {
if (Printer.Queue.playerShouldBeFacing == null) return packet;
public static Packet<?> getFixedLookPacket(ClientPlayerEntity playerEntity, Packet<?> packet, Direction direction) {
if (direction == null) return packet;

float yaw = Implementation.getRequiredYaw(playerEntity, Printer.Queue.playerShouldBeFacing);
float pitch = Implementation.getRequiredPitch(playerEntity, Printer.Queue.playerShouldBeFacing);
float yaw = Implementation.getRequiredYaw(playerEntity, direction);
float pitch = Implementation.getRequiredPitch(playerEntity, direction);

double x = ((PlayerMoveC2SPacketAccessor) packet).getX();
double y = ((PlayerMoveC2SPacketAccessor) packet).getY();
Expand All @@ -81,16 +95,43 @@ protected static float getRequiredPitch(ClientPlayerEntity playerEntity, Directi
}
}

public static boolean isInteractable(Block block) {
MappingResolver resolver = FabricLoader.getInstance().getMappingResolver();

// try {
// return block.getClass().getMethod(resolver.unmapClassName("intermediary", AbstractBlock.class.getName()))
// .getDeclaringClass().equals(AbstractBlock.class);
// } catch (NoSuchMethodException ignored) {
// return false;
// }

for (Class<?> clazz : interactableBlocks) {
if (clazz.isInstance(block)) {
return true;
}
}

return false;
}

public enum NewBlocks {
LICHEN(AbstractLichenBlock.class),
ROD(RodBlock.class),
CANDLES(CandleBlock.class),
AMETHYST(AmethystClusterBlock.class);

public Class<?> clazz;
public final Class<?> clazz;

NewBlocks(Class<?> clazz) {
this.clazz = clazz;
}
}

public static Class<?>[] interactableBlocks = {
ChestBlock.class, AbstractFurnaceBlock.class, CraftingTableBlock.class,
AbstractButtonBlock.class, LeverBlock.class, DoorBlock.class, TrapdoorBlock.class,
BedBlock.class, RedstoneWireBlock.class,
};


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.Packet;
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
import net.minecraft.util.math.Direction;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -20,13 +22,20 @@ public class ClientPlayNetworkHandlerMixin {

@Overwrite
public void sendPacket(Packet<?> packet) {
if (Implementation.isLookAndMovePacket(packet) && Printer.shouldBlockLookPackets()) {
Packet<?> fixedPacket = Implementation.getFixedLookPacket(client.player, packet);
if (Printer.getPrinter() == null) {
this.connection.send(packet);
return;
}

Direction direction = Printer.getPrinter().queue.lookDir;

if (direction != null && Implementation.isLookAndMovePacket(packet)) {
Packet<?> fixedPacket = Implementation.getFixedLookPacket(client.player, packet, direction);

if (fixedPacket != null) {
this.connection.send(fixedPacket);
}
} else if (!(Implementation.isLookOnlyPacket(packet) && Printer.shouldBlockLookPackets())) {
} else if (direction == null || !Implementation.isLookOnlyPacket(packet)) {
this.connection.send(packet);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ public MixinClientPlayerEntity(ClientWorld world, GameProfile profile) {

@Inject(at = @At("HEAD"), method = "tick")
public void tick(CallbackInfo ci) {
if (!(this.world.isPosLoaded(this.getBlockX(), this.getBlockZ())))
return;

if (!didCheckForUpdates) {
didCheckForUpdates = true;

checkForUpdates();
}

if (printer == null) {
if (client != null && client.player != null && client.world != null) {
printer = new Printer(client, client.player, client.world);
}

printer = Printer.init(client);
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package me.aleksilassila.litematica.printer.mixin;

import me.aleksilassila.litematica.printer.interfaces.IClientPlayerInteractionManager;
import me.aleksilassila.litematica.printer.printer.PlacementGuide;
import me.aleksilassila.litematica.printer.printer.Printer;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.MappingResolver;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerInteractionManager;
Expand All @@ -19,6 +25,8 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.lang.reflect.Method;

@Mixin(ClientPlayerInteractionManager.class)
public abstract class MixinClientPlayerInteractionManager implements IClientPlayerInteractionManager {
@Shadow
Expand All @@ -45,5 +53,11 @@ public abstract ActionResult interactItem(PlayerEntity playerEntity_1,
// @Inject(at = @At("HEAD"), method = "interactBlock")
// public void interactBlock(ClientPlayerEntity player, ClientWorld world, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable<ActionResult> cir) {
// System.out.println("Player interactBlock: pos: (" + hitResult.getBlockPos().toShortString() + "), side: " + hitResult.getSide().getName() + ", vector: " + hitResult.getPos().toString());
// PlacementGuide.Action a = Printer.getPrinter().guide.getAction(hitResult.getBlockPos());
// for (Direction side : a.getSides().keySet()) {
// System.out.println("Side: " + side + ", " + a.getSides().get(side).toString());
// }
// System.out.println("Valid: " + a.getValidSide(world, hitResult.getBlockPos()));
// System.out.println("Look: " + a.getLookDirection());
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public interface PlayerMoveC2SPacketAccessor {
@Accessor("z")
public double getZ();

@Accessor("yaw")
public float getYaw();

@Accessor("onGround")
public boolean getOnGround();

Expand Down

This file was deleted.

Loading

0 comments on commit 81b1d02

Please sign in to comment.