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) @Contract(pure = true)
@NotNull Block withHandler(@Nullable BlockHandler handler); @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) @Contract(pure = true)
@Nullable NBTCompound getNbt(); @Nullable NBTCompound getNbt();
@ -59,7 +51,17 @@ public interface Block extends ProtocolObject, TagReadable, BlockConstants {
@Nullable BlockHandler getHandler(); @Nullable BlockHandler getHandler();
@Contract(pure = true) @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) @Contract(pure = true)
@NotNull Registry.BlockEntry registry(); @NotNull Registry.BlockEntry registry();

View File

@ -19,6 +19,8 @@ class BlockTest implements Block {
private final NBTCompound compound; private final NBTCompound compound;
private final BlockHandler handler; private final BlockHandler handler;
private final Map<String, String> unmodifiableProperties;
BlockTest(Registry.BlockEntry registry, BlockTest(Registry.BlockEntry registry,
Map<String, String> properties, Map<String, String> properties,
NBTCompound compound, NBTCompound compound,
@ -27,6 +29,9 @@ class BlockTest implements Block {
this.properties = properties; this.properties = properties;
this.compound = compound; this.compound = compound;
this.handler = handler; this.handler = handler;
this.unmodifiableProperties = properties != null ?
Collections.unmodifiableMap(properties) : null;
} }
BlockTest(Registry.BlockEntry registry, BlockTest(Registry.BlockEntry registry,
@ -52,11 +57,6 @@ class BlockTest implements Block {
return new BlockTest(registry, properties, compound, handler); return new BlockTest(registry, properties, compound, handler);
} }
@Override
public @NotNull String getProperty(@NotNull String property) {
return properties.get(property);
}
@Override @Override
public @Nullable NBTCompound getNbt() { public @Nullable NBTCompound getNbt() {
return compound != null ? compound.deepClone() : null; return compound != null ? compound.deepClone() : null;
@ -68,8 +68,8 @@ class BlockTest implements Block {
} }
@Override @Override
public @NotNull Map<String, String> getPropertiesMap() { public @NotNull Map<String, String> getProperties() {
return Collections.unmodifiableMap(properties); return unmodifiableProperties;
} }
@Override @Override

View File

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