mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
Codec stuff
This commit is contained in:
@@ -19,7 +19,6 @@ import com.dfsek.terra.fabric.world.FabricMaterialData;
|
||||
import com.dfsek.terra.fabric.world.FabricWorldHandle;
|
||||
import com.dfsek.terra.fabric.world.TerraBiomeSource;
|
||||
import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.world.generator.TerraChunkGeneratorCodec;
|
||||
import com.dfsek.terra.registry.ConfigRegistry;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import net.fabricmc.api.EnvType;
|
||||
@@ -42,9 +41,9 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
|
||||
private final Map<Long, TerraWorld> worldMap = new HashMap<>();
|
||||
private static TerraFabricPlugin instance;
|
||||
private final TerraChunkGeneratorCodec chunkGeneratorCodec = new TerraChunkGeneratorCodec(this);
|
||||
|
||||
public static TerraFabricPlugin getInstance() {
|
||||
return instance;
|
||||
@@ -165,15 +164,11 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
GeneratorTypeAccessor.getValues().add(new GeneratorType("terra") {
|
||||
@Override
|
||||
protected ChunkGenerator getChunkGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
|
||||
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed), seed);
|
||||
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed), seed, registry.get("DEFAULT"));
|
||||
}
|
||||
});
|
||||
}
|
||||
Registry.register(Registry.CHUNK_GENERATOR, new Identifier("terra:terra"), FabricChunkGeneratorWrapper.CODEC);
|
||||
Registry.register(Registry.BIOME_SOURCE, new Identifier("terra:terra"), TerraBiomeSource.CODEC);
|
||||
}
|
||||
|
||||
public TerraChunkGeneratorCodec getChunkGeneratorCodec() {
|
||||
return chunkGeneratorCodec;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.dfsek.terra.fabric.codec;
|
||||
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.DataResult;
|
||||
import com.mojang.serialization.DynamicOps;
|
||||
|
||||
public class ConfigPackCodec implements Codec<ConfigPack> {
|
||||
@Override
|
||||
public <T> DataResult<Pair<ConfigPack, T>> decode(DynamicOps<T> ops, T input) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> DataResult<T> encode(ConfigPack input, DynamicOps<T> ops, T prefix) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.dfsek.terra.fabric.mixin;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.screen.world.CreateWorldScreen;
|
||||
import net.minecraft.client.gui.screen.world.MoreOptionsDialog;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(MoreOptionsDialog.class)
|
||||
public class MoreOptionsDialogMixin {
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "method_28092(Lnet/minecraft/client/gui/screen/world/CreateWorldScreen;Lnet/minecraft/client/MinecraftClient;Lnet/minecraft/client/font/TextRenderer;)V")
|
||||
private void draw(final CreateWorldScreen parent, MinecraftClient client, TextRenderer textRenderer, CallbackInfo info) {
|
||||
System.out.println("More options opened");
|
||||
}
|
||||
|
||||
/*@Inject(at = @At("RETURN"), method = "setVisible(B)V")
|
||||
private void setVisible(boolean visible, CallbackInfo info) {
|
||||
System.out.println("redraw");
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.dfsek.terra.fabric.world.generator;
|
||||
import com.dfsek.terra.api.gaea.math.MathUtil;
|
||||
import com.dfsek.terra.api.gaea.util.FastRandom;
|
||||
import com.dfsek.terra.api.generic.Handle;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.world.TerraBiomeSource;
|
||||
import com.dfsek.terra.fabric.world.handles.chunk.FabricChunkRegionChunk;
|
||||
@@ -35,17 +36,26 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Handl
|
||||
private final long seed;
|
||||
private final TerraChunkGenerator delegate;
|
||||
private final TerraBiomeSource biomeSource;
|
||||
public static final Codec<ConfigPack> PACK_CODEC = (RecordCodecBuilder.create(config -> config.group(
|
||||
Codec.STRING.fieldOf("pack").forGetter(pack -> pack.getTemplate().getID())
|
||||
).apply(config, config.stable(TerraFabricPlugin.getInstance().getRegistry()::get))));
|
||||
public static final Codec<FabricChunkGeneratorWrapper> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||
TerraBiomeSource.CODEC.fieldOf("biome_source").forGetter(generator -> generator.biomeSource),
|
||||
Codec.LONG.fieldOf("seed").stable().forGetter(generator -> generator.seed))
|
||||
Codec.LONG.fieldOf("seed").stable().forGetter(generator -> generator.seed),
|
||||
PACK_CODEC.fieldOf("pack").stable().forGetter(generator -> generator.pack))
|
||||
.apply(instance, instance.stable(FabricChunkGeneratorWrapper::new)));
|
||||
private final ConfigPack pack;
|
||||
|
||||
|
||||
private final CavePopulator cavePopulator = new CavePopulator(TerraFabricPlugin.getInstance());
|
||||
private final FloraPopulator floraPopulator = new FloraPopulator(TerraFabricPlugin.getInstance());
|
||||
private final OrePopulator orePopulator = new OrePopulator(TerraFabricPlugin.getInstance());
|
||||
public FabricChunkGeneratorWrapper(TerraBiomeSource biomeSource, long seed) {
|
||||
super(biomeSource, new StructuresConfig(false));
|
||||
|
||||
this.delegate = new TerraChunkGenerator(TerraFabricPlugin.getInstance().getRegistry().get("DEFAULT"), TerraFabricPlugin.getInstance());
|
||||
public FabricChunkGeneratorWrapper(TerraBiomeSource biomeSource, long seed, ConfigPack configPack) {
|
||||
super(biomeSource, new StructuresConfig(false));
|
||||
this.pack = configPack;
|
||||
|
||||
this.delegate = new TerraChunkGenerator(configPack, TerraFabricPlugin.getInstance());
|
||||
delegate.getMain().getLogger().info("Loading world...");
|
||||
this.biomeSource = biomeSource;
|
||||
|
||||
@@ -64,7 +74,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Handl
|
||||
|
||||
@Override
|
||||
public ChunkGenerator withSeed(long seed) {
|
||||
return new FabricChunkGeneratorWrapper((TerraBiomeSource) this.biomeSource.withSeed(seed), seed);
|
||||
return new FabricChunkGeneratorWrapper((TerraBiomeSource) this.biomeSource.withSeed(seed), seed, pack);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.dfsek.terra.fabric.world.generator;
|
||||
|
||||
import com.dfsek.terra.api.generic.TerraPlugin;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.DataResult;
|
||||
import com.mojang.serialization.DynamicOps;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class TerraChunkGeneratorCodec implements Codec<TerraChunkGenerator> {
|
||||
private final TerraPlugin main;
|
||||
|
||||
public TerraChunkGeneratorCodec(TerraPlugin main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> DataResult<Pair<TerraChunkGenerator, T>> decode(DynamicOps<T> ops, T input) {
|
||||
Optional<String> s = ops.getStringValue(input).get().left();
|
||||
if(!s.isPresent()) return DataResult.error("No data present");
|
||||
if(main.getRegistry().contains(s.get())) {
|
||||
return DataResult.success(new Pair<>(new TerraChunkGenerator(main.getRegistry().get(s.get()), main), input));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> DataResult<T> encode(TerraChunkGenerator input, DynamicOps<T> ops, T prefix) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,8 @@
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [],
|
||||
"client": [
|
||||
"GeneratorTypeAccessor"
|
||||
"GeneratorTypeAccessor",
|
||||
"MoreOptionsDialogMixin"
|
||||
],
|
||||
"server": [],
|
||||
"injectors": {
|
||||
|
||||
Reference in New Issue
Block a user