Clean up some of the filtering - a lot of unnecessary repeated code removed
This commit is contained in:
parent
d4bd9fca02
commit
cf78ff792a
|
@ -5,42 +5,46 @@ import cpw.mods.fml.common.Mod;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public final class RecipeRegistryProxy
|
/**
|
||||||
{
|
* @deprecated
|
||||||
public static void addRecipe(Object recipeOutput, List<?> recipeInputList)
|
* @see com.pahimar.ee3.api.recipe.RecipeRegistryProxy
|
||||||
{
|
*/
|
||||||
init();
|
@Deprecated
|
||||||
|
public final class RecipeRegistryProxy {
|
||||||
|
|
||||||
// NOOP if EquivalentExchange3 is not present
|
/**
|
||||||
if (ee3Mod != null)
|
*
|
||||||
{
|
* @deprecated
|
||||||
EE3Wrapper.ee3mod.getRecipeRegistry().addRecipe(recipeOutput, recipeInputList);
|
* @param recipeOutput
|
||||||
}
|
* @param recipeInputList
|
||||||
|
* @see com.pahimar.ee3.api.recipe.RecipeRegistryProxy#addRecipe(Object, List)
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static void addRecipe(Object recipeOutput, List<?> recipeInputList) {
|
||||||
|
|
||||||
|
com.pahimar.ee3.api.recipe.RecipeRegistryProxy.addRecipe(recipeOutput, recipeInputList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void dumpRecipeRegistryToLog()
|
/**
|
||||||
{
|
* @deprecated
|
||||||
init();
|
* @see com.pahimar.ee3.api.recipe.RecipeRegistryProxy#dumpRecipeRegistryToLog()
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static void dumpRecipeRegistryToLog() {
|
||||||
|
|
||||||
// NOOP if EquivalentExchange3 is not present
|
com.pahimar.ee3.api.recipe.RecipeRegistryProxy.dumpRecipeRegistryToLog();
|
||||||
if (ee3Mod != null)
|
|
||||||
{
|
|
||||||
EE3Wrapper.ee3mod.getRecipeRegistry().dumpRecipeRegistryToLog();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.Instance("EE3")
|
@Mod.Instance("EE3")
|
||||||
private static Object ee3Mod;
|
private static Object ee3Mod;
|
||||||
|
|
||||||
private static class EE3Wrapper
|
private static class EE3Wrapper {
|
||||||
{
|
|
||||||
private static EquivalentExchange3 ee3mod;
|
private static EquivalentExchange3 ee3mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void init()
|
private static void init() {
|
||||||
{
|
|
||||||
if (ee3Mod != null)
|
if (ee3Mod != null) {
|
||||||
{
|
|
||||||
EE3Wrapper.ee3mod = (EquivalentExchange3) ee3Mod;
|
EE3Wrapper.ee3mod = (EquivalentExchange3) ee3Mod;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.pahimar.ee3.api.recipe;
|
||||||
|
|
||||||
|
import com.pahimar.ee3.EquivalentExchange3;
|
||||||
|
import cpw.mods.fml.common.Mod;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public final class RecipeRegistryProxy {
|
||||||
|
|
||||||
|
public static void addRecipe(Object recipeOutput, List<?> recipeInputList) {
|
||||||
|
|
||||||
|
init();
|
||||||
|
|
||||||
|
// NOOP if EquivalentExchange3 is not present
|
||||||
|
if (ee3Mod != null) {
|
||||||
|
EE3Wrapper.ee3mod.getRecipeRegistry().addRecipe(recipeOutput, recipeInputList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void dumpRecipeRegistryToLog() {
|
||||||
|
|
||||||
|
init();
|
||||||
|
|
||||||
|
// NOOP if EquivalentExchange3 is not present
|
||||||
|
if (ee3Mod != null) {
|
||||||
|
EE3Wrapper.ee3mod.getRecipeRegistry().dumpRecipeRegistryToLog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.Instance("EE3")
|
||||||
|
private static Object ee3Mod;
|
||||||
|
|
||||||
|
private static class EE3Wrapper {
|
||||||
|
private static EquivalentExchange3 ee3mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void init() {
|
||||||
|
|
||||||
|
if (ee3Mod != null) {
|
||||||
|
EE3Wrapper.ee3mod = (EquivalentExchange3) ee3Mod;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -188,7 +188,7 @@ public class ContainerAlchenomicon extends ContainerEE implements IElementButton
|
||||||
this.requiresUpdate = true;
|
this.requiresUpdate = true;
|
||||||
boolean shouldUpdateInventory = false;
|
boolean shouldUpdateInventory = false;
|
||||||
ItemStack[] newInventory = new ItemStack[80];
|
ItemStack[] newInventory = new ItemStack[80];
|
||||||
List<ItemStack> filteredList = new ArrayList(FilterUtils.filterByNameContains(inventoryAlchenomicon.getKnownTransmutations(), searchTerm, Comparators.displayNameComparator));
|
List<ItemStack> filteredList = new ArrayList(FilterUtils.filterByDisplayName(inventoryAlchenomicon.getKnownTransmutations(), searchTerm, FilterUtils.NameFilterType.CONTAINS, Comparators.displayNameComparator));
|
||||||
|
|
||||||
maxPageOffset = filteredList.size() / 80;
|
maxPageOffset = filteredList.size() / 80;
|
||||||
if (pageOffset > maxPageOffset)
|
if (pageOffset > maxPageOffset)
|
||||||
|
|
|
@ -62,7 +62,7 @@ public abstract class ContainerEE extends Container
|
||||||
|
|
||||||
if (slot.isItemValid(itemStack) && stackInSlot == null)
|
if (slot.isItemValid(itemStack) && stackInSlot == null)
|
||||||
{
|
{
|
||||||
slot.putStack(ItemHelper.cloneItemStack(itemStack, Math.min(itemStack.stackSize, slot.getSlotStackLimit())));
|
slot.putStack(ItemHelper.clone(itemStack, Math.min(itemStack.stackSize, slot.getSlotStackLimit())));
|
||||||
slot.onSlotChanged();
|
slot.onSlotChanged();
|
||||||
|
|
||||||
if (slot.getStack() != null)
|
if (slot.getStack() != null)
|
||||||
|
|
|
@ -202,7 +202,7 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
||||||
{
|
{
|
||||||
ItemStack[] newInventory = new ItemStack[30];
|
ItemStack[] newInventory = new ItemStack[30];
|
||||||
|
|
||||||
Set<ItemStack> filteredSet = FilterUtils.filterByNameContains(this.inventoryTransmutationTablet.getKnownTransmutations(), searchTerm);
|
Set<ItemStack> filteredSet = FilterUtils.filterByDisplayName(this.inventoryTransmutationTablet.getKnownTransmutations(), searchTerm, FilterUtils.NameFilterType.CONTAINS);
|
||||||
List<ItemStack> filteredList = new ArrayList(FilterUtils.filterByEnergyValue(filteredSet, energyValue));
|
List<ItemStack> filteredList = new ArrayList(FilterUtils.filterByEnergyValue(filteredSet, energyValue));
|
||||||
|
|
||||||
int adjustedStartIndex = (int) ((scrollBarPosition / 187f) * filteredList.size());
|
int adjustedStartIndex = (int) ((scrollBarPosition / 187f) * filteredList.size());
|
||||||
|
|
|
@ -90,12 +90,12 @@ public class TransmutationKnowledge implements JsonSerializer<TransmutationKnowl
|
||||||
|
|
||||||
public Set<ItemStack> filterByNameStartsWith(String filterString)
|
public Set<ItemStack> filterByNameStartsWith(String filterString)
|
||||||
{
|
{
|
||||||
return FilterUtils.filterByNameStartsWith(getKnownTransmutations(), filterString);
|
return FilterUtils.filterByDisplayName(getKnownTransmutations(), filterString, FilterUtils.NameFilterType.STARTS_WITH);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<ItemStack> filterByNameContains(String filterString)
|
public Set<ItemStack> filterByNameContains(String filterString)
|
||||||
{
|
{
|
||||||
return FilterUtils.filterByNameContains(getKnownTransmutations(), filterString);
|
return FilterUtils.filterByDisplayName(getKnownTransmutations(), filterString, FilterUtils.NameFilterType.CONTAINS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class TransmutationKnowledgeRegistry
|
||||||
loadTemplateKnowledgeFromDisk();
|
loadTemplateKnowledgeFromDisk();
|
||||||
}
|
}
|
||||||
|
|
||||||
return FilterUtils.filterByNameStartsWith(templateKnowledge.getKnownTransmutations(), filterString);
|
return FilterUtils.filterByDisplayName(templateKnowledge.getKnownTransmutations(), filterString, FilterUtils.NameFilterType.STARTS_WITH);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<ItemStack> getTemplatesKnownTransmutationsFilteredContains(String filterString)
|
public Set<ItemStack> getTemplatesKnownTransmutationsFilteredContains(String filterString)
|
||||||
|
@ -77,7 +77,7 @@ public class TransmutationKnowledgeRegistry
|
||||||
loadTemplateKnowledgeFromDisk();
|
loadTemplateKnowledgeFromDisk();
|
||||||
}
|
}
|
||||||
|
|
||||||
return FilterUtils.filterByNameContains(templateKnowledge.getKnownTransmutations(), filterString);
|
return FilterUtils.filterByDisplayName(templateKnowledge.getKnownTransmutations(), filterString, FilterUtils.NameFilterType.CONTAINS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean doesTemplateKnow(ItemStack itemStack)
|
public boolean doesTemplateKnow(ItemStack itemStack)
|
||||||
|
|
|
@ -71,6 +71,7 @@ public class RecipeRegistry {
|
||||||
public Multimap<WrappedStack, List<WrappedStack>> getRecipeMappings() {
|
public Multimap<WrappedStack, List<WrappedStack>> getRecipeMappings() {
|
||||||
|
|
||||||
if (immutableRecipeMap == null) {
|
if (immutableRecipeMap == null) {
|
||||||
|
// FIXME Check to ensure we don't have multiple entries {@link https://github.com/pahimar/Equivalent-Exchange-3/issues/1046}
|
||||||
immutableRecipeMap = ImmutableMultimap.copyOf(recipeRegistry.recipeMap);
|
immutableRecipeMap = ImmutableMultimap.copyOf(recipeRegistry.recipeMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,153 +3,104 @@ package com.pahimar.ee3.util;
|
||||||
import com.pahimar.ee3.api.exchange.EnergyValue;
|
import com.pahimar.ee3.api.exchange.EnergyValue;
|
||||||
import com.pahimar.ee3.api.exchange.EnergyValueRegistryProxy;
|
import com.pahimar.ee3.api.exchange.EnergyValueRegistryProxy;
|
||||||
import com.pahimar.ee3.reference.Comparators;
|
import com.pahimar.ee3.reference.Comparators;
|
||||||
import net.minecraft.item.ItemBlock;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Collection;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
public class FilterUtils
|
public class FilterUtils {
|
||||||
{
|
|
||||||
public static Set<ItemStack> filterForItemBlock(Set<ItemStack> unfilteredItemStackSet)
|
public static Set<ItemStack> filterByDisplayName(Set<ItemStack> itemStacks, String filterString) {
|
||||||
{
|
return filterByDisplayName(itemStacks, filterString, NameFilterType.STARTS_WITH, null);
|
||||||
return filterForItemBlock(unfilteredItemStackSet, Comparators.idComparator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<ItemStack> filterForItemBlock(Set<ItemStack> unfilteredItemStackSet, Comparator comparator)
|
public static Set<ItemStack> filterByDisplayName(Set<ItemStack> itemStacks, String filterString, NameFilterType filterType) {
|
||||||
{
|
return filterByDisplayName(itemStacks, filterString, filterType, null);
|
||||||
Set<ItemStack> itemBlockOnlySet = new TreeSet<ItemStack>(comparator);
|
}
|
||||||
|
|
||||||
for (ItemStack itemStack : unfilteredItemStackSet)
|
public static Set<ItemStack> filterByDisplayName(Collection<ItemStack> itemStacks, String filterString, NameFilterType filterType, Comparator comparator) {
|
||||||
{
|
|
||||||
if (itemStack.getItem() instanceof ItemBlock)
|
Set<ItemStack> filteredSet = (comparator != null ? new TreeSet<>(comparator) : new TreeSet<>(Comparators.displayNameComparator));
|
||||||
{
|
|
||||||
itemBlockOnlySet.add(itemStack);
|
if (itemStacks != null) {
|
||||||
|
if (filterString == null || filterString.isEmpty()) {
|
||||||
|
filteredSet.addAll(itemStacks);
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
|
for (ItemStack itemStack : itemStacks) {
|
||||||
|
|
||||||
return itemBlockOnlySet;
|
String itemDisplayName = itemStack.getDisplayName().toLowerCase();
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<ItemStack> filterByNameStartsWith(Set<ItemStack> unfilteredItemStackSet, String filterString)
|
if (filterType == NameFilterType.STARTS_WITH && itemDisplayName.startsWith(filterString.toLowerCase())) {
|
||||||
{
|
filteredSet.add(itemStack);
|
||||||
return filterByNameStartsWith(unfilteredItemStackSet, filterString, Comparators.idComparator);
|
} else if (filterType == NameFilterType.CONTAINS && itemDisplayName.contains(filterString.toLowerCase())) {
|
||||||
}
|
filteredSet.add(itemStack);
|
||||||
|
}
|
||||||
public static Set<ItemStack> filterByNameStartsWith(Set<ItemStack> unfilteredItemStackSet, String filterString, Comparator comparator)
|
|
||||||
{
|
|
||||||
Set<ItemStack> nameSortedSet = new TreeSet<ItemStack>(comparator);
|
|
||||||
|
|
||||||
for (ItemStack itemStack : unfilteredItemStackSet)
|
|
||||||
{
|
|
||||||
String itemDisplayName = itemStack.getDisplayName().toLowerCase();
|
|
||||||
|
|
||||||
if (filterString != null)
|
|
||||||
{
|
|
||||||
if (itemDisplayName.startsWith(filterString.toLowerCase()))
|
|
||||||
{
|
|
||||||
nameSortedSet.add(itemStack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
nameSortedSet.add(itemStack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nameSortedSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<ItemStack> filterByNameContains(Collection<ItemStack> unfilteredCollection, String filterString)
|
|
||||||
{
|
|
||||||
Set<ItemStack> nameSortedSet = new HashSet<ItemStack>();
|
|
||||||
|
|
||||||
for (ItemStack itemStack : unfilteredCollection)
|
|
||||||
{
|
|
||||||
String itemDisplayName = itemStack.getDisplayName().toLowerCase();
|
|
||||||
|
|
||||||
if (filterString != null)
|
|
||||||
{
|
|
||||||
if (itemDisplayName.contains(filterString.toLowerCase()))
|
|
||||||
{
|
|
||||||
nameSortedSet.add(itemStack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
nameSortedSet.add(itemStack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nameSortedSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<ItemStack> filterByNameContains(Collection<ItemStack> unfilteredCollection, String filterString, Comparator comparator)
|
|
||||||
{
|
|
||||||
Set<ItemStack> nameSortedSet = new TreeSet<ItemStack>(comparator);
|
|
||||||
|
|
||||||
for (ItemStack itemStack : unfilteredCollection)
|
|
||||||
{
|
|
||||||
String itemDisplayName = itemStack.getDisplayName().toLowerCase();
|
|
||||||
|
|
||||||
if (filterString != null)
|
|
||||||
{
|
|
||||||
if (itemDisplayName.contains(filterString.toLowerCase()))
|
|
||||||
{
|
|
||||||
nameSortedSet.add(itemStack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
nameSortedSet.add(itemStack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nameSortedSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<ItemStack> filterByEnergyValue(Collection<ItemStack> unfilteredCollection, EnergyValue energyValue)
|
|
||||||
{
|
|
||||||
return filterByEnergyValue(unfilteredCollection, energyValue.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<ItemStack> filterByEnergyValue(Collection<ItemStack> unfilteredCollection, EnergyValue energyValue, Comparator<ItemStack> comparator)
|
|
||||||
{
|
|
||||||
return filterByEnergyValue(unfilteredCollection, energyValue.getValue(), comparator);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<ItemStack> filterByEnergyValue(Collection<ItemStack> unfilteredCollection, float energyValue)
|
|
||||||
{
|
|
||||||
Set<ItemStack> sortedSet = new HashSet<ItemStack>();
|
|
||||||
|
|
||||||
for (ItemStack itemStack : unfilteredCollection)
|
|
||||||
{
|
|
||||||
if (energyValue > 0f && EnergyValueRegistryProxy.hasEnergyValue(itemStack))
|
|
||||||
{
|
|
||||||
if (EnergyValueRegistryProxy.getEnergyValue(itemStack).getValue() <= energyValue)
|
|
||||||
{
|
|
||||||
sortedSet.add(itemStack);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sortedSet;
|
return filteredSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<ItemStack> filterByEnergyValue(Collection<ItemStack> unfilteredCollection, float energyValue, Comparator<ItemStack> comparator)
|
public static Set<ItemStack> filterByEnergyValue(Collection<ItemStack> itemStacks, Number valueBound) {
|
||||||
{
|
return filterByEnergyValue(itemStacks, new EnergyValue(valueBound.floatValue()), ValueFilterType.VALUE_LOWER_THAN_BOUND, null);
|
||||||
Set<ItemStack> sortedSet = new TreeSet<ItemStack>(comparator);
|
}
|
||||||
|
|
||||||
for (ItemStack itemStack : unfilteredCollection)
|
public static Set<ItemStack> filterByEnergyValue(Collection<ItemStack> itemStacks, EnergyValue valueBound) {
|
||||||
{
|
return filterByEnergyValue(itemStacks, valueBound, ValueFilterType.VALUE_LOWER_THAN_BOUND, null);
|
||||||
if (energyValue > 0f && EnergyValueRegistryProxy.hasEnergyValue(itemStack))
|
}
|
||||||
{
|
|
||||||
if (EnergyValueRegistryProxy.getEnergyValue(itemStack).getValue() <= energyValue)
|
public static Set<ItemStack> filterByEnergyValue(Collection<ItemStack> itemStacks, Number valueBound, ValueFilterType filterType) {
|
||||||
{
|
return filterByEnergyValue(itemStacks, new EnergyValue(valueBound.floatValue()), filterType, null);
|
||||||
sortedSet.add(itemStack);
|
}
|
||||||
|
|
||||||
|
public static Set<ItemStack> filterByEnergyValue(Collection<ItemStack> itemStacks, EnergyValue valueBound, ValueFilterType filterType) {
|
||||||
|
return filterByEnergyValue(itemStacks, valueBound, filterType, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Set<ItemStack> filterByEnergyValue(Collection<ItemStack> itemStacks, Number valueBound, ValueFilterType filterType, Comparator comparator) {
|
||||||
|
return filterByEnergyValue(itemStacks, new EnergyValue(valueBound.floatValue()), filterType, comparator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Set<ItemStack> filterByEnergyValue(Collection<ItemStack> itemStacks, EnergyValue valueBound, ValueFilterType filterType, Comparator comparator) {
|
||||||
|
|
||||||
|
Set<ItemStack> filteredSet = (comparator != null ? new TreeSet<>(comparator) : new TreeSet<>(Comparators.displayNameComparator));
|
||||||
|
|
||||||
|
if (itemStacks != null) {
|
||||||
|
|
||||||
|
if (valueBound == null) {
|
||||||
|
filteredSet.addAll(itemStacks);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (ItemStack itemStack : itemStacks) {
|
||||||
|
|
||||||
|
EnergyValue energyValue = EnergyValueRegistryProxy.getEnergyValue(itemStack);
|
||||||
|
|
||||||
|
if (energyValue != null) {
|
||||||
|
if (filterType == ValueFilterType.VALUE_LOWER_THAN_BOUND && energyValue.compareTo(valueBound) <= 0) {
|
||||||
|
filteredSet.add(itemStack);
|
||||||
|
}
|
||||||
|
else if (filterType == ValueFilterType.VALUE_GREATER_THAN_BOUND && energyValue.compareTo(valueBound) >= 0) {
|
||||||
|
filteredSet.add(itemStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sortedSet;
|
return filteredSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum NameFilterType {
|
||||||
|
STARTS_WITH,
|
||||||
|
CONTAINS
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ValueFilterType {
|
||||||
|
VALUE_GREATER_THAN_BOUND,
|
||||||
|
VALUE_LOWER_THAN_BOUND
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,18 +3,22 @@ package com.pahimar.ee3.util;
|
||||||
import com.pahimar.ee3.reference.Comparators;
|
import com.pahimar.ee3.reference.Comparators;
|
||||||
import com.pahimar.ee3.reference.Names;
|
import com.pahimar.ee3.reference.Names;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ItemHelper
|
public class ItemHelper {
|
||||||
{
|
|
||||||
public static ItemStack cloneItemStack(ItemStack itemStack, int stackSize)
|
public static ItemStack clone(ItemStack itemStack, int stackSize) {
|
||||||
{
|
|
||||||
ItemStack clonedItemStack = itemStack.copy();
|
if (itemStack != null) {
|
||||||
clonedItemStack.stackSize = stackSize;
|
ItemStack clonedItemStack = itemStack.copy();
|
||||||
return clonedItemStack;
|
clonedItemStack.stackSize = stackSize;
|
||||||
|
return clonedItemStack;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,60 +29,25 @@ public class ItemHelper
|
||||||
* @param second The second ItemStack being tested for equality
|
* @param second The second ItemStack being tested for equality
|
||||||
* @return true if the two ItemStacks are equivalent, false otherwise
|
* @return true if the two ItemStacks are equivalent, false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean equals(ItemStack first, ItemStack second)
|
public static boolean equals(ItemStack first, ItemStack second) {
|
||||||
{
|
|
||||||
return (Comparators.idComparator.compare(first, second) == 0);
|
return (Comparators.idComparator.compare(first, second) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean equalsIgnoreStackSize(ItemStack itemStack1, ItemStack itemStack2)
|
public static boolean equalsIgnoreStackSize(ItemStack itemStack1, ItemStack itemStack2) {
|
||||||
{
|
return equals(clone(itemStack1, 1), clone(itemStack2, 1));
|
||||||
if (itemStack1 != null && itemStack2 != null)
|
|
||||||
{
|
|
||||||
// Sort on itemID
|
|
||||||
if (Item.getIdFromItem(itemStack1.getItem()) - Item.getIdFromItem(itemStack2.getItem()) == 0)
|
|
||||||
{
|
|
||||||
// Sort on item
|
|
||||||
if (itemStack1.getItem() == itemStack2.getItem())
|
|
||||||
{
|
|
||||||
// Then sort on meta
|
|
||||||
if (itemStack1.getItemDamage() == itemStack2.getItemDamage())
|
|
||||||
{
|
|
||||||
// Then sort on NBT
|
|
||||||
if (itemStack1.hasTagCompound() && itemStack2.hasTagCompound())
|
|
||||||
{
|
|
||||||
// Then sort on stack size
|
|
||||||
if (ItemStack.areItemStackTagsEqual(itemStack1, itemStack2))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (!itemStack1.hasTagCompound() && !itemStack2.hasTagCompound())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int compare(ItemStack itemStack1, ItemStack itemStack2)
|
public static int compare(ItemStack itemStack1, ItemStack itemStack2) {
|
||||||
{
|
|
||||||
return Comparators.idComparator.compare(itemStack1, itemStack2);
|
return Comparators.idComparator.compare(itemStack1, itemStack2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String toString(ItemStack itemStack)
|
public static String toString(ItemStack itemStack) {
|
||||||
{
|
|
||||||
if (itemStack != null)
|
if (itemStack != null) {
|
||||||
{
|
if (itemStack.hasTagCompound()) {
|
||||||
if (itemStack.hasTagCompound())
|
|
||||||
{
|
|
||||||
return String.format("%sxitemStack[%s@%s:%s]", itemStack.stackSize, itemStack.getUnlocalizedName(), itemStack.getItemDamage(), itemStack.getTagCompound());
|
return String.format("%sxitemStack[%s@%s:%s]", itemStack.stackSize, itemStack.getUnlocalizedName(), itemStack.getItemDamage(), itemStack.getTagCompound());
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
return String.format("%sxitemStack[%s@%s]", itemStack.stackSize, itemStack.getUnlocalizedName(), itemStack.getItemDamage());
|
return String.format("%sxitemStack[%s@%s]", itemStack.stackSize, itemStack.getUnlocalizedName(), itemStack.getItemDamage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,13 +55,11 @@ public class ItemHelper
|
||||||
return "null";
|
return "null";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasOwner(ItemStack itemStack)
|
public static boolean hasOwner(ItemStack itemStack) {
|
||||||
{
|
|
||||||
return (NBTHelper.hasTag(itemStack, Names.NBT.OWNER_UUID_MOST_SIG) && NBTHelper.hasTag(itemStack, Names.NBT.OWNER_UUID_LEAST_SIG)) || NBTHelper.hasTag(itemStack, Names.NBT.OWNER);
|
return (NBTHelper.hasTag(itemStack, Names.NBT.OWNER_UUID_MOST_SIG) && NBTHelper.hasTag(itemStack, Names.NBT.OWNER_UUID_LEAST_SIG)) || NBTHelper.hasTag(itemStack, Names.NBT.OWNER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasOwnerUUID(ItemStack itemStack)
|
public static boolean hasOwnerUUID(ItemStack itemStack) {
|
||||||
{
|
|
||||||
return NBTHelper.hasTag(itemStack, Names.NBT.OWNER_UUID_MOST_SIG) && NBTHelper.hasTag(itemStack, Names.NBT.OWNER_UUID_LEAST_SIG);
|
return NBTHelper.hasTag(itemStack, Names.NBT.OWNER_UUID_MOST_SIG) && NBTHelper.hasTag(itemStack, Names.NBT.OWNER_UUID_LEAST_SIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue