mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Reduce implementation code
This commit is contained in:
parent
c0c19a1e44
commit
41cb35782e
@ -44,14 +44,6 @@ public interface Block extends ProtocolObject, TagReadable, BlockConstants {
|
||||
@Contract(pure = true)
|
||||
@NotNull Block withHandler(@Nullable BlockHandler handler);
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull String getProperty(@NotNull String property);
|
||||
|
||||
@Contract(pure = true)
|
||||
default <T> @NotNull String getProperty(@NotNull BlockProperty<T> property) {
|
||||
return getProperty(property.getName());
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@Nullable NBTCompound getNbt();
|
||||
|
||||
@ -59,7 +51,17 @@ public interface Block extends ProtocolObject, TagReadable, BlockConstants {
|
||||
@Nullable BlockHandler getHandler();
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull Map<String, String> getPropertiesMap();
|
||||
@NotNull Map<String, String> getProperties();
|
||||
|
||||
@Contract(pure = true)
|
||||
default @NotNull String getProperty(@NotNull String property) {
|
||||
return getProperties().get(property);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
default <T> @NotNull String getProperty(@NotNull BlockProperty<T> property) {
|
||||
return getProperty(property.getName());
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull Registry.BlockEntry registry();
|
||||
|
@ -19,6 +19,8 @@ class BlockTest implements Block {
|
||||
private final NBTCompound compound;
|
||||
private final BlockHandler handler;
|
||||
|
||||
private final Map<String, String> unmodifiableProperties;
|
||||
|
||||
BlockTest(Registry.BlockEntry registry,
|
||||
Map<String, String> properties,
|
||||
NBTCompound compound,
|
||||
@ -27,6 +29,9 @@ class BlockTest implements Block {
|
||||
this.properties = properties;
|
||||
this.compound = compound;
|
||||
this.handler = handler;
|
||||
|
||||
this.unmodifiableProperties = properties != null ?
|
||||
Collections.unmodifiableMap(properties) : null;
|
||||
}
|
||||
|
||||
BlockTest(Registry.BlockEntry registry,
|
||||
@ -52,11 +57,6 @@ class BlockTest implements Block {
|
||||
return new BlockTest(registry, properties, compound, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getProperty(@NotNull String property) {
|
||||
return properties.get(property);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable NBTCompound getNbt() {
|
||||
return compound != null ? compound.deepClone() : null;
|
||||
@ -68,8 +68,8 @@ class BlockTest implements Block {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Map<String, String> getPropertiesMap() {
|
||||
return Collections.unmodifiableMap(properties);
|
||||
public @NotNull Map<String, String> getProperties() {
|
||||
return unmodifiableProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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.getPropertiesMap();
|
||||
Map<String, String> propertiesMap = block.getProperties();
|
||||
if (propertiesMap.size() != 0) {
|
||||
NBTCompound properties = new NBTCompound();
|
||||
propertiesMap.forEach(properties::setString);
|
||||
|
Loading…
Reference in New Issue
Block a user