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));
}
Aggregations