Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package net.blay09.mods.cookingforblockheads.utils;

public class DirectionUtils {

/**
* 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
*/
private static double modulus(final double number, final int modulus) {
if (number < 0) {
return number - (modulus * Math.floor(number / modulus));
} else {
return number % modulus;
}
}

/**
* Maps direction, calculated from the nearest cardinal-directions, as {South, West, North, East} to {0, 1, 2, 3}
*
* @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;
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 (binary)
* being before or after (clockwise) the nearest cardinal-direction
*
* @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);
modified_yaw = modulus(modified_yaw, 2);
return Math.floor(modified_yaw) == 0;
}
}