diff --git a/v1_19_4/src/main/java/me/aleksilassila/litematica/printer/v1_19_4/implementation/PrinterPlacementContext.java b/v1_19_4/src/main/java/me/aleksilassila/litematica/printer/v1_19_4/implementation/PrinterPlacementContext.java new file mode 100644 index 000000000..7a9ca7b5a --- /dev/null +++ b/v1_19_4/src/main/java/me/aleksilassila/litematica/printer/v1_19_4/implementation/PrinterPlacementContext.java @@ -0,0 +1,59 @@ +package me.aleksilassila.litematica.printer.v1_19_4.implementation; + +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.Direction; +import org.jetbrains.annotations.Nullable; + +public class PrinterPlacementContext extends ItemPlacementContext { + public final @Nullable Direction lookDirection; + public final boolean shouldSneak; + public final BlockHitResult hitResult; + public final int requiredItemSlot; + + public PrinterPlacementContext(PlayerEntity player, BlockHitResult hitResult, ItemStack requiredItem, int requiredItemSlot) { + this(player, hitResult, requiredItem, requiredItemSlot, null, false); + } + + public PrinterPlacementContext(PlayerEntity player, BlockHitResult hitResult, ItemStack requiredItem, int requiredItemSlot, @Nullable Direction lookDirection, boolean requiresSneaking) { + super(player, Hand.MAIN_HAND, requiredItem, hitResult); + + this.lookDirection = lookDirection; + this.shouldSneak = requiresSneaking; + this.hitResult = hitResult; + this.requiredItemSlot = requiredItemSlot; + } + + @Override + public Direction getPlayerLookDirection() { + return lookDirection == null ? super.getPlayerLookDirection() : lookDirection; + } + + @Override + public Direction getVerticalPlayerLookDirection() { + if (lookDirection != null && lookDirection.getOpposite() == super.getVerticalPlayerLookDirection()) + return lookDirection; + return super.getVerticalPlayerLookDirection(); + } + + @Override + public Direction getHorizontalPlayerFacing() { + if (lookDirection == null || !lookDirection.getAxis().isHorizontal()) return super.getHorizontalPlayerFacing(); + + return lookDirection; + } + + @Override + public String toString() { + return "PrinterPlacementContext{" + + "lookDirection=" + lookDirection + + ", requiresSneaking=" + shouldSneak + + ", blockPos=" + hitResult.getBlockPos() + + ", side=" + hitResult.getSide() + +// ", hitVec=" + hitResult + + '}'; + } +} diff --git a/v1_19_4/src/main/java/me/aleksilassila/litematica/printer/v1_19_4/implementation/actions/InteractActionImpl.java b/v1_19_4/src/main/java/me/aleksilassila/litematica/printer/v1_19_4/implementation/actions/InteractActionImpl.java index 97d4fa3b2..ffddbc979 100644 --- a/v1_19_4/src/main/java/me/aleksilassila/litematica/printer/v1_19_4/implementation/actions/InteractActionImpl.java +++ b/v1_19_4/src/main/java/me/aleksilassila/litematica/printer/v1_19_4/implementation/actions/InteractActionImpl.java @@ -1,6 +1,6 @@ package me.aleksilassila.litematica.printer.v1_19_4.implementation.actions; -import me.aleksilassila.litematica.printer.v1_19_4.PrinterPlacementContext; +import me.aleksilassila.litematica.printer.v1_19_4.implementation.PrinterPlacementContext; import me.aleksilassila.litematica.printer.v1_19_4.actions.InteractAction; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity;