def recalcSlice(): global worldSlice, hmTrees, hmOceanFloor, heightmap worldSlice = WorldSlice( x1, z1, x2, z2, ["MOTION_BLOCKING_NO_LEAVES", "WORLD_SURFACE", "OCEAN_FLOOR"]) hmTrees = worldSlice.heightmaps["WORLD_SURFACE"] hmOceanFloor = worldSlice.heightmaps["OCEAN_FLOOR"] heightmap = calcGoodHeightmap(worldSlice) heightmap = heightmap.astype(np.uint8)
from matplotlib.pyplot import plot from numpy import random from worldLoader import WorldSlice import cv2 import numpy as np import matplotlib.pyplot as plt # you can edit the area here # (x, y, width, height) rect = (-32, -32, 64, 64) slice = WorldSlice(rect) # heightmap = np.zeros((rect[2],rect[3]), dtype = np.uint8) # for lx in range(rect[2]): # x = rect[0] + lx # for lz in range(rect[3]): # z = rect[1] + lz # for y in range(127, -1, -1): # block = slice.getBlockAt((x, y, z)) # if block != None and block["Name"].value != "minecraft:air": # heightmap[lx, lz] = y # + random.uniform(0, 16) # break heightmap = np.array(slice.heightmaps["MOTION_BLOCKING_NO_LEAVES"], dtype = np.uint8) heightmap2 = np.array(slice.heightmaps["OCEAN_FLOOR"], dtype = np.uint8) watermap = 255 - ((heightmap+1 >> 6) % 2) * 255
# see if a build area has been specified # you can set a build area in minecraft using the /setbuildarea command buildArea = interfaceUtils.requestBuildArea() if buildArea != -1: x1 = buildArea["xFrom"] z1 = buildArea["zFrom"] x2 = buildArea["xTo"] z2 = buildArea["zTo"] # print(buildArea) area = (x1, z1, x2 - x1, z2 - z1) print("Build area is at position %s, %s with size %s, %s" % area) # load the world data # this uses the /chunks endpoint in the background worldSlice = WorldSlice(area) heightmap = worldSlice.heightmaps["MOTION_BLOCKING"] heightmap = worldSlice.heightmaps["MOTION_BLOCKING_NO_LEAVES"] heightmap = worldSlice.heightmaps["OCEAN_FLOOR"] heightmap = worldSlice.heightmaps["WORLD_SURFACE"] # caclulate a heightmap that ignores trees: heightmap = mapUtils.calcGoodHeightmap(worldSlice) # show the heightmap as an image # mapUtils.visualize(heightmap, title="heightmap") # define a function for easier heightmap access # heightmap coordinates are not equal to world coordinates! def heightAt(x, z):
# w = h = 15 w = h = 5 layers = 3 area = (700, -750, w * 5 * 3, h * 5 * 3) buildArea = interfaceUtils.requestBuildArea() if buildArea != -1: x1 = buildArea["xFrom"] z1 = buildArea["zFrom"] x2 = buildArea["xTo"] z2 = buildArea["zTo"] # print(buildArea) area = (x1, z1, int((x2 - x1) / 15) * 15, int((z2 - z1) / 15) * 15) print("Build area is at position %s, %s with size %s, %s" % area) worldSlice = WorldSlice(area) strctElmt3x3 = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3)) # crossKernel3x3 = np.array([[0,1,0],[1,1,1],[0,1,0]) kernel1x3 = np.array([[1, 1, 1]]) kernel3x1 = np.transpose(kernel1x3) kernel3x3 = kernel3x1 * kernel1x3 heightmap = np.array(worldSlice.heightmaps["WORLD_SURFACE"], dtype=np.uint8) # heightmap = mapUtils.fractalnoise((area[2], area[3])) floorWallMappings = [ # [f,w,c,s] (floor, wall, ceiling, space) [1, 1, 1], # 0: wall [1, 0, 0], # 1: walkway [0, 0, 0], # 2: void [1, 0, 1], # 3: floor/ceiling [1, 1, 1] # 4: seawall
rect = (0, 0, 128, 128) # default build area # see if a different build area was defined ingame buildArea = interfaceUtils.requestBuildArea() if buildArea != -1: x1 = buildArea["xFrom"] z1 = buildArea["zFrom"] x2 = buildArea["xTo"] z2 = buildArea["zTo"] # DEBUG: print(buildArea) rect = (x1, z1, x2 - x1, z2 - z1) # DEBUG: print(rect) # load the world data and extract the heightmap(s) slice = WorldSlice(rect) heightmap1 = np.array(slice.heightmaps["MOTION_BLOCKING_NO_LEAVES"], dtype=np.uint8) heightmap2 = np.array(slice.heightmaps["OCEAN_FLOOR"], dtype=np.uint8) heightmap = np.minimum(heightmap1, heightmap2) # calculate the gradient (steepness) gradientX = cv2.Scharr(heightmap, cv2.CV_16S, 1, 0) gradientY = cv2.Scharr(heightmap, cv2.CV_16S, 0, 1) # create a dictionary mapping block ids ("minecraft:...") to colors palette = {} for hex, blocks in blockColors.PALETTE.items(): for block in blocks:
__all__ = ['WorldSlice'] # __version__ import blockColors import cv2 import interfaceUtils import matplotlib.pyplot as plt import numpy as np from worldLoader import WorldSlice if __name__ == '__main__': # see if a different build area was defined ingame x1, y1, z1, x2, y2, z2 = interfaceUtils.requestBuildArea() # load the world data and extract the heightmap(s) slice = WorldSlice(x1, z1, x2, z2) heightmap = np.array(slice.heightmaps["OCEAN_FLOOR"], dtype=np.uint8) # calculate the gradient (steepness) gradientX = cv2.Scharr(heightmap, cv2.CV_16S, 1, 0) gradientY = cv2.Scharr(heightmap, cv2.CV_16S, 0, 1) # create a dictionary mapping block ids ("minecraft:...") to colors palette = {} for hex, blocks in blockColors.PALETTE.items(): for block in blocks: palette[block] = hex # create a 2d map containing the surface block colors
h = 128 interfaceUtils.runCommand( f"execute at @p run setbuildarea ~-{int(w/2)} 0 ~-{int(h/2)} ~{int(w/2)} 256 ~{int(h/2)}" ) # 2D build area buildArea = interfaceUtils.requestBuildArea() if buildArea != -1: x1 = buildArea["xFrom"] z1 = buildArea["zFrom"] x2 = buildArea["xTo"] z2 = buildArea["zTo"] # print(buildArea) area = (x1, z1, x2 - x1, z2 - z1) ws = WorldSlice(area, ["MOTION_BLOCKING_NO_LEAVES", "OCEAN_FLOOR", "WORLD_SURFACE"]) heightmap = calcGoodHeightmap(ws).astype(np.uint8) hmTrees = ws.heightmaps["WORLD_SURFACE"] heightmapOcean = ws.heightmaps["OCEAN_FLOOR"].astype(np.uint8) borderMap = np.ones(heightmap.shape, dtype=np.uint8) borderMap[1:-1, 1:-1] = 0 landmapBorder = ((heightmapOcean > 62) & (borderMap == 0)).astype(np.uint8) landmap = ((heightmapOcean > 62)).astype(np.uint8) # visualize(landmapBorder) dst, labels = cv2.distanceTransformWithLabels(landmapBorder,
import cv2 from matplotlib import pyplot as plt from mapUtils import distanceToCenter, fractalnoise, normalize, registerSetBlock, runCommand, sendBlocks, minecraft_colors, visualize from worldLoader import WorldSlice import numpy as np import random area = np.array([10000, 2000, 256, 256]) slice = WorldSlice(area) hm_mbnl = np.array(slice.heightmaps["MOTION_BLOCKING_NO_LEAVES"], dtype=np.uint8) heightmap2 = np.array(slice.heightmaps["OCEAN_FLOOR"], dtype=np.uint8) heightmap3 = np.array(slice.heightmaps["MOTION_BLOCKING"], dtype=np.uint8) heightmap4 = np.array(slice.heightmaps["WORLD_SURFACE"], dtype=np.uint8) # for key in slice.heightmaps.keys(): # hm = np.array(slice.heightmaps[key]) # hm = hm.astype(np.uint8) # plt.figure() # plt.title(key) # plt_image = cv2.cvtColor(hm, cv2.COLOR_BGR2RGB) # imgplot = plt.imshow(plt_image) # plt.show() # input() # testm = np.zeros(mbnl.shape, dtype=np.uint8) heightmapNoTrees = hm_mbnl[:]
import sys from worldLoader import WorldSlice ######################## GLOBAL VARIABLES ######################## AREA = buildUtils.BuildArea(buildUtils.getBuildArea()) if len(sys.argv) < 2: pass elif len(sys.argv) == 4: AREA.x = int(sys.argv[1]) AREA.z = int(sys.argv[2]) AREA.size = int(sys.argv[3]) MAP_SIZE = AREA.size WORLD_SLICE = WorldSlice(AREA.get()) HEIGHT_MAP = mapUtils.calcGoodHeightmap(WORLD_SLICE) USE_BATCHING = True BUILD_MAP = buildUtils.BuildMap(MAP_SIZE, (AREA.x, AREA.z)) BUILDER = buildUtils.Builder(HEIGHT_MAP, AREA.get(), USE_BATCHING) ################################################################## ########################### WORLD SETUP ######################### ################################################################## # plot fence perimeter_area = (AREA.x-1, AREA.z-1, AREA.size + 2, AREA.size + 2) perimeter_h_map = mapUtils.calcGoodHeightmap(WorldSlice(perimeter_area)) area_builder = buildUtils.Builder(perimeter_h_map, perimeter_area, USE_BATCHING) area_builder.generatePlotFence()
def rectanglesOverlap(r1, r2): """Check whether r1 and r2 overlap.""" if ((r1[0] >= r2[0] + r2[2]) or (r1[0] + r1[2] <= r2[0]) or (r1[1] + r1[3] <= r2[1]) or (r1[1] >= r2[1] + r2[3])): return False else: return True if __name__ == '__main__': print(f"Build area is at position {startx}, {startz}" f" with size {endx}, {endz}") # load the world data # this uses the /chunks endpoint in the background worldSlice = WorldSlice(startx, startz, endx, endz) # calculate a heightmap suitable for building: heightmap = mapUtils.calcGoodHeightmap(worldSlice) heightmap = heightmap.astype(np.uint8) hmo = heightmap heightmap = cv2.medianBlur(heightmap, 13) # structElmt = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5)) # heightmap = cv2.erode(heightmap, structElmt) # heightmap = cv2.dilate(heightmap, structElmt) # hist = cv2.calcHist([heightmap], [0], None, [256], [0, 256]) # histo = cv2.calcHist([hmo], [0], None, [256], [0, 256])
from worldLoader import WorldSlice import interfaceUtils # for testing interfaceUtils.runCommand("execute at @p run setbuildarea ~ ~-1 ~ ~ ~ ~") # 2D build area buildArea = interfaceUtils.requestBuildArea() if buildArea != -1: x1 = buildArea["xFrom"] y1 = buildArea["yFrom"] z1 = buildArea["zFrom"] x2 = buildArea["xTo"] y2 = buildArea["yTo"] z2 = buildArea["zTo"] # print(buildArea) area = (x1, z1, x2 - x1, z2 - z1) ws = WorldSlice(area, []) block = ws.getBlockCompoundAt((x1, y1, z1)) print(block) print(block["Properties"]) print(block["Properties"]["half"])
from numpy.core.defchararray import mod from numpy.lib.function_base import diff import requests from worldLoader import WorldSlice, setBlock import cv2 import numpy as np import matplotlib.pyplot as plt from math import ceil, copysign, log2 # rect = (-64, -92 - 218-92, 80+64, 218-92) # rect = (-32, -32, 64, 64) # rect = (-200 + 255, -200 - 60, 401, 401) # rect = (-32-64, -32-64-128, 64, 64) rect = (-128, -128, 256, 256) slice = WorldSlice(rect) heightmap1 = np.array(slice.heightmaps["MOTION_BLOCKING_NO_LEAVES"], dtype=np.uint8) heightmap2 = np.array(slice.heightmaps["OCEAN_FLOOR"], dtype=np.uint8) heightmap = np.minimum(heightmap1, heightmap2) watermap = heightmap - heightmap2 + 128 bHM = cv2.blur(heightmap, (7, 7)) dx = cv2.Scharr(heightmap, cv2.CV_16S, 1, 0) dy = cv2.Scharr(heightmap, cv2.CV_16S, 0, 1) atan = np.arctan2(dx, dy, dtype=np.float64) * 5 / 6.283 atan = atan % 5