mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
Reduce subclass impl
This commit is contained in:
parent
84f22a6ed4
commit
34b7133f17
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user