Skip to content

Commit 23314c8

Browse files
author
Gegy
committed
add void chunk generator implementation
1 parent e038101 commit 23314c8

File tree

4 files changed

+136
-4
lines changed

4 files changed

+136
-4
lines changed

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ yarn_mappings=1.17+build.12
77
loader_version=0.11.6
88

99
# Mod Properties
10-
mod_version=0.4.1
10+
mod_version=0.4.2
1111
maven_group=xyz.nucleoid
1212
archives_base_name=fantasy
1313

1414
# Dependencies
15-
fabric_version=0.35.2+1.17
15+
fabric_version=0.35.2+1.17
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package xyz.nucleoid.fantasy;
2+
3+
import net.fabricmc.api.ModInitializer;
4+
import net.minecraft.util.Identifier;
5+
import net.minecraft.util.registry.Registry;
6+
import xyz.nucleoid.fantasy.util.VoidChunkGenerator;
7+
8+
public final class FantasyInitializer implements ModInitializer {
9+
@Override
10+
public void onInitialize() {
11+
Registry.register(Registry.CHUNK_GENERATOR, new Identifier(Fantasy.ID, "void"), VoidChunkGenerator.CODEC);
12+
}
13+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package xyz.nucleoid.fantasy.util;
2+
3+
import com.mojang.serialization.Codec;
4+
import com.mojang.serialization.codecs.RecordCodecBuilder;
5+
import net.minecraft.block.BlockState;
6+
import net.minecraft.server.world.ServerWorld;
7+
import net.minecraft.structure.StructureManager;
8+
import net.minecraft.util.math.BlockPos;
9+
import net.minecraft.util.math.ChunkPos;
10+
import net.minecraft.util.registry.DynamicRegistryManager;
11+
import net.minecraft.util.registry.Registry;
12+
import net.minecraft.util.registry.RegistryKey;
13+
import net.minecraft.world.ChunkRegion;
14+
import net.minecraft.world.HeightLimitView;
15+
import net.minecraft.world.Heightmap;
16+
import net.minecraft.world.StructureWorldAccess;
17+
import net.minecraft.world.biome.Biome;
18+
import net.minecraft.world.biome.BiomeKeys;
19+
import net.minecraft.world.biome.source.BiomeAccess;
20+
import net.minecraft.world.biome.source.FixedBiomeSource;
21+
import net.minecraft.world.chunk.Chunk;
22+
import net.minecraft.world.gen.GenerationStep;
23+
import net.minecraft.world.gen.StructureAccessor;
24+
import net.minecraft.world.gen.chunk.ChunkGenerator;
25+
import net.minecraft.world.gen.chunk.StructuresConfig;
26+
import net.minecraft.world.gen.chunk.VerticalBlockSample;
27+
import net.minecraft.world.gen.feature.StructureFeature;
28+
import org.jetbrains.annotations.Nullable;
29+
30+
import java.util.Collections;
31+
import java.util.Optional;
32+
import java.util.concurrent.CompletableFuture;
33+
import java.util.concurrent.Executor;
34+
import java.util.function.Supplier;
35+
36+
public class VoidChunkGenerator extends ChunkGenerator {
37+
public static final Codec<VoidChunkGenerator> CODEC = RecordCodecBuilder.create(instance -> {
38+
return instance.group(
39+
Biome.REGISTRY_CODEC.stable().fieldOf("biome").forGetter(g -> g.biome)
40+
).apply(instance, instance.stable(VoidChunkGenerator::new));
41+
});
42+
43+
private static final VerticalBlockSample EMPTY_SAMPLE = new VerticalBlockSample(0, new BlockState[0]);
44+
45+
private final Supplier<Biome> biome;
46+
47+
public VoidChunkGenerator(Supplier<Biome> biome) {
48+
super(new FixedBiomeSource(biome), new StructuresConfig(Optional.empty(), Collections.emptyMap()));
49+
this.biome = biome;
50+
}
51+
52+
public VoidChunkGenerator(Registry<Biome> biomeRegistry) {
53+
this(biomeRegistry, BiomeKeys.THE_VOID);
54+
}
55+
56+
public VoidChunkGenerator(Registry<Biome> biomeRegistry, RegistryKey<Biome> biome) {
57+
this(() -> biomeRegistry.get(biome));
58+
}
59+
60+
@Override
61+
protected Codec<? extends ChunkGenerator> getCodec() {
62+
return CODEC;
63+
}
64+
65+
@Override
66+
public ChunkGenerator withSeed(long seed) {
67+
return this;
68+
}
69+
70+
@Override
71+
public void setStructureStarts(DynamicRegistryManager registryManager, StructureAccessor accessor, Chunk chunk, StructureManager manager, long seed) {
72+
}
73+
74+
@Override
75+
public void addStructureReferences(StructureWorldAccess world, StructureAccessor accessor, Chunk chunk) {
76+
}
77+
78+
@Override
79+
public CompletableFuture<Chunk> populateNoise(Executor executor, StructureAccessor accessor, Chunk chunk) {
80+
return CompletableFuture.completedFuture(chunk);
81+
}
82+
83+
@Override
84+
public void buildSurface(ChunkRegion region, Chunk chunk) {
85+
}
86+
87+
@Override
88+
public void carve(long seed, BiomeAccess access, Chunk chunk, GenerationStep.Carver carver) {
89+
}
90+
91+
@Override
92+
public void generateFeatures(ChunkRegion region, StructureAccessor accessor) {
93+
}
94+
95+
@Override
96+
public void populateEntities(ChunkRegion region) {
97+
}
98+
99+
@Override
100+
public int getHeight(int x, int z, Heightmap.Type heightmap, HeightLimitView world) {
101+
return 0;
102+
}
103+
104+
@Override
105+
public VerticalBlockSample getColumnSample(int x, int z, HeightLimitView world) {
106+
return EMPTY_SAMPLE;
107+
}
108+
109+
@Nullable
110+
@Override
111+
public BlockPos locateStructure(ServerWorld world, StructureFeature<?> feature, BlockPos center, int radius, boolean skipExistingChunks) {
112+
return null;
113+
}
114+
115+
@Override
116+
public boolean isStrongholdStartingChunk(ChunkPos chunkPos) {
117+
return false;
118+
}
119+
}

src/main/resources/fabric.mod.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
"id": "fantasy",
44
"version": "${version}",
55
"name": "Fantasy",
6-
"description": "Dynamic dimensions",
6+
"description": "Fantasy is a library that allows for dimensions to be created and destroyed at runtime on the server.",
77
"authors": ["Nucleoid Contributors"],
88
"license": "LGPLv3",
99
"environment": "*",
1010
"entrypoints": {
11-
"main": []
11+
"main": ["xyz.nucleoid.fantasy.FantasyInitializer"]
1212
},
1313
"mixins": ["fantasy.mixins.json"],
1414
"accessWidener": "fantasy.accesswidener",

0 commit comments

Comments
 (0)