MaterialData is gone

This commit is contained in:
dfsek
2021-02-22 19:47:15 -07:00
parent a328ff2f2a
commit 358bd350b5
52 changed files with 266 additions and 365 deletions

View File

@@ -19,7 +19,7 @@ public interface Block extends Handle {
Location getLocation();
MaterialData getType();
BlockType getType();
int getX();

View File

@@ -3,11 +3,14 @@ package com.dfsek.terra.api.platform.block;
import com.dfsek.terra.api.platform.Handle;
public interface BlockData extends Cloneable, Handle {
MaterialData getMaterial();
boolean matches(MaterialData materialData);
BlockType getBlockType();
boolean matches(BlockData other);
BlockData clone();
String getAsString();
boolean isAir();
}

View File

@@ -0,0 +1,9 @@
package com.dfsek.terra.api.platform.block;
import com.dfsek.terra.api.platform.Handle;
public interface BlockType extends Handle {
BlockData getDefaultData();
boolean isSolid();
}

View File

@@ -1,17 +0,0 @@
package com.dfsek.terra.api.platform.block;
import com.dfsek.terra.api.platform.Handle;
public interface MaterialData extends Handle {
boolean matches(MaterialData other);
boolean matches(BlockData other);
boolean isSolid();
boolean isAir();
double getMaxDurability();
BlockData createBlockData();
}

View File

@@ -1,13 +1,13 @@
package com.dfsek.terra.api.platform.handle;
import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.api.platform.inventory.ItemStack;
import com.dfsek.terra.api.platform.inventory.Item;
import com.dfsek.terra.api.platform.inventory.item.Enchantment;
import java.util.Set;
public interface ItemHandle {
ItemStack newItemStack(MaterialData material, int amount);
Item createItem(String data);
Enchantment getEnchantment(String id);

View File

@@ -2,7 +2,6 @@ package com.dfsek.terra.api.platform.handle;
import com.dfsek.terra.api.platform.block.Block;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.api.platform.entity.EntityType;
/**
@@ -13,11 +12,7 @@ public interface WorldHandle {
BlockData getBlockData(Block block);
MaterialData getType(Block block);
BlockData createBlockData(String data);
MaterialData createMaterialData(String data);
EntityType getEntity(String id);
}

View File

@@ -0,0 +1,12 @@
package com.dfsek.terra.api.platform.inventory;
import com.dfsek.terra.api.platform.Handle;
/**
* An inventory item.
*/
public interface Item extends Handle {
ItemStack newItemStack(int amount);
double getMaxDurability();
}

View File

@@ -1,7 +1,6 @@
package com.dfsek.terra.api.platform.inventory;
import com.dfsek.terra.api.platform.Handle;
import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.api.platform.inventory.item.ItemMeta;
public interface ItemStack extends Handle, Cloneable {
@@ -9,7 +8,7 @@ public interface ItemStack extends Handle, Cloneable {
void setAmount(int i);
MaterialData getType();
Item getType();
ItemStack clone();

View File

@@ -1,7 +1,7 @@
package com.dfsek.terra.api.structures.loot;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.api.platform.inventory.Item;
import com.dfsek.terra.api.platform.inventory.ItemStack;
import com.dfsek.terra.api.structures.loot.functions.AmountFunction;
import com.dfsek.terra.api.structures.loot.functions.DamageFunction;
@@ -19,10 +19,9 @@ import java.util.Random;
* Representation of a single item entry within a Loot Table pool.
*/
public class Entry {
private final MaterialData item;
private final Item item;
private final long weight;
private final List<LootFunction> functions = new GlueList<>();
private final TerraPlugin main;
/**
* Instantiates an Entry from a JSON representation.
@@ -30,9 +29,8 @@ public class Entry {
* @param entry The JSON Object to instantiate from.
*/
public Entry(JSONObject entry, TerraPlugin main) {
this.main = main;
String id = entry.get("name").toString();
this.item = main.getWorldHandle().createMaterialData(id);
this.item = main.getItemHandle().createItem(id);
long weight1;
try {
@@ -85,7 +83,7 @@ public class Entry {
* @return ItemStack - The ItemStack with all functions applied.
*/
public ItemStack getItem(Random r) {
ItemStack item = main.getItemHandle().newItemStack(this.item, 1);
ItemStack item = this.item.newItemStack(1);
for(LootFunction f : functions) {
item = f.apply(item, r);
}

View File

@@ -1,27 +1,37 @@
package com.dfsek.terra.api.util.collections;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.api.platform.block.BlockType;
import java.util.Arrays;
import java.util.HashSet;
public class MaterialSet extends HashSet<MaterialData> {
public class MaterialSet extends HashSet<BlockType> {
private static final long serialVersionUID = 3056512763631017301L;
public static MaterialSet singleton(MaterialData material) {
public static MaterialSet singleton(BlockType material) {
MaterialSet set = new MaterialSet();
set.add(material);
return set;
}
public static MaterialSet get(MaterialData... materials) {
public static MaterialSet get(BlockType... materials) {
MaterialSet set = new MaterialSet();
set.addAll(Arrays.asList(materials));
return set;
}
public static MaterialSet get(BlockData... materials) {
MaterialSet set = new MaterialSet();
Arrays.stream(materials).forEach(set::add);
return set;
}
public static MaterialSet empty() {
return new MaterialSet();
}
private void add(BlockData data) {
add(data.getMaterial());
add(data.getBlockType());
}
}

View File

@@ -2,13 +2,12 @@ package com.dfsek.terra.api.world.tree;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.api.util.collections.MaterialSet;
import java.util.Random;
import java.util.Set;
public interface Tree {
boolean plant(Location l, Random r);
Set<MaterialData> getSpawnable();
MaterialSet getSpawnable();
}

View File

@@ -11,8 +11,8 @@ import java.util.Random;
public class Cactus extends FractalTree {
@Override
public MaterialSet getSpawnable() {
return MaterialSet.get(main.getWorldHandle().createMaterialData("minecraft:sand"),
main.getWorldHandle().createMaterialData("minecraft:red_sand"));
return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:sand"),
main.getWorldHandle().createBlockData("minecraft:red_sand"));
}

View File

@@ -19,10 +19,10 @@ public class IceSpike extends FractalTree {
@Override
public MaterialSet getSpawnable() {
return MaterialSet.get(main.getWorldHandle().createMaterialData("minecraft:stone"),
main.getWorldHandle().createMaterialData("minecraft:gravel"),
main.getWorldHandle().createMaterialData("minecraft:snow_block"),
main.getWorldHandle().createMaterialData("minecraft:grass_block"));
return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:stone"),
main.getWorldHandle().createBlockData("minecraft:gravel"),
main.getWorldHandle().createBlockData("minecraft:snow_block"),
main.getWorldHandle().createBlockData("minecraft:grass_block"));
}
/**

View File

@@ -17,8 +17,8 @@ public class OakTree extends FractalTree {
@Override
public MaterialSet getSpawnable() {
return MaterialSet.get(main.getWorldHandle().createMaterialData("minecraft:podzol"),
main.getWorldHandle().createMaterialData("minecraft:grass_block"));
return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:podzol"),
main.getWorldHandle().createBlockData("minecraft:grass_block"));
}
/**

View File

@@ -12,7 +12,7 @@ public class ShatteredPillar extends FractalTree {
@Override
public MaterialSet getSpawnable() {
return MaterialSet.get(main.getWorldHandle().createMaterialData("minecraft:end_stone"));
return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:end_stone"));
}
/**

View File

@@ -20,7 +20,7 @@ public class ShatteredTree extends FractalTree {
@Override
public MaterialSet getSpawnable() {
return MaterialSet.get(main.getWorldHandle().createMaterialData("minecraft:end_stone"));
return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:end_stone"));
}
/**

View File

@@ -12,7 +12,7 @@ public class SmallShatteredPillar extends FractalTree {
@Override
public MaterialSet getSpawnable() {
return MaterialSet.get(main.getWorldHandle().createMaterialData("minecraft:end_stone"));
return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:end_stone"));
}
/**

View File

@@ -20,7 +20,7 @@ public class SmallShatteredTree extends FractalTree {
@Override
public MaterialSet getSpawnable() {
return MaterialSet.get(main.getWorldHandle().createMaterialData("minecraft:end_stone"));
return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:end_stone"));
}
/**

View File

@@ -16,8 +16,8 @@ public class SpruceTree extends FractalTree {
@Override
public MaterialSet getSpawnable() {
return MaterialSet.get(main.getWorldHandle().createMaterialData("minecraft:podzol"),
main.getWorldHandle().createMaterialData("minecraft:grass_block"));
return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:podzol"),
main.getWorldHandle().createBlockData("minecraft:grass_block"));
}
/**

View File

@@ -1,7 +1,7 @@
package com.dfsek.terra.carving;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.api.platform.block.BlockType;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
@@ -29,7 +29,7 @@ public class CarverPalette {
return layers[y];
}
public boolean canReplace(MaterialData material) {
public boolean canReplace(BlockType material) {
return blacklist != replace.contains(material);
}

View File

@@ -8,6 +8,7 @@ import com.dfsek.terra.api.math.GridSpawn;
import com.dfsek.terra.api.math.Range;
import com.dfsek.terra.api.math.noise.samplers.ImageSampler;
import com.dfsek.terra.api.math.noise.samplers.noise.CellularSampler;
import com.dfsek.terra.api.platform.block.BlockType;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
import com.dfsek.terra.api.util.seeded.SourceSeeded;
@@ -92,6 +93,7 @@ public class GenericLoaders implements LoaderRegistrar {
.registerLoader(SourceSeeded.class, new SourceBuilderLoader())
.registerLoader(StageSeeded.class, new StageBuilderLoader())
.registerLoader(TerraAddon.class, main.getAddons())
.registerLoader(BlockType.class, (t, object, cf) -> main.getWorldHandle().createBlockData((String) object).getBlockType())
.registerLoader(BiomeProvider.BiomeProviderBuilder.class, new BiomeProviderBuilderLoader())
.registerLoader(ImageSampler.Channel.class, (t, object, cf) -> ImageSampler.Channel.valueOf((String) object))
.registerLoader(BiomeProvider.Type.class, (t, object, cf) -> BiomeProvider.Type.valueOf((String) object))

View File

@@ -3,7 +3,7 @@ package com.dfsek.terra.config.loaders;
import com.dfsek.tectonic.exception.LoadException;
import com.dfsek.tectonic.loading.ConfigLoader;
import com.dfsek.tectonic.loading.TypeLoader;
import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.api.platform.block.BlockType;
import com.dfsek.terra.api.util.collections.MaterialSet;
import java.lang.reflect.Type;
@@ -18,7 +18,7 @@ public class MaterialSetLoader implements TypeLoader<MaterialSet> {
for(String string : stringData) {
try {
set.add(configLoader.loadClass(MaterialData.class, string));
set.add(configLoader.loadClass(BlockType.class, string));
} catch(NullPointerException e) {
throw new LoadException("Invalid data identifier \"" + string + "\"", e);
}

View File

@@ -1,7 +1,6 @@
package com.dfsek.terra.config.loaders;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.api.world.flora.Flora;
@@ -10,15 +9,12 @@ import com.dfsek.terra.api.world.tree.Tree;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.Set;
/**
* Class to hold Type instances for types with generics.
*/
@SuppressWarnings("unused")
public final class Types {
public static final Type MATERIAL_SET_TYPE;
public static final Type MATERIAL_PROBABILITY_COLLECTION_TYPE;
public static final Type BLOCK_DATA_PALETTE_TYPE;
public static final Type BLOCK_DATA_PROBABILITY_COLLECTION_TYPE;
public static final Type FLORA_PROBABILITY_COLLECTION_TYPE;
@@ -27,8 +23,6 @@ public final class Types {
public static final Type TERRA_BIOME_TERRA_BIOME_PROBABILITY_COLLECTION_MAP;
static {
MATERIAL_SET_TYPE = getType("materialSet");
MATERIAL_PROBABILITY_COLLECTION_TYPE = getType("materialProbabilityCollection");
BLOCK_DATA_PALETTE_TYPE = getType("blockDataPalette");
BLOCK_DATA_PROBABILITY_COLLECTION_TYPE = getType("blockDataProbabilityCollection");
FLORA_PROBABILITY_COLLECTION_TYPE = getType("floraProbabilityCollection");
@@ -37,9 +31,7 @@ public final class Types {
TERRA_BIOME_TERRA_BIOME_PROBABILITY_COLLECTION_MAP = getType("terraBiomeProbabilityCollectionMap");
}
private Set<MaterialData> materialSet;
private Palette<BlockData> blockDataPalette;
private ProbabilityCollection<MaterialData> materialProbabilityCollection;
private ProbabilityCollection<BlockData> blockDataProbabilityCollection;
private ProbabilityCollection<Flora> floraProbabilityCollection;
private ProbabilityCollection<Tree> treeProbabilityCollection;

View File

@@ -14,7 +14,7 @@ import com.dfsek.terra.api.math.noise.samplers.noise.ConstantSampler;
import com.dfsek.terra.api.math.paralithic.BlankFunction;
import com.dfsek.terra.api.math.paralithic.defined.UserDefinedFunction;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.api.platform.block.BlockType;
import com.dfsek.terra.api.platform.world.Biome;
import com.dfsek.terra.api.util.GlueList;
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
@@ -158,12 +158,12 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
@Value("slabs.palettes")
@Abstractable
@Default
private Map<MaterialData, Palette<BlockData>> slabPalettes;
private Map<BlockType, Palette<BlockData>> slabPalettes;
@Value("slabs.stair-palettes")
@Abstractable
@Default
private Map<MaterialData, Palette<BlockData>> stairPalettes;
private Map<BlockType, Palette<BlockData>> stairPalettes;
@Value("slant.threshold")
@Abstractable
@@ -237,11 +237,11 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
return doSlabs;
}
public Map<MaterialData, Palette<BlockData>> getSlabPalettes() {
public Map<BlockType, Palette<BlockData>> getSlabPalettes() {
return slabPalettes;
}
public Map<MaterialData, Palette<BlockData>> getStairPalettes() {
public Map<BlockType, Palette<BlockData>> getStairPalettes() {
return stairPalettes;
}

View File

@@ -4,7 +4,7 @@ import com.dfsek.tectonic.annotations.Abstractable;
import com.dfsek.tectonic.annotations.Default;
import com.dfsek.tectonic.annotations.Value;
import com.dfsek.terra.api.math.Range;
import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.api.platform.block.BlockType;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.carving.CarverPalette;
@@ -104,7 +104,7 @@ public class CarverTemplate extends AbstractableTemplate {
@Value("shift")
@Abstractable
@Default
private Map<MaterialData, MaterialSet> shift = new HashMap<>();
private Map<BlockType, MaterialSet> shift = new HashMap<>();
@Value("update")
@Abstractable
@@ -187,7 +187,7 @@ public class CarverTemplate extends AbstractableTemplate {
return inner;
}
public Map<MaterialData, MaterialSet> getShift() {
public Map<BlockType, MaterialSet> getShift() {
return shift;
}

View File

@@ -2,7 +2,6 @@ package com.dfsek.terra.registry.config;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.world.flora.Flora;
import com.dfsek.terra.registry.OpenRegistry;
@@ -52,8 +51,8 @@ public class FloraRegistry extends OpenRegistry<Flora> {
addItem("BROWN_MUSHROOM", () -> new ConstantFlora(mushroom, Collections.singletonList(data("minecraft:brown_mushroom"))));
}
private MaterialData create(String s) {
return main.getWorldHandle().createMaterialData(s);
private BlockData create(String s) {
return main.getWorldHandle().createBlockData(s);
}
private void addItem(String id, Callable<ConstantFlora> flora) {

View File

@@ -3,7 +3,7 @@ package com.dfsek.terra.registry.config;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.block.BlockFace;
import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.world.tree.Tree;
import com.dfsek.terra.api.world.tree.fractal.FractalTree;
import com.dfsek.terra.api.world.tree.fractal.trees.Cactus;
@@ -19,7 +19,6 @@ import com.dfsek.terra.registry.OpenRegistry;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Random;
import java.util.Set;
public class TreeRegistry extends OpenRegistry<Tree> {
private final TerraPlugin main;
@@ -71,7 +70,7 @@ public class TreeRegistry extends OpenRegistry<Tree> {
}
@Override
public Set<MaterialData> getSpawnable() {
public MaterialSet getSpawnable() {
return tree.getSpawnable();
}
}

View File

@@ -5,7 +5,7 @@ import com.dfsek.terra.api.math.Range;
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.block.BlockFace;
import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.api.platform.block.BlockType;
import com.dfsek.terra.api.platform.block.data.Bisected;
import com.dfsek.terra.api.platform.block.data.Slab;
import com.dfsek.terra.api.platform.block.data.Stairs;
@@ -37,7 +37,7 @@ import java.util.Random;
public class DefaultChunkGenerator3D implements TerraChunkGenerator {
private final ConfigPack configPack;
private final TerraPlugin main;
private final MaterialData water;
private final BlockType water;
private final SinglePalette<BlockData> blank;
private final Carver carver;
@@ -49,7 +49,7 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
this.configPack = c;
this.main = main;
carver = new NoiseCarver(new Range(0, 255), main.getWorldHandle().createBlockData("minecraft:air"), main);
water = main.getWorldHandle().createMaterialData("minecraft:water");
water = main.getWorldHandle().createBlockData("minecraft:water").getBlockType();
blank = new SinglePalette<>(main.getWorldHandle().createBlockData("minecraft:air"));
this.cache = cache;
}
@@ -150,11 +150,11 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
}
}
private void prepareBlockPartFloor(BlockData down, BlockData orig, ChunkData chunk, Vector3 block, Map<MaterialData, Palette<BlockData>> slabs,
Map<MaterialData, Palette<BlockData>> stairs, double thresh, Sampler sampler) {
private void prepareBlockPartFloor(BlockData down, BlockData orig, ChunkData chunk, Vector3 block, Map<BlockType, Palette<BlockData>> slabs,
Map<BlockType, Palette<BlockData>> stairs, double thresh, Sampler sampler) {
if(sampler.sample(block.getX(), block.getY() - 0.4, block.getZ()) > thresh) {
if(stairs != null) {
Palette<BlockData> stairPalette = stairs.get(down.getMaterial());
Palette<BlockData> stairPalette = stairs.get(down.getBlockType());
if(stairPalette != null) {
BlockData stair = stairPalette.get(0, block.getX(), block.getY(), block.getZ()).clone();
if(stair instanceof Stairs) {
@@ -163,19 +163,19 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
}
}
}
BlockData slab = slabs.getOrDefault(down.getMaterial(), blank).get(0, block.getX(), block.getY(), block.getZ());
BlockData slab = slabs.getOrDefault(down.getBlockType(), blank).get(0, block.getX(), block.getY(), block.getZ());
if(slab instanceof Waterlogged) {
((Waterlogged) slab).setWaterlogged(orig.matches(water));
} else if(orig.matches(water)) return;
((Waterlogged) slab).setWaterlogged(orig.getBlockType().equals(water));
} else if(orig.getBlockType().equals(water)) return;
chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), slab);
}
}
private void prepareBlockPartCeiling(BlockData up, BlockData orig, ChunkData chunk, Vector3 block, Map<MaterialData, Palette<BlockData>> slabs,
Map<MaterialData, Palette<BlockData>> stairs, double thresh, Sampler sampler) {
private void prepareBlockPartCeiling(BlockData up, BlockData orig, ChunkData chunk, Vector3 block, Map<BlockType, Palette<BlockData>> slabs,
Map<BlockType, Palette<BlockData>> stairs, double thresh, Sampler sampler) {
if(sampler.sample(block.getX(), block.getY() + 0.4, block.getZ()) > thresh) {
if(stairs != null) {
Palette<BlockData> stairPalette = stairs.get(up.getMaterial());
Palette<BlockData> stairPalette = stairs.get(up.getBlockType());
if(stairPalette != null) {
BlockData stair = stairPalette.get(0, block.getX(), block.getY(), block.getZ()).clone();
if(stair instanceof Stairs) {
@@ -185,12 +185,12 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
}
}
}
BlockData slab = slabs.getOrDefault(up.getMaterial(), blank).get(0, block.getX(), block.getY(), block.getZ()).clone();
BlockData slab = slabs.getOrDefault(up.getBlockType(), blank).get(0, block.getX(), block.getY(), block.getZ()).clone();
if(slab instanceof Bisected) ((Bisected) slab).setHalf(Bisected.Half.TOP);
if(slab instanceof Slab) ((Slab) slab).setType(Slab.Type.TOP);
if(slab instanceof Waterlogged) {
((Waterlogged) slab).setWaterlogged(orig.matches(water));
} else if(orig.matches(water)) return; // Only replace water if waterlogged.
((Waterlogged) slab).setWaterlogged(orig.getBlockType().equals(water));
} else if(orig.getBlockType().equals(water)) return; // Only replace water if waterlogged.
chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), slab);
}
}
@@ -208,7 +208,7 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
stairNew.setFacing(BlockFace.EAST);
} else stairNew = null;
if(stairNew != null) {
if(orig.matches(water)) stairNew.setWaterlogged(orig.matches(water));
if(orig.getBlockType().equals(water)) stairNew.setWaterlogged(orig.getBlockType().equals(water));
chunk.setBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ(), stairNew);
return true;
}

View File

@@ -4,7 +4,7 @@ import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.block.Block;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.api.platform.block.BlockType;
import com.dfsek.terra.api.platform.handle.WorldHandle;
import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.platform.world.World;
@@ -24,7 +24,7 @@ import java.util.Random;
import java.util.Set;
public class CavePopulator implements TerraBlockPopulator {
private static final Map<MaterialData, BlockData> shiftStorage = new HashMap<>(); // Persist BlockData created for shifts, to avoid re-calculating each time.
private static final Map<BlockType, BlockData> shiftStorage = new HashMap<>(); // Persist BlockData created for shifts, to avoid re-calculating each time.
private final TerraPlugin main;
public CavePopulator(TerraPlugin main) {
@@ -44,51 +44,52 @@ public class CavePopulator implements TerraBlockPopulator {
for(UserDefinedCarver c : config.getCarvers()) {
CarverTemplate template = c.getConfig();
Map<Location, MaterialData> shiftCandidate = new HashMap<>();
Map<Location, BlockData> shiftCandidate = new HashMap<>();
Set<Block> updateNeeded = new HashSet<>();
c.carve(chunk.getX(), chunk.getZ(), world, (v, type) -> {
Block b = chunk.getBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ());
MaterialData m = handle.getType(b);
BlockData m = handle.getBlockData(b);
BlockType re = m.getBlockType();
switch(type) {
case CENTER:
if(template.getInner().canReplace(m)) {
if(template.getInner().canReplace(re)) {
b.setBlockData(template.getInner().get(v.getBlockY()).get(random), false);
if(template.getUpdate().contains(m)) updateNeeded.add(b);
if(template.getShift().containsKey(m)) shiftCandidate.put(b.getLocation(), m);
if(template.getUpdate().contains(re)) updateNeeded.add(b);
if(template.getShift().containsKey(re)) shiftCandidate.put(b.getLocation(), m);
}
break;
case WALL:
if(template.getOuter().canReplace(m)) {
if(template.getOuter().canReplace(re)) {
b.setBlockData(template.getOuter().get(v.getBlockY()).get(random), false);
if(template.getUpdate().contains(m)) updateNeeded.add(b);
if(template.getShift().containsKey(m)) shiftCandidate.put(b.getLocation(), m);
if(template.getUpdate().contains(re)) updateNeeded.add(b);
if(template.getShift().containsKey(re)) shiftCandidate.put(b.getLocation(), m);
}
break;
case TOP:
if(template.getTop().canReplace(m)) {
if(template.getTop().canReplace(re)) {
b.setBlockData(template.getTop().get(v.getBlockY()).get(random), false);
if(template.getUpdate().contains(m)) updateNeeded.add(b);
if(template.getShift().containsKey(m)) shiftCandidate.put(b.getLocation(), m);
if(template.getUpdate().contains(re)) updateNeeded.add(b);
if(template.getShift().containsKey(re)) shiftCandidate.put(b.getLocation(), m);
}
break;
case BOTTOM:
if(template.getBottom().canReplace(m)) {
if(template.getBottom().canReplace(re)) {
b.setBlockData(template.getBottom().get(v.getBlockY()).get(random), false);
if(template.getUpdate().contains(m)) updateNeeded.add(b);
if(template.getShift().containsKey(m)) shiftCandidate.put(b.getLocation(), m);
if(template.getUpdate().contains(re)) updateNeeded.add(b);
if(template.getShift().containsKey(re)) shiftCandidate.put(b.getLocation(), m);
}
break;
}
});
for(Map.Entry<Location, MaterialData> entry : shiftCandidate.entrySet()) {
for(Map.Entry<Location, BlockData> entry : shiftCandidate.entrySet()) {
Location l = entry.getKey();
Location mut = l.clone();
MaterialData orig = handle.getType(l.getBlock());
BlockData orig = handle.getBlockData(l.getBlock());
do mut.subtract(0, 1, 0);
while(mut.getY() > 0 && handle.getType(mut.getBlock()).equals(orig));
while(mut.getY() > 0 && handle.getBlockData(mut.getBlock()).matches(orig));
try {
if(template.getShift().get(entry.getValue()).contains(mut.getBlock().getType())) {
handle.setBlockData(mut.getBlock(), shiftStorage.computeIfAbsent(entry.getValue(), MaterialData::createBlockData), false);
if(template.getShift().get(entry.getValue().getBlockType()).contains(mut.getBlock().getBlockData().getBlockType())) {
handle.setBlockData(mut.getBlock(), shiftStorage.computeIfAbsent(entry.getValue().getBlockType(), BlockType::getDefaultData), false);
}
} catch(NullPointerException ignore) {
}