Add docs to CompareUtils, small fixes

This commit is contained in:
Raoul Van den Berge
2016-07-19 12:39:44 +02:00
parent 0923702b3e
commit 36f117c0d7
2 changed files with 42 additions and 6 deletions

View File

@@ -5,17 +5,43 @@ import net.minecraftforge.oredict.OreDictionary;
import org.apache.commons.lang3.ArrayUtils;
/**
* Comparison utils.
* Utilities for comparing {@link ItemStack}.
*/
public final class CompareUtils {
public static final int COMPARE_DAMAGE = 1;
public static final int COMPARE_NBT = 2;
public static final int COMPARE_QUANTITY = 4;
/**
* Compares two stacks by NBT, damage and quantity.
*
* @param left The left stack
* @param right The right stack
* @return Whether the left and right stack are equal
*/
public static boolean compareStack(ItemStack left, ItemStack right) {
return compareStack(left, right, COMPARE_NBT | COMPARE_DAMAGE | COMPARE_QUANTITY);
}
/**
* Compares two stacks by NBT and damage.
*
* @param left The left stack
* @param right The right stack
* @return Whether the left and right stack are equal
*/
public static boolean compareStackNoQuantity(ItemStack left, ItemStack right) {
return compareStack(left, right, COMPARE_NBT | COMPARE_DAMAGE);
}
/**
* Compares two stacks by the given flags.
*
* @param left The left stack
* @param right The right stack
* @param flags The flags to compare with
* @return Whether the left and right stack are equal
*/
public static boolean compareStack(ItemStack left, ItemStack right, int flags) {
if (left == null && right == null) {
return true;
@@ -50,6 +76,13 @@ public final class CompareUtils {
return true;
}
/**
* Compares the NBT tags of two stacks.
*
* @param left The left stack
* @param right The right stack
* @return Whether the NBT tags are equal
*/
public static boolean compareNbt(ItemStack left, ItemStack right) {
if (!ItemStack.areItemStackTagsEqual(left, right)) {
if (left.hasTagCompound() && !right.hasTagCompound() && left.getTagCompound().hasNoTags()) {
@@ -64,10 +97,13 @@ public final class CompareUtils {
return true;
}
public static boolean compareStackNoQuantity(ItemStack left, ItemStack right) {
return compareStack(left, right, COMPARE_NBT | COMPARE_DAMAGE);
}
/**
* Compares two stacks and checks if they share the same ore dictionary entry.
*
* @param left The left stack
* @param right The right stack
* @return Whether the stacks share the same ore dictionary entry
*/
public static boolean compareStackOreDict(ItemStack left, ItemStack right) {
if (left == null && right == null) {
return true;

View File

@@ -279,7 +279,7 @@ public abstract class GuiBase extends GuiContainer {
return guiTop;
}
public static int calculateOffsetOnScale(int pos, float scale) {
protected int calculateOffsetOnScale(int pos, float scale) {
float multiplier = (pos / scale);
return (int) multiplier;