This commit is contained in:
brausjonas
2022-05-15 23:41:02 +02:00
4 changed files with 95 additions and 11 deletions
+5 -1
View File
@@ -541,6 +541,8 @@ MonoBehaviour:
textures: 0a0a0a0a0a0a
- name: Leafs
textures: 101010101010
- name: Log
textures: 050506060505
--- !u!1 &1353507538
GameObject:
m_ObjectHideFlags: 0
@@ -1148,7 +1150,9 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
mouseSpeed: 4
walkSpeed: 5
defaultSpeed: 5
sprintSpeed: 8
sneakSpeed: 2
jumpForce: 8
world: {fileID: 948138834}
--- !u!1 &1849105196
+90 -3
View File
@@ -21,8 +21,8 @@ public class World : MonoBehaviour
[SerializeField] private int transferDelay;
private void Start()
{
randomOffsetX = Random.Range(0, 10000);
randomOffsetZ = Random.Range(0, 10000);
// randomOffsetX = Random.Range(0, 10000);
// randomOffsetZ = Random.Range(0, 10000);
if (File.Exists(Application.dataPath + "\\save.world"))
{
@@ -63,6 +63,7 @@ public class World : MonoBehaviour
else
{
CreateChunks();
CreateTrees();
}
Console.WriteLine("world loaded! \n");
server = new Server(this, transferDelay);
@@ -91,6 +92,78 @@ public class World : MonoBehaviour
}
//Create Trees
private void CreateTrees()
{
for (int x = 4; x < worldSize * Data.chunkWidth - 4; x++)
{
for (int z = 4; z < worldSize * Data.chunkWidth - 4; z++)
{
if (CheckTree(x, z))
{
ChunkCoord chunk = new ChunkCoord((int)(x / Data.chunkWidth),
(int)(z / Data.chunkWidth));
int xInChunk = (int)(x - chunk.x * Data.chunkWidth);
int yInChunk = (int)(GetHeight(x, z));
int zInChunk = (int)(z - chunk.z * Data.chunkWidth);
int height = Random.Range(5, 9);
for (int i = 0; i <= height; i++)
{
chunks[chunk.x, chunk.z].blocks[xInChunk, yInChunk + i, zInChunk] = 7;
}
chunks[chunk.x, chunk.z].blocks[xInChunk, yInChunk + height + 2, zInChunk] = 6;
for (int ty = -1; ty <= 0; ty++)
{
for (int tx = -2; tx <= 2; tx++)
{
for (int tz = -2; tz <= 2; tz++)
{
ChunkCoord tempChunk = new ChunkCoord((int)((x - tx) / Data.chunkWidth),
(int)((z - tz) / Data.chunkWidth));
int xTempInChunk = (int)((x - tx) - tempChunk.x * Data.chunkWidth);
int zTempInChunk = (int)((z - tz) - tempChunk.z * Data.chunkWidth);
if (chunks[tempChunk.x, tempChunk.z].blocks[xTempInChunk, yInChunk + height + ty,
zTempInChunk] != 7)
{
chunks[tempChunk.x, tempChunk.z].blocks[xTempInChunk, yInChunk + height + ty,
zTempInChunk] = 6;
}
}
}
}
for (int tx = -1; tx <= 1; tx++)
{
for (int tz = -1; tz <= 1; tz++)
{
ChunkCoord tempChunk = new ChunkCoord((int)((x - tx) / Data.chunkWidth),
(int)((z - tz) / Data.chunkWidth));
int xTempInChunk = (int)((x - tx) - tempChunk.x * Data.chunkWidth);
int zTempInChunk = (int)((z - tz) - tempChunk.z * Data.chunkWidth);
if (chunks[tempChunk.x, tempChunk.z].blocks[xTempInChunk, yInChunk + height + 1,
zTempInChunk] != 7)
{
chunks[tempChunk.x, tempChunk.z].blocks[xTempInChunk, yInChunk + height + 1,
zTempInChunk] = 6;
}
}
}
}
}
}
}
//return the ID of a block
public byte GetBlockID(Vector3 positionInWorld)
{
@@ -174,6 +247,20 @@ public class World : MonoBehaviour
return height;
}
private bool CheckTree(int x, int z)
{
float scale = .99f;
float threshold = .96f;
if (Mathf.PerlinNoise((x) * scale + 0.1f, (z) * scale + 0.1f) >= threshold)
{
return true;
}
return false;
}
public void EditBlock(ChunkCoord chunk, Vector3 positionInChunk, byte blockID)
{
byte xInChunk = (byte)(positionInChunk.x);
@@ -189,7 +276,7 @@ public class World : MonoBehaviour
private void OnApplicationQuit()
{
SaveWorld();
//SaveWorld();
server.Disconnect();
}
Binary file not shown.
-7
View File
@@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 940041af630d8d944ac3b74467aa4ae7
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: