From 13e3581c99ffae32dbab769f132ad5b6cd37a0e6 Mon Sep 17 00:00:00 2001 From: Carson Swoveland Date: Fri, 9 Apr 2021 21:38:02 -0600 Subject: [PATCH] Fixed cave generation --- craft.py | 7 +++++-- util.py | 2 ++ world.py | 20 +++++++++++--------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/craft.py b/craft.py index d05a749..920d3f5 100644 --- a/craft.py +++ b/craft.py @@ -65,11 +65,14 @@ def worldToFolderName(name: str) -> str: class WorldLoadMode(Mode): loadStage: int = 0 - def __init__(self, app, worldName, nextMode, seed=40, importPath=''): + def __init__(self, app, worldName, nextMode, seed=None, importPath=''): self.nextMode = nextMode app.timerDelay = 10 + if seed is None: + seed = random.random() + #app.world = World(worldName, seed, anvilpath='C:/Users/Carson/AppData/Roaming/.minecraft/saves/TheTempleofNotch/region/') app.world = World(worldName, seed, importPath=importPath) @@ -854,7 +857,7 @@ def appStarted(app): app.mode = WorldLoadMode(app, 'world', TitleMode) #def makePlayingMode(app): return PlayingMode(app, False) - #app.mode = WorldLoadMode(app, 'demoworld', makePlayingMode, seed=random.random()) + #app.mode = WorldLoadMode(app, 'cavetest3', makePlayingMode, seed=random.random()) #app.mode = CreateWorldMode(app) app.entities = [entity.Entity(app, 'creeper', 0.0, 71.0, 1.0), entity.Entity(app, 'fox', 5.0, 72.0, 3.0)] diff --git a/util.py b/util.py index ba7dd6f..c279208 100644 --- a/util.py +++ b/util.py @@ -1,3 +1,5 @@ +"""Types and functions useful for the whole codebase.""" + import decimal from typing import NamedTuple, Tuple, Optional diff --git a/world.py b/world.py index c98aa93..074407d 100644 --- a/world.py +++ b/world.py @@ -100,7 +100,7 @@ def __init__(self, pos: BlockPos): self.z = pos.z self.yaw = 0.0 - self.pitch = -60.0 + self.pitch = math.radians(-35.0) self.count = 0 @@ -111,10 +111,12 @@ def step(self, seed: int) -> bool: # Caves should not intersect with the bottom of the world, # so make them go back upwards if they're too low - if self.y > 10 or self.pitch > 0.0: - pitchOffset = 0.0 - else: + if self.y > 100 and self.pitch > 0.0: + pitchOffset = -math.exp(-0.1 * (128 - self.y)) + if self.y < 10 and self.pitch < 0.0: pitchOffset = math.exp(-0.5 * self.y) + else: + pitchOffset = 0.0 self.pitch += ((random.random() * 2.0) - 1.0 + pitchOffset) * math.radians(20.0) @@ -476,7 +478,7 @@ def generate(self, world, instData, cavePositions, seed): minVal = 100.0 maxVal = -100.0 - positions = set() + positions = [] minIdx = binarySearchMin(cavePositions, self.pos.x * 16 - 1) maxIdx = binarySearchMax(cavePositions, (self.pos.x + 1) * 16) @@ -486,7 +488,7 @@ def generate(self, world, instData, cavePositions, seed): minIdx = 0 if maxIdx is None: maxIdx = len(cavePositions) - 1 - + for posIdx in range(minIdx, maxIdx + 1): pos = cavePositions[posIdx] for xOff in range(-1, 2): @@ -495,10 +497,10 @@ def generate(self, world, instData, cavePositions, seed): pos2 = BlockPos(pos.x + xOff, pos.y + yOff, pos.z + zOff) (ckPos, ckLocal) = toChunkLocal(pos2) if ckPos == self.pos: - positions.add(ckLocal) + positions.append(ckLocal) + print(f"{len(positions)}-many positions: ") - print(f"{len(positions)}-many positions: ") for xIdx in range(0, 16): for zIdx in range(0, 16): @@ -1164,7 +1166,7 @@ def __init__(self, name: str, seed=None, importPath=''): except FileNotFoundError: self.saveMetaFile() - self.caveBlocks = generateCaveCenter(BlockPos(8, 78, 8), self.seed) + self.caveBlocks = generateCaveCenter(BlockPos(8, 72, 8), self.seed) print(self.caveBlocks) def saveMetaFile(self):