Skip to content

Commit

Permalink
Fixed cave generation
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperTails committed Apr 10, 2021
1 parent be9f044 commit 13e3581
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
7 changes: 5 additions & 2 deletions craft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)]
Expand Down
2 changes: 2 additions & 0 deletions util.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Types and functions useful for the whole codebase."""

import decimal
from typing import NamedTuple, Tuple, Optional

Expand Down
20 changes: 11 additions & 9 deletions world.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 13e3581

Please sign in to comment.