From 23c280f210585aaf80c83fb89b959489de757c03 Mon Sep 17 00:00:00 2001 From: winterflyt <36+winterflyt@noreply.skidsolutions.xyz> Date: Mon, 30 Nov 2026 06:02:30 +0200 Subject: [PATCH] Upload files to "src/openonyx/interaction" --- src/openonyx/interaction/BlockUtils.java | 140 +++++++++++++++++++++++ src/openonyx/interaction/SwingMode.java | 66 +++++++++++ 2 files changed, 206 insertions(+) create mode 100644 src/openonyx/interaction/BlockUtils.java create mode 100644 src/openonyx/interaction/SwingMode.java diff --git a/src/openonyx/interaction/BlockUtils.java b/src/openonyx/interaction/BlockUtils.java new file mode 100644 index 0000000..61fbffc --- /dev/null +++ b/src/openonyx/interaction/BlockUtils.java @@ -0,0 +1,140 @@ +package openonyx.interaction; + +import java.util.function.BooleanSupplier; +import net.minecraft.block.Block; +import net.minecraft.block.BlockSlab; +import net.minecraft.block.BlockStairs; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.BlockPos; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.world.World; +import openonyx.core.MinecraftAccess; +import openonyx.utilities.HotbarManager; + +public class BlockUtils implements MinecraftAccess { + public static final AxisAlignedBB AXIS_ALIGNED_BB = new AxisAlignedBB(0.0, 0.0, 0.0, 1.0, 1.0, 1.0); + + public static boolean L(MovingObjectPosition movingObjectPosition) { + MovingObjectPosition movingObjectPosition1 = movingObjectPosition; + ItemStack itemStack; + int i = (itemStack = mc.thePlayer.inventory.getStackInSlot(HotbarManager.INSTANCE.L())) == null ? 0 : itemStack.stackSize; + if (!mc.playerController + .onPlayerRightClick( + mc.thePlayer, mc.theWorld, itemStack, movingObjectPosition1.getBlockPos(), movingObjectPosition1.sideHit, movingObjectPosition1.hitVec + )) { + return false; + } + + if (itemStack != null && itemStack.stackSize == 0) { + mc.thePlayer.inventory.mainInventory[HotbarManager.INSTANCE.L()] = null; + } else if (itemStack != null && (itemStack.stackSize != i || mc.playerController.isInCreativeMode())) { + mc.entityRenderer.itemRenderer.resetEquippedProgress(); + } + + return true; + } + + public static AxisAlignedBB L(IBlockState iBlockState, BlockPos blockPos) { + IBlockState iBlockState1 = iBlockState; + Block block; + (block = iBlockState1.getBlock()).setBlockBoundsBasedOnState(mc.theWorld, blockPos); + AxisAlignedBB axisAlignedBB; + boolean bl = (axisAlignedBB = new AxisAlignedBB( + block.getBlockBoundsMinX(), + block.getBlockBoundsMinY(), + block.getBlockBoundsMinZ(), + block.getBlockBoundsMaxX(), + block.getBlockBoundsMaxY(), + block.getBlockBoundsMaxZ() + )) + .getXsize() + <= 0.0 + || axisAlignedBB.getYsize() <= 0.0 + || axisAlignedBB.getZsize() <= 0.0; + return bl ? AXIS_ALIGNED_BB : axisAlignedBB; + } + + public static BlockPos L(MovingObjectPosition movingObjectPosition) { + return movingObjectPosition.getBlockPos().offset(movingObjectPosition.sideHit); + } + + public static Block L(BlockPos blockPos) { + BlockPos blockPos1 = blockPos; + IBlockState iBlockState; + return (iBlockState = L(blockPos1)) == null ? null : iBlockState.getBlock(); + } + + public static boolean d(BlockPos blockPos) { + BlockPos blockPos1 = blockPos; + Block block; + return (block = L(blockPos1)) == null || block.getMaterial() == Material.air; + } + + public static IBlockState d(BlockPos blockPos) { + BlockPos blockPos1 = blockPos; + IBlockState iBlockState; + return (iBlockState = L(blockPos1)) != null ? iBlockState : Blocks.air.getDefaultState(); + } + + public static void L(MovingObjectPosition movingObjectPosition) { + L(movingObjectPosition, () -> true, () -> true, SwingMode.DO_NOT_HIDE); + } + + public static boolean L(IBlockState iBlockState, BlockPos blockPos, ItemStack itemStack) { + return iBlockState.getBlock().isReplaceable(mc.theWorld, blockPos); + } + + public static IBlockState L(BlockPos blockPos) { + return mc.theWorld == null ? null : mc.theWorld.getBlockState(blockPos); + } + + public static void L(MovingObjectPosition movingObjectPosition, BooleanSupplier booleanSupplier, BooleanSupplier booleanSupplier1, SwingMode swingMode) { + MovingObjectPosition movingObjectPosition1 = movingObjectPosition; + ItemStack itemStack; + int i = (itemStack = mc.thePlayer.inventory.getStackInSlot(HotbarManager.INSTANCE.L())) == null ? 0 : itemStack.stackSize; + if (!mc.playerController + .onPlayerRightClick( + mc.thePlayer, mc.theWorld, itemStack, movingObjectPosition1.getBlockPos(), movingObjectPosition1.sideHit, movingObjectPosition1.hitVec + )) { + if (itemStack != null) { + if (mc.playerController.sendUseItem(mc.thePlayer, mc.theWorld, itemStack)) { + if (booleanSupplier1.getAsBoolean()) { + swingMode.L(); + } + + mc.entityRenderer.itemRenderer.resetEquippedProgress2(); + } + } + } else { + if (booleanSupplier.getAsBoolean()) { + swingMode.L(); + } + + if (itemStack != null && itemStack.stackSize == 0) { + mc.thePlayer.inventory.mainInventory[HotbarManager.INSTANCE.L()] = null; + } else { + if (itemStack != null && (itemStack.stackSize != i || mc.playerController.isInCreativeMode())) { + mc.entityRenderer.itemRenderer.resetEquippedProgress(); + } + } + } + } + + public static AxisAlignedBB L(BlockPos blockPos) { + BlockPos blockPos1 = blockPos; + IBlockState iBlockState; + return (iBlockState = L(blockPos1)) != null && iBlockState.getBlock().getMaterial() != Material.air ? L(iBlockState, blockPos1) : AXIS_ALIGNED_BB; + } + + public static boolean L(Block block) { + return block instanceof BlockSlab || block instanceof BlockStairs; + } + + public static boolean L(BlockPos blockPos) { + return L(blockPos) != null && World.doesBlockHaveSolidTopSurface(mc.theWorld, blockPos); + } +} diff --git a/src/openonyx/interaction/SwingMode.java b/src/openonyx/interaction/SwingMode.java new file mode 100644 index 0000000..0f3e886 --- /dev/null +++ b/src/openonyx/interaction/SwingMode.java @@ -0,0 +1,66 @@ +package openonyx.interaction; + +import net.minecraft.network.play.client.C0APacketAnimation; +import openonyx.core.MinecraftAccess; +import openonyx.history.DisplayNamed; + +public enum SwingMode implements DisplayNamed, Runnable, MinecraftAccess { + HIDE_BOTH("Hide for both", false), + HIDE_SERVER("Hide for server", false), + HIDE_CLIENT("Hide for client", true), + DO_NOT_HIDE("Do not hide", true); + + private final boolean i; + private final String e; + + public boolean L() { + return this.i; + } + + private static SwingMode[] L() { + SwingMode[] swingModes = new SwingMode[4]; + boolean bl = true; + swingModes[0] = DO_NOT_HIDE; + swingModes[1] = HIDE_BOTH; + swingModes[2] = HIDE_CLIENT; + swingModes[3] = HIDE_SERVER; + return swingModes; + } + + SwingMode(String string1, boolean bl) { + this.e = string1; + this.i = bl; + } + + @Override + public void run() { + switch (this) { + case HIDE_BOTH: + while (false) { + } + + mc.thePlayer.swingItem(); + return; + case HIDE_SERVER: + return; + case HIDE_CLIENT: + mc.getNetHandler().addToSendQueue(new C0APacketAnimation()); + return; + case DO_NOT_HIDE: + mc.thePlayer.swingItemClientOnly(); + } + } + + @Override + public String getDisplayName() { + return this.e; + } + + public void L() { + this.run(); + } + + public String d() { + return this.e; + } +}