Small cleanup

This commit is contained in:
TheMode 2021-06-16 00:46:39 +02:00
parent 2d57235198
commit 235100e87b
4 changed files with 9 additions and 14 deletions

View File

@ -43,7 +43,7 @@ public interface Block extends ProtocolObject, TagReadable, BlockConstants {
@Nullable BlockHandler getHandler();
@NotNull Map<String, String> createPropertiesMap();
@NotNull Map<String, String> getPropertiesMap();
@NotNull Registry.BlockEntry registry();

View File

@ -53,7 +53,7 @@ class BlockRegistry {
JsonObject stateOverride = stateEntry.getValue().getAsJsonObject();
final int stateId = stateOverride.get("stateId").getAsInt();
final var propertyMap = getPropertyMap(query);
final Block block = new BlockTest(object, stateOverride, propertyMap);
final Block block = new BlockTest(Registry.block(object, stateOverride), propertyMap);
BLOCK_STATE_MAP.put(stateId, block);
propertyEntry.propertyMap.put(propertyMap, block);
});

View File

@ -1,12 +1,12 @@
package net.minestom.server.instance.block;
import com.google.gson.JsonObject;
import net.minestom.server.registry.Registry;
import net.minestom.server.tag.Tag;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@ -34,11 +34,6 @@ class BlockTest implements Block {
this(registry, properties, null, null);
}
BlockTest(JsonObject jsonObject, JsonObject override,
Map<String, String> properties) {
this(Registry.block(jsonObject, override), properties);
}
@Override
public @NotNull Block withProperty(@NotNull String property, @NotNull String value) {
var properties = new HashMap<>(this.properties);
@ -48,9 +43,9 @@ class BlockTest implements Block {
@Override
public @NotNull <T> Block withTag(@NotNull Tag<T> tag, @Nullable T value) {
var block = new BlockTest(registry, properties, compound.deepClone(), handler);
tag.write(block.compound, value);
return block;
var compound = this.compound != null ? this.compound.deepClone() : new NBTCompound();
tag.write(compound, value);
return new BlockTest(registry, properties, compound, handler);
}
@Override
@ -79,8 +74,8 @@ class BlockTest implements Block {
}
@Override
public @NotNull Map<String, String> createPropertiesMap() {
return new HashMap<>(properties);
public @NotNull Map<String, String> getPropertiesMap() {
return Collections.unmodifiableMap(properties);
}
@Override

View File

@ -45,7 +45,7 @@ public class BiomeParticles {
NBTCompound nbtCompound = new NBTCompound();
nbtCompound.setString("type", type);
nbtCompound.setString("Name", block.getName());
Map<String, String> propertiesMap = block.createPropertiesMap();
Map<String, String> propertiesMap = block.getPropertiesMap();
if (propertiesMap.size() != 0) {
NBTCompound properties = new NBTCompound();
propertiesMap.forEach(properties::setString);