use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.
the class RecipeInputEnchantedBook method matches.
@Override
public boolean matches(ItemStack stack) {
if (validEnchantments == null) {
validEnchantments = new HashSet<Enchantment>();
ItemStack[] items = { new ItemStack(BetterStorageItems.cardboardHelmet), new ItemStack(BetterStorageItems.cardboardChestplate), new ItemStack(BetterStorageItems.cardboardLeggings), new ItemStack(BetterStorageItems.cardboardBoots), new ItemStack(BetterStorageItems.cardboardSword), new ItemStack(BetterStorageItems.cardboardPickaxe), new ItemStack(BetterStorageItems.cardboardShovel), new ItemStack(BetterStorageItems.cardboardAxe), new ItemStack(BetterStorageItems.cardboardHoe) };
for (Enchantment ench : Enchantment.enchantmentsList) {
if ((ench == null) || !ench.isAllowedOnBooks())
continue;
for (ItemStack item : items) if (item.getItem() != null && ench.canApply(item)) {
validEnchantments.add(ench);
break;
}
}
}
if (stack.getItem() instanceof ItemEnchantedBook) {
Map<Integer, Integer> enchants = EnchantmentHelper.getEnchantments(stack);
for (Enchantment ench : validEnchantments) if (enchants.containsKey(ench.effectId))
return true;
}
return false;
}
use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.
the class InventoryCrateBlockView method setInventorySlotContents.
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
access();
if ((slot < 0) || (slot >= getSizeInventory()))
return;
ItemStack oldStack = null;
if (slot > 0) {
oldStack = originalStacks[slot - 1];
exposedStacks[slot - 1] = stack;
originalStacks[slot - 1] = ItemStack.copyItemStack(stack);
}
isModifying = true;
if (oldStack != null) {
// If the two stacks match, just add/remove the difference.
if (StackUtils.matches(oldStack, stack)) {
int count = stack.stackSize - oldStack.stackSize;
if (count > 0)
data.addItems(StackUtils.copyStack(stack, count));
else if (count < 0)
data.removeItems(StackUtils.copyStack(stack, -count));
isModifying = false;
return;
}
data.removeItems(oldStack);
}
data.addItems(stack);
isModifying = false;
}
use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.
the class InventoryCratePlayerView method decrStackSize.
@Override
public ItemStack decrStackSize(int slot, int amount) {
ItemStack stack = getStackInSlot(slot);
if (stack == null)
return null;
amount = Math.min(amount, stack.stackSize);
ItemIdentifier item = new ItemIdentifier(stack);
getMapData(item).itemCount -= amount;
stack.stackSize -= amount;
if (stack.stackSize <= 0)
tempContents[slot] = null;
ignoreModifiedItems = true;
ItemStack result = data.removeItems(item, amount);
ignoreModifiedItems = false;
if (tempContents[slot] == null)
onSlotEmptied(slot);
return result;
}
use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.
the class InventoryCratePlayerView method onSlotEmptied.
private void onSlotEmptied(int slot) {
int emptySlots = 0;
for (int s = 0; s < tempContents.length; s++) if (tempContents[s] == null)
emptySlots++;
if (emptySlots <= data.getFreeSlots())
return;
for (ItemStack stack : data.getContents().getItems()) {
ItemIdentifier item = new ItemIdentifier(stack);
MapData itemData = getMapData(item);
int count = (stack.stackSize - itemData.itemCount);
if (count <= 0)
continue;
setItemsInSlot(slot, item, itemData, count);
}
}
use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.
the class DrinkingHelmetRecipe method getCraftingResult.
@Override
public ItemStack getCraftingResult(InventoryCrafting crafting) {
ItemStack drinkingHelmet = null;
ItemStack[] potions = null;
for (int i = 0; i < crafting.getSizeInventory(); i++) {
drinkingHelmet = crafting.getStackInSlot(i);
if ((drinkingHelmet != null) && (drinkingHelmet.getItem() instanceof ItemDrinkingHelmet)) {
drinkingHelmet = drinkingHelmet.copy();
potions = new ItemStack[] { crafting.getStackInSlot(i + 1), crafting.getStackInSlot(i - 1) };
break;
}
}
ItemDrinkingHelmet.setPotions(drinkingHelmet, potions);
return drinkingHelmet;
}
Aggregations