BloodMagic/src/main/java/WayofTime/bloodmagic/util/ItemStackWrapper.java

114 lines
2.8 KiB
Java
Raw Normal View History

package WayofTime.bloodmagic.util;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
2017-01-01 21:43:34 -08:00
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
@Deprecated
2017-08-15 21:30:48 -07:00
public class ItemStackWrapper {
public final Item item;
public final int stackSize;
public final int meta;
public NBTTagCompound nbtTag;
2017-08-15 20:21:54 -07:00
public ItemStackWrapper(Item item, int stackSize, int meta) {
this.item = item;
this.stackSize = stackSize;
this.meta = meta;
}
2017-08-15 21:30:48 -07:00
public ItemStackWrapper(Item item, int stackSize) {
this(item, stackSize, 0);
}
2017-08-15 21:30:48 -07:00
public ItemStackWrapper(Item item) {
this(item, 1, 0);
}
2017-08-15 21:30:48 -07:00
public ItemStackWrapper(Block block, int stackSize, int meta) {
this(Item.getItemFromBlock(block), stackSize, meta);
}
2017-08-15 21:30:48 -07:00
public ItemStackWrapper(Block block, int stackSize) {
this(block, stackSize, 0);
}
2017-08-15 21:30:48 -07:00
public ItemStackWrapper(Block block) {
this(block, 1, 0);
}
2017-08-15 21:30:48 -07:00
public ItemStackWrapper(BlockStack blockStack) {
this(blockStack.getBlock(), 1, blockStack.getMeta());
}
2017-08-15 21:30:48 -07:00
public ItemStack toStack() {
return new ItemStack(item, stackSize, meta);
}
2017-08-15 21:30:48 -07:00
public String getDisplayName() {
return toStack().getDisplayName();
}
@Override
2017-08-15 21:30:48 -07:00
public String toString() {
return stackSize + "x" + item.getUnlocalizedName() + "@" + this.meta;
}
2017-08-15 21:30:48 -07:00
public ItemStack toStack(int count) {
ItemStack result = new ItemStack(item, count, meta);
result.setTagCompound(nbtTag);
return result;
}
2017-08-15 20:21:54 -07:00
public Item getItem() {
return item;
}
public int getStackSize() {
return stackSize;
}
public int getMeta() {
return meta;
}
public NBTTagCompound getNbtTag() {
return nbtTag;
}
public void setNbtTag(NBTTagCompound nbtTag) {
this.nbtTag = nbtTag;
}
2017-08-15 21:30:48 -07:00
@Nullable
public static ItemStackWrapper getHolder(ItemStack stack) {
if (stack.isEmpty())
return null;
ItemStackWrapper wrapper = new ItemStackWrapper(stack.getItem(), stack.getCount(), stack.getItemDamage());
wrapper.setNbtTag(stack.getTagCompound());
return wrapper;
}
public static List<ItemStackWrapper> toWrapperList(List<ItemStack> itemStackList) {
List<ItemStackWrapper> wrapperList = new ArrayList<>();
2017-08-15 21:30:48 -07:00
for (ItemStack stack : itemStackList)
wrapperList.add(ItemStackWrapper.getHolder(stack));
return wrapperList;
}
public static List<ItemStack> toStackList(List<ItemStackWrapper> wrapperList) {
List<ItemStack> stackList = new ArrayList<>();
2017-08-15 21:30:48 -07:00
for (ItemStackWrapper wrapper : wrapperList)
stackList.add(wrapper.toStack());
return stackList;
}
}