mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-22 15:22:56 +01:00
Improve memory usage
This commit is contained in:
parent
65f92bf071
commit
a83482efb8
@ -43,8 +43,10 @@ class BlockRegistry {
|
|||||||
blocks.entrySet().forEach(entry -> {
|
blocks.entrySet().forEach(entry -> {
|
||||||
final String blockNamespace = entry.getKey();
|
final String blockNamespace = entry.getKey();
|
||||||
final JsonObject blockObject = entry.getValue().getAsJsonObject();
|
final JsonObject blockObject = entry.getValue().getAsJsonObject();
|
||||||
|
final JsonObject stateObject = blockObject.remove("states").getAsJsonObject();
|
||||||
|
blockObject.remove("properties");
|
||||||
|
|
||||||
retrieveState(blockNamespace, blockObject);
|
retrieveState(blockNamespace, blockObject, stateObject);
|
||||||
final int defaultState = blockObject.get("defaultStateId").getAsInt();
|
final int defaultState = blockObject.get("defaultStateId").getAsInt();
|
||||||
final Block defaultBlock = getState(defaultState);
|
final Block defaultBlock = getState(defaultState);
|
||||||
final int id = blockObject.get("id").getAsInt();
|
final int id = blockObject.get("id").getAsInt();
|
||||||
@ -53,24 +55,14 @@ class BlockRegistry {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void retrieveState(String namespace, JsonObject object) {
|
private static void retrieveState(String namespace, JsonObject object, JsonObject stateObject) {
|
||||||
final JsonObject states = object.getAsJsonObject("states");
|
|
||||||
|
|
||||||
PropertyEntry propertyEntry = new PropertyEntry();
|
PropertyEntry propertyEntry = new PropertyEntry();
|
||||||
states.entrySet().forEach(stateEntry -> {
|
stateObject.entrySet().forEach(stateEntry -> {
|
||||||
final String query = stateEntry.getKey();
|
final String query = stateEntry.getKey();
|
||||||
|
|
||||||
JsonObject stateObject = object.deepCopy();
|
|
||||||
|
|
||||||
stateObject.remove("states");
|
|
||||||
stateObject.remove("properties");
|
|
||||||
|
|
||||||
JsonObject stateOverride = stateEntry.getValue().getAsJsonObject();
|
JsonObject stateOverride = stateEntry.getValue().getAsJsonObject();
|
||||||
stateOverride.entrySet().forEach(entry -> stateObject.add(entry.getKey(), entry.getValue()));
|
|
||||||
final int stateId = stateOverride.get("stateId").getAsInt();
|
final int stateId = stateOverride.get("stateId").getAsInt();
|
||||||
|
|
||||||
final var propertyMap = getPropertyMap(query);
|
final var propertyMap = getPropertyMap(query);
|
||||||
final Block block = new BlockTest(stateObject);
|
final Block block = new BlockTest(object, stateOverride);
|
||||||
BLOCK_STATE_MAP.put(stateId, block);
|
BLOCK_STATE_MAP.put(stateId, block);
|
||||||
propertyEntry.propertyMap.put(propertyMap, block);
|
propertyEntry.propertyMap.put(propertyMap, block);
|
||||||
});
|
});
|
||||||
|
@ -23,8 +23,8 @@ class BlockTest implements Block {
|
|||||||
this.registry = registry;
|
this.registry = registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockTest(JsonObject jsonObject) {
|
BlockTest(JsonObject jsonObject, JsonObject override) {
|
||||||
this(Registry.block(jsonObject));
|
this(Registry.block(jsonObject, override));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -8,14 +8,15 @@ import org.jetbrains.annotations.ApiStatus;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
public class Registry {
|
public class Registry {
|
||||||
|
|
||||||
protected static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
|
protected static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
|
||||||
|
|
||||||
public static BlockEntry block(@NotNull JsonObject jsonObject) {
|
public static BlockEntry block(@NotNull JsonObject jsonObject, JsonObject override) {
|
||||||
return new BlockEntry(jsonObject);
|
return new BlockEntry(jsonObject, override);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject load(Resource resource) {
|
public static JsonObject load(Resource resource) {
|
||||||
@ -36,8 +37,8 @@ public class Registry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class BlockEntry extends Entry {
|
public static class BlockEntry extends Entry {
|
||||||
private BlockEntry(JsonObject json) {
|
private BlockEntry(JsonObject main, JsonObject override) {
|
||||||
super(json);
|
super(main, override);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String namespace() {
|
public String namespace() {
|
||||||
@ -86,10 +87,11 @@ public class Registry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class Entry {
|
public static class Entry {
|
||||||
private final JsonObject json;
|
private final JsonObject main, override;
|
||||||
|
|
||||||
private Entry(JsonObject json) {
|
private Entry(JsonObject main, JsonObject override) {
|
||||||
this.json = json;
|
this.main = main;
|
||||||
|
this.override = override;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getString(String name) {
|
public String getString(String name) {
|
||||||
@ -109,7 +111,7 @@ public class Registry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected JsonElement element(String name) {
|
protected JsonElement element(String name) {
|
||||||
return json.get(name);
|
return Objects.requireNonNullElseGet(override.get(name), () -> main.get(name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user