//credit to stitch37 for this code public void destroyBlocks(IWorldAccessor world, BlockPos min, BlockPos max, IPlayer player, BlockPos centerBlockPos, ItemSlot slot) { int energy = slot.Itemstack.Attributes.GetInt("energy", 0); var centerBlock = world.BlockAccessor.GetBlock(centerBlockPos); var itemStack = new ItemStack(this); Block tempBlock; var miningTimeMainBlock = GetMiningSpeed(itemStack, centerBlock, player); float miningTime; var tempPos = new BlockPos(); for (int x = min.X; x <= max.X; x++) { for (int y = min.Y; y <= max.Y; y++) { for (int z = min.Z; z <= max.Z; z++) { tempPos.Set(x, y, z); tempBlock = world.BlockAccessor.GetBlock(tempPos); if (player.WorldData.CurrentGameMode == EnumGameMode.Creative) { world.BlockAccessor.SetBlock(0, tempPos); } else { if (energy >= consume) { miningTime = tempBlock.GetMiningSpeed(itemStack, tempBlock, player); if (this.ToolTier >= tempBlock.RequiredMiningTier && miningTimeMainBlock * 1.5f >= miningTime && MiningSpeed.ContainsKey(tempBlock.BlockMaterial)) { world.BlockAccessor.BreakBlock(tempPos, player); } } } } } } }
public void destroyBlocks(IWorldAccessor world, BlockPos min, BlockPos max, IPlayer player, BlockPos centerBlockPos) { var centerBlock = world.BlockAccessor.GetBlock(centerBlockPos); var itemStack = new ItemStack(this); Block tempBlock; var miningTimeMainBlock = GetMiningSpeed(itemStack, centerBlock, player); float miningTime; var tempPos = new BlockPos(); for (int x = min.X; x <= max.X; x++) { for (int y = min.Y; y <= max.Y; y++) { for (int z = min.Z; z <= max.Z; z++) { tempPos.Set(x, y, z); tempBlock = world.BlockAccessor.GetBlock(tempPos); if (player.WorldData.CurrentGameMode == EnumGameMode.Creative) { world.BlockAccessor.SetBlock(0, tempPos); } else { //Check if we can mine this block miningTime = tempBlock.GetMiningSpeed(itemStack, tempBlock, player); if (this.ToolTier >= tempBlock.RequiredMiningTier && //Нужный уровень инструмента miningTimeMainBlock * 1.5f >= miningTime && //Время добычи не сильно отличается MiningSpeed.ContainsKey(tempBlock.BlockMaterial)) //И материал металл или камень { world.BlockAccessor.BreakBlock(tempPos, player); } } } } } }