2016-11-16 16:59:00 +01:00
|
|
|
/*
|
|
|
|
* 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;
|
2016-11-20 20:13:26 +01:00
|
|
|
import net.minecraft.util.NonNullList;
|
2016-11-16 16:59:00 +01:00
|
|
|
|
|
|
|
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){
|
2016-11-19 21:11:17 +01:00
|
|
|
return stack != null && !stack.func_190926_b();
|
2016-11-16 16:59:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static ItemStack getNull(){
|
2016-11-19 21:11:17 +01:00
|
|
|
return ItemStack.field_190927_a;
|
2016-11-16 16:59:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static int getStackSize(ItemStack stack){
|
|
|
|
if(!isValid(stack)){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else{
|
2016-11-19 21:11:17 +01:00
|
|
|
return stack.func_190916_E();
|
2016-11-16 16:59:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ItemStack setStackSize(ItemStack stack, int size){
|
|
|
|
if(size <= 0){
|
|
|
|
if(isValid(stack)){
|
|
|
|
return stack.getItem().getContainerItem(stack);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return getNull();
|
|
|
|
}
|
|
|
|
}
|
2016-11-19 21:11:17 +01:00
|
|
|
stack.func_190920_e(size);
|
2016-11-16 16:59:00 +01:00
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ItemStack addStackSize(ItemStack stack, int size){
|
|
|
|
return setStackSize(stack, getStackSize(stack)+size);
|
|
|
|
}
|
2016-11-19 21:11:17 +01:00
|
|
|
|
2016-11-20 20:13:26 +01:00
|
|
|
public static boolean isIInvEmpty(NonNullList<ItemStack> slots){
|
2016-11-19 21:11:17 +01:00
|
|
|
for(ItemStack stack : slots){
|
|
|
|
if(StackUtil.isValid(stack)){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-11-20 20:13:26 +01:00
|
|
|
|
|
|
|
public static NonNullList<ItemStack> createSlots(int size){
|
|
|
|
return NonNullList.func_191197_a(size, getNull());
|
|
|
|
}
|
2016-11-21 17:50:33 +01:00
|
|
|
|
|
|
|
|
2016-11-16 16:59:00 +01:00
|
|
|
}
|