Skip to content

Commit

Permalink
Add initial stage of chunk builder
Browse files Browse the repository at this point in the history
  • Loading branch information
cheyao committed Oct 12, 2024
1 parent 736819a commit 535f60c
Show file tree
Hide file tree
Showing 9 changed files with 580 additions and 27 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ publishing {
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}

loom {
accessWidenerPath = file("src/main/resources/flat-minecraft.accesswidener")
}
47 changes: 47 additions & 0 deletions src/main/java/com/cyao/FlatCarverContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.cyao;

import net.minecraft.block.BlockState;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.HeightLimitView;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.HeightContext;
import net.minecraft.world.gen.chunk.ChunkNoiseSampler;
import net.minecraft.world.gen.noise.NoiseConfig;
import net.minecraft.world.gen.surfacebuilder.MaterialRules;

import java.util.Optional;
import java.util.function.Function;

public class FlatCarverContext extends HeightContext {
private final DynamicRegistryManager registryManager;
private final ChunkNoiseSampler chunkNoiseSampler;
private final NoiseConfig noiseConfig;
private final MaterialRules.MaterialRule materialRule;

public FlatCarverContext(PaperChunkGenerator noiseChunkGenerator, DynamicRegistryManager registryManager, HeightLimitView heightLimitView, ChunkNoiseSampler chunkNoiseSampler, NoiseConfig noiseConfig, MaterialRules.MaterialRule materialRule) {
super(noiseChunkGenerator, heightLimitView);
this.registryManager = registryManager;
this.chunkNoiseSampler = chunkNoiseSampler;
this.noiseConfig = noiseConfig;
this.materialRule = materialRule;
}

/** @deprecated */
@Deprecated
public Optional<BlockState> applyMaterialRule(Function<BlockPos, RegistryEntry<Biome>> posToBiome, Chunk chunk, BlockPos pos, boolean hasFluid) {
return this.noiseConfig.getSurfaceBuilder().applyMaterialRule(this.materialRule, this, posToBiome, chunk, this.chunkNoiseSampler, pos, hasFluid);
}

/** @deprecated */
@Deprecated
public DynamicRegistryManager getRegistryManager() {
return this.registryManager;
}

public NoiseConfig getNoiseConfig() {
return this.noiseConfig;
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/cyao/FlatMinecraft.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package com.cyao;

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

import static net.minecraft.registry.Registries.CHUNK_GENERATOR;

public class FlatMinecraft implements ModInitializer {
public static final String MOD_ID = "flat-minecraft";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

@Override
public void onInitialize() {
LOGGER.info("Initializing mod");
Registry.register(CHUNK_GENERATOR,
Identifier.of("flat-minecraft:2D-world"),
PaperChunkGenerator.CODEC);
}
}
Loading

0 comments on commit 535f60c

Please sign in to comment.