mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
Implement WorldHandle
This commit is contained in:
@@ -25,7 +25,7 @@ java {
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
val versionObj = Version("2", "1", "0", true)
|
||||
val versionObj = Version("2", "2", "0", true)
|
||||
|
||||
version = versionObj
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.dfsek.terra;
|
||||
|
||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||
import com.dfsek.terra.api.bukkit.BukkitWorldHandle;
|
||||
import com.dfsek.terra.api.generic.TerraPlugin;
|
||||
import com.dfsek.terra.api.generic.world.WorldHandle;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import com.dfsek.terra.biome.palette.PaletteHolder;
|
||||
import com.dfsek.terra.biome.palette.PaletteLayer;
|
||||
@@ -64,12 +67,13 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class Terra extends GaeaPlugin {
|
||||
public class Terra extends GaeaPlugin implements TerraPlugin {
|
||||
private final Map<String, TerraChunkGenerator> generatorMap = new HashMap<>();
|
||||
private final Map<World, TerraWorld> worldMap = new HashMap<>();
|
||||
private final Map<String, ConfigPack> worlds = new HashMap<>();
|
||||
private final ConfigRegistry registry = new ConfigRegistry();
|
||||
private final PluginConfig config = new PluginConfig();
|
||||
private final WorldHandle handle = new BukkitWorldHandle();
|
||||
|
||||
public void reload() {
|
||||
Map<World, TerraWorld> newMap = new HashMap<>();
|
||||
@@ -190,4 +194,9 @@ public class Terra extends GaeaPlugin {
|
||||
public PluginConfig getTerraConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldHandle getHandle() {
|
||||
return handle;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.dfsek.terra.api.bukkit;
|
||||
|
||||
import com.dfsek.terra.api.generic.world.WorldHandle;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
public class BukkitWorldHandle implements WorldHandle {
|
||||
@Override
|
||||
public void setBlockData(Block block, BlockData data, boolean physics) {
|
||||
block.setBlockData(data, physics);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData getBlockData(Block block) {
|
||||
return block.getBlockData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material getType(Block block) {
|
||||
return block.getType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.dfsek.terra.api.generic;
|
||||
|
||||
import com.dfsek.terra.api.generic.world.WorldHandle;
|
||||
|
||||
public interface TerraPlugin {
|
||||
WorldHandle getHandle();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.dfsek.terra.api.generic.world;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
/**
|
||||
* Interface to be implemented for world manipulation.
|
||||
*/
|
||||
public interface WorldHandle {
|
||||
void setBlockData(Block block, BlockData data, boolean physics);
|
||||
|
||||
BlockData getBlockData(Block block);
|
||||
|
||||
Material getType(Block block);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.command.structure.load;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.structure.Rotation;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
@@ -35,8 +36,8 @@ public class LoadFullCommand extends LoadCommand implements DebugCommand {
|
||||
return true;
|
||||
}
|
||||
Structure struc = Structure.load(new File(getMain().getDataFolder() + File.separator + "export" + File.separator + "structures", args[0] + ".tstructure"));
|
||||
if(chunk) struc.paste(sender.getLocation(), sender.getLocation().getChunk(), r);
|
||||
else struc.paste(sender.getLocation(), r);
|
||||
if(chunk) struc.paste(sender.getLocation(), sender.getLocation().getChunk(), r, (Terra) getMain());
|
||||
else struc.paste(sender.getLocation(), r, (Terra) getMain());
|
||||
//sender.sendMessage(String.valueOf(struc.checkSpawns(sender.getLocation(), r)));
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.command.structure.load;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.api.generic.world.WorldHandle;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.structure.Structure;
|
||||
import com.dfsek.terra.structure.StructureContainedBlock;
|
||||
@@ -36,6 +38,7 @@ public class LoadRawCommand extends LoadCommand implements DebugCommand {
|
||||
@Override
|
||||
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
|
||||
try {
|
||||
WorldHandle handle = ((Terra) getMain()).getHandle();
|
||||
Structure struc = Structure.load(new File(getMain().getDataFolder() + File.separator + "export" + File.separator + "structures", args[0] + ".tstructure"));
|
||||
StructureInfo info = struc.getStructureInfo();
|
||||
int centerX = info.getCenterX();
|
||||
@@ -45,21 +48,21 @@ public class LoadRawCommand extends LoadCommand implements DebugCommand {
|
||||
for(StructureContainedBlock block : level1) {
|
||||
Location bLocation = sender.getLocation().add(block.getX() - centerX, block.getY(), block.getZ() - centerZ);
|
||||
if(!block.getPull().equals(StructureContainedBlock.Pull.NONE)) {
|
||||
bLocation.getBlock().setBlockData(Material.OAK_SIGN.createBlockData(), false);
|
||||
handle.setBlockData(bLocation.getBlock(), Material.OAK_SIGN.createBlockData(), false);
|
||||
Sign sign = (Sign) bLocation.getBlock().getState();
|
||||
sign.setLine(1, "[PULL=" + block.getPull() + "_" + block.getPullOffset() + "]");
|
||||
String data = block.getBlockData().getAsString(true);
|
||||
setTerraSign(sign, data);
|
||||
sign.update();
|
||||
} else if(!block.getRequirement().equals(StructureSpawnRequirement.BLANK)) {
|
||||
bLocation.getBlock().setBlockData(Material.OAK_SIGN.createBlockData(), false);
|
||||
handle.setBlockData(bLocation.getBlock(), Material.OAK_SIGN.createBlockData(), false);
|
||||
Sign sign = (Sign) bLocation.getBlock().getState();
|
||||
sign.setLine(1, "[SPAWN=" + block.getRequirement() + "]");
|
||||
String data = block.getBlockData().getAsString(true);
|
||||
setTerraSign(sign, data);
|
||||
sign.update();
|
||||
} else {
|
||||
bLocation.getBlock().setBlockData(block.getBlockData(), false);
|
||||
handle.setBlockData(bLocation.getBlock(), block.getBlockData(), false);
|
||||
if(block.getState() != null) {
|
||||
block.getState().getState(bLocation.getBlock().getState()).update(true, false);
|
||||
}
|
||||
@@ -72,7 +75,7 @@ public class LoadRawCommand extends LoadCommand implements DebugCommand {
|
||||
StructureContainedBlock block = struc.getRawStructure()[centerX][centerZ][y];
|
||||
if(block.getRequirement().equals(StructureSpawnRequirement.BLANK) && block.getPull().equals(StructureContainedBlock.Pull.NONE)) {
|
||||
Location bLocation = sender.getLocation().add(block.getX() - centerX, block.getY(), block.getZ() - centerZ);
|
||||
bLocation.getBlock().setBlockData(Material.OAK_SIGN.createBlockData(), false);
|
||||
handle.setBlockData(bLocation.getBlock(), Material.OAK_SIGN.createBlockData(), false);
|
||||
Sign sign = (Sign) bLocation.getBlock().getState();
|
||||
sign.setLine(1, "[CENTER]");
|
||||
String data = block.getBlockData().getAsString(true);
|
||||
|
||||
@@ -150,14 +150,14 @@ public class ConfigPack {
|
||||
abstractConfigLoader.registerLoader(Structure.class, new StructureLoader(loader))
|
||||
.registerLoader(LootTable.class, new LootTableLoader(loader)); // These loaders need access to the Loader instance to get files.
|
||||
loader
|
||||
.open("palettes").then(streams -> buildAll(new PaletteFactory(), paletteRegistry, abstractConfigLoader.load(streams, PaletteTemplate::new))).close()
|
||||
.open("ores").then(streams -> buildAll(new OreFactory(), oreRegistry, abstractConfigLoader.load(streams, OreTemplate::new))).close()
|
||||
.open("flora").then(streams -> buildAll(new FloraFactory(), floraRegistry, abstractConfigLoader.load(streams, FloraTemplate::new))).close()
|
||||
.open("carving").then(streams -> buildAll(new CarverFactory(this, main), carverRegistry, abstractConfigLoader.load(streams, CarverTemplate::new))).close()
|
||||
.open("structures/trees").then(streams -> buildAll(new TreeFactory(), treeRegistry, abstractConfigLoader.load(streams, TreeTemplate::new))).close()
|
||||
.open("structures/single").then(streams -> buildAll(new StructureFactory(), structureRegistry, abstractConfigLoader.load(streams, StructureTemplate::new))).close()
|
||||
.open("biomes").then(streams -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.load(streams, () -> new BiomeTemplate(this)))).close()
|
||||
.open("grids").then(streams -> buildAll(new BiomeGridFactory(), biomeGridRegistry, abstractConfigLoader.load(streams, BiomeGridTemplate::new))).close();
|
||||
.open("palettes").then(streams -> buildAll(new PaletteFactory(), paletteRegistry, abstractConfigLoader.load(streams, PaletteTemplate::new), main)).close()
|
||||
.open("ores").then(streams -> buildAll(new OreFactory(), oreRegistry, abstractConfigLoader.load(streams, OreTemplate::new), main)).close()
|
||||
.open("flora").then(streams -> buildAll(new FloraFactory(), floraRegistry, abstractConfigLoader.load(streams, FloraTemplate::new), main)).close()
|
||||
.open("carving").then(streams -> buildAll(new CarverFactory(this), carverRegistry, abstractConfigLoader.load(streams, CarverTemplate::new), main)).close()
|
||||
.open("structures/trees").then(streams -> buildAll(new TreeFactory(), treeRegistry, abstractConfigLoader.load(streams, TreeTemplate::new), main)).close()
|
||||
.open("structures/single").then(streams -> buildAll(new StructureFactory(), structureRegistry, abstractConfigLoader.load(streams, StructureTemplate::new), main)).close()
|
||||
.open("biomes").then(streams -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.load(streams, () -> new BiomeTemplate(this)), main)).close()
|
||||
.open("grids").then(streams -> buildAll(new BiomeGridFactory(), biomeGridRegistry, abstractConfigLoader.load(streams, BiomeGridTemplate::new), main)).close();
|
||||
for(UserDefinedBiome b : biomeRegistry.entries()) {
|
||||
try {
|
||||
Objects.requireNonNull(b.getErode()); // Throws NPE if it cannot load erosion biomes.
|
||||
@@ -179,8 +179,8 @@ public class ConfigPack {
|
||||
LangUtil.log("config-pack.loaded", Level.INFO, template.getID(), String.valueOf((System.nanoTime() - start) / 1000000D), template.getAuthor(), template.getVersion());
|
||||
}
|
||||
|
||||
private <C extends AbstractableTemplate, O> void buildAll(TerraFactory<C, O> factory, TerraRegistry<O> registry, List<C> configTemplates) throws LoadException {
|
||||
for(C template : configTemplates) registry.add(template.getID(), factory.build(template));
|
||||
private <C extends AbstractableTemplate, O> void buildAll(TerraFactory<C, O> factory, TerraRegistry<O> registry, List<C> configTemplates, Terra main) throws LoadException {
|
||||
for(C template : configTemplates) registry.add(template.getID(), factory.build(template, main));
|
||||
}
|
||||
|
||||
public UserDefinedBiome getBiome(String id) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.builder.GeneratorBuilder;
|
||||
@@ -15,7 +16,7 @@ public class BiomeFactory implements TerraFactory<BiomeTemplate, UserDefinedBiom
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDefinedBiome build(BiomeTemplate template) {
|
||||
public UserDefinedBiome build(BiomeTemplate template, Terra main) {
|
||||
UserDefinedDecorator decorator = new UserDefinedDecorator(new ProbabilityCollection<>(), new ProbabilityCollection<>(), 0, 0);
|
||||
GeneratorBuilder generatorBuilder = new GeneratorBuilder();
|
||||
generatorBuilder.setElevationEquation(template.getElevationEquation());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.builder.biomegrid.BiomeGridBuilder;
|
||||
import com.dfsek.terra.config.builder.biomegrid.UserDefinedGridBuilder;
|
||||
@@ -11,7 +12,7 @@ import java.util.List;
|
||||
public class BiomeGridFactory implements TerraFactory<BiomeGridTemplate, BiomeGridBuilder> {
|
||||
|
||||
@Override
|
||||
public UserDefinedGridBuilder build(BiomeGridTemplate config) {
|
||||
public UserDefinedGridBuilder build(BiomeGridTemplate config, Terra main) {
|
||||
|
||||
UserDefinedGridBuilder holder = new UserDefinedGridBuilder();
|
||||
holder.setXFreq(config.getXFreq());
|
||||
|
||||
@@ -13,15 +13,13 @@ import java.util.List;
|
||||
|
||||
public class CarverFactory implements TerraFactory<CarverTemplate, UserDefinedCarver> {
|
||||
private final ConfigPack pack;
|
||||
private final Terra main;
|
||||
|
||||
public CarverFactory(ConfigPack pack, Terra main) {
|
||||
public CarverFactory(ConfigPack pack) {
|
||||
this.pack = pack;
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDefinedCarver build(CarverTemplate config) throws LoadException {
|
||||
public UserDefinedCarver build(CarverTemplate config, Terra main) throws LoadException {
|
||||
double[] start = new double[] {config.getStartX(), config.getStartY(), config.getStartZ()};
|
||||
double[] mutate = new double[] {config.getMutateX(), config.getMutateY(), config.getMutateZ()};
|
||||
List<String> radius = Arrays.asList(config.getRadMX(), config.getRadMY(), config.getRadMZ());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.palette.PaletteLayer;
|
||||
import com.dfsek.terra.config.templates.FloraTemplate;
|
||||
import com.dfsek.terra.generation.items.flora.TerraFlora;
|
||||
@@ -11,11 +12,11 @@ import org.polydev.gaea.world.palette.RandomPalette;
|
||||
|
||||
public class FloraFactory implements TerraFactory<FloraTemplate, Flora> {
|
||||
@Override
|
||||
public TerraFlora build(FloraTemplate config) {
|
||||
public TerraFlora build(FloraTemplate config, Terra main) {
|
||||
Palette<BlockData> palette = new RandomPalette<>(new FastRandom(2403));
|
||||
for(PaletteLayer layer : config.getFloraPalette()) {
|
||||
palette.add(layer.getLayer(), layer.getSize());
|
||||
}
|
||||
return new TerraFlora(palette, config.doPhysics(), config.isCeiling(), config.getIrrigable(), config.getSpawnable(), config.getReplaceable(), config.getRotatable(), config.getMaxPlacements(), config.getSearch(), config.isSpawnBlacklist(), config.getIrrigableOffset());
|
||||
return new TerraFlora(palette, config.doPhysics(), config.isCeiling(), config.getIrrigable(), config.getSpawnable(), config.getReplaceable(), config.getRotatable(), config.getMaxPlacements(), config.getSearch(), config.isSpawnBlacklist(), config.getIrrigableOffset(), main);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.templates.OreTemplate;
|
||||
import com.dfsek.terra.generation.items.ores.DeformedSphereOre;
|
||||
import com.dfsek.terra.generation.items.ores.Ore;
|
||||
@@ -8,13 +9,13 @@ import org.bukkit.block.data.BlockData;
|
||||
|
||||
public class OreFactory implements TerraFactory<OreTemplate, Ore> {
|
||||
@Override
|
||||
public Ore build(OreTemplate config) {
|
||||
public Ore build(OreTemplate config, Terra main) {
|
||||
BlockData m = config.getMaterial();
|
||||
switch(config.getType()) {
|
||||
case SPHERE:
|
||||
return new DeformedSphereOre(m, config.getReplaceable(), config.doPhysics(), config.getDeform(), config.getDeformFrequency(), config.getSize());
|
||||
return new DeformedSphereOre(m, config.getReplaceable(), config.doPhysics(), config.getDeform(), config.getDeformFrequency(), config.getSize(), main);
|
||||
case VANILLA:
|
||||
return new VanillaOre(m, config.getReplaceable(), config.doPhysics(), config.getSize());
|
||||
return new VanillaOre(m, config.getReplaceable(), config.doPhysics(), config.getSize(), main);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.palette.PaletteLayer;
|
||||
import com.dfsek.terra.config.templates.PaletteTemplate;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -11,7 +12,7 @@ import org.polydev.gaea.world.palette.SimplexPalette;
|
||||
|
||||
public class PaletteFactory implements TerraFactory<PaletteTemplate, Palette<BlockData>> {
|
||||
@Override
|
||||
public Palette<BlockData> build(PaletteTemplate config) {
|
||||
public Palette<BlockData> build(PaletteTemplate config, Terra main) {
|
||||
Palette<BlockData> palette;
|
||||
if(config.isSimplex()) {
|
||||
FastNoiseLite noise = new FastNoiseLite((int) config.getSeed());
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.templates.StructureTemplate;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
|
||||
public class StructureFactory implements TerraFactory<StructureTemplate, TerraStructure> {
|
||||
@Override
|
||||
public TerraStructure build(StructureTemplate config) throws LoadException {
|
||||
public TerraStructure build(StructureTemplate config, Terra main) throws LoadException {
|
||||
return new TerraStructure(config.getStructures(), config.getBound(), config.getY(), config.getSpawn(), config.getLoot(), config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.terra.Terra;
|
||||
|
||||
public interface TerraFactory<C extends ConfigTemplate, O> {
|
||||
O build(C config) throws LoadException;
|
||||
O build(C config, Terra main) throws LoadException;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.templates.TreeTemplate;
|
||||
import com.dfsek.terra.generation.items.tree.TerraTree;
|
||||
import org.polydev.gaea.tree.Tree;
|
||||
|
||||
public class TreeFactory implements TerraFactory<TreeTemplate, Tree> {
|
||||
@Override
|
||||
public Tree build(TreeTemplate config) throws LoadException {
|
||||
public Tree build(TreeTemplate config, Terra main) throws LoadException {
|
||||
return new TerraTree(config.getSpawnable(), config.getyOffset(), config.getStructures());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.generation.items.flora;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.api.generic.world.WorldHandle;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import net.jafama.FastMath;
|
||||
import org.bukkit.Chunk;
|
||||
@@ -39,7 +41,9 @@ public class TerraFlora implements Flora {
|
||||
|
||||
private final int irrigableOffset;
|
||||
|
||||
public TerraFlora(Palette<BlockData> floraPalette, boolean physics, boolean ceiling, MaterialSet irrigable, MaterialSet spawnable, MaterialSet replaceable, MaterialSet testRotation, int maxPlacements, Search search, boolean spawnBlacklist, int irrigableOffset) {
|
||||
private final Terra main;
|
||||
|
||||
public TerraFlora(Palette<BlockData> floraPalette, boolean physics, boolean ceiling, MaterialSet irrigable, MaterialSet spawnable, MaterialSet replaceable, MaterialSet testRotation, int maxPlacements, Search search, boolean spawnBlacklist, int irrigableOffset, Terra main) {
|
||||
this.floraPalette = floraPalette;
|
||||
this.physics = physics;
|
||||
this.testRotation = testRotation;
|
||||
@@ -51,6 +55,7 @@ public class TerraFlora implements Flora {
|
||||
this.maxPlacements = maxPlacements;
|
||||
this.search = search;
|
||||
this.irrigableOffset = irrigableOffset;
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,6 +94,7 @@ public class TerraFlora implements Flora {
|
||||
|
||||
@Override
|
||||
public boolean plant(Location location) {
|
||||
WorldHandle handle = main.getHandle();
|
||||
|
||||
boolean doRotation = testRotation.size() > 0;
|
||||
int size = floraPalette.getSize();
|
||||
@@ -112,7 +118,7 @@ public class TerraFlora implements Flora {
|
||||
((Rotatable) data).setRotation(oneFace);
|
||||
}
|
||||
}
|
||||
location.clone().add(0, i + c, 0).getBlock().setBlockData(data, physics);
|
||||
handle.setBlockData(location.clone().add(0, i + c, 0).getBlock(), data, physics);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.generation.items.ores;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.api.generic.world.WorldHandle;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -15,8 +17,8 @@ public class DeformedSphereOre extends Ore {
|
||||
private final double deformFrequency;
|
||||
private final Range size;
|
||||
|
||||
public DeformedSphereOre(BlockData material, MaterialSet replaceable, boolean applyGravity, double deform, double deformFrequency, Range size) {
|
||||
super(material, replaceable, applyGravity);
|
||||
public DeformedSphereOre(BlockData material, MaterialSet replaceable, boolean applyGravity, double deform, double deformFrequency, Range size, Terra main) {
|
||||
super(material, replaceable, applyGravity, main);
|
||||
this.deform = deform;
|
||||
this.deformFrequency = deformFrequency;
|
||||
this.size = size;
|
||||
@@ -25,6 +27,7 @@ public class DeformedSphereOre extends Ore {
|
||||
|
||||
@Override
|
||||
public void generate(Vector origin, Chunk c, Random r) {
|
||||
WorldHandle handle = main.getHandle();
|
||||
FastNoiseLite ore = new FastNoiseLite(r.nextInt());
|
||||
ore.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
||||
ore.setFrequency(deformFrequency);
|
||||
@@ -38,7 +41,7 @@ public class DeformedSphereOre extends Ore {
|
||||
if(oreLoc.distance(origin) < (rad + 0.5) * ((ore.getNoise(x, y, z) + 1) * deform)) {
|
||||
Block b = c.getBlock(oreLoc.getBlockX(), oreLoc.getBlockY(), oreLoc.getBlockZ());
|
||||
if(getReplaceable().contains(b.getType()) && b.getLocation().getY() >= 0)
|
||||
b.setBlockData(getMaterial(), isApplyGravity());
|
||||
handle.setBlockData(b, getMaterial(), isApplyGravity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.generation.items.ores;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -12,12 +13,14 @@ public abstract class Ore {
|
||||
private final BlockData material;
|
||||
private final MaterialSet replaceable;
|
||||
private final boolean applyGravity;
|
||||
protected Terra main;
|
||||
|
||||
public Ore(BlockData material, MaterialSet replaceable, boolean applyGravity) {
|
||||
public Ore(BlockData material, MaterialSet replaceable, boolean applyGravity, Terra main) {
|
||||
|
||||
this.material = material;
|
||||
this.replaceable = replaceable;
|
||||
this.applyGravity = applyGravity;
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
public abstract void generate(Vector origin, Chunk c, Random r);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.generation.items.ores;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.api.generic.world.WorldHandle;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
import net.jafama.FastMath;
|
||||
import org.bukkit.Chunk;
|
||||
@@ -14,13 +16,14 @@ import java.util.Random;
|
||||
public class VanillaOre extends Ore {
|
||||
private final Range sizeRange;
|
||||
|
||||
public VanillaOre(BlockData material, MaterialSet replaceable, boolean applyGravity, Range size) {
|
||||
super(material, replaceable, applyGravity);
|
||||
public VanillaOre(BlockData material, MaterialSet replaceable, boolean applyGravity, Range size, Terra main) {
|
||||
super(material, replaceable, applyGravity, main);
|
||||
this.sizeRange = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(Vector location, Chunk chunk, Random random) {
|
||||
WorldHandle handle = main.getHandle();
|
||||
double size = sizeRange.get(random);
|
||||
|
||||
int centerX = location.getBlockX();
|
||||
@@ -65,7 +68,7 @@ public class VanillaOre extends Ore {
|
||||
if(x > 15 || z > 15 || y > 255 || x < 0 || z < 0 || y < 0) continue;
|
||||
Block block = chunk.getBlock(x, y, z);
|
||||
if((d13 * d13 + d14 * d14 + d15 * d15 < 1.0D) && getReplaceable().contains(block.getType())) {
|
||||
block.setBlockData(getMaterial(), isApplyGravity());
|
||||
handle.setBlockData(block, getMaterial(), isApplyGravity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class TerraTree implements Tree {
|
||||
Structure struc = structure.get(random);
|
||||
Rotation rotation = Rotation.fromDegrees(random.nextInt(4) * 90);
|
||||
if(!struc.checkSpawns(mut, rotation, (Terra) main)) return false;
|
||||
struc.paste(mut, rotation);
|
||||
struc.paste(mut, rotation, (Terra) main);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class TerraTree implements Tree {
|
||||
return spawnable;
|
||||
}
|
||||
|
||||
public boolean plantBlockCheck(Location location, Random random) {
|
||||
public boolean plantBlockCheck(Location location, Random random, Terra main) {
|
||||
Location mut = location.clone().subtract(0, yOffset, 0);
|
||||
if(!spawnable.contains(location.getBlock().getType())) return false;
|
||||
Structure struc = structure.get(random);
|
||||
@@ -61,7 +61,7 @@ public class TerraTree implements Tree {
|
||||
break;
|
||||
}
|
||||
}
|
||||
struc.paste(mut, rotation);
|
||||
struc.paste(mut, rotation, main);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class EventListener implements Listener {
|
||||
Tree tree = registry.get(TreeType.fromBukkit(e.getSpecies()).toString());
|
||||
Debug.info("Overriding tree type: " + e.getSpecies());
|
||||
if(tree instanceof TerraTree) {
|
||||
if(!((TerraTree) tree).plantBlockCheck(e.getLocation().subtract(0, 1, 0), new FastRandom())) {
|
||||
if(!((TerraTree) tree).plantBlockCheck(e.getLocation().subtract(0, 1, 0), new FastRandom(), main)) {
|
||||
block.setBlockData(data);
|
||||
}
|
||||
} else if(!tree.plant(e.getLocation().subtract(0, 1, 0), new FastRandom(), main)) block.setBlockData(data);
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.population;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.api.generic.world.WorldHandle;
|
||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.templates.CarverTemplate;
|
||||
@@ -36,6 +37,7 @@ public class CavePopulator extends BlockPopulator {
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random r, @NotNull Chunk chunk) {
|
||||
TerraWorld tw = main.getWorld(world);
|
||||
WorldHandle handle = main.getHandle();
|
||||
try(ProfileFuture ignored = tw.getProfiler().measure("CaveTime")) {
|
||||
Random random = PopulationUtil.getRandom(chunk);
|
||||
if(!tw.isSafe()) return;
|
||||
@@ -47,32 +49,32 @@ public class CavePopulator extends BlockPopulator {
|
||||
Set<Block> updateNeeded = new HashSet<>();
|
||||
c.carve(chunk.getX(), chunk.getZ(), world, (v, type) -> {
|
||||
Block b = chunk.getBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ());
|
||||
Material m = b.getType();
|
||||
Material m = handle.getType(b);
|
||||
switch(type) {
|
||||
case CENTER:
|
||||
if(template.getInner().canReplace(m)) {
|
||||
b.setBlockData(template.getInner().get(v.getBlockY()).get(random), false);
|
||||
handle.setBlockData(b, 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);
|
||||
}
|
||||
break;
|
||||
case WALL:
|
||||
if(template.getOuter().canReplace(m)) {
|
||||
b.setBlockData(template.getOuter().get(v.getBlockY()).get(random), false);
|
||||
handle.setBlockData(b, 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);
|
||||
}
|
||||
break;
|
||||
case TOP:
|
||||
if(template.getTop().canReplace(m)) {
|
||||
b.setBlockData(template.getTop().get(v.getBlockY()).get(random), false);
|
||||
handle.setBlockData(b, 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);
|
||||
}
|
||||
break;
|
||||
case BOTTOM:
|
||||
if(template.getBottom().canReplace(m)) {
|
||||
b.setBlockData(template.getBottom().get(v.getBlockY()).get(random), false);
|
||||
handle.setBlockData(b, 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);
|
||||
}
|
||||
@@ -82,20 +84,20 @@ public class CavePopulator extends BlockPopulator {
|
||||
for(Map.Entry<Location, Material> entry : shiftCandidate.entrySet()) {
|
||||
Location l = entry.getKey();
|
||||
Location mut = l.clone();
|
||||
Material orig = l.getBlock().getType();
|
||||
Material orig = handle.getType(l.getBlock());
|
||||
do mut.subtract(0, 1, 0);
|
||||
while(mut.getBlock().getType().equals(orig));
|
||||
while(handle.getType(mut.getBlock()).equals(orig));
|
||||
try {
|
||||
if(template.getShift().get(entry.getValue()).contains(mut.getBlock().getType())) {
|
||||
mut.getBlock().setBlockData(shiftStorage.computeIfAbsent(entry.getValue(), Material::createBlockData), false);
|
||||
handle.setBlockData(mut.getBlock(), shiftStorage.computeIfAbsent(entry.getValue(), Material::createBlockData), false);
|
||||
}
|
||||
} catch(NullPointerException ignore) {
|
||||
}
|
||||
}
|
||||
for(Block b : updateNeeded) {
|
||||
BlockData orig = b.getBlockData();
|
||||
b.setBlockData(AIR, false);
|
||||
b.setBlockData(orig, true);
|
||||
BlockData orig = handle.getBlockData(b);
|
||||
handle.setBlockData(b, AIR, false);
|
||||
handle.setBlockData(b, orig, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ public class StructurePopulator extends BlockPopulator {
|
||||
if(!struc.checkSpawns(spawn, rotation, main)) continue;
|
||||
double horizontal = struc.getStructureInfo().getMaxHorizontal();
|
||||
if(FastMath.abs((cx + 8) - spawn.getBlockX()) <= horizontal && FastMath.abs((cz + 8) - spawn.getBlockZ()) <= horizontal) {
|
||||
struc.paste(spawn, chunk, rotation);
|
||||
struc.paste(spawn, chunk, rotation, main);
|
||||
for(StructureContainedInventory i : struc.getInventories()) {
|
||||
try {
|
||||
Vector2 lootCoords = RotationUtil.getRotatedCoords(new Vector2(i.getX() - struc.getStructureInfo().getCenterX(), i.getZ() - struc.getStructureInfo().getCenterZ()), rotation.inverse());
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.structure;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.api.generic.world.WorldHandle;
|
||||
import com.dfsek.terra.debug.Debug;
|
||||
import com.dfsek.terra.procgen.math.Vector2;
|
||||
import com.dfsek.terra.util.structure.RotationUtil;
|
||||
@@ -162,10 +163,10 @@ public class Structure implements Serializable {
|
||||
* @param origin Origin location
|
||||
* @param r Rotation
|
||||
*/
|
||||
public void paste(@NotNull Location origin, Rotation r) {
|
||||
public void paste(@NotNull Location origin, Rotation r, Terra main) {
|
||||
Range xRange = getRange(Rotation.Axis.X, r);
|
||||
Range zRange = getRange(Rotation.Axis.Z, r);
|
||||
this.executeForBlocksInRange(xRange, getRange(Rotation.Axis.Y, r), zRange, block -> pasteBlock(block, origin, r), r);
|
||||
this.executeForBlocksInRange(xRange, getRange(Rotation.Axis.Y, r), zRange, block -> pasteBlock(block, origin, r, main.getHandle()), r);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,7 +176,7 @@ public class Structure implements Serializable {
|
||||
* @param origin The origin location
|
||||
* @param r The rotation of the structure
|
||||
*/
|
||||
private void pasteBlock(StructureContainedBlock block, Location origin, Rotation r) {
|
||||
private void pasteBlock(StructureContainedBlock block, Location origin, Rotation r, WorldHandle handle) {
|
||||
BlockData data = block.getBlockData().clone();
|
||||
if(!data.getMaterial().equals(Material.STRUCTURE_VOID)) {
|
||||
|
||||
@@ -203,7 +204,7 @@ public class Structure implements Serializable {
|
||||
|
||||
RotationUtil.rotateBlockData(data, r);
|
||||
|
||||
worldBlock.setBlockData(data, false);
|
||||
handle.setBlockData(worldBlock, data, false);
|
||||
if(block.getState() != null) {
|
||||
block.getState().getState(worldBlock.getState()).update(true, false);
|
||||
}
|
||||
@@ -309,13 +310,13 @@ public class Structure implements Serializable {
|
||||
* @param chunk Chunk to confine pasting to
|
||||
* @param r Rotation
|
||||
*/
|
||||
public void paste(Location origin, Chunk chunk, Rotation r) {
|
||||
public void paste(Location origin, Chunk chunk, Rotation r, Terra main) {
|
||||
int xOr = (chunk.getX() << 4);
|
||||
int zOr = (chunk.getZ() << 4);
|
||||
Range intersectX = new Range(xOr, xOr + 16).sub(origin.getBlockX() - structureInfo.getCenterX());
|
||||
Range intersectZ = new Range(zOr, zOr + 16).sub(origin.getBlockZ() - structureInfo.getCenterZ());
|
||||
if(intersectX == null || intersectZ == null) return;
|
||||
executeForBlocksInRange(intersectX, getRange(Rotation.Axis.Y, r), intersectZ, block -> pasteBlock(block, origin, r), r);
|
||||
executeForBlocksInRange(intersectX, getRange(Rotation.Axis.Y, r), intersectZ, block -> pasteBlock(block, origin, r, main.getHandle()), r);
|
||||
Debug.info(intersectX.toString() + " : " + intersectZ.toString());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user