Micro cleanup

This commit is contained in:
TheMode 2021-07-10 20:26:30 +02:00
parent a8a9f59715
commit 98f645b344
2 changed files with 8 additions and 8 deletions

View File

@ -58,13 +58,12 @@ public class DynamicChunk extends Chunk {
final NBTCompound nbt = block.nbt();
if (handler != null || nbt != null) {
this.entries.put(index, block);
// Block tick
if (handler != null && handler.isTickable()) {
this.tickableMap.put(index, block);
}
} else {
this.entries.remove(index);
}
// Tickable
if (handler != null && handler.isTickable()) {
this.tickableMap.put(index, block);
} else {
this.tickableMap.remove(index);
}
}

View File

@ -8,15 +8,15 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import java.time.Duration;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
class BlockImpl implements Block {
private static final Cache<NBTCompound, NBTCompound> NBT_CACHE = Caffeine.newBuilder()
.expireAfterWrite(5, TimeUnit.MINUTES)
.expireAfterWrite(Duration.ofMinutes(5))
.weakValues()
.build();
@ -56,7 +56,8 @@ class BlockImpl implements Block {
public @NotNull <T> Block withTag(@NotNull Tag<T> tag, @Nullable T value) {
var compound = Objects.requireNonNullElseGet(nbt(), NBTCompound::new);
tag.write(compound, value);
return new BlockImpl(registry, properties, NBT_CACHE.get(compound, c -> compound), handler);
final var nbt = compound.getSize() > 0 ? NBT_CACHE.get(compound, c -> compound) : null;
return new BlockImpl(registry, properties, nbt, handler);
}
@Override