mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-06 16:37:38 +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;
|
package net.minestom.server.instance.block;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMap;
|
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.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
class BlockRegistry {
|
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
|
// Block namespace -> registry data
|
||||||
private static final Map<String, Block> NAMESPACE_MAP = new ConcurrentHashMap<>();
|
private static final Map<String, Block> NAMESPACE_MAP = new ConcurrentHashMap<>();
|
||||||
// Block id -> registry data
|
// Block id -> registry data
|
||||||
@ -46,22 +38,6 @@ class BlockRegistry {
|
|||||||
static {
|
static {
|
||||||
// Load data from file
|
// 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
|
// Blocks
|
||||||
JsonObject blocks = Registry.load(Registry.Resource.BLOCK);
|
JsonObject blocks = Registry.load(Registry.Resource.BLOCK);
|
||||||
blocks.entrySet().forEach(entry -> {
|
blocks.entrySet().forEach(entry -> {
|
||||||
@ -125,10 +101,14 @@ class BlockRegistry {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized @Nullable Block get(@NotNull String namespace) {
|
public static @Nullable Block get(@NotNull String namespace) {
|
||||||
return NAMESPACE_MAP.get(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) {
|
public static @Nullable Block getState(int stateId) {
|
||||||
return BLOCK_STATE_MAP.get(stateId);
|
return BLOCK_STATE_MAP.get(stateId);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user