ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/util/StackUtil.java
Ellpeck 6e34f9e345 This only took 20 years
Prepared for 1.11 ItemStack updates
2016-11-16 16:59:00 +01:00

68 lines
1.7 KiB
Java

/*
* This file ("StackUtil.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.util;
import net.minecraft.item.ItemStack;
public final class StackUtil{
public static ItemStack validateCopy(ItemStack stack){
if(isValid(stack)){
return stack.copy();
}
else{
return getNull();
}
}
public static ItemStack validateCheck(ItemStack stack){
if(isValid(stack)){
return stack;
}
else{
return getNull();
}
}
public static boolean isValid(ItemStack stack){
return stack != null && !ItemStack.areItemStacksEqual(stack, getNull()) && stack.stackSize > 0 && stack.getItem() != null;
}
public static ItemStack getNull(){
return null;
}
public static int getStackSize(ItemStack stack){
if(!isValid(stack)){
return 0;
}
else{
return stack.stackSize;
}
}
public static ItemStack setStackSize(ItemStack stack, int size){
if(size <= 0){
if(isValid(stack)){
return stack.getItem().getContainerItem(stack);
}
else{
return getNull();
}
}
stack.stackSize = size;
return stack;
}
public static ItemStack addStackSize(ItemStack stack, int size){
return setStackSize(stack, getStackSize(stack)+size);
}
}