Reduce implementation code

This commit is contained in:
TheMode 2021-06-18 03:44:15 +02:00
parent c0c19a1e44
commit 41cb35782e
3 changed files with 19 additions and 17 deletions

View File

@ -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();

View File

@ -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

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.getPropertiesMap();
Map<String, String> propertiesMap = block.getProperties();
if (propertiesMap.size() != 0) {
NBTCompound properties = new NBTCompound();
propertiesMap.forEach(properties::setString);