-
-
Save Sevadus/af0c80e29f4fd2a5e3b0db35380ebe68 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import anvil | |
from collections import defaultdict | |
import datetime | |
import math | |
regions = dict() | |
chunks = dict() | |
mineables = {'coal_ore','iron_ore','redstone_ore','diamond_ore','gold_ore','lapis_ore','emerald_ore'} | |
csv_filename = "minedata" + str(datetime.datetime.now().strftime("%Y%m%d-%H%M%S")) + ".csv" | |
def get_block_penis(x, y, z): | |
# Find the region & chunk the block is in | |
block_x = x % 16 | |
block_z = z % 16 | |
chunk_x = x // 16 | |
chunk_z = z // 16 | |
region_x = chunk_x // 32 | |
region_z = chunk_z // 32 | |
region = (region_x, region_z) | |
chunk = (chunk_x, chunk_z) | |
if region not in regions: | |
regions[region] = anvil.Region.from_file(f'server/world/region/r.{region_x}.{region_z}.mca') | |
if chunk not in chunks: | |
chunks[chunk] = anvil.Chunk.from_region(regions[region], chunk_x, chunk_z) | |
return(chunks[chunk].get_block(block_x, y, block_z).id) | |
def mine(x, y, z): | |
return(get_block_penis(x, y, z)) | |
def check_blocks(x_min, x_max, y_min, y_max, z_min, z_max, mineables, mined_blocks, backpack): | |
blocks_to_mine = set() | |
offsets = [(1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0), (0, 0, 1), (0, 0, -1)] | |
for x in range(x_min, x_max + 1): | |
for y in range(y_min, y_max + 1): | |
for z in range(z_min, z_max + 1): | |
blocks_to_mine.add((x, y, z)) | |
counter = 0 | |
while len(blocks_to_mine) > 0: | |
counter += 1 | |
block = blocks_to_mine.pop() | |
mined_blocks.add(block) | |
block_type = get_block_penis(block[0], block[1], block[2]) | |
# Add to backpack | |
backpack[block_type] += 1 | |
# OMG I FOUND A DIAMOND | |
#if block_type == "diamond_ore": | |
# print("Found Diamond at:", block[0], block[1], block[2]) | |
# Add all newly exposed blocks to blocks_to_check | |
for offset in offsets: | |
check = tuple(sum(dingus) for dingus in zip(block, offset)) | |
if check not in blocks_to_mine and check not in mined_blocks and get_block_penis(*check) in mineables: | |
blocks_to_mine.add(check) | |
return(mined_blocks, backpack) | |
def mine1x2(mining_rectangle, length_of_tunnel, blocks_between_tunnels, standing_on_y): | |
mined_blocks = set() | |
backpack = defaultdict(int) | |
count = 0 | |
for x in range(mining_rectangle[0], mining_rectangle[2], blocks_between_tunnels + 1): | |
#print("Running Tunnel At x =", x) | |
for length in range(mining_rectangle[1], mining_rectangle[3], length_of_tunnel): | |
count += 1 | |
#print("Mining tunnel", x, length, "to", x, length + length_of_tunnel) | |
mined_blocks, backpack = check_blocks(x, x, standing_on_y + 1, standing_on_y + 2, | |
length, length + length_of_tunnel, mineables, mined_blocks, backpack) | |
print(f"Total Diamonds Found: {backpack['diamond_ore']}\nTotal Blocks Mined: {len(mined_blocks)}\n" | |
f"Diamond Efficiency: {100 * backpack['diamond_ore'] / len(mined_blocks)}%") | |
print(backpack) | |
f = open(csv_filename, "a") | |
f.write(f"{blocks_between_tunnels},{backpack['diamond_ore']},{len(mined_blocks)},{100 * backpack['diamond_ore'] / len(mined_blocks)}%\n") | |
f.close() | |
def main(): | |
# Sim: Dig 1 x 2 tunnel 512 blocks, count diamonds encountered | |
length_of_tunnel = 512 | |
blocks_between_tunnels = 0 | |
standing_on_y = 10 | |
mining_rectangle = [0, 0, 512, 512] #(x1, z1, x2, z2) | |
#mining_rectangle = [-2048, -2048, 2048, 2048] #(x1, z1, x2, z2) | |
f = open(csv_filename, "w") | |
f.write("Blocks Between Tunnels,Diamond Ore Mined,Total Blocks Mined,Diamond Efficiency\n") | |
f.close() | |
for b in range(13): | |
print(f"Running simulation with {b} blocks between tunnels.") | |
mine1x2(mining_rectangle, length_of_tunnel, b, standing_on_y) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment