Compare commits
32
Commits
Some-Stuff
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de9d2c8cb3 | ||
|
|
d950af6735 | ||
|
|
3c765a23dd | ||
|
|
c60d589d19 | ||
|
|
c35c655b5e | ||
|
|
2636b0a224 | ||
|
|
04484f1252 | ||
|
|
b3cd361501 | ||
|
|
8ee82521a0 | ||
|
|
c926777024 | ||
|
|
05eb503927 | ||
|
|
b7f8a517ac | ||
|
|
db5d6eb781 | ||
|
|
6255fcbd9b | ||
|
|
ee55664811 | ||
|
|
9b905de6db | ||
|
|
7e8e0a93f9 | ||
|
|
df176f6898 | ||
|
|
07dc6e72a0 | ||
|
|
856fe1e1c7 | ||
|
|
2eda55ad16 | ||
|
|
57f1e8b958 | ||
|
|
5c45f8b253 | ||
|
|
2df724a4a8 | ||
|
|
2cf099a4d9 | ||
|
|
ed4f60bfdb | ||
|
|
f23fc16f0d | ||
|
|
45aae55fe2 | ||
|
|
6d9e1180fd | ||
|
|
04bb44a5c8 | ||
|
|
e065cdd988 | ||
|
|
5e816c08f0 |
@@ -58,3 +58,4 @@ sysinfo.txt
|
|||||||
# Crashlytics generated file
|
# Crashlytics generated file
|
||||||
crashlytics-build.properties
|
crashlytics-build.properties
|
||||||
|
|
||||||
|
Minecraft Server/Assets/save.world
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 18 KiB |
@@ -87,6 +87,78 @@ TextureImporter:
|
|||||||
overridden: 0
|
overridden: 0
|
||||||
androidETC2FallbackOverride: 0
|
androidETC2FallbackOverride: 0
|
||||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
|
- serializedVersion: 3
|
||||||
|
buildTarget: iPhone
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
|
- serializedVersion: 3
|
||||||
|
buildTarget: Lumin
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
|
- serializedVersion: 3
|
||||||
|
buildTarget: WebGL
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
|
- serializedVersion: 3
|
||||||
|
buildTarget: tvOS
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
|
- serializedVersion: 3
|
||||||
|
buildTarget: Windows Store Apps
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
|
- serializedVersion: 3
|
||||||
|
buildTarget: Android
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
spriteSheet:
|
spriteSheet:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
sprites: []
|
sprites: []
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ Transform:
|
|||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 6443714940181712877}
|
m_GameObject: {fileID: 6443714940181712877}
|
||||||
m_LocalRotation: {x: -0.7071068, y: 0, z: 0, w: 0.7071068}
|
m_LocalRotation: {x: -0.7071068, y: 0, z: 0, w: 0.7071068}
|
||||||
m_LocalPosition: {x: 0, y: -0.132, z: 0.024}
|
m_LocalPosition: {x: 0, y: -0.092, z: 0.024}
|
||||||
m_LocalScale: {x: 0.24999988, y: 0.24999988, z: 0.25}
|
m_LocalScale: {x: 0.24999988, y: 0.24999988, z: 0.25}
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 4093383343133656141}
|
m_Father: {fileID: 4093383343133656141}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,7 @@ public class Chunk
|
|||||||
private Material material;
|
private Material material;
|
||||||
private ChunkCoord chunkPosition;
|
private ChunkCoord chunkPosition;
|
||||||
private World world;
|
private World world;
|
||||||
|
public bool active = false;
|
||||||
|
|
||||||
//rendering
|
//rendering
|
||||||
public GameObject gameObject;
|
public GameObject gameObject;
|
||||||
@@ -87,9 +88,9 @@ public class Chunk
|
|||||||
y + Data.faceChecks[f].y,
|
y + Data.faceChecks[f].y,
|
||||||
z + Data.faceChecks[f].z + chunkPosition.z * Data.chunkWidth))))
|
z + Data.faceChecks[f].z + chunkPosition.z * Data.chunkWidth))))
|
||||||
{
|
{
|
||||||
if(!world.IsBlockTransparent(world.GetBlockID(new Vector3(x + chunkPosition.x * Data.chunkWidth,
|
if(world.GetBlockID(new Vector3(x + chunkPosition.x * Data.chunkWidth,
|
||||||
y,
|
y,
|
||||||
z + chunkPosition.z * Data.chunkWidth))))
|
z + chunkPosition.z * Data.chunkWidth)) != 9)
|
||||||
{
|
{
|
||||||
for (int v = 0; v < 6; v++)
|
for (int v = 0; v < 6; v++)
|
||||||
{
|
{
|
||||||
@@ -136,6 +137,17 @@ public class Chunk
|
|||||||
meshFilter.mesh = mesh;
|
meshFilter.mesh = mesh;
|
||||||
meshRenderer.material = material;
|
meshRenderer.material = material;
|
||||||
collider.sharedMesh = mesh;
|
collider.sharedMesh = mesh;
|
||||||
|
active = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DestroyMesh()
|
||||||
|
{
|
||||||
|
meshFilter.mesh = null;
|
||||||
|
vertices.Clear();
|
||||||
|
triangles.Clear();
|
||||||
|
uv.Clear();
|
||||||
|
collider.sharedMesh = null;
|
||||||
|
active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Edit(byte x, byte y, byte z, byte blockID)
|
public void Edit(byte x, byte y, byte z, byte blockID)
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ public class Client
|
|||||||
{
|
{
|
||||||
for (int z = 0; z < Data.chunkWidth; z++)
|
for (int z = 0; z < Data.chunkWidth; z++)
|
||||||
{
|
{
|
||||||
blocks[x, y, z] = data[i];
|
blocks[x, y, z] = (byte)(data[i] - 32);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ public class Data
|
|||||||
{
|
{
|
||||||
public static int chunkWidth = 15, chunkHeight = 250;
|
public static int chunkWidth = 15, chunkHeight = 250;
|
||||||
public static int textureAtlasSize = 16;
|
public static int textureAtlasSize = 16;
|
||||||
|
public static int viewDistance = 4;
|
||||||
|
|
||||||
public static readonly Vector3[] vertices =
|
public static readonly Vector3[] vertices =
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class Options : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private Text viewDistanceText;
|
||||||
|
[SerializeField] private Slider viewDistanceSlider;
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
if (PlayerPrefs.HasKey("viewDistance"))
|
||||||
|
{
|
||||||
|
int value = PlayerPrefs.GetInt("viewDistance");
|
||||||
|
viewDistanceText.text = value.ToString();
|
||||||
|
viewDistanceSlider.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SliderViewDistanceChanged(float value)
|
||||||
|
{
|
||||||
|
viewDistanceText.text = ((int)value).ToString();
|
||||||
|
PlayerPrefs.SetInt("viewDistance", (int)value);
|
||||||
|
PlayerPrefs.Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ab80d1e654833ae4f88450121509e895
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -2,6 +2,7 @@ using System;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
public class Player : MonoBehaviour
|
public class Player : MonoBehaviour
|
||||||
{
|
{
|
||||||
@@ -14,6 +15,7 @@ public class Player : MonoBehaviour
|
|||||||
[SerializeField] private float jumpForce;
|
[SerializeField] private float jumpForce;
|
||||||
[SerializeField] private World world;
|
[SerializeField] private World world;
|
||||||
[SerializeField] private Hotbar hotbar;
|
[SerializeField] private Hotbar hotbar;
|
||||||
|
[SerializeField] private Text positionText;
|
||||||
private float playerWidth = 0.15f;
|
private float playerWidth = 0.15f;
|
||||||
private float playerOffsetWidth = 0.1f;
|
private float playerOffsetWidth = 0.1f;
|
||||||
private float horizontal;
|
private float horizontal;
|
||||||
@@ -81,6 +83,7 @@ public class Player : MonoBehaviour
|
|||||||
if (lastPosition.x != position.x || lastPosition.y != position.y || lastPosition.z != position.z)
|
if (lastPosition.x != position.x || lastPosition.y != position.y || lastPosition.z != position.z)
|
||||||
{
|
{
|
||||||
client.SendPositionUpdate(transform.position);
|
client.SendPositionUpdate(transform.position);
|
||||||
|
positionText.text = "X: " + (int) position.x + " Y: " + (int) position.y + " Z: " + (int) position.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rotation.w != lastRotation.w || rotation.x != lastRotation.x || rotation.y != lastRotation.y ||
|
if (rotation.w != lastRotation.w || rotation.x != lastRotation.x || rotation.y != lastRotation.y ||
|
||||||
@@ -101,6 +104,8 @@ public class Player : MonoBehaviour
|
|||||||
mouseX = Input.GetAxis("Mouse X");
|
mouseX = Input.GetAxis("Mouse X");
|
||||||
mouseY = Input.GetAxis("Mouse Y");
|
mouseY = Input.GetAxis("Mouse Y");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Sprinting
|
//Sprinting
|
||||||
if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetButtonDown("Left Stick Button"))
|
if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetButtonDown("Left Stick Button"))
|
||||||
{
|
{
|
||||||
@@ -277,10 +282,10 @@ public class Player : MonoBehaviour
|
|||||||
private float CheckUpSpeed(float upSpeed)
|
private float CheckUpSpeed(float upSpeed)
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
world.CheckBlock(new Vector3(transform.position.x - playerWidth, transform.position.y + upSpeed + 2f, transform.position.z - playerWidth)) ||
|
world.CheckBlock(new Vector3(transform.position.x - playerWidth, transform.position.y + upSpeed + 1.9f, transform.position.z - playerWidth)) ||
|
||||||
world.CheckBlock(new Vector3(transform.position.x + playerWidth, transform.position.y + upSpeed + 2f, transform.position.z - playerWidth)) ||
|
world.CheckBlock(new Vector3(transform.position.x + playerWidth, transform.position.y + upSpeed + 1.9f, transform.position.z - playerWidth)) ||
|
||||||
world.CheckBlock(new Vector3(transform.position.x + playerWidth, transform.position.y + upSpeed + 2f, transform.position.z + playerWidth)) ||
|
world.CheckBlock(new Vector3(transform.position.x + playerWidth, transform.position.y + upSpeed + 1.9f, transform.position.z + playerWidth)) ||
|
||||||
world.CheckBlock(new Vector3(transform.position.x - playerWidth, transform.position.y + upSpeed + 2f, transform.position.z + playerWidth))
|
world.CheckBlock(new Vector3(transform.position.x - playerWidth, transform.position.y + upSpeed + 1.9f, transform.position.z + playerWidth))
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
@@ -387,8 +392,8 @@ public class Player : MonoBehaviour
|
|||||||
|
|
||||||
public Vector3 GetDefaultPlayerPosition()
|
public Vector3 GetDefaultPlayerPosition()
|
||||||
{
|
{
|
||||||
return new Vector3((byte)transform.position.x,
|
return new Vector3(world.worldSize * Data.chunkWidth / 2,
|
||||||
world.GetHeight((byte)transform.position.x, (byte)transform.position.z) + 2, (byte)transform.position.z);
|
world.GetHeight((byte)transform.position.x, (byte)transform.position.z) + 2, world.worldSize * Data.chunkWidth / 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,14 @@ public class World : MonoBehaviour
|
|||||||
[SerializeField] private Player player;
|
[SerializeField] private Player player;
|
||||||
[SerializeField] private GameObject deadScreen;
|
[SerializeField] private GameObject deadScreen;
|
||||||
[SerializeField] private GameObject pauseScreen;
|
[SerializeField] private GameObject pauseScreen;
|
||||||
|
[SerializeField] private GameObject optionsScreen;
|
||||||
|
private ChunkCoord lastPlayerChunkCoord = new ChunkCoord(0, 0);
|
||||||
|
|
||||||
//chunks
|
//chunks
|
||||||
private Chunk[,] chunks;
|
private Chunk[,] chunks;
|
||||||
private Queue<ChunkCoord> chunksToUpdate = new Queue<ChunkCoord>();
|
private Queue<ChunkCoord> chunksToUpdate = new Queue<ChunkCoord>();
|
||||||
|
private Queue<ChunkCoord> chunksToUpdate1 = new Queue<ChunkCoord>();
|
||||||
|
private List<Chunk> lastActiveChunks = new List<Chunk>();
|
||||||
|
|
||||||
//blocks
|
//blocks
|
||||||
[SerializeField] public BlockData[] blockData;
|
[SerializeField] public BlockData[] blockData;
|
||||||
@@ -40,6 +44,12 @@ public class World : MonoBehaviour
|
|||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
//get default information
|
//get default information
|
||||||
|
|
||||||
|
if (PlayerPrefs.HasKey("viewDistance"))
|
||||||
|
{
|
||||||
|
Data.viewDistance = PlayerPrefs.GetInt("viewDistance");
|
||||||
|
}
|
||||||
|
|
||||||
name = PlayerPrefs.GetString("userName");
|
name = PlayerPrefs.GetString("userName");
|
||||||
ip = PlayerPrefs.GetString("serverIP");
|
ip = PlayerPrefs.GetString("serverIP");
|
||||||
port = int.Parse(PlayerPrefs.GetString("port"));
|
port = int.Parse(PlayerPrefs.GetString("port"));
|
||||||
@@ -54,12 +64,30 @@ public class World : MonoBehaviour
|
|||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
|
ChunkCoord playerChunkCoord = new ChunkCoord((int)(player.transform.position.x / Data.chunkWidth),
|
||||||
|
(int)(player.transform.position.z / Data.chunkWidth));
|
||||||
|
|
||||||
|
if (lastPlayerChunkCoord.x != playerChunkCoord.x || lastPlayerChunkCoord.z != playerChunkCoord.z)
|
||||||
|
{
|
||||||
|
LoadChunks(playerChunkCoord);
|
||||||
|
}
|
||||||
|
|
||||||
|
lastPlayerChunkCoord = new ChunkCoord((int)(player.transform.position.x / Data.chunkWidth),
|
||||||
|
(int)(player.transform.position.z / Data.chunkWidth));
|
||||||
|
|
||||||
//update 1 chunk in list
|
//update 1 chunk in list
|
||||||
if (chunksToUpdate.Count > 0)
|
if (chunksToUpdate.Count > 0)
|
||||||
{
|
{
|
||||||
ChunkCoord chunk = chunksToUpdate.Dequeue();
|
ChunkCoord chunk = chunksToUpdate.Dequeue();
|
||||||
chunks[chunk.x, chunk.z].Update();
|
chunks[chunk.x, chunk.z].Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//update 1 chunk in list
|
||||||
|
if (chunksToUpdate1.Count > 0)
|
||||||
|
{
|
||||||
|
ChunkCoord chunk = chunksToUpdate1.Dequeue();
|
||||||
|
chunks[chunk.x, chunk.z].Update();
|
||||||
|
}
|
||||||
|
|
||||||
//create 1 player in list
|
//create 1 player in list
|
||||||
if (playersToCreate.Count > 0)
|
if (playersToCreate.Count > 0)
|
||||||
@@ -107,22 +135,73 @@ public class World : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void LoadChunks(ChunkCoord playerChunk)
|
||||||
|
{
|
||||||
|
List<Chunk> checkList = new List<Chunk>();
|
||||||
|
|
||||||
|
chunksToUpdate1.Clear();
|
||||||
|
|
||||||
|
for (int x = playerChunk.x - Data.viewDistance; x <= playerChunk.x + Data.viewDistance; x++)
|
||||||
|
{
|
||||||
|
for (int z = playerChunk.z - Data.viewDistance; z <= playerChunk.z + Data.viewDistance; z++)
|
||||||
|
{
|
||||||
|
if(z >= 0 && x >= 0 && z < worldSize && x < worldSize)
|
||||||
|
{
|
||||||
|
if (chunks[x, z].gameObject == null)
|
||||||
|
{
|
||||||
|
chunks[x, z].Initialize();
|
||||||
|
chunks[x, z].gameObject.transform.SetParent(gameObject.transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chunks[x, z].active)
|
||||||
|
{
|
||||||
|
chunksToUpdate1.Enqueue(new ChunkCoord(x, z));
|
||||||
|
}
|
||||||
|
|
||||||
|
checkList.Add(chunks[x, z]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Chunk c in lastActiveChunks)
|
||||||
|
{
|
||||||
|
if (!checkList.Contains(c))
|
||||||
|
{
|
||||||
|
c.DestroyMesh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lastActiveChunks.Clear();
|
||||||
|
|
||||||
|
lastActiveChunks = new List<Chunk>(checkList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//enqueue player position update to list
|
//enqueue player position update to list
|
||||||
public void UpdatePlayerPosition(Vector3 position, byte id)
|
public void UpdatePlayerPosition(Vector3 position, byte id)
|
||||||
{
|
{
|
||||||
playersPositionsToUpdate.Enqueue(new Player.PlayerPositionUpdateData(id, position, false));
|
if(playersPositionsToUpdate.Count < 50)
|
||||||
|
{
|
||||||
|
playersPositionsToUpdate.Enqueue(new Player.PlayerPositionUpdateData(id, position, false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//enqueue player rotation update to list
|
//enqueue player rotation update to list
|
||||||
public void UpdatePlayerRotation(Quaternion rotation, byte id)
|
public void UpdatePlayerRotation(Quaternion rotation, byte id)
|
||||||
{
|
{
|
||||||
playersRotationsToUpdate.Enqueue(new Player.PlayerRotationsUpdateData(id, rotation));
|
if(playersRotationsToUpdate.Count < 50)
|
||||||
|
{
|
||||||
|
playersRotationsToUpdate.Enqueue(new Player.PlayerRotationsUpdateData(id, rotation));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//enqueue player create data to list
|
//enqueue player create data to list
|
||||||
public void AddPlayer(byte id)
|
public void AddPlayer(byte id)
|
||||||
{
|
{
|
||||||
playersToCreate.Enqueue(id);
|
if(!otherPlayers.ContainsKey(id))
|
||||||
|
{
|
||||||
|
playersToCreate.Enqueue(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//creates the array for chunk objects
|
//creates the array for chunk objects
|
||||||
@@ -140,14 +219,14 @@ public class World : MonoBehaviour
|
|||||||
//initialized the chunk objects
|
//initialized the chunk objects
|
||||||
public void CreateChunks()
|
public void CreateChunks()
|
||||||
{
|
{
|
||||||
for (int x = 0; x < worldSize; x++)
|
for (int x = worldSize / 2 - Data.viewDistance; x < worldSize / 2 + Data.viewDistance; x++)
|
||||||
{
|
{
|
||||||
for (int z = 0; z < worldSize; z++)
|
for (int z = worldSize / 2 - Data.viewDistance; z < worldSize / 2 + Data.viewDistance; z++)
|
||||||
{
|
{
|
||||||
chunks[x, z].Initialize();
|
chunks[x, z].Initialize();
|
||||||
chunks[x, z].gameObject.transform.SetParent(gameObject.transform);
|
chunks[x, z].gameObject.transform.SetParent(gameObject.transform);
|
||||||
chunks[x, z].AddBlocks();
|
chunksToUpdate.Enqueue(new ChunkCoord(x, z));
|
||||||
chunks[x, z].CreateMesh();
|
lastActiveChunks.Add(chunks[x, z]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -204,11 +283,11 @@ public class World : MonoBehaviour
|
|||||||
int zInChunk = z - (zChunk * Data.chunkWidth);
|
int zInChunk = z - (zChunk * Data.chunkWidth);
|
||||||
|
|
||||||
Chunk c = chunks[xChunk, zChunk];
|
Chunk c = chunks[xChunk, zChunk];
|
||||||
for (int y = 0; y < Data.chunkHeight; y++)
|
for (int y = Data.chunkHeight - 1; y > 0; y--)
|
||||||
{
|
{
|
||||||
if (c.blocks[xInChunk, y, zInChunk] == 0)
|
if (c.blocks[xInChunk, y, zInChunk] != 0)
|
||||||
{
|
{
|
||||||
return (byte)(y - 1);
|
return (byte)(y + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,8 +368,20 @@ public class World : MonoBehaviour
|
|||||||
{
|
{
|
||||||
Cursor.visible = true;
|
Cursor.visible = true;
|
||||||
Cursor.lockState = CursorLockMode.None;
|
Cursor.lockState = CursorLockMode.None;
|
||||||
|
optionsScreen.SetActive(false);
|
||||||
pauseScreen.SetActive(true);
|
pauseScreen.SetActive(true);
|
||||||
Time.timeScale = 0;
|
Time.timeScale = 0;
|
||||||
|
|
||||||
|
if (PlayerPrefs.HasKey("viewDistance"))
|
||||||
|
{
|
||||||
|
int value = PlayerPrefs.GetInt("viewDistance");
|
||||||
|
if (value != Data.viewDistance)
|
||||||
|
{
|
||||||
|
Data.viewDistance = value;
|
||||||
|
LoadChunks(new ChunkCoord((int)(player.transform.position.x / Data.chunkWidth),
|
||||||
|
(int)(player.transform.position.z / Data.chunkWidth)));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RespawnButton()
|
public void RespawnButton()
|
||||||
@@ -300,6 +391,8 @@ public class World : MonoBehaviour
|
|||||||
Time.timeScale = 1;
|
Time.timeScale = 1;
|
||||||
player.transform.position = player.GetDefaultPlayerPosition();
|
player.transform.position = player.GetDefaultPlayerPosition();
|
||||||
deadScreen.SetActive(false);
|
deadScreen.SetActive(false);
|
||||||
|
LoadChunks(new ChunkCoord((int)(player.transform.position.x / Data.chunkWidth),
|
||||||
|
(int)(player.transform.position.z / Data.chunkWidth)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResumeButton()
|
public void ResumeButton()
|
||||||
@@ -317,7 +410,13 @@ public class World : MonoBehaviour
|
|||||||
SceneManager.LoadScene("Login");
|
SceneManager.LoadScene("Login");
|
||||||
deadScreen.SetActive(false);
|
deadScreen.SetActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ShowOptionsScreen()
|
||||||
|
{
|
||||||
|
pauseScreen.SetActive(false);
|
||||||
|
optionsScreen.SetActive(true);
|
||||||
|
}
|
||||||
|
|
||||||
public void SaveButton()
|
public void SaveButton()
|
||||||
{
|
{
|
||||||
client.SaveWorld();
|
client.SaveWorld();
|
||||||
|
|||||||
@@ -605,7 +605,7 @@ PlayerSettings:
|
|||||||
additionalCompilerArguments: {}
|
additionalCompilerArguments: {}
|
||||||
platformArchitecture: {}
|
platformArchitecture: {}
|
||||||
scriptingBackend:
|
scriptingBackend:
|
||||||
Standalone: 0
|
Standalone: 1
|
||||||
il2cppCompilerConfiguration: {}
|
il2cppCompilerConfiguration: {}
|
||||||
managedStrippingLevel: {}
|
managedStrippingLevel: {}
|
||||||
incrementalIl2cppBuild: {}
|
incrementalIl2cppBuild: {}
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class Noise
|
||||||
|
{
|
||||||
|
public byte GetHeight(int x, int z, int randomOffsetX, int randomOffsetZ)
|
||||||
|
{
|
||||||
|
float scale = 0.025f;
|
||||||
|
byte perlinHeight = 10;
|
||||||
|
byte groundHeight = 50;
|
||||||
|
|
||||||
|
byte height = (byte)(Mathf.PerlinNoise((x + randomOffsetX) * scale + 0.1f, (z + randomOffsetZ) * scale + 0.1f) * perlinHeight + groundHeight);
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public 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 bool Get3DPerlin(Vector3 position, float offset, float scale, float threshold)
|
||||||
|
{
|
||||||
|
float x = (position.x + offset + .1f) * scale;
|
||||||
|
float y = (position.y + offset + .1f) * scale;
|
||||||
|
float z = (position.z + offset + .1f) * scale;
|
||||||
|
|
||||||
|
float AB = Mathf.PerlinNoise(x, y);
|
||||||
|
float BC = Mathf.PerlinNoise(y, z);
|
||||||
|
float AC = Mathf.PerlinNoise(x, z);
|
||||||
|
|
||||||
|
float BA = Mathf.PerlinNoise(y, x);
|
||||||
|
float CB = Mathf.PerlinNoise(z, y);
|
||||||
|
float CA = Mathf.PerlinNoise(z, x);
|
||||||
|
|
||||||
|
if ((AB + BC + AC + BA + CB + CA) / 6f > threshold)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dedaa2ec7a8b12443a08f16cad880f84
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -313,7 +313,7 @@ public class Server
|
|||||||
{
|
{
|
||||||
for (int z = 0; z < Data.chunkWidth; z++)
|
for (int z = 0; z < Data.chunkWidth; z++)
|
||||||
{
|
{
|
||||||
send[i] = world.chunks[xChunk, zChunk].blocks[x, y, z];
|
send[i] = (byte)(world.chunks[xChunk, zChunk].blocks[x, y, z] + 32);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ public class World : MonoBehaviour
|
|||||||
private int randomOffsetX, randomOffsetZ;
|
private int randomOffsetX, randomOffsetZ;
|
||||||
private int seed = 0;
|
private int seed = 0;
|
||||||
private string dataPath;
|
private string dataPath;
|
||||||
|
private Noise noise = new Noise();
|
||||||
|
|
||||||
//chunks
|
//chunks
|
||||||
public Chunk[,] chunks;
|
public Chunk[,] chunks;
|
||||||
@@ -29,6 +30,8 @@ public class World : MonoBehaviour
|
|||||||
|
|
||||||
if (File.Exists(Application.dataPath + "\\save.world"))
|
if (File.Exists(Application.dataPath + "\\save.world"))
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("loading world... \n");
|
||||||
|
|
||||||
chunks = new Chunk[worldSize, worldSize];
|
chunks = new Chunk[worldSize, worldSize];
|
||||||
for (int x = 0; x < worldSize; x++)
|
for (int x = 0; x < worldSize; x++)
|
||||||
{
|
{
|
||||||
@@ -54,7 +57,7 @@ public class World : MonoBehaviour
|
|||||||
{
|
{
|
||||||
for (int z = 0; z < Data.chunkWidth; z++)
|
for (int z = 0; z < Data.chunkWidth; z++)
|
||||||
{
|
{
|
||||||
chunks[xChunk, zChunk].blocks[x, y, z] = save[i];
|
chunks[xChunk, zChunk].blocks[x, y, z] = (byte)(save[i] - 32);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,6 +68,8 @@ public class World : MonoBehaviour
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("generate world... \n");
|
||||||
|
|
||||||
CreateChunks();
|
CreateChunks();
|
||||||
CreateTrees();
|
CreateTrees();
|
||||||
}
|
}
|
||||||
@@ -102,12 +107,12 @@ public class World : MonoBehaviour
|
|||||||
{
|
{
|
||||||
for (int z = 4; z < worldSize * Data.chunkWidth - 4; z++)
|
for (int z = 4; z < worldSize * Data.chunkWidth - 4; z++)
|
||||||
{
|
{
|
||||||
if (CheckTree(x, z))
|
if (noise.CheckTree(x, z))
|
||||||
{
|
{
|
||||||
ChunkCoord chunk = new ChunkCoord((int)(x / Data.chunkWidth),
|
ChunkCoord chunk = new ChunkCoord((int)(x / Data.chunkWidth),
|
||||||
(int)(z / Data.chunkWidth));
|
(int)(z / Data.chunkWidth));
|
||||||
int xInChunk = (int)(x - chunk.x * Data.chunkWidth);
|
int xInChunk = (int)(x - chunk.x * Data.chunkWidth);
|
||||||
int yInChunk = (int)(GetHeight(x, z));
|
int yInChunk = (int)(noise.GetHeight(x, z, randomOffsetX, randomOffsetZ));
|
||||||
int zInChunk = (int)(z - chunk.z * Data.chunkWidth);
|
int zInChunk = (int)(z - chunk.z * Data.chunkWidth);
|
||||||
|
|
||||||
int height = Random.Range(5, 9);
|
int height = Random.Range(5, 9);
|
||||||
@@ -157,11 +162,6 @@ public class World : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,7 +170,7 @@ public class World : MonoBehaviour
|
|||||||
//return the ID of a block
|
//return the ID of a block
|
||||||
public byte GetBlockID(Vector3 positionInWorld)
|
public byte GetBlockID(Vector3 positionInWorld)
|
||||||
{
|
{
|
||||||
byte height = GetHeight((int)positionInWorld.x, (int)positionInWorld.z);
|
byte height = noise.GetHeight((int)positionInWorld.x, (int)positionInWorld.z, randomOffsetX, randomOffsetZ);
|
||||||
|
|
||||||
//world pass
|
//world pass
|
||||||
if (positionInWorld.x < 0 || positionInWorld.y < 0 || positionInWorld.z < 0 ||
|
if (positionInWorld.x < 0 || positionInWorld.y < 0 || positionInWorld.z < 0 ||
|
||||||
@@ -180,24 +180,55 @@ public class World : MonoBehaviour
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//chunk pass
|
//surface pass
|
||||||
if ((int)positionInWorld.y == height)
|
if ((int)positionInWorld.y == height)
|
||||||
{
|
{
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//bedrock pass
|
||||||
if ((int)positionInWorld.y == 0)
|
if ((int)positionInWorld.y == 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//dirt pass
|
||||||
if ((int)positionInWorld.y > height - 3)
|
if ((int)positionInWorld.y > height - 3)
|
||||||
{
|
{
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//underground pass
|
||||||
if ((int)positionInWorld.y < height)
|
if ((int)positionInWorld.y < height)
|
||||||
{
|
{
|
||||||
|
//dirt
|
||||||
|
if((int)positionInWorld.y > 6 && (int)positionInWorld.y < height - 3)
|
||||||
|
{
|
||||||
|
if (noise.Get3DPerlin(positionInWorld, 3, 0.28f, 0.65f))
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//coal
|
||||||
|
if((int)positionInWorld.y > 6 && (int)positionInWorld.y < height - 8)
|
||||||
|
{
|
||||||
|
if (noise.Get3DPerlin(positionInWorld, 5, 0.28f, 0.65f))
|
||||||
|
{
|
||||||
|
return 12;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// //caves
|
||||||
|
// if((int)positionInWorld.y > 6 && (int)positionInWorld.y < height - 8)
|
||||||
|
// {
|
||||||
|
// if (noise.Get3DPerlin(positionInWorld, 0, 0.18f, 0.5f))
|
||||||
|
// {
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,30 +271,6 @@ public class World : MonoBehaviour
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte GetHeight(int x, int z)
|
|
||||||
{
|
|
||||||
float scale = 0.025f;
|
|
||||||
byte perlinHeight = 10;
|
|
||||||
byte groundHeight = 10;
|
|
||||||
|
|
||||||
byte height = (byte)(Mathf.PerlinNoise((x + randomOffsetX) * scale + 0.1f, (z + randomOffsetZ) * scale + 0.1f) * perlinHeight + groundHeight);
|
|
||||||
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)
|
public void EditBlock(ChunkCoord chunk, Vector3 positionInChunk, byte blockID)
|
||||||
{
|
{
|
||||||
byte xInChunk = (byte)(positionInChunk.x);
|
byte xInChunk = (byte)(positionInChunk.x);
|
||||||
@@ -300,7 +307,7 @@ public class World : MonoBehaviour
|
|||||||
{
|
{
|
||||||
for (int z = 0; z < Data.chunkWidth; z++)
|
for (int z = 0; z < Data.chunkWidth; z++)
|
||||||
{
|
{
|
||||||
save[i] = chunks[xChunk, zChunk].blocks[x, y, z];
|
save[i] = (byte)(chunks[xChunk, zChunk].blocks[x, y, z] + 32);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -311,6 +318,6 @@ public class World : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
writer.Close();
|
writer.Close();
|
||||||
Console.WriteLine("world saved! \n");
|
Console.WriteLine("world saved! (save.world) \n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,5 +166,5 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 5457f26f725053d46bffb9885acfd7d8, type: 3}
|
m_Script: {fileID: 11500000, guid: 5457f26f725053d46bffb9885acfd7d8, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
worldSize: 20
|
worldSize: 60
|
||||||
transferDelay: 5
|
transferDelay: 5
|
||||||
|
|||||||
Binary file not shown.
@@ -1,7 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 940041af630d8d944ac3b74467aa4ae7
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
Binary file not shown.
@@ -0,0 +1,40 @@
|
|||||||
|
This is an simple Minecraft Multiplayer Clone
|
||||||
|
|
||||||
|
Source code for the client:
|
||||||
|
https://github.com/jonasbraus/Minecraft/tree/main/Minecraft%20Client/Assets/Scripts
|
||||||
|
|
||||||
|
Source code for the server:
|
||||||
|
https://github.com/jonasbraus/Minecraft/tree/main/Minecraft%20Server/Assets/Game
|
||||||
|
|
||||||
|
1. You can download the installer under: https://github.com/jonasbraus/Minecraft/releases/download/Caves-and-Chunk-Loading/Minecraft.Clone.Online.Installer.exe
|
||||||
|
|
||||||
|
2. Just keep default settings in the installer
|
||||||
|
|
||||||
|
3. You should get this two icons on your desktop:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
4. Start the server application
|
||||||
|
|
||||||
|
5. If the server has been started you should get a window looking like this:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
6. Now start the Minecraft Clone application
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
7. For "User Name" you can enter any name you want
|
||||||
|
|
||||||
|
8. If you play on your pc you can set "Server IP" to "localhost". To let others join, give them your computers IP
|
||||||
|
|
||||||
|
9. For "Port" you can enter "8051" by default
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
10. Click "Play" and wait until the world has been loaded
|
||||||
|
|
||||||
|
11. Ready to Play
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
Reference in New Issue
Block a user