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