package com.teamwizardry.refraction.api;

import com.teamwizardry.librarianlib.common.util.ItemNBTHelper;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;

/**
 * Created by Saad on 9/9/2016.
 */
public interface IPrecision {

	final class Helper {

		public static final String MODE_TAG = "mode";
		public static final int DEFAULT_MULTIPLIER = 4;

		public static final float[] multipliers = {
				0.125f, 0.25f, 0.5f, 1,
				5, 22.5f, 45, 90
		};

		public static float getRotationMultiplier(ItemStack stack) {
			return multipliers[getRotationIndex(stack)];
		}

		public static int getRotationIndex(ItemStack stack) {
			int i = ItemNBTHelper.getInt(stack, MODE_TAG, DEFAULT_MULTIPLIER);
			return MathHelper.clamp(i, 0, multipliers.length - 1);
		}
	}

	default void adjust(World worldIn, BlockPos pos, ItemStack stack, boolean sneaking, EnumFacing side) {
		IBlockState state = worldIn.getBlockState(pos);
		if (state.getBlock() instanceof IPrecision && !worldIn.isRemote) {
			float jump = Helper.getRotationMultiplier(stack) * (sneaking ? -1 : 1);

			if (side.getAxis() == EnumFacing.Axis.Y) {
				setRotY(worldIn, pos, (getRotY(worldIn, pos) + jump) % 360);
			} else {
				setRotX(worldIn, pos, (getRotX(worldIn, pos) + jump) % 360);
			}
		}
	}

	float getRotX(World worldIn, BlockPos pos);

	void setRotX(World worldIn, BlockPos pos, float x);

	float getRotY(World worldIn, BlockPos pos);

	final class Helper {

		public static final String MODE_TAG = "mode";
		public static final int DEFAULT_MULTIPLIER = 4;

		public static final float[] multipliers = {
				0.125f, 0.25f, 0.5f, 1,
				5, 22.5f, 45, 90
		};

		public static float getRotationMultiplier(ItemStack stack) {
			return multipliers[getRotationIndex(stack)];
		}

		public static int getRotationIndex(ItemStack stack) {
			int i = ItemNBTHelper.getInt(stack, MODE_TAG, DEFAULT_MULTIPLIER);
			return MathHelper.clamp(i, 0, multipliers.length - 1);
		}
	}

	void setRotY(World worldIn, BlockPos pos, float y);

}

@@ -414,539 +414,8 @@
  %7B%0A%0A
-%09final class Helper %7B%0A%0A%09%09public static final String MODE_TAG = %22mode%22;%0A%09%09public static final int DEFAULT_MULTIPLIER = 4;%0A%0A%09%09public static final float%5B%5D multipliers = %7B%0A%09%09%09%090.125f, 0.25f, 0.5f, 1,%0A%09%09%09%095, 22.5f, 45, 90%0A%09%09%7D;%0A%0A%09%09public static float getRotationMultiplier(ItemStack stack) %7B%0A%09%09%09return multipliers%5BgetRotationIndex(stack)%5D;%0A%09%09%7D%0A%0A%09%09public static int getRotationIndex(ItemStack stack) %7B%0A%09%09%09int i = ItemNBTHelper.getInt(stack, MODE_TAG, DEFAULT_MULTIPLIER);%0A%09%09%09return MathHelper.clamp(i, 0, multipliers.length - 1);%0A%09%09%7D%0A%09%7D%0A%0A
 %09def
@@ -514,16 +514,16 @@
 side) %7B%0A
+
 %09%09IBlock
@@ -1056,16 +1056,70 @@
  pos);%0A%0A
+%09void setRotY(World worldIn, BlockPos pos, float y);%0A%0A
 %09final c
@@ -1641,64 +1641,10 @@
 %09%09%7D%0A
+
 %09%7D%0A%0A
-%09void setRotY(World worldIn, BlockPos pos, float y);%0A%0A
 %7D%0A

remove unusual duplicate helper class