Search in sources :

Example 1 with ItemStackWrapper

use of WayofTime.bloodmagic.util.ItemStackWrapper in project BloodMagic by WayofTime.

the class BindingRecipeMaker method getRecipes.

@Nonnull
public static List<BindingRecipeJEI> getRecipes() {
    Map<List<ItemStack>, AlchemyArrayRecipeRegistry.AlchemyArrayRecipe> alchemyArrayRecipeMap = AlchemyArrayRecipeRegistry.getRecipes();
    ArrayList<BindingRecipeJEI> recipes = new ArrayList<>();
    for (Map.Entry<List<ItemStack>, AlchemyArrayRecipeRegistry.AlchemyArrayRecipe> itemStackAlchemyArrayRecipeEntry : alchemyArrayRecipeMap.entrySet()) {
        List<ItemStack> input = itemStackAlchemyArrayRecipeEntry.getValue().getInput();
        BiMap<ItemStackWrapper, AlchemyArrayEffect> catalystMap = itemStackAlchemyArrayRecipeEntry.getValue().catalystMap;
        for (Map.Entry<ItemStackWrapper, AlchemyArrayEffect> entry : catalystMap.entrySet()) {
            ItemStack catalyst = entry.getKey().toStack();
            if (AlchemyArrayRecipeRegistry.getAlchemyArrayEffect(input, catalyst) instanceof AlchemyArrayEffectBinding) {
                ItemStack output = ((AlchemyArrayEffectBinding) itemStackAlchemyArrayRecipeEntry.getValue().getAlchemyArrayEffectForCatalyst(catalyst)).outputStack;
                BindingRecipeJEI recipe = new BindingRecipeJEI(input, catalyst, output);
                recipes.add(recipe);
            }
        }
    }
    return recipes;
}
Also used : ArrayList(java.util.ArrayList) AlchemyArrayEffectBinding(WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffectBinding) AlchemyArrayEffect(WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffect) List(java.util.List) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) ItemStackWrapper(WayofTime.bloodmagic.util.ItemStackWrapper) BiMap(com.google.common.collect.BiMap) Map(java.util.Map) Nonnull(javax.annotation.Nonnull)

Example 2 with ItemStackWrapper

use of WayofTime.bloodmagic.util.ItemStackWrapper in project BloodMagic by WayofTime.

the class ItemBoundTool method dropStacks.

protected static void dropStacks(Multiset<ItemStackWrapper> drops, World world, BlockPos posToDrop) {
    for (Multiset.Entry<ItemStackWrapper> entry : drops.entrySet()) {
        int count = entry.getCount();
        ItemStackWrapper stack = entry.getElement();
        int maxStackSize = stack.item.getItemStackLimit(stack.toStack(1));
        while (count >= maxStackSize) {
            world.spawnEntity(new EntityItem(world, posToDrop.getX(), posToDrop.getY(), posToDrop.getZ(), stack.toStack(maxStackSize)));
            count -= maxStackSize;
        }
        if (count > 0)
            world.spawnEntity(new EntityItem(world, posToDrop.getX(), posToDrop.getY(), posToDrop.getZ(), stack.toStack(count)));
    }
}
Also used : Multiset(com.google.common.collect.Multiset) ItemStackWrapper(WayofTime.bloodmagic.util.ItemStackWrapper) EntityItem(net.minecraft.entity.item.EntityItem)

Example 3 with ItemStackWrapper

use of WayofTime.bloodmagic.util.ItemStackWrapper in project BloodMagic by WayofTime.

the class AlchemyArrayRecipeRegistry method getRecipeForOutputStack.

/**
 * @param stack of the recipe
 * @return an array of two ItemStacks - first index is the input stack,
 * second is the catalyst stack. Returns {null, null} if no recipe
 * is valid.
 */
public static ItemStack[] getRecipeForOutputStack(ItemStack stack) {
    for (Entry<List<ItemStack>, AlchemyArrayRecipe> entry : recipes.entrySet()) {
        AlchemyArrayRecipe recipe = entry.getValue();
        if (recipe != null && entry.getKey().size() > 0) {
            for (Entry<ItemStackWrapper, AlchemyArrayEffect> effectEntry : recipe.catalystMap.entrySet()) {
                if (effectEntry.getValue() instanceof AlchemyArrayEffectCrafting) {
                    AlchemyArrayEffectCrafting craftingEffect = (AlchemyArrayEffectCrafting) effectEntry.getValue();
                    ItemStack resultStack = craftingEffect.outputStack;
                    if (!resultStack.isEmpty()) {
                        if (resultStack.getItem() == stack.getItem() && resultStack.getItemDamage() == stack.getItemDamage()) {
                            return new ItemStack[] { entry.getKey().get(0), effectEntry.getKey().toStack() };
                        }
                    }
                }
            }
        }
    }
    return new ItemStack[] { null, null };
}
Also used : AlchemyArrayEffectCrafting(WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffectCrafting) AlchemyArrayEffect(WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffect) List(java.util.List) ItemStackWrapper(WayofTime.bloodmagic.util.ItemStackWrapper) ItemStack(net.minecraft.item.ItemStack)

Example 4 with ItemStackWrapper

use of WayofTime.bloodmagic.util.ItemStackWrapper in project BloodMagic by WayofTime.

the class ItemBoundPickaxe method onBoundRelease.

@Override
protected void onBoundRelease(ItemStack stack, World world, EntityPlayer player, int charge) {
    if (world.isRemote)
        return;
    boolean silkTouch = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0;
    int fortuneLvl = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
    // Charge is a max of 30 - want 5 to be the max
    int range = (charge / 6);
    HashMultiset<ItemStackWrapper> drops = HashMultiset.create();
    BlockPos playerPos = player.getPosition();
    for (int i = -range; i <= range; i++) {
        for (int j = 0; j <= 2 * range; j++) {
            for (int k = -range; k <= range; k++) {
                BlockPos blockPos = playerPos.add(i, j, k);
                BlockStack blockStack = BlockStack.getStackFromPos(world, blockPos);
                if (blockStack.getBlock().isAir(blockStack.getState(), world, blockPos))
                    continue;
                if (blockStack.getState().getMaterial() != Material.ROCK && !EFFECTIVE_ON.contains(blockStack.getBlock()))
                    continue;
                BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, blockPos, blockStack.getState(), player);
                if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
                    continue;
                if (blockStack.getBlock() != null && blockStack.getBlock().getBlockHardness(blockStack.getState(), world, blockPos) != -1) {
                    float strengthVsBlock = getDestroySpeed(stack, blockStack.getState());
                    if (strengthVsBlock > 1.1F && world.canMineBlockBody(player, blockPos)) {
                        if (silkTouch && blockStack.getBlock().canSilkHarvest(world, blockPos, world.getBlockState(blockPos), player))
                            drops.add(new ItemStackWrapper(blockStack));
                        else {
                            List<ItemStack> itemDrops = blockStack.getBlock().getDrops(world, blockPos, world.getBlockState(blockPos), fortuneLvl);
                            for (ItemStack stacks : itemDrops) drops.add(ItemStackWrapper.getHolder(stacks));
                        }
                        world.setBlockToAir(blockPos);
                    }
                }
            }
        }
    }
    NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, (int) (charge * charge * charge / 2.7));
    world.createExplosion(player, playerPos.getX(), playerPos.getY(), playerPos.getZ(), 0.5F, false);
    dropStacks(drops, world, playerPos.add(0, 1, 0));
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) ItemStackWrapper(WayofTime.bloodmagic.util.ItemStackWrapper) BlockStack(WayofTime.bloodmagic.util.BlockStack) ItemStack(net.minecraft.item.ItemStack) BlockEvent(net.minecraftforge.event.world.BlockEvent)

Example 5 with ItemStackWrapper

use of WayofTime.bloodmagic.util.ItemStackWrapper in project BloodMagic by WayofTime.

the class ItemBoundAxe method onBoundRelease.

@Override
protected void onBoundRelease(ItemStack stack, World world, EntityPlayer player, int charge) {
    if (world.isRemote)
        return;
    boolean silkTouch = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0;
    int fortuneLvl = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
    // Charge is a max of 30 - want 5 to be the max
    int range = charge / 6;
    HashMultiset<ItemStackWrapper> drops = HashMultiset.create();
    BlockPos playerPos = player.getPosition();
    for (int i = -range; i <= range; i++) {
        for (int j = 0; j <= 2 * range; j++) {
            for (int k = -range; k <= range; k++) {
                BlockPos blockPos = playerPos.add(i, j, k);
                BlockStack blockStack = BlockStack.getStackFromPos(world, blockPos);
                if (blockStack.getBlock().isAir(blockStack.getState(), world, blockPos))
                    continue;
                if (blockStack.getState().getMaterial() != Material.WOOD && !EFFECTIVE_ON.contains(blockStack.getBlock()))
                    continue;
                BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, blockPos, blockStack.getState(), player);
                if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
                    continue;
                if (blockStack.getState().getBlockHardness(world, blockPos) != -1.0F) {
                    float strengthVsBlock = getDestroySpeed(stack, blockStack.getState());
                    if (strengthVsBlock > 1.1F || blockStack.getBlock() instanceof BlockLeaves && world.canMineBlockBody(player, blockPos)) {
                        if (silkTouch && blockStack.getBlock().canSilkHarvest(world, blockPos, world.getBlockState(blockPos), player))
                            drops.add(new ItemStackWrapper(blockStack));
                        else {
                            List<ItemStack> itemDrops = blockStack.getBlock().getDrops(world, blockPos, world.getBlockState(blockPos), fortuneLvl);
                            for (ItemStack stacks : itemDrops) drops.add(ItemStackWrapper.getHolder(stacks));
                        }
                        world.setBlockToAir(blockPos);
                    }
                }
            }
        }
    }
    NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, (int) (charge * charge * charge / 2.7));
    world.createExplosion(player, playerPos.getX(), playerPos.getY(), playerPos.getZ(), 0.1F, false);
    dropStacks(drops, world, playerPos.add(0, 1, 0));
}
Also used : BlockStack(WayofTime.bloodmagic.util.BlockStack) BlockLeaves(net.minecraft.block.BlockLeaves) BlockPos(net.minecraft.util.math.BlockPos) ItemStackWrapper(WayofTime.bloodmagic.util.ItemStackWrapper) ItemStack(net.minecraft.item.ItemStack) BlockEvent(net.minecraftforge.event.world.BlockEvent)

Aggregations

ItemStackWrapper (WayofTime.bloodmagic.util.ItemStackWrapper)6 ItemStack (net.minecraft.item.ItemStack)5 BlockStack (WayofTime.bloodmagic.util.BlockStack)3 BlockPos (net.minecraft.util.math.BlockPos)3 BlockEvent (net.minecraftforge.event.world.BlockEvent)3 AlchemyArrayEffect (WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffect)2 List (java.util.List)2 AlchemyArrayEffectBinding (WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffectBinding)1 AlchemyArrayEffectCrafting (WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffectCrafting)1 BiMap (com.google.common.collect.BiMap)1 Multiset (com.google.common.collect.Multiset)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Nonnull (javax.annotation.Nonnull)1 BlockLeaves (net.minecraft.block.BlockLeaves)1 Material (net.minecraft.block.material.Material)1 EntityItem (net.minecraft.entity.item.EntityItem)1