Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import org.jspecify.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class SnowloggingStorage {
public static final String TAG = "snow:snowlogged_layers";
Expand All @@ -39,12 +41,16 @@ public static List<Layers> store(ChunkAccess chunk, SerializableChunkData data)
}

public static void restore(SerializableChunkData data, List<Layers> layers) {
Set<LevelChunkSection> changed = new HashSet<>();
for (Layers entry : layers) {
LevelChunkSection section = section(data, entry.pos());
if (section != null && getBlockState(section, entry.pos()).is(Snowlogging.SNOWLOGGABLE)) {
setBlockState(section, entry.pos(), Blocks.SNOW.defaultBlockState().setValue(SnowLayerBlock.LAYERS, entry.layers()));
changed.add(section);
}
}

changed.forEach(LevelChunkSection::recalcBlockCounts);
}

public static void write(CompoundTag tag, List<Layers> layers) {
Expand Down Expand Up @@ -73,7 +79,7 @@ private static BlockState getBlockState(LevelChunkSection section, BlockPos pos)
}

private static void setBlockState(LevelChunkSection section, BlockPos pos, BlockState state) {
section.setBlockState(SectionPos.sectionRelative(pos.getX()), SectionPos.sectionRelative(pos.getY()), SectionPos.sectionRelative(pos.getZ()), state, false);
section.getStates().getAndSetUnchecked(SectionPos.sectionRelative(pos.getX()), SectionPos.sectionRelative(pos.getY()), SectionPos.sectionRelative(pos.getZ()), state);
}

public record Layers(BlockPos pos, int layers) {
Expand Down
Loading