Skip to content

Commit

Permalink
Whole chunk deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
cheyao committed Oct 13, 2024
1 parent d58b84f commit 9a1949e
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 205,553 deletions.
6 changes: 0 additions & 6 deletions src/main/java/com/cyao/FlatMinecraft.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.cyao;

import net.fabricmc.api.ModInitializer;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -14,8 +11,5 @@ public class FlatMinecraft implements ModInitializer {
@Override
public void onInitialize() {
LOGGER.info("Initializing mod");
Registry.register(Registries.CHUNK_GENERATOR,
Identifier.of("flat-minecraft:paper-world"),
PaperChunkGenerator.CODEC);
}
}
464 changes: 0 additions & 464 deletions src/main/java/com/cyao/PaperChunkGenerator.java

This file was deleted.

51 changes: 51 additions & 0 deletions src/main/java/com/cyao/mixin/ChunkMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.cyao.mixin;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.collection.BoundedRegionArray;
import net.minecraft.util.collection.PackedIntegerArray;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.Heightmap;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.*;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Map;
import java.util.concurrent.CompletableFuture;

@Mixin(ChunkGenerating.class)
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();

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();
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);
ReadableContainer<RegistryEntry<Biome>> biomeContainer = chunkSection.getBiomeContainer();
sections[i] = new ChunkSection(blockStateContainer, biomeContainer);
}

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

int elementBits = MathHelper.ceilLog2(chunk.getHeight() + 1);
long[] emptyHeightmap = new PackedIntegerArray(elementBits, 256).getData();
for (Map.Entry<Heightmap.Type, Heightmap> entry : chunk.getHeightmaps()) {
entry.getValue().setTo(chunk, entry.getKey(), emptyHeightmap);
}
}
}
}
44 changes: 0 additions & 44 deletions src/main/java/com/cyao/mixin/WorldPresetMixin.java

This file was deleted.

3 changes: 0 additions & 3 deletions src/main/resources/assets/flat-minecraft/lang/en_us.json

This file was deleted.

Loading

0 comments on commit 9a1949e

Please sign in to comment.