mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
directly instantiate biomes
This commit is contained in:
@@ -9,14 +9,15 @@ import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.util.seeded.SeededTerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class BiomeConfigType implements ConfigType<BiomeTemplate, SeededTerraBiome> {
|
||||
public class BiomeConfigType implements ConfigType<BiomeTemplate, TerraBiome> {
|
||||
private final ConfigPack pack;
|
||||
private final BiomeFactory factory;
|
||||
|
||||
public static final TypeKey<SeededTerraBiome> BIOME_TYPE_TOKEN = new TypeKey<>() {};
|
||||
public static final TypeKey<TerraBiome> BIOME_TYPE_TOKEN = new TypeKey<>() {};
|
||||
|
||||
public BiomeConfigType(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
@@ -29,20 +30,20 @@ public class BiomeConfigType implements ConfigType<BiomeTemplate, SeededTerraBio
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFactory<BiomeTemplate, SeededTerraBiome> getFactory() {
|
||||
public ConfigFactory<BiomeTemplate, TerraBiome> getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKey<SeededTerraBiome> getTypeClass() {
|
||||
public TypeKey<TerraBiome> getTypeClass() {
|
||||
return BIOME_TYPE_TOKEN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Supplier<OpenRegistry<SeededTerraBiome>> registrySupplier() {
|
||||
return () -> pack.getRegistryFactory().create(registry -> (TypeLoader<SeededTerraBiome>) (t, c, loader) -> {
|
||||
public Supplier<OpenRegistry<TerraBiome>> registrySupplier() {
|
||||
return () -> pack.getRegistryFactory().create(registry -> (TypeLoader<TerraBiome>) (t, c, loader) -> {
|
||||
if(c.equals("SELF")) return null;
|
||||
SeededTerraBiome obj = registry.get((String) c);
|
||||
TerraBiome obj = registry.get((String) c);
|
||||
if(obj == null)
|
||||
throw new LoadException("No such " + t.getType().getTypeName() + " matching \"" + c + "\" was found in this registry.");
|
||||
return obj;
|
||||
|
||||
@@ -4,8 +4,9 @@ import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.util.seeded.SeededTerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
|
||||
public class BiomeFactory implements ConfigFactory<BiomeTemplate, SeededTerraBiome> {
|
||||
public class BiomeFactory implements ConfigFactory<BiomeTemplate, TerraBiome> {
|
||||
private final ConfigPack pack;
|
||||
|
||||
public BiomeFactory(ConfigPack pack) {
|
||||
@@ -13,7 +14,9 @@ public class BiomeFactory implements ConfigFactory<BiomeTemplate, SeededTerraBio
|
||||
}
|
||||
|
||||
@Override
|
||||
public SeededTerraBiome build(BiomeTemplate template, TerraPlugin main) {
|
||||
return new UserDefinedSeededTerraBiome(template);
|
||||
public TerraBiome build(BiomeTemplate template, TerraPlugin main) {
|
||||
UserDefinedGenerator generator = new UserDefinedGenerator(template.getNoiseEquation(), template.getElevationEquation(), template.getCarvingEquation(), template.getBiomeNoise(), template.getElevationWeight(),
|
||||
template.getBlendDistance(), template.getBlendStep(), template.getBlendWeight());
|
||||
return new UserDefinedBiome(template.getVanilla(), generator, template);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,16 +20,15 @@ public class UserDefinedBiome implements TerraBiome {
|
||||
private final int color;
|
||||
private final Set<String> tags;
|
||||
|
||||
private final Context context;
|
||||
private final Context context = new Context();
|
||||
|
||||
public UserDefinedBiome(ProbabilityCollection<Biome> vanilla, UserDefinedGenerator gen, BiomeTemplate config, Context context) {
|
||||
public UserDefinedBiome(ProbabilityCollection<Biome> vanilla, UserDefinedGenerator gen, BiomeTemplate config) {
|
||||
this.vanilla = vanilla;
|
||||
this.gen = gen;
|
||||
this.id = config.getID();
|
||||
this.config = config;
|
||||
this.color = config.getColor();
|
||||
this.tags = config.getTags();
|
||||
this.context = context;
|
||||
tags.add("BIOME:" + id);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.dfsek.terra.addons.biome;
|
||||
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.util.seeded.SeededTerraBiome;
|
||||
import com.dfsek.terra.api.world.biome.Biome;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class UserDefinedSeededTerraBiome implements SeededTerraBiome {
|
||||
private final BiomeTemplate template;
|
||||
private final Context context = new Context();
|
||||
|
||||
private final Map<Long, UserDefinedBiome> biomeMap = new ConcurrentHashMap<>();
|
||||
|
||||
public UserDefinedSeededTerraBiome(BiomeTemplate template) {
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDefinedBiome build(long seed) {
|
||||
synchronized(biomeMap) {
|
||||
return biomeMap.computeIfAbsent(seed,
|
||||
s -> {
|
||||
UserDefinedGenerator generator = new UserDefinedGenerator(template.getNoiseEquation(), template.getElevationEquation(), template.getCarvingEquation(), template.getBiomeNoise(), template.getElevationWeight(),
|
||||
template.getBlendDistance(), template.getBlendStep(), template.getBlendWeight());
|
||||
return new UserDefinedBiome(template.getVanilla(), generator, template, context);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProbabilityCollection<Biome> getVanillaBiomes() {
|
||||
return template.getVanilla();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context getContext() {
|
||||
return context;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user