mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-19 07:11:14 +00:00
Reformat all code
Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
This commit is contained in:
+9
-8
@@ -11,22 +11,23 @@ import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
|
||||
|
||||
@Addon("config-palette")
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public class PaletteAddon extends TerraAddon {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
main.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
event.getPack().registerConfigType(new PaletteConfigType(main), "PALETTE", 2);
|
||||
event.getPack().applyLoader(PaletteLayerHolder.class, new PaletteLayerLoader());
|
||||
})
|
||||
.failThrough();
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
event.getPack().registerConfigType(new PaletteConfigType(main), "PALETTE", 2);
|
||||
event.getPack().applyLoader(PaletteLayerHolder.class, new PaletteLayerLoader());
|
||||
})
|
||||
.failThrough();
|
||||
}
|
||||
}
|
||||
|
||||
+24
-21
@@ -2,6 +2,9 @@ package com.dfsek.terra.addons.palette;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.addons.palette.palette.PaletteImpl;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
@@ -11,42 +14,42 @@ import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class PaletteConfigType implements ConfigType<PaletteTemplate, Palette> {
|
||||
public static final TypeKey<Palette> PALETTE_TYPE_TOKEN = new TypeKey<>() {
|
||||
};
|
||||
private final PaletteFactory factory = new PaletteFactory();
|
||||
private final TerraPlugin main;
|
||||
|
||||
public static final TypeKey<Palette> PALETTE_TYPE_TOKEN = new TypeKey<>(){};
|
||||
|
||||
|
||||
public PaletteConfigType(TerraPlugin main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaletteTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
|
||||
return new PaletteTemplate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFactory<PaletteTemplate, Palette> getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKey<Palette> getTypeKey() {
|
||||
return PALETTE_TYPE_TOKEN;
|
||||
}
|
||||
|
||||
|
||||
@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(main.getWorldHandle().createBlockData(((String) c).substring(6))); // Return single palette for BLOCK: shortcut.
|
||||
return new PaletteImpl.Singleton(
|
||||
main.getWorldHandle().createBlockData(((String) c).substring(6))); // Return single palette for BLOCK: shortcut.
|
||||
Palette 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;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaletteTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
|
||||
return new PaletteTemplate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFactory<PaletteTemplate, Palette> getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKey<Palette> getTypeKey() {
|
||||
return PALETTE_TYPE_TOKEN;
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -6,6 +6,7 @@ import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.world.generator.Palette;
|
||||
|
||||
|
||||
public class PaletteFactory implements ConfigFactory<PaletteTemplate, Palette> {
|
||||
@Override
|
||||
public Palette build(PaletteTemplate config, TerraPlugin main) {
|
||||
|
||||
+9
-7
@@ -3,34 +3,36 @@ package com.dfsek.terra.addons.palette;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Final;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.palette.palette.PaletteLayerHolder;
|
||||
import com.dfsek.terra.api.config.AbstractableTemplate;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings({"FieldMayBeFinal", "unused"})
|
||||
@SuppressWarnings({ "FieldMayBeFinal", "unused" })
|
||||
public class PaletteTemplate implements AbstractableTemplate {
|
||||
@Value("noise")
|
||||
@Default
|
||||
private @Meta NoiseSampler noise = NoiseSampler.zero();
|
||||
|
||||
|
||||
@Value("id")
|
||||
@Final
|
||||
private String id;
|
||||
|
||||
|
||||
@Value("layers")
|
||||
private @Meta List<@Meta PaletteLayerHolder> palette;
|
||||
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public List<PaletteLayerHolder> getPalette() {
|
||||
return palette;
|
||||
}
|
||||
|
||||
|
||||
public NoiseSampler getNoise() {
|
||||
return noise;
|
||||
}
|
||||
|
||||
+5
-4
@@ -1,17 +1,18 @@
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
|
||||
+23
-23
@@ -1,13 +1,13 @@
|
||||
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.generator.Palette;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* A class representation of a "slice" of the world.
|
||||
@@ -15,14 +15,14 @@ import java.util.Random;
|
||||
*/
|
||||
public abstract class PaletteImpl implements Palette {
|
||||
private final List<PaletteLayer> pallet = new ArrayList<>();
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a blank palette.
|
||||
*/
|
||||
public PaletteImpl() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Palette add(BlockState m, int layers, NoiseSampler sampler) {
|
||||
for(int i = 0; i < layers; i++) {
|
||||
@@ -30,7 +30,7 @@ public abstract class PaletteImpl implements Palette {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Palette add(ProbabilityCollection<BlockState> m, int layers, NoiseSampler sampler) {
|
||||
for(int i = 0; i < layers; i++) {
|
||||
@@ -38,17 +38,17 @@ public abstract class PaletteImpl implements Palette {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return pallet.size();
|
||||
}
|
||||
|
||||
|
||||
public List<PaletteLayer> getLayers() {
|
||||
return pallet;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Class representation of a layer of a BlockPalette.
|
||||
*/
|
||||
@@ -57,7 +57,7 @@ public abstract class PaletteImpl implements Palette {
|
||||
private final NoiseSampler sampler;
|
||||
private ProbabilityCollection<BlockState> collection;
|
||||
private BlockState m;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a PaletteLayerHolder with a ProbabilityCollection of materials and a number of layers.
|
||||
*
|
||||
@@ -69,7 +69,7 @@ public abstract class PaletteImpl implements Palette {
|
||||
this.col = true;
|
||||
this.collection = type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a PaletteLayerHolder with a single Material and a number of layers.
|
||||
*
|
||||
@@ -81,29 +81,29 @@ public abstract class PaletteImpl implements Palette {
|
||||
this.col = false;
|
||||
this.m = type;
|
||||
}
|
||||
|
||||
public NoiseSampler getSampler() {
|
||||
return sampler;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
+7
-5
@@ -1,30 +1,32 @@
|
||||
package com.dfsek.terra.addons.palette.palette;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public class PaletteLayerHolder {
|
||||
private final ProbabilityCollection<BlockState> layer;
|
||||
private final NoiseSampler sampler;
|
||||
private final int size;
|
||||
|
||||
|
||||
public PaletteLayerHolder(@NotNull ProbabilityCollection<BlockState> layer, NoiseSampler sampler, int size) {
|
||||
this.layer = layer;
|
||||
this.sampler = sampler;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public ProbabilityCollection<BlockState> getLayer() {
|
||||
return layer;
|
||||
}
|
||||
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
public NoiseSampler getSampler() {
|
||||
return sampler;
|
||||
}
|
||||
|
||||
+12
-10
@@ -3,38 +3,40 @@ package com.dfsek.terra.addons.palette.palette;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class PaletteLayerLoader implements TypeLoader<PaletteLayerHolder> {
|
||||
private static final AnnotatedType BLOCK_DATA_PROBABILITY_COLLECTION_TYPE;
|
||||
|
||||
static {
|
||||
try {
|
||||
BLOCK_DATA_PROBABILITY_COLLECTION_TYPE = PaletteLayerLoader.class.getDeclaredField("blockStateProbabilityCollection").getAnnotatedType();
|
||||
BLOCK_DATA_PROBABILITY_COLLECTION_TYPE = PaletteLayerLoader.class.getDeclaredField("blockStateProbabilityCollection")
|
||||
.getAnnotatedType();
|
||||
} catch(NoSuchFieldException e) {
|
||||
throw new Error("this should never happen. i dont know what you did to make this happen but something is very wrong.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private ProbabilityCollection<BlockState> blockStateProbabilityCollection;
|
||||
|
||||
|
||||
@Override
|
||||
public PaletteLayerHolder load(AnnotatedType type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||
Map<String, Object> map = (Map<String, Object>) o;
|
||||
ProbabilityCollection<BlockState> collection = (ProbabilityCollection<BlockState>) configLoader.loadType(BLOCK_DATA_PROBABILITY_COLLECTION_TYPE, map.get("materials"));
|
||||
|
||||
ProbabilityCollection<BlockState> collection = (ProbabilityCollection<BlockState>) configLoader.loadType(
|
||||
BLOCK_DATA_PROBABILITY_COLLECTION_TYPE, map.get("materials"));
|
||||
|
||||
NoiseSampler sampler = null;
|
||||
if(map.containsKey("noise")) {
|
||||
sampler = configLoader.loadType(NoiseSampler.class, map.get("noise"));
|
||||
}
|
||||
|
||||
|
||||
if(collection == null) throw new LoadException("Collection is null: " + map.get("materials"));
|
||||
return new PaletteLayerHolder(collection, sampler, (Integer) map.get("layers"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user