Search in sources :

Example 6 with ItemStackWrapper

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

the class ItemBoundShovel 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;
                Material material = blockStack.getState().getMaterial();
                if (material != Material.GROUND && material != Material.CLAY && material != Material.GRASS && !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 : Material(net.minecraft.block.material.Material) BlockStack(WayofTime.bloodmagic.util.BlockStack) 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