use of mcjty.lib.varia.ItemStackList in project RFTools by McJty.
the class StorageFilterItem method onItemUse.
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack stack = playerIn.getHeldItem(hand);
if (playerIn.isSneaking()) {
if (!worldIn.isRemote) {
TileEntity te = worldIn.getTileEntity(pos);
if (InventoryHelper.isInventory(te)) {
ItemStackList stacks = ItemStackList.create();
Set<ResourceLocation> registeredItems = new HashSet<>();
InventoryHelper.getItems(te, s -> true).forEach(s -> addItem(te, stacks, registeredItems, s));
if (!stack.hasTagCompound()) {
stack.setTagCompound(new NBTTagCompound());
}
StorageFilterInventory.convertItemsToNBT(stack.getTagCompound(), stacks);
playerIn.sendStatusMessage(new TextComponentString(TextFormatting.GREEN + "Stored inventory contents in filter"), false);
} else {
IBlockState state = worldIn.getBlockState(pos);
ItemStack blockStack = state.getBlock().getItem(worldIn, pos, state);
if (!blockStack.isEmpty()) {
if (!stack.hasTagCompound()) {
stack.setTagCompound(new NBTTagCompound());
}
Set<ResourceLocation> registeredItems = new HashSet<>();
ItemStackList stacks = ItemStackList.create(FILTER_SLOTS);
NBTTagList bufferTagList = stack.getTagCompound().getTagList("Items", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < bufferTagList.tagCount(); i++) {
NBTTagCompound nbtTagCompound = bufferTagList.getCompoundTagAt(i);
stacks.set(i, new ItemStack(nbtTagCompound));
}
for (int i = 0; i < FILTER_SLOTS; i++) {
if (stacks.get(i).isEmpty()) {
stacks.set(i, blockStack);
playerIn.sendStatusMessage(new TextComponentString(TextFormatting.GREEN + "Added " + blockStack.getDisplayName() + " to the filter!"), false);
StorageFilterInventory.convertItemsToNBT(stack.getTagCompound(), stacks);
break;
}
}
}
}
}
return EnumActionResult.SUCCESS;
}
return super.onItemUse(playerIn, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
use of mcjty.lib.varia.ItemStackList in project RFTools by McJty.
the class ModifierItem method getItemStacks.
public static ItemStackList getItemStacks(NBTTagCompound tagCompound) {
NBTTagList bufferTagList = tagCompound.getTagList("Items", Constants.NBT.TAG_COMPOUND);
ItemStackList stacks = ItemStackList.create(ModifierContainer.COUNT_SLOTS);
for (int i = 0; i < bufferTagList.tagCount(); i++) {
NBTTagCompound nbtTagCompound = bufferTagList.getCompoundTagAt(i);
stacks.set(i, new ItemStack(nbtTagCompound));
}
return stacks;
}
use of mcjty.lib.varia.ItemStackList in project RFTools by McJty.
the class ModifierItem method addOp.
private static void addOp(ItemStack stack, ModifierFilterType type, ModifierFilterOperation op) {
List<ModifierEntry> modifiers = getModifiers(stack);
NBTTagCompound tagCompound = stack.getTagCompound();
ItemStackList stacks = getItemStacks(tagCompound);
ItemStack stackIn = stacks.get(ModifierContainer.SLOT_FILTER);
ItemStack stackOut = stacks.get(ModifierContainer.SLOT_REPLACEMENT);
modifiers.add(new ModifierEntry(stackIn, stackOut, type, op));
stacks.set(ModifierContainer.SLOT_FILTER, ItemStack.EMPTY);
stacks.set(ModifierContainer.SLOT_REPLACEMENT, ItemStack.EMPTY);
ModifierInventory.convertItemsToNBT(tagCompound, stacks);
updateModifiers(stack, modifiers);
}
use of mcjty.lib.varia.ItemStackList in project RFTools by McJty.
the class ModifierItem method delOp.
private static void delOp(ItemStack stack, int index) {
List<ModifierEntry> modifiers = getModifiers(stack);
ModifierEntry entry = modifiers.get(index);
ItemStack in = entry.getIn();
ItemStack out = entry.getOut();
NBTTagCompound tagCompound = stack.getTagCompound();
ItemStackList stacks = getItemStacks(tagCompound);
if (!in.isEmpty() && !stacks.get(ModifierContainer.SLOT_FILTER).isEmpty()) {
// Something is in the way
return;
}
if (!out.isEmpty() && !stacks.get(ModifierContainer.SLOT_REPLACEMENT).isEmpty()) {
// Something is in the way
return;
}
if (!in.isEmpty()) {
stacks.set(ModifierContainer.SLOT_FILTER, in.copy());
}
if (!out.isEmpty()) {
stacks.set(ModifierContainer.SLOT_REPLACEMENT, out.copy());
}
ModifierInventory.convertItemsToNBT(tagCompound, stacks);
modifiers.remove(index);
updateModifiers(stack, modifiers);
}
use of mcjty.lib.varia.ItemStackList in project RFTools by McJty.
the class RFToolsJeiPlugin method transferRecipe.
public static void transferRecipe(Map<Integer, ? extends IGuiIngredient<ItemStack>> guiIngredients, BlockPos pos) {
ItemStackList items = ItemStackList.create(10);
for (Map.Entry<Integer, ? extends IGuiIngredient<ItemStack>> entry : guiIngredients.entrySet()) {
int recipeSlot = entry.getKey();
List<ItemStack> allIngredients = entry.getValue().getAllIngredients();
if (!allIngredients.isEmpty()) {
items.set(recipeSlot, allIngredients.get(0));
}
}
RFToolsMessages.INSTANCE.sendToServer(new PacketSendRecipe(items, pos));
}
Aggregations