Reduce subclass impl

This commit is contained in:
TheMode 2021-06-16 14:04:22 +02:00
parent 84f22a6ed4
commit 34b7133f17
2 changed files with 7 additions and 9 deletions

View File

@ -10,6 +10,7 @@ import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import java.util.Map;
import java.util.Objects;
import java.util.function.BiPredicate;
/**
@ -27,10 +28,14 @@ public interface Block extends ProtocolObject, TagReadable, BlockConstants {
return withProperty(property.getName(), value.toString());
}
<T> @NotNull Block withTag(@NotNull Tag<T> tag, @Nullable T value);
@NotNull Block withNbt(@Nullable NBTCompound compound);
default <T> @NotNull Block withTag(@NotNull Tag<T> tag, @Nullable T value) {
var compound = Objects.requireNonNullElseGet(getNbt(), NBTCompound::new);
tag.write(compound, value);
return withNbt(compound);
}
@NotNull Block withHandler(@Nullable BlockHandler handler);
@NotNull String getProperty(@NotNull String property);

View File

@ -41,13 +41,6 @@ class BlockTest implements Block {
return Objects.requireNonNull(BlockRegistry.getProperties(this, properties));
}
@Override
public @NotNull <T> Block withTag(@NotNull Tag<T> tag, @Nullable T value) {
var compound = this.compound != null ? this.compound.deepClone() : new NBTCompound();
tag.write(compound, value);
return new BlockTest(registry, properties, compound, handler);
}
@Override
public @NotNull Block withNbt(@Nullable NBTCompound compound) {
return new BlockTest(registry, properties, compound, handler);