mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
No need for block properties file
This commit is contained in:
parent
679030e75b
commit
65f92bf071
@ -1,6 +1,5 @@
|
||||
package net.minestom.server.instance.block;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMap;
|
||||
@ -12,20 +11,13 @@ import net.minestom.server.utils.math.IntRange;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
class BlockRegistry {
|
||||
|
||||
// Property name -> values
|
||||
private static final Map<String, List<String>> PROPERTIES_MAP = new ConcurrentHashMap<>();
|
||||
// Unique name -> IG key
|
||||
private static final Map<String, String> PROPERTIES_NAME_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
// Block namespace -> registry data
|
||||
private static final Map<String, Block> NAMESPACE_MAP = new ConcurrentHashMap<>();
|
||||
// Block id -> registry data
|
||||
@ -46,22 +38,6 @@ class BlockRegistry {
|
||||
static {
|
||||
// Load data from file
|
||||
|
||||
// Block properties
|
||||
JsonObject properties = Registry.load(Registry.Resource.BLOCK_PROPERTY);
|
||||
properties.entrySet().forEach(entry -> {
|
||||
final String propertyName = entry.getKey();
|
||||
final JsonObject propertyObject = entry.getValue().getAsJsonObject();
|
||||
|
||||
final String key = propertyObject.get("key").getAsString();
|
||||
final JsonArray values = propertyObject.getAsJsonArray("values");
|
||||
|
||||
List<String> stringValues = new ArrayList<>(values.size());
|
||||
values.forEach(jsonElement -> stringValues.add(jsonElement.toString()));
|
||||
|
||||
PROPERTIES_MAP.put(key, stringValues);
|
||||
PROPERTIES_NAME_MAP.put(propertyName, key);
|
||||
});
|
||||
|
||||
// Blocks
|
||||
JsonObject blocks = Registry.load(Registry.Resource.BLOCK);
|
||||
blocks.entrySet().forEach(entry -> {
|
||||
@ -125,10 +101,14 @@ class BlockRegistry {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static synchronized @Nullable Block get(@NotNull String namespace) {
|
||||
public static @Nullable Block get(@NotNull String namespace) {
|
||||
return NAMESPACE_MAP.get(namespace);
|
||||
}
|
||||
|
||||
public static @Nullable Block getId(int id) {
|
||||
return BLOCK_ID_MAP.get(id);
|
||||
}
|
||||
|
||||
public static @Nullable Block getState(int stateId) {
|
||||
return BLOCK_STATE_MAP.get(stateId);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user