mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-30 12:01:26 +01:00
Update Registry to retrieve a block material
This commit is contained in:
parent
b22d030a6f
commit
5b044a2d38
@ -164,7 +164,7 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
api "com.github.Minestom:DependencyGetter:v1.0.1"
|
api "com.github.Minestom:DependencyGetter:v1.0.1"
|
||||||
implementation 'com.github.Minestom:MinestomDataGenerator:2bebcda9f8'
|
implementation 'com.github.Minestom:MinestomDataGenerator:386c3ef9c0'
|
||||||
|
|
||||||
// Adventure, for user-interface
|
// Adventure, for user-interface
|
||||||
api "net.kyori:adventure-api:$adventureVersion"
|
api "net.kyori:adventure-api:$adventureVersion"
|
||||||
|
@ -4,17 +4,18 @@ import com.google.gson.Gson;
|
|||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import net.minestom.server.item.Material;
|
||||||
import net.minestom.server.utils.NamespaceID;
|
import net.minestom.server.utils.NamespaceID;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
public class Registry {
|
public class Registry {
|
||||||
|
private 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, JsonObject override) {
|
public static BlockEntry block(@NotNull JsonObject jsonObject, JsonObject override) {
|
||||||
return new BlockEntry(jsonObject, override);
|
return new BlockEntry(jsonObject, override);
|
||||||
@ -27,8 +28,7 @@ public class Registry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum Resource {
|
public enum Resource {
|
||||||
BLOCK("blocks"),
|
BLOCK("blocks");
|
||||||
BLOCK_PROPERTY("block_properties");
|
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
@ -50,6 +50,7 @@ public class Registry {
|
|||||||
private final boolean solid;
|
private final boolean solid;
|
||||||
private final boolean liquid;
|
private final boolean liquid;
|
||||||
private final String blockEntity;
|
private final String blockEntity;
|
||||||
|
private final Supplier<Material> materialSupplier;
|
||||||
|
|
||||||
private BlockEntry(JsonObject main, JsonObject override) {
|
private BlockEntry(JsonObject main, JsonObject override) {
|
||||||
super(main, override);
|
super(main, override);
|
||||||
@ -59,14 +60,15 @@ public class Registry {
|
|||||||
this.hardness = getDouble("hardness");
|
this.hardness = getDouble("hardness");
|
||||||
this.explosionResistance = getDouble("explosionResistance");
|
this.explosionResistance = getDouble("explosionResistance");
|
||||||
this.friction = getDouble("friction");
|
this.friction = getDouble("friction");
|
||||||
this.speedFactor = getDouble("speedFactor");
|
this.speedFactor = getDouble("speedFactor", 1);
|
||||||
this.jumpFactor = getDouble("jumpFactor");
|
this.jumpFactor = getDouble("jumpFactor", 1);
|
||||||
this.air = getBoolean("air");
|
this.air = getBoolean("air", false);
|
||||||
this.solid = getBoolean("solid");
|
this.solid = getBoolean("solid");
|
||||||
this.liquid = getBoolean("liquid");
|
this.liquid = getBoolean("liquid", false);
|
||||||
|
this.blockEntity = getString("blockEntity", null);
|
||||||
{
|
{
|
||||||
final var blockEntityElement = element("blockEntity");
|
final String materialNamespace = getString("correspondingItem", null);
|
||||||
this.blockEntity = blockEntityElement != null ? blockEntityElement.getAsString() : null;
|
this.materialSupplier = materialNamespace != null ? () -> Registries.getMaterial(materialNamespace) : () -> null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +123,10 @@ public class Registry {
|
|||||||
public @Nullable String blockEntity() {
|
public @Nullable String blockEntity() {
|
||||||
return blockEntity;
|
return blockEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @Nullable Material material() {
|
||||||
|
return materialSupplier.get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Entry {
|
public static class Entry {
|
||||||
@ -131,18 +137,38 @@ public class Registry {
|
|||||||
this.override = override;
|
this.override = override;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getString(String name, String defaultValue) {
|
||||||
|
var element = element(name);
|
||||||
|
return element != null ? element.getAsString() : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
public String getString(String name) {
|
public String getString(String name) {
|
||||||
return element(name).getAsString();
|
return element(name).getAsString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getDouble(String name, double defaultValue) {
|
||||||
|
var element = element(name);
|
||||||
|
return element != null ? element.getAsDouble() : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
public double getDouble(String name) {
|
public double getDouble(String name) {
|
||||||
return element(name).getAsDouble();
|
return element(name).getAsDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getInt(String name, int defaultValue) {
|
||||||
|
var element = element(name);
|
||||||
|
return element != null ? element.getAsInt() : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
public int getInt(String name) {
|
public int getInt(String name) {
|
||||||
return element(name).getAsInt();
|
return element(name).getAsInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getBoolean(String name, boolean defaultValue) {
|
||||||
|
var element = element(name);
|
||||||
|
return element != null ? element.getAsBoolean() : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean getBoolean(String name) {
|
public boolean getBoolean(String name) {
|
||||||
return element(name).getAsBoolean();
|
return element(name).getAsBoolean();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user