-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
load blocks from registry, actually texture all (most) blocks
- Loading branch information
1 parent
ab2d453
commit 7871fb3
Showing
11 changed files
with
137 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,57 @@ | ||
namespace Godotcraft.scripts.world.block { | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using Godot; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using File = Godot.File; | ||
|
||
namespace Godotcraft.scripts.world.block { | ||
public class BlockRegistry { | ||
|
||
public static double TotalNumberOfStates = 11336; | ||
|
||
public static BlockState AIR = new BlockState(); | ||
public static BlockState DIRT = new BlockState(); | ||
public static BlockState AIR; | ||
public static BlockState DIRT; | ||
|
||
private static Dictionary<uint, BlockState> idToState = new Dictionary<uint, BlockState>(); | ||
private static Dictionary<BlockState, uint> stateToId = new Dictionary<BlockState, uint>(); | ||
private static Dictionary<string, BlockState> nameToState = new Dictionary<string, BlockState>(); | ||
|
||
static BlockRegistry() { | ||
loadRegistry(); | ||
|
||
AIR = nameToState["air"]; | ||
DIRT = nameToState["dirt"]; | ||
} | ||
|
||
private static void loadRegistry() { | ||
File registryFile = new File(); | ||
registryFile.Open("user://mcdata/reports/blocks.json", File.ModeFlags.Read); | ||
string content = registryFile.GetAsText(); | ||
JObject o = JObject.Parse(content); | ||
foreach (var entry in o) { | ||
string name = entry.Key.Split(':')[1]; | ||
JArray states = (entry.Value["states"]) as JArray; | ||
foreach (var state in states) { | ||
uint id = state["id"].Value<uint>(); | ||
add(new BlockState(name, id)); | ||
} | ||
} | ||
GD.Print($"Loaded {idToState.Count} states"); | ||
} | ||
|
||
private static void add(BlockState state) { | ||
idToState[state.id] = state; | ||
stateToId[state] = state.id; | ||
nameToState[state.name] = state; | ||
} | ||
|
||
public static BlockState GetStateFromGlobalPaletteID(uint id) { | ||
return DIRT; | ||
return idToState[id]; | ||
} | ||
|
||
public static uint GetGlobalPaletteIDFromState(BlockState state) { | ||
if (state == AIR) { | ||
return 0; | ||
} | ||
else { | ||
return 1; | ||
} | ||
return stateToId[state]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,47 @@ | ||
namespace Godotcraft.scripts.world.block { | ||
public class BlockState { | ||
|
||
public string name { get; } | ||
public uint id { get; } | ||
|
||
public bool transparent { get; } | ||
|
||
public BlockState(string name, uint id) { | ||
this.name = name; | ||
this.id = id; | ||
|
||
if (name.Contains("air") || name.Contains("glass")) { | ||
transparent = true; | ||
} | ||
else { | ||
transparent = false; | ||
} | ||
} | ||
|
||
protected bool Equals(BlockState other) { | ||
return name == other.name && id == other.id; | ||
} | ||
|
||
public override bool Equals(object obj) { | ||
if (ReferenceEquals(null, obj)) { | ||
return false; | ||
} | ||
|
||
if (ReferenceEquals(this, obj)) { | ||
return true; | ||
} | ||
|
||
if (obj.GetType() != this.GetType()) { | ||
return false; | ||
} | ||
|
||
return Equals((BlockState) obj); | ||
} | ||
|
||
public override int GetHashCode() { | ||
unchecked { | ||
return ((name != null ? name.GetHashCode() : 0) * 397) ^ (int) id; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters