Skip to content

Commit

Permalink
Save before redo
Browse files Browse the repository at this point in the history
  • Loading branch information
cheyao committed Oct 13, 2024
1 parent 9a1949e commit ac1448c
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/main/java/com/cyao/mixin/ChunkMixin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cyao.mixin;

import com.cyao.FlatMinecraft;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand All @@ -25,20 +26,41 @@ public class ChunkMixin {
@Inject(method = "initializeLight", at = @At("HEAD"))
private static void getInitializeLightingFuture(ChunkGenerationContext context, ChunkGenerationStep step, BoundedRegionArray<AbstractChunkHolder> chunks, Chunk chunk, CallbackInfoReturnable<CompletableFuture<Chunk>> cir) {
BlockPos spawn = context.world().getLevelProperties().getSpawnPos();

int z = spawn.getZ() - 1;
ChunkPos pos = chunk.getPos();
if ((pos.x < 1874999 && pos.x > -1875000 && pos.z < 1874999 && pos.z > -1875000) &&
(pos.z * 16 > spawn.getZ() || (pos.z + 1) * 16 < spawn.getZ())) {
ChunkSection[] sections = chunk.getSectionArray();
ChunkSection[] sections = chunk.getSectionArray();
int offset = spawn.getZ() % 16;

if (!((pos.z * 16) > spawn.getZ() || ((pos.z + 1) * 16) <= spawn.getZ())) {
FlatMinecraft.LOGGER.info("Saving chunk at {} with spawn at {}", pos, spawn);

// Here are the blocks
/*
for (int i = 0; i < sections.length; i++) {
ChunkSection chunkSection = sections[i];
PalettedContainer<BlockState> blockStateContainer = chunkSection.getBlockStateContainer();
blockStateContainer.forEachValue(blockStateCounter);
ReadableContainer<RegistryEntry<Biome>> biomeContainer = chunkSection.getBiomeContainer();
sections[i] = new ChunkSection(blockStateContainer, biomeContainer);
}
*/

// Prob chests and stuff
for (BlockPos block : chunk.getBlockEntityPositions()) {
if (block.getZ() < z || block.getZ() > z + 2) {
chunk.removeBlockEntity(block);
}
}
} else if ((pos.x < 1874999 && pos.x > -1875000 && pos.z < 1874999 && pos.z > -1875000)) {
for (int i = 0; i < sections.length; i++) {
ChunkSection chunkSection = sections[i];
PalettedContainer<BlockState> blockStateContainer = new PalettedContainer<>(Block.STATE_IDS, Blocks.AIR.getDefaultState(), PalettedContainer.PaletteProvider.BLOCK_STATE);
PalettedContainer<BlockState> blockStateContainer = new PalettedContainer<>(Block.STATE_IDS, Blocks.BARRIER.getDefaultState(), PalettedContainer.PaletteProvider.BLOCK_STATE);
ReadableContainer<RegistryEntry<Biome>> biomeContainer = chunkSection.getBiomeContainer();
sections[i] = new ChunkSection(blockStateContainer, biomeContainer);
}

for (BlockPos bePos : chunk.getBlockEntityPositions()) {
chunk.removeBlockEntity(bePos);
for (BlockPos block : chunk.getBlockEntityPositions()) {
chunk.removeBlockEntity(block);
}

int elementBits = MathHelper.ceilLog2(chunk.getHeight() + 1);
Expand Down

0 comments on commit ac1448c

Please sign in to comment.