From 041eb1b50cad2d71b5ea6b61c65c28a2d1284202 Mon Sep 17 00:00:00 2001 From: Wheeler-Shigley <115506442+WheelerShigley@users.noreply.github.com> Date: Thu, 2 Apr 2026 00:01:54 -0500 Subject: [PATCH 1/2] Hinge-Direction bugfix (#23788) + Abstracted, Corrected, and Commented relative directions for some Containers, when placed (bugfix) --- .../block/BlockCounter.java | 7 ++- .../block/BlockFridge.java | 7 ++- .../utils/DirectionUtils.java | 46 +++++++++++++++++++ 3 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 src/main/java/net/blay09/mods/cookingforblockheads/utils/DirectionUtils.java diff --git a/src/main/java/net/blay09/mods/cookingforblockheads/block/BlockCounter.java b/src/main/java/net/blay09/mods/cookingforblockheads/block/BlockCounter.java index 0a8be46a3..858ca1546 100644 --- a/src/main/java/net/blay09/mods/cookingforblockheads/block/BlockCounter.java +++ b/src/main/java/net/blay09/mods/cookingforblockheads/block/BlockCounter.java @@ -6,6 +6,7 @@ import net.blay09.mods.cookingforblockheads.GuiHandler; import net.blay09.mods.cookingforblockheads.client.render.block.CounterBlockRenderer; import net.blay09.mods.cookingforblockheads.tile.TileCounter; +import net.blay09.mods.cookingforblockheads.utils.DirectionUtils; import net.blay09.mods.cookingforblockheads.utils.DyeUtils; import net.minecraft.block.Block; import net.minecraft.block.material.Material; @@ -16,7 +17,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; -import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; @@ -99,9 +99,8 @@ public void onBlockAdded(World world, int x, int y, int z) { @Override public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase placer, ItemStack itemStack) { - double blockRotation = (double) (placer.rotationYaw * 4.0F / 360.0F) + 0.5D; - boolean flipped = Math.abs(blockRotation - (int) blockRotation) < 0.5; - int orientation = MathHelper.floor_double(blockRotation) & 3; + boolean flipped = DirectionUtils.isHalfDirection(placer.rotationYaw); + int orientation = DirectionUtils.getDirection(placer.rotationYaw); if (orientation == 0) { world.setBlockMetadataWithNotify(x, y, z, 2, 2); } diff --git a/src/main/java/net/blay09/mods/cookingforblockheads/block/BlockFridge.java b/src/main/java/net/blay09/mods/cookingforblockheads/block/BlockFridge.java index ab9867df7..23f7ebdb0 100644 --- a/src/main/java/net/blay09/mods/cookingforblockheads/block/BlockFridge.java +++ b/src/main/java/net/blay09/mods/cookingforblockheads/block/BlockFridge.java @@ -7,6 +7,7 @@ import net.blay09.mods.cookingforblockheads.client.render.block.FridgeBlockRenderer; import net.blay09.mods.cookingforblockheads.item.ItemBlockFridge; import net.blay09.mods.cookingforblockheads.tile.TileFridge; +import net.blay09.mods.cookingforblockheads.utils.DirectionUtils; import net.blay09.mods.cookingforblockheads.utils.DyeUtils; import net.minecraft.block.Block; import net.minecraft.block.material.Material; @@ -17,7 +18,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; -import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; @@ -142,9 +142,8 @@ public void onBlockAdded(World world, int x, int y, int z) { @Override public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase placer, ItemStack itemStack) { - double blockRotation = (double) (placer.rotationYaw * 4.0F / 360.0F) + 0.5D; - boolean flipped = Math.abs(blockRotation - (int) blockRotation) < 0.5; - int orientation = MathHelper.floor_double(blockRotation) & 3; + boolean flipped = DirectionUtils.isHalfDirection(placer.rotationYaw); + int orientation = DirectionUtils.getDirection(placer.rotationYaw); if (orientation == 0) { world.setBlockMetadataWithNotify(x, y, z, 2, 2); } diff --git a/src/main/java/net/blay09/mods/cookingforblockheads/utils/DirectionUtils.java b/src/main/java/net/blay09/mods/cookingforblockheads/utils/DirectionUtils.java new file mode 100644 index 000000000..d65161e24 --- /dev/null +++ b/src/main/java/net/blay09/mods/cookingforblockheads/utils/DirectionUtils.java @@ -0,0 +1,46 @@ +package net.blay09.mods.cookingforblockheads.utils; + +public class DirectionUtils { + /** + * Returns the result of the mathematical operation, modulus of two numbers. + * This is distinct from Java's "mod" operator, %, which returns the remainder of two numbers; + * the mathematic operation, "modulus" returns the remainder, in whole multiples + * + * @param number operand + * @param modulus zero-congruent definition (maximum space for modular arithmetic) + * @return + */ + private static double modulus(final double number, final int modulus) { + if(number < 0) { + return (modulus - (Math.abs(number) % modulus) ) % modulus; + } else { + return number % modulus; + } + } + + /** + * Reformats directions (like an "enum") calculated from the nearest cardinal-directions, as + * {South, West, North, East} to {0, 1, 2, 3} + * + * @param yaw latteral-direction of gaze + * @return cardinal-direction index + */ + public static int getDirection(final double yaw) { + double modified_yaw = ( yaw * (4.0/360.0) ) + 0.5; + modified_yaw = modulus(modified_yaw, 4); + return (int)Math.floor(modified_yaw); + } + + /** + * Returns the "handedness" of a current gaze, relative to the nearest cardinal-direction, + * represented as being before or after (clockwise) the nearest cardinal-direction + * + * @param yaw latteral-direction of gaze + * @return truth of being before the center of the nearest cardinal-direction + */ + public static boolean isHalfDirection(final double yaw) { + double modified_yaw = yaw * (8.0/360.0); + modified_yaw = modulus(modified_yaw, 2); + return Math.floor(modified_yaw) == 0; + } +} From aa2c1c6c17f5eddd3601fefc2c1f0eb56cb361b4 Mon Sep 17 00:00:00 2001 From: Wheeler-Shigley <115506442+WheelerShigley@users.noreply.github.com> Date: Thu, 2 Apr 2026 10:30:15 -0500 Subject: [PATCH 2/2] DirectionUtils splotless-formatting + Corrected some spelling errors + Re-worded some comments + Reformatted several operating (for task splotlessApply) --- .../utils/DirectionUtils.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/net/blay09/mods/cookingforblockheads/utils/DirectionUtils.java b/src/main/java/net/blay09/mods/cookingforblockheads/utils/DirectionUtils.java index d65161e24..be67f2b62 100644 --- a/src/main/java/net/blay09/mods/cookingforblockheads/utils/DirectionUtils.java +++ b/src/main/java/net/blay09/mods/cookingforblockheads/utils/DirectionUtils.java @@ -1,45 +1,45 @@ package net.blay09.mods.cookingforblockheads.utils; public class DirectionUtils { + /** - * Returns the result of the mathematical operation, modulus of two numbers. - * This is distinct from Java's "mod" operator, %, which returns the remainder of two numbers; - * the mathematic operation, "modulus" returns the remainder, in whole multiples - * - * @param number operand + * Returns the result of the mathematical-operation "modulus" of any pair of a number and integer. This is distinct + * from Java's mod-operator (%), which returns the remainder of any two numbers; the mathematics-operation, + * "modulus" returns the remainder, in whole multiples. + * + * @param number operand * @param modulus zero-congruent definition (maximum space for modular arithmetic) - * @return + * @return */ private static double modulus(final double number, final int modulus) { - if(number < 0) { - return (modulus - (Math.abs(number) % modulus) ) % modulus; + if (number < 0) { + return number - (modulus * Math.floor(number / modulus)); } else { return number % modulus; } } /** - * Reformats directions (like an "enum") calculated from the nearest cardinal-directions, as - * {South, West, North, East} to {0, 1, 2, 3} + * Maps direction, calculated from the nearest cardinal-directions, as {South, West, North, East} to {0, 1, 2, 3} * - * @param yaw latteral-direction of gaze + * @param yaw lateral-direction of gaze * @return cardinal-direction index */ public static int getDirection(final double yaw) { - double modified_yaw = ( yaw * (4.0/360.0) ) + 0.5; + double modified_yaw = (yaw * (4.0 / 360.0)) + 0.5; modified_yaw = modulus(modified_yaw, 4); - return (int)Math.floor(modified_yaw); + return (int) Math.floor(modified_yaw); } /** - * Returns the "handedness" of a current gaze, relative to the nearest cardinal-direction, - * represented as being before or after (clockwise) the nearest cardinal-direction + * Returns the "handedness" of a current gaze, relative to the nearest cardinal-direction, represented as (binary) + * being before or after (clockwise) the nearest cardinal-direction * - * @param yaw latteral-direction of gaze + * @param yaw lateral-direction of gaze * @return truth of being before the center of the nearest cardinal-direction */ public static boolean isHalfDirection(final double yaw) { - double modified_yaw = yaw * (8.0/360.0); + double modified_yaw = yaw * (8.0 / 360.0); modified_yaw = modulus(modified_yaw, 2); return Math.floor(modified_yaw) == 0; }