Search in sources :

Example 6 with BlockStack

use of WayofTime.bloodmagic.util.BlockStack 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

BlockStack (WayofTime.bloodmagic.util.BlockStack)6 BlockPos (net.minecraft.util.math.BlockPos)4 ItemStackWrapper (WayofTime.bloodmagic.util.ItemStackWrapper)3 ItemStack (net.minecraft.item.ItemStack)3 BlockEvent (net.minecraftforge.event.world.BlockEvent)3 BlockBloodRune (WayofTime.bloodmagic.block.BlockBloodRune)2 IInventory (net.minecraft.inventory.IInventory)2 ItemBlock (net.minecraft.item.ItemBlock)2 IItemHandler (net.minecraftforge.items.IItemHandler)2 ArrayList (java.util.ArrayList)1 Block (net.minecraft.block.Block)1 BlockLeaves (net.minecraft.block.BlockLeaves)1 Material (net.minecraft.block.material.Material)1 TileEntity (net.minecraft.tileentity.TileEntity)1 World (net.minecraft.world.World)1