mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-04 23:06:05 +00:00
clean up palette addon
This commit is contained in:
@@ -32,17 +32,6 @@ public class PaletteConfigType implements ConfigType<PaletteTemplate, Palette> {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Supplier<OpenRegistry<Palette>> registrySupplier(ConfigPack pack) {
|
||||
return () -> pack.getRegistryFactory().create(registry -> (TypeLoader<Palette>) (t, c, loader) -> {
|
||||
if(((String) c).startsWith("BLOCK:"))
|
||||
return new PaletteImpl.Singleton(
|
||||
platform.getWorldHandle().createBlockData(((String) c).substring(6))); // Return single palette for BLOCK: shortcut.
|
||||
return registry.get((String) c).orElseThrow(() -> new LoadException(
|
||||
"No such " + t.getType().getTypeName() + " matching \"" + c + "\" was found in this registry."));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaletteTemplate getTemplate(ConfigPack pack, Platform platform) {
|
||||
return new PaletteTemplate();
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
package com.dfsek.terra.addons.palette;
|
||||
|
||||
import com.dfsek.terra.addons.palette.palette.NoisePalette;
|
||||
import com.dfsek.terra.addons.palette.palette.PaletteImpl;
|
||||
import com.dfsek.terra.addons.palette.palette.PaletteLayerHolder;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
@@ -17,7 +17,7 @@ import com.dfsek.terra.api.world.chunk.generation.util.Palette;
|
||||
public class PaletteFactory implements ConfigFactory<PaletteTemplate, Palette> {
|
||||
@Override
|
||||
public Palette build(PaletteTemplate config, Platform platform) {
|
||||
NoisePalette palette = new NoisePalette(config.getNoise());
|
||||
PaletteImpl palette = new PaletteImpl(config.getNoise());
|
||||
for(PaletteLayerHolder layer : config.getPalette()) {
|
||||
palette.add(layer.getLayer(), layer.getSize(), layer.getSampler());
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.palette.palette;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
public class NoisePalette extends PaletteImpl {
|
||||
private final NoiseSampler sampler;
|
||||
|
||||
public NoisePalette(NoiseSampler sampler) {
|
||||
this.sampler = sampler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState get(int layer, double x, double y, double z, long seed) {
|
||||
PaletteLayer paletteLayer;
|
||||
if(layer > this.getSize()) paletteLayer = this.getLayers().get(this.getLayers().size() - 1);
|
||||
else {
|
||||
List<PaletteLayer> pl = getLayers();
|
||||
if(layer >= pl.size()) paletteLayer = pl.get(pl.size() - 1);
|
||||
else paletteLayer = pl.get(layer);
|
||||
}
|
||||
NoiseSampler paletteSampler = paletteLayer.getSampler();
|
||||
return paletteLayer.get(paletteSampler == null ? sampler : paletteSampler, x, y, z, seed);
|
||||
}
|
||||
}
|
||||
@@ -7,27 +7,25 @@
|
||||
|
||||
package com.dfsek.terra.addons.palette.palette;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.Palette;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* A class representation of a "slice" of the world.
|
||||
* Used to get a section of blocks, based on the depth at which they are found.
|
||||
*/
|
||||
public abstract class PaletteImpl implements Palette {
|
||||
public class PaletteImpl implements Palette {
|
||||
private final List<PaletteLayer> pallet = new ArrayList<>();
|
||||
private final NoiseSampler sampler;
|
||||
|
||||
/**
|
||||
* Constructs a blank palette.
|
||||
*/
|
||||
public PaletteImpl() {
|
||||
|
||||
public PaletteImpl(NoiseSampler sampler) {
|
||||
this.sampler = sampler;
|
||||
}
|
||||
|
||||
public Palette add(ProbabilityCollection<BlockState> m, int layers, NoiseSampler sampler) {
|
||||
@@ -37,6 +35,19 @@ public abstract class PaletteImpl implements Palette {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState get(int layer, double x, double y, double z, long seed) {
|
||||
PaletteLayer paletteLayer;
|
||||
if(layer > this.getSize()) paletteLayer = this.getLayers().get(this.getLayers().size() - 1);
|
||||
else {
|
||||
List<PaletteLayer> pl = getLayers();
|
||||
if(layer >= pl.size()) paletteLayer = pl.get(pl.size() - 1);
|
||||
else paletteLayer = pl.get(layer);
|
||||
}
|
||||
NoiseSampler paletteSampler = paletteLayer.getSampler();
|
||||
return paletteLayer.get(paletteSampler == null ? sampler : paletteSampler, x, y, z, seed);
|
||||
}
|
||||
|
||||
|
||||
public int getSize() {
|
||||
return pallet.size();
|
||||
@@ -50,10 +61,8 @@ public abstract class PaletteImpl implements Palette {
|
||||
* Class representation of a layer of a BlockPalette.
|
||||
*/
|
||||
public static class PaletteLayer {
|
||||
private final boolean col; // Is layer using a collection?
|
||||
private final NoiseSampler sampler;
|
||||
private ProbabilityCollection<BlockState> collection;
|
||||
private BlockState m;
|
||||
private final ProbabilityCollection<BlockState> collection;
|
||||
|
||||
/**
|
||||
* Constructs a PaletteLayerHolder with a ProbabilityCollection of materials and a number of layers.
|
||||
@@ -63,47 +72,16 @@ public abstract class PaletteImpl implements Palette {
|
||||
*/
|
||||
public PaletteLayer(ProbabilityCollection<BlockState> type, NoiseSampler sampler) {
|
||||
this.sampler = sampler;
|
||||
this.col = true;
|
||||
this.collection = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a PaletteLayerHolder with a single Material and a number of layers.
|
||||
*
|
||||
* @param type The material to use.
|
||||
* @param sampler Noise sampler to use
|
||||
*/
|
||||
public PaletteLayer(BlockState type, NoiseSampler sampler) {
|
||||
this.sampler = sampler;
|
||||
this.col = false;
|
||||
this.m = type;
|
||||
}
|
||||
|
||||
public BlockState get(NoiseSampler random, double x, double y, double z, long seed) {
|
||||
if(col) return this.collection.get(random, x, y, z, seed);
|
||||
return m;
|
||||
return this.collection.get(random, x, y, z, seed);
|
||||
}
|
||||
|
||||
public NoiseSampler getSampler() {
|
||||
return sampler;
|
||||
}
|
||||
|
||||
public ProbabilityCollection<BlockState> getCollection() {
|
||||
return collection;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Singleton extends PaletteImpl {
|
||||
private final BlockState item;
|
||||
|
||||
public Singleton(BlockState item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState get(int layer, double x, double y, double z, long seed) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user