Add Supplier instead of direct reference and fix a @NotNull error.

This commit is contained in:
Articdive 2021-05-25 19:07:26 +02:00
parent b31f76615a
commit 674c6d6182
No known key found for this signature in database
GPG Key ID: B069585F0F7D90DE
3 changed files with 9 additions and 6 deletions

View File

@ -5,9 +5,11 @@ import net.minestom.server.map.MapColors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.function.Supplier;
class BlockDataImpl implements BlockData {
private final double explosionResistance;
private final @NotNull Material item;
private final @NotNull Supplier<@NotNull Material> item;
private final double friction;
private final double speedFactor;
private final double jumpFactor;
@ -30,7 +32,7 @@ class BlockDataImpl implements BlockData {
BlockDataImpl(
double explosionResistance,
@NotNull Material item,
@NotNull Supplier<@NotNull Material> item,
double friction,
double speedFactor,
double jumpFactor,
@ -78,7 +80,7 @@ class BlockDataImpl implements BlockData {
@Override
public @Nullable Material getCorrespondingItem() {
return item;
return item.get();
}
@Override

View File

@ -251,7 +251,8 @@ class BlockImpl implements Block {
double speedFactor = block.get("speedFactor").getAsDouble();
double jumpFactor = block.get("jumpFactor").getAsDouble();
boolean blockEntity = block.get("blockEntity").getAsBoolean();
Material item = Registries.getMaterial(block.get("itemId").getAsString());
final String blockId = block.get("itemId").getAsString();
java.util.function.Supplier<Material> itemSupplier = () -> Registries.getMaterial(blockId);
JsonArray states = block.get("states").getAsJsonArray();
for (JsonElement stateEntry : states) {
// Load Data
@ -262,7 +263,7 @@ class BlockImpl implements Block {
stateId,
new BlockDataImpl(
explosionResistance,
item,
itemSupplier,
friction,
speedFactor,
jumpFactor,

View File

@ -25,7 +25,7 @@ public enum ChatPosition {
private final MessageType messageType;
ChatPosition(@NotNull MessageType messageType) {
ChatPosition(@Nullable MessageType messageType) {
this.messageType = messageType;
}