mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
Cleanup
This commit is contained in:
parent
3628097438
commit
6aa55ad7b6
@ -12,7 +12,7 @@ import java.time.Duration;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.function.Function;
|
||||||
|
|
||||||
final class BlockImpl implements Block {
|
final class BlockImpl implements Block {
|
||||||
private static final Cache<NBTCompound, NBTCompound> NBT_CACHE = Caffeine.newBuilder()
|
private static final Cache<NBTCompound, NBTCompound> NBT_CACHE = Caffeine.newBuilder()
|
||||||
@ -54,16 +54,16 @@ final class BlockImpl implements Block {
|
|||||||
return compute(properties); // Map should be complete
|
return compute(properties); // Map should be complete
|
||||||
}
|
}
|
||||||
var newProperties = new HashMap<>(this.properties);
|
var newProperties = new HashMap<>(this.properties);
|
||||||
newProperties.replaceAll((key, value) -> Objects.requireNonNullElse(properties.get(key), value));
|
newProperties.putAll(properties);
|
||||||
return compute(newProperties);
|
return compute(newProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull <T> Block withTag(@NotNull Tag<T> tag, @Nullable T value) {
|
public @NotNull <T> Block withTag(@NotNull Tag<T> tag, @Nullable T value) {
|
||||||
var compound = Objects.requireNonNullElseGet(nbt(), NBTCompound::new);
|
var temporaryNbt = nbt != null ? nbt.deepClone() : new NBTCompound();
|
||||||
tag.write(compound, value);
|
tag.write(temporaryNbt, value);
|
||||||
final var nbt = compound.getSize() > 0 ? NBT_CACHE.get(compound, c -> compound) : null;
|
final var finalNbt = temporaryNbt.getSize() > 0 ? NBT_CACHE.get(temporaryNbt, Function.identity()) : null;
|
||||||
return new BlockImpl(registry, propertyEntry, properties, nbt, handler);
|
return new BlockImpl(registry, propertyEntry, properties, finalNbt, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user