From 904221ac1490918ada7423213c39a6ea1fb6fbff Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Fri, 28 Jan 2022 15:24:03 +0800 Subject: [PATCH] worldgen water, fixes --- internal/asset/texture/world/planks_oak.png | Bin 0 -> 268 bytes internal/asset/texture/world/water.png | Bin 0 -> 411 bytes internal/game/logic.go | 6 +- internal/util/itype/vec.go | 10 ++- internal/world/block.go | 24 +++--- internal/world/blocks/default.go | 49 ++++++++++++ internal/world/blocks/helper_appendface.go | 78 ++++++++++++++++++++ internal/world/blocks/water.go | 37 ++++++++++ internal/world/chunk.go | 11 ++- internal/world/default_blocks.go | 40 ---------- internal/world/render.go | 13 +++- internal/world/world.go | 21 ++++++ internal/world/worldgen/worldgen.go | 28 ++++--- 13 files changed, 245 insertions(+), 72 deletions(-) create mode 100644 internal/asset/texture/world/planks_oak.png create mode 100644 internal/asset/texture/world/water.png create mode 100644 internal/world/blocks/default.go create mode 100644 internal/world/blocks/helper_appendface.go create mode 100644 internal/world/blocks/water.go delete mode 100644 internal/world/default_blocks.go diff --git a/internal/asset/texture/world/planks_oak.png b/internal/asset/texture/world/planks_oak.png new file mode 100644 index 0000000000000000000000000000000000000000..5de38610602e3601a4a45948d5adac0df927af07 GIT binary patch literal 268 zcmV+n0rUQeP)d}))YiJcst*L_5hXWb9mRfl3ayPp=~$O_3b zeNKfj-ajZPAnST0RprC^c?Aht3F*2Zxuymg&m8!iy-GFv)T4Lcqsw-4gl?q~Ds`*b zXMA+v9IHL>nD2xD%{#SFg=#N67r%Bq+s!o>;EDMk_#RaH3=NW->*1PI`|$>T?sCRx SFZvV!0000Px#1ZP1_K>z@;j|==^1poj6MM*?KR5(v?|47!en>AYhCSSOQ+xk$MYu1K8P@hHzr%;S zKBtZ+5fRusFFx37g}(lcF?>KInn>GwXg9V9u}7cETm-0Ac2@}~m?_`s8X1sPr};bi zgrF2A!1Vz_sp*7D+ya#8>;X4|A8K+mQQrX@v?}Lis0amyu9gn;WkvyejArn0lVaEU zyfO8q1BNP7nIou)kmi*Pi)7m*;CwcwN8+LJPL!-Vxj*;Xv= ChunkSizeY { + return Block{} + } + + c.SetBlock(cix, ciy, ciz, id, aux) + return Block{ + Id: int(c.Id[cix][ciy][ciz]), + Aux: int(c.Aux[cix][ciy][ciz]), + Dataset: nil, + Behaviour: GetBlockBehaviour(int(c.Id[cix][ciy][ciz])), + } +} + // LoadChunkFromGob loads (or overwrites) chunk [id.x, id.z] from the Gob-encoding file. func (w *World) LoadChunkFromGob(id itype.Vec2i, file io.Reader) (err error) { c := &Chunk{} diff --git a/internal/world/worldgen/worldgen.go b/internal/world/worldgen/worldgen.go index 6c62767..8699d81 100644 --- a/internal/world/worldgen/worldgen.go +++ b/internal/world/worldgen/worldgen.go @@ -4,6 +4,7 @@ import ( "sync" packworld "edgaru089.ml/go/gl01/internal/world" + "edgaru089.ml/go/gl01/internal/world/blocks" "github.com/aquilax/go-perlin" ) @@ -15,8 +16,8 @@ const ( AltitudeDensity = 10 // Density of the noise in altitude Sealevel = 63 // Space with Y=63 and lower should be the sea - Highest = 72 // Highest part of the terrain - Lowest = 56 // Lowest part of the terrain + Highest = 84 // Highest part of the terrain + Lowest = 60 // Lowest part of the terrain ) var perlins map[int64]*perlin.Perlin @@ -54,21 +55,30 @@ func Chunk(chunk *packworld.Chunk, world *packworld.World, seed int64) { float64(offZ+z)/AltitudeDensity)) //log.Printf("height = %d (noise=%.5f)", height, p.Noise2D(float64(offX+x), float64(offZ+z))) + // water + for y := Sealevel; y > height; y-- { + chunk.Id[x][y][z] = blocks.Water + } + // covering dirt - chunk.Id[x][height][z] = packworld.BlockGrass - //chunk.Id[x][height][z] = packworld.BlockDebugDir - chunk.Id[x][height-1][z] = packworld.BlockDirt - chunk.Id[x][height-2][z] = packworld.BlockDirt - chunk.Id[x][height-3][z] = packworld.BlockDirt + if height >= Sealevel { + chunk.Id[x][height][z] = blocks.Grass + } else { + chunk.Id[x][height][z] = blocks.Dirt + } + //chunk.Id[x][height][z] = blocks.DebugDir + chunk.Id[x][height-1][z] = blocks.Dirt + chunk.Id[x][height-2][z] = blocks.Dirt + chunk.Id[x][height-3][z] = blocks.Dirt height -= 4 // stone in the middle for y := height; y >= 1; y-- { - chunk.Id[x][y][z] = packworld.BlockStone + chunk.Id[x][y][z] = blocks.Stone } // bedrock at the bottom - chunk.Id[x][0][z] = packworld.BlockBedrock + chunk.Id[x][0][z] = blocks.Bedrock // plant trees if height >= 50 && height <= 70 {