From 235100e87bd90cfdad0df40e4235d0dd5aec6e1b Mon Sep 17 00:00:00 2001 From: TheMode Date: Wed, 16 Jun 2021 00:46:39 +0200 Subject: [PATCH] Small cleanup --- .../minestom/server/instance/block/Block.java | 2 +- .../server/instance/block/BlockRegistry.java | 2 +- .../server/instance/block/BlockTest.java | 17 ++++++----------- .../server/world/biomes/BiomeParticles.java | 2 +- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/minestom/server/instance/block/Block.java b/src/main/java/net/minestom/server/instance/block/Block.java index f54509454..00ea534a6 100644 --- a/src/main/java/net/minestom/server/instance/block/Block.java +++ b/src/main/java/net/minestom/server/instance/block/Block.java @@ -43,7 +43,7 @@ public interface Block extends ProtocolObject, TagReadable, BlockConstants { @Nullable BlockHandler getHandler(); - @NotNull Map createPropertiesMap(); + @NotNull Map getPropertiesMap(); @NotNull Registry.BlockEntry registry(); diff --git a/src/main/java/net/minestom/server/instance/block/BlockRegistry.java b/src/main/java/net/minestom/server/instance/block/BlockRegistry.java index 591cd9bae..542bed477 100644 --- a/src/main/java/net/minestom/server/instance/block/BlockRegistry.java +++ b/src/main/java/net/minestom/server/instance/block/BlockRegistry.java @@ -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); }); diff --git a/src/main/java/net/minestom/server/instance/block/BlockTest.java b/src/main/java/net/minestom/server/instance/block/BlockTest.java index 0da016c6a..1cd5e2935 100644 --- a/src/main/java/net/minestom/server/instance/block/BlockTest.java +++ b/src/main/java/net/minestom/server/instance/block/BlockTest.java @@ -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 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 Block withTag(@NotNull Tag 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 createPropertiesMap() { - return new HashMap<>(properties); + public @NotNull Map getPropertiesMap() { + return Collections.unmodifiableMap(properties); } @Override diff --git a/src/main/java/net/minestom/server/world/biomes/BiomeParticles.java b/src/main/java/net/minestom/server/world/biomes/BiomeParticles.java index 9da9f01ba..0c7234e0c 100644 --- a/src/main/java/net/minestom/server/world/biomes/BiomeParticles.java +++ b/src/main/java/net/minestom/server/world/biomes/BiomeParticles.java @@ -45,7 +45,7 @@ public class BiomeParticles { NBTCompound nbtCompound = new NBTCompound(); nbtCompound.setString("type", type); nbtCompound.setString("Name", block.getName()); - Map propertiesMap = block.createPropertiesMap(); + Map propertiesMap = block.getPropertiesMap(); if (propertiesMap.size() != 0) { NBTCompound properties = new NBTCompound(); propertiesMap.forEach(properties::setString);