Merge pull request #57 from PolyhedralDev/biome

Biome Stuff
This commit is contained in:
dfsek
2021-02-07 15:40:45 -07:00
committed by GitHub
358 changed files with 5714 additions and 3985 deletions

View File

@@ -1,6 +1,8 @@
package com.dfsek.terra.bukkit;
import com.dfsek.terra.api.platform.world.entity.Entity;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.entity.Entity;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
public class BukkitEntity implements Entity {
private final org.bukkit.entity.Entity entity;
@@ -13,4 +15,14 @@ public class BukkitEntity implements Entity {
public org.bukkit.entity.Entity getHandle() {
return entity;
}
@Override
public Location getLocation() {
return BukkitAdapter.adapt(entity.getLocation());
}
@Override
public void sendMessage(String message) {
entity.sendMessage(message);
}
}

View File

@@ -1,7 +1,7 @@
package com.dfsek.terra.bukkit;
import com.dfsek.terra.api.Player;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.Player;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
public class BukkitPlayer implements Player {
@@ -21,4 +21,9 @@ public class BukkitPlayer implements Player {
org.bukkit.Location bukkit = delegate.getLocation();
return new Location(BukkitAdapter.adapt(bukkit.getWorld()), bukkit.getX(), bukkit.getY(), bukkit.getZ());
}
@Override
public void sendMessage(String message) {
delegate.sendMessage(message);
}
}

View File

@@ -1,19 +1,13 @@
package com.dfsek.terra.bukkit;
import com.dfsek.tectonic.loading.TypeRegistry;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.api.GenericLoaders;
import com.dfsek.terra.api.language.Language;
import com.dfsek.terra.api.platform.TerraPlugin;
import com.dfsek.terra.api.core.TerraPlugin;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.api.platform.handle.ItemHandle;
import com.dfsek.terra.api.platform.handle.WorldHandle;
import com.dfsek.terra.api.platform.world.Biome;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.transform.MapTransform;
import com.dfsek.terra.api.transform.Transformer;
import com.dfsek.terra.bukkit.command.command.TerraCommand;
import com.dfsek.terra.bukkit.command.command.structure.LocateCommand;
import com.dfsek.terra.bukkit.generator.BukkitChunkGeneratorWrapper;
@@ -23,14 +17,18 @@ import com.dfsek.terra.bukkit.listeners.CommonListener;
import com.dfsek.terra.bukkit.listeners.PaperListener;
import com.dfsek.terra.bukkit.listeners.SpigotListener;
import com.dfsek.terra.bukkit.util.PaperUtil;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.bukkit.world.BukkitBiome;
import com.dfsek.terra.bukkit.world.BukkitTree;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.base.PluginConfig;
import com.dfsek.terra.config.GenericLoaders;
import com.dfsek.terra.config.PluginConfig;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.debug.Debug;
import com.dfsek.terra.generation.MasterChunkGenerator;
import com.dfsek.terra.config.lang.Language;
import com.dfsek.terra.config.pack.ConfigPack;
import com.dfsek.terra.debug.DebugLogger;
import com.dfsek.terra.registry.ConfigRegistry;
import com.dfsek.terra.world.TerraWorld;
import com.dfsek.terra.world.generation.MasterChunkGenerator;
import io.papermc.lib.PaperLib;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
@@ -54,8 +52,9 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
private final ConfigRegistry registry = new ConfigRegistry();
private final PluginConfig config = new PluginConfig();
private final ItemHandle itemHandle = new BukkitItemHandle();
private WorldHandle handle = new BukkitWorldHandle(this);
private WorldHandle handle = new BukkitWorldHandle();
private final GenericLoaders genericLoaders = new GenericLoaders(this);
private DebugLogger debugLogger;
public static final Version BUKKIT_VERSION;
@@ -100,6 +99,18 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
this.handle = handle;
}
@Override
public void packPreLoadCallback(ConfigPack pack) {
for(TreeType value : TreeType.values()) {
pack.getTreeRegistry().add(BukkitAdapter.TREE_TRANSFORMER.translate(value), new BukkitTree(value, this));
}
}
@Override
public DebugLogger getDebugLogger() {
return debugLogger;
}
@Override
public void onDisable() {
BukkitChunkGeneratorWrapper.saveAll();
@@ -107,26 +118,13 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
@Override
public void onEnable() {
Debug.setLogger(getLogger()); // Set debug logger.
debugLogger = new DebugLogger(getLogger());
getLogger().info("Running on version " + BUKKIT_VERSION);
if(BUKKIT_VERSION.equals(Version.UNKNOWN)) {
getLogger().warning("Terra is running on an unknown Bukkit version. Proceed with caution.");
}
((BukkitWorldHandle) handle).setTreeTransformer(new Transformer.Builder<String, Tree>()
.addTransform(id -> new BukkitTree(TreeType.valueOf(id), this)) // First try getting directly from enum
.addTransform(new MapTransform<String, Tree>() // Then try map of less stupid names
.add("JUNGLE_COCOA", new BukkitTree(TreeType.COCOA_TREE, this))
.add("LARGE_OAK", new BukkitTree(TreeType.BIG_TREE, this))
.add("LARGE_SPRUCE", new BukkitTree(TreeType.TALL_REDWOOD, this))
.add("SPRUCE", new BukkitTree(TreeType.REDWOOD, this))
.add("OAK", new BukkitTree(TreeType.TREE, this))
.add("MEGA_SPRUCE", new BukkitTree(TreeType.MEGA_REDWOOD, this))
.add("SWAMP_OAK", new BukkitTree(TreeType.SWAMP, this)))
.addTransform(id -> new BukkitTree(TreeType.valueOf(id), this)) // Finally, try stripping minecraft namespace.
.build());
saveDefaultConfig();
Metrics metrics = new Metrics(this, 9017); // Set up bStats.
@@ -134,7 +132,7 @@ public class TerraBukkitPlugin extends JavaPlugin implements TerraPlugin {
config.load(this); // Load master config.yml
LangUtil.load(config.getLanguage(), this); // Load language.
Debug.setDebug(isDebug());
debugLogger.setDebug(isDebug());
registry.loadAll(this); // Load all config packs.

View File

@@ -1,6 +1,6 @@
package com.dfsek.terra.bukkit.command;
import com.dfsek.terra.api.platform.TerraPlugin;
import com.dfsek.terra.api.core.TerraPlugin;
import com.dfsek.terra.bukkit.BukkitCommandSender;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;

View File

@@ -0,0 +1,44 @@
package com.dfsek.terra.bukkit.command.command;
import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
public class GetBlockCommand extends WorldCommand {
public GetBlockCommand(com.dfsek.terra.bukkit.command.Command parent) {
super(parent);
}
@Override
public boolean execute(@NotNull Player player, @NotNull Command command, @NotNull String s, @NotNull String[] strings, World world) {
player.sendMessage("Block: " + getMain().getWorld(BukkitAdapter.adapt(world)).getUngeneratedBlock(BukkitAdapter.adapt(player.getLocation())).getAsString());
return true;
}
@Override
public String getName() {
return "block";
}
@Override
public List<com.dfsek.terra.bukkit.command.Command> getSubCommands() {
return Collections.emptyList();
}
@Override
public int arguments() {
return 0;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) {
return Collections.emptyList();
}
}

View File

@@ -2,8 +2,8 @@ package com.dfsek.terra.bukkit.command.command;
import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.command.Command;
import com.dfsek.terra.config.base.ConfigPackTemplate;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.config.pack.ConfigPackTemplate;
import com.dfsek.terra.registry.ConfigRegistry;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

View File

@@ -1,11 +1,10 @@
package com.dfsek.terra.bukkit.command.command;
import com.dfsek.terra.api.platform.TerraPlugin;
import com.dfsek.terra.api.core.TerraPlugin;
import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.command.Command;
import com.dfsek.terra.bukkit.command.command.biome.BiomeCommand;
import com.dfsek.terra.bukkit.command.command.geometry.GeometryCommand;
import com.dfsek.terra.bukkit.command.command.image.ImageCommand;
import com.dfsek.terra.bukkit.command.command.profile.ProfileCommand;
import com.dfsek.terra.bukkit.command.command.structure.StructureCommand;
import com.dfsek.terra.config.lang.LangUtil;
@@ -22,10 +21,10 @@ public class TerraCommand extends Command {
new ProfileCommand(this),
new SaveDataCommand(this),
new StructureCommand(this),
new ImageCommand(this),
new GeometryCommand(this),
new FixChunkCommand(this),
new VersionCommand(this),
new GetBlockCommand(this),
new PacksCommand(this));
public TerraCommand(TerraPlugin main) {

View File

@@ -1,8 +1,7 @@
package com.dfsek.terra.bukkit.command.command.biome;
import com.dfsek.terra.api.world.generation.GenerationPhase;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
import com.dfsek.terra.biome.provider.BiomeProvider;
import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.lang.LangUtil;
@@ -23,8 +22,8 @@ public class BiomeCommand extends WorldCommand {
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
TerraBiomeGrid grid = getMain().getWorld(BukkitAdapter.adapt(sender.getWorld())).getGrid();
UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome(BukkitAdapter.adapt(sender.getLocation()), GenerationPhase.POPULATE);
BiomeProvider grid = getMain().getWorld(BukkitAdapter.adapt(sender.getWorld())).getBiomeProvider();
UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome(BukkitAdapter.adapt(sender.getLocation()));
LangUtil.send("command.biome.in", BukkitAdapter.adapt(sender), biome.getID());
return true;
}

View File

@@ -1,15 +1,14 @@
package com.dfsek.terra.bukkit.command.command.biome;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.config.pack.ConfigPack;
import com.dfsek.terra.config.templates.BiomeTemplate;
import com.dfsek.terra.population.items.TerraStructure;
import com.dfsek.terra.world.TerraWorld;
import com.dfsek.terra.world.population.items.TerraStructure;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -18,7 +17,6 @@ import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class BiomeInfoCommand extends WorldCommand {
@@ -32,15 +30,13 @@ public class BiomeInfoCommand extends WorldCommand {
ConfigPack cfg = getMain().getWorld(BukkitAdapter.adapt(world)).getConfig();
UserDefinedBiome b;
try {
b = cfg.getBiome(id);
b = (UserDefinedBiome) cfg.getBiome(id);
} catch(IllegalArgumentException | NullPointerException e) {
LangUtil.send("command.biome.invalid", new BukkitCommandSender(sender), id);
return true;
}
sender.sendMessage("Biome info for \"" + b.getID() + "\".");
sender.sendMessage("Vanilla biome: " + b.getVanillaBiome());
sender.sendMessage("Eroded by: " + b.getErode().getConfig().getID());
sender.sendMessage("TerraBiome info for \"" + b.getID() + "\".");
sender.sendMessage("Vanilla biome: " + b.getVanillaBiomes());
BiomeTemplate bio = b.getConfig();
@@ -56,16 +52,6 @@ public class BiomeInfoCommand extends WorldCommand {
}
}
Map<UserDefinedCarver, Integer> carverConfigs = bio.getCarvers();
if(structureConfigs.size() == 0) sender.sendMessage("No Carvers");
else {
sender.sendMessage("---------Carvers--------");
for(Map.Entry<UserDefinedCarver, Integer> entry : carverConfigs.entrySet()) {
sender.sendMessage(" - " + entry.getKey().getConfig().getID() + ": " + entry.getValue() + "%");
}
}
return true;
}

View File

@@ -1,13 +1,13 @@
package com.dfsek.terra.bukkit.command.command.biome;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.async.AsyncBiomeFinder;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.TerraBiome;
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.world.TerraWorld;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
@@ -41,14 +41,14 @@ public class BiomeLocateCommand extends WorldCommand {
LangUtil.send("command.biome.invalid-radius", BukkitAdapter.adapt(sender), args[1]);
return true;
}
UserDefinedBiome b;
TerraBiome b;
try {
b = getMain().getWorld(BukkitAdapter.adapt(world)).getConfig().getBiome(id);
} catch(IllegalArgumentException | NullPointerException e) {
LangUtil.send("command.biome.invalid", BukkitAdapter.adapt(sender), id);
return true;
}
Bukkit.getScheduler().runTaskAsynchronously((TerraBukkitPlugin) getMain(), new AsyncBiomeFinder(getMain().getWorld(BukkitAdapter.adapt(world)).getGrid(), b, BukkitAdapter.adapt(sender.getLocation().clone().multiply((1D / ((TerraBukkitPlugin) getMain()).getTerraConfig().getBiomeSearchResolution()))), 0, maxRadius, location -> {
Bukkit.getScheduler().runTaskAsynchronously((TerraBukkitPlugin) getMain(), new AsyncBiomeFinder(getMain().getWorld(BukkitAdapter.adapt(world)).getBiomeProvider(), b, BukkitAdapter.adapt(sender.getLocation().clone().multiply((1D / ((TerraBukkitPlugin) getMain()).getTerraConfig().getBiomeSearchResolution()))), 0, maxRadius, location -> {
if(location != null) {
ComponentBuilder cm = new ComponentBuilder(String.format("The nearest %s is at ", id.toLowerCase()))
.append(String.format("[%d, ~, %d]", location.getBlockX(), location.getBlockZ()), ComponentBuilder.FormatRetention.NONE)

View File

@@ -4,7 +4,6 @@ import com.dfsek.terra.api.math.noise.samplers.FastNoiseLite;
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.math.voxel.DeformedSphere;
import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.BukkitPlayer;
import com.dfsek.terra.bukkit.command.PlayerCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.lang.LangUtil;
@@ -48,7 +47,7 @@ public class DeformedSphereCommand extends PlayerCommand {
FastNoiseLite n = new FastNoiseLite((int) sender.getWorld().getSeed());
n.setNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
n.setFrequency(freq);
DeformedSphere sphere = new DeformedSphere(new BukkitPlayer(sender).getLocation().toVector(), radius, deform, n);
DeformedSphere sphere = new DeformedSphere(BukkitAdapter.adapt(sender).getLocation().toVector(), radius, deform, n);
for(Vector3 v : sphere.getGeometry()) {
v.toLocation(BukkitAdapter.adapt(sender.getWorld())).getBlock().setBlockData(getMain().getWorldHandle().createBlockData("minecraft:stone"), false);
}

View File

@@ -1,47 +0,0 @@
package com.dfsek.terra.bukkit.command.command.image;
import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.command.command.image.gui.GUICommand;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class ImageCommand extends WorldCommand {
public ImageCommand(com.dfsek.terra.bukkit.command.Command parent) {
super(parent);
}
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) {
LangUtil.send("command.image.main-menu", new BukkitCommandSender(sender));
return true;
}
@Override
public String getName() {
return "image";
}
@Override
public List<com.dfsek.terra.bukkit.command.Command> getSubCommands() {
return Arrays.asList(new RenderCommand(this), new GUICommand(this));
}
@Override
public int arguments() {
return 1;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@@ -1,61 +0,0 @@
package com.dfsek.terra.bukkit.command.command.image;
import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.image.WorldImageGenerator;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.Collections;
import java.util.List;
public class RenderCommand extends WorldCommand {
public RenderCommand(com.dfsek.terra.bukkit.command.Command parent) {
super(parent);
}
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
try {
WorldImageGenerator g = new WorldImageGenerator(BukkitAdapter.adapt(world), Integer.parseInt(args[0]), Integer.parseInt(args[1]), getMain());
g.drawWorld(sender.getLocation().getBlockX(), sender.getLocation().getBlockZ());
File file = new File(getMain().getDataFolder() + File.separator + "export" + File.separator + "map" + File.separator + "map_" + System.currentTimeMillis() + ".png");
//noinspection ResultOfMethodCallIgnored
file.mkdirs();
//noinspection ResultOfMethodCallIgnored
file.createNewFile();
g.save(file);
LangUtil.send("command.image.render.save", BukkitAdapter.adapt(sender), file.getAbsolutePath());
return true;
} catch(Exception e) {
e.printStackTrace();
LangUtil.send("command.image.render.error", BukkitAdapter.adapt(sender));
return true;
}
}
@Override
public String getName() {
return "render";
}
@Override
public List<com.dfsek.terra.bukkit.command.Command> getSubCommands() {
return Collections.emptyList();
}
@Override
public int arguments() {
return 2;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@@ -1,47 +0,0 @@
package com.dfsek.terra.bukkit.command.command.image.gui;
import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.command.DebugCommand;
import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class GUICommand extends WorldCommand implements DebugCommand {
public GUICommand(com.dfsek.terra.bukkit.command.Command parent) {
super(parent);
}
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
LangUtil.send("command.image.gui.main-menu", new BukkitCommandSender(sender));
return true;
}
@Override
public String getName() {
return "gui";
}
@Override
public List<com.dfsek.terra.bukkit.command.Command> getSubCommands() {
return Arrays.asList(new StepGUICommand(this), new RawGUICommand(this));
}
@Override
public int arguments() {
return 1;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@@ -1,48 +0,0 @@
package com.dfsek.terra.bukkit.command.command.image.gui;
import com.dfsek.terra.bukkit.command.DebugCommand;
import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.image.ImageLoader;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
public class RawGUICommand extends WorldCommand implements DebugCommand {
public RawGUICommand(com.dfsek.terra.bukkit.command.Command parent) {
super(parent);
}
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
ImageLoader loader = getMain().getWorld(BukkitAdapter.adapt(world)).getConfig().getTemplate().getImageLoader();
if(loader != null) loader.debug(false, BukkitAdapter.adapt(sender.getWorld()), getMain());
else ImageLoader.debugWorld(false, BukkitAdapter.adapt(world), getMain());
return true;
}
@Override
public String getName() {
return "raw";
}
@Override
public List<com.dfsek.terra.bukkit.command.Command> getSubCommands() {
return Collections.emptyList();
}
@Override
public int arguments() {
return 0;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@@ -1,48 +0,0 @@
package com.dfsek.terra.bukkit.command.command.image.gui;
import com.dfsek.terra.bukkit.command.DebugCommand;
import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.image.ImageLoader;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
public class StepGUICommand extends WorldCommand implements DebugCommand {
public StepGUICommand(com.dfsek.terra.bukkit.command.Command parent) {
super(parent);
}
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
ImageLoader loader = (getMain()).getWorld(BukkitAdapter.adapt(world)).getConfig().getTemplate().getImageLoader();
if(loader != null) loader.debug(true, BukkitAdapter.adapt(sender.getWorld()), getMain());
else ImageLoader.debugWorld(true, BukkitAdapter.adapt(world), getMain());
return true;
}
@Override
public String getName() {
return "step";
}
@Override
public List<com.dfsek.terra.bukkit.command.Command> getSubCommands() {
return Collections.emptyList();
}
@Override
public int arguments() {
return 0;
}
@Override
public List<String> getTabCompletions(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
return Collections.emptyList();
}
}

View File

@@ -1,8 +1,8 @@
package com.dfsek.terra.bukkit.command.command.profile;
import com.dfsek.terra.api.profiler.WorldProfiler;
import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.profiler.WorldProfiler;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

View File

@@ -1,10 +1,10 @@
package com.dfsek.terra.bukkit.command.command.profile;
import com.dfsek.terra.api.profiler.WorldProfiler;
import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.profiler.WorldProfiler;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

View File

@@ -1,10 +1,10 @@
package com.dfsek.terra.bukkit.command.command.profile;
import com.dfsek.terra.api.profiler.WorldProfiler;
import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.profiler.WorldProfiler;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

View File

@@ -1,10 +1,10 @@
package com.dfsek.terra.bukkit.command.command.profile;
import com.dfsek.terra.api.profiler.WorldProfiler;
import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.profiler.WorldProfiler;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

View File

@@ -1,13 +1,13 @@
package com.dfsek.terra.bukkit.command.command.structure;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.async.AsyncStructureFinder;
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
import com.dfsek.terra.bukkit.command.WorldCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.population.items.TerraStructure;
import com.dfsek.terra.world.TerraWorld;
import com.dfsek.terra.world.population.items.TerraStructure;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent;
@@ -51,7 +51,7 @@ public class LocateCommand extends WorldCommand {
LangUtil.send("command.structure.invalid", BukkitAdapter.adapt(sender), id);
return true;
}
Bukkit.getScheduler().runTaskAsynchronously((TerraBukkitPlugin) getMain(), new AsyncStructureFinder(getMain().getWorld(BukkitAdapter.adapt(world)).getGrid(), s, BukkitAdapter.adapt(sender.getLocation()), 0, maxRadius, (location) -> {
Bukkit.getScheduler().runTaskAsynchronously((TerraBukkitPlugin) getMain(), new AsyncStructureFinder(getMain().getWorld(BukkitAdapter.adapt(world)).getBiomeProvider(), s, BukkitAdapter.adapt(sender.getLocation()), 0, maxRadius, (location) -> {
if(sender.isOnline()) {
if(location != null) {
ComponentBuilder cm = new ComponentBuilder(String.format("The nearest %s is at ", id.toLowerCase()))

View File

@@ -18,6 +18,7 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
public class SpawnCommand extends WorldCommand implements DebugCommand {
@@ -35,7 +36,7 @@ public class SpawnCommand extends WorldCommand implements DebugCommand {
com.dfsek.terra.api.platform.world.World w = BukkitAdapter.adapt(world);
String check = new CheckFunction(getMain(), new NumericConstant(0, dummy), new NumericConstant(0, dummy), new NumericConstant(0, dummy), getMain().getWorld(w).getConfig().getSamplerCache(), dummy).apply(new TerraImplementationArguments(new StructureBuffer(
new com.dfsek.terra.api.math.vector.Location(w, x, y, z)
), Rotation.NONE, new FastRandom(), 0));
), Rotation.NONE, new FastRandom(), 0), new HashMap<>());
sender.sendMessage("Found: " + check);
return true;

View File

@@ -1,9 +1,9 @@
package com.dfsek.terra.bukkit.command.command.structure.load;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.bukkit.command.DebugCommand;
import com.dfsek.terra.bukkit.command.PlayerCommand;
import com.dfsek.terra.world.TerraWorld;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

View File

@@ -1,6 +1,5 @@
package com.dfsek.terra.bukkit.command.command.structure.load;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.structures.script.StructureScript;
import com.dfsek.terra.api.structures.structure.Rotation;
@@ -9,6 +8,7 @@ import com.dfsek.terra.bukkit.command.DebugCommand;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.bukkit.world.BukkitChunk;
import com.dfsek.terra.util.PopulationUtil;
import com.dfsek.terra.world.TerraWorld;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

View File

@@ -1,9 +1,9 @@
package com.dfsek.terra.bukkit.generator;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.generator.BlockPopulator;
import com.dfsek.terra.api.platform.world.BiomeGrid;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.platform.world.generator.BlockPopulator;
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
import com.dfsek.terra.bukkit.world.BukkitBiomeGrid;
import com.dfsek.terra.bukkit.world.BukkitWorld;
@@ -16,7 +16,7 @@ import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
public class BukkitChunkGenerator implements com.dfsek.terra.api.platform.generator.ChunkGenerator {
public class BukkitChunkGenerator implements com.dfsek.terra.api.platform.world.generator.ChunkGenerator {
private final ChunkGenerator delegate;
public BukkitChunkGenerator(ChunkGenerator delegate) {

View File

@@ -1,20 +1,22 @@
package com.dfsek.terra.bukkit.generator;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.api.platform.TerraPlugin;
import com.dfsek.terra.api.platform.generator.GeneratorWrapper;
import com.dfsek.terra.api.core.TerraPlugin;
import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper;
import com.dfsek.terra.api.world.generation.TerraBlockPopulator;
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
import com.dfsek.terra.api.world.generation.population.PopulationManager;
import com.dfsek.terra.bukkit.population.PopulationManager;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.bukkit.world.BukkitBiomeGrid;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.debug.Debug;
import com.dfsek.terra.population.CavePopulator;
import com.dfsek.terra.population.FloraPopulator;
import com.dfsek.terra.population.OrePopulator;
import com.dfsek.terra.population.StructurePopulator;
import com.dfsek.terra.population.TreePopulator;
import com.dfsek.terra.profiler.DataType;
import com.dfsek.terra.profiler.Measurement;
import com.dfsek.terra.world.TerraWorld;
import com.dfsek.terra.world.population.FloraPopulator;
import com.dfsek.terra.world.population.OrePopulator;
import com.dfsek.terra.world.population.StructurePopulator;
import com.dfsek.terra.world.population.TreePopulator;
import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
@@ -23,12 +25,12 @@ import org.jetbrains.annotations.NotNull;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.logging.Level;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class BukkitChunkGeneratorWrapper extends ChunkGenerator implements GeneratorWrapper {
@@ -40,6 +42,8 @@ public class BukkitChunkGeneratorWrapper extends ChunkGenerator implements Gener
private final TerraPlugin main;
private final List<TerraBlockPopulator> populators = new LinkedList<>();
private boolean needsLoad = true;
public BukkitChunkGeneratorWrapper(TerraChunkGenerator delegate) {
@@ -49,6 +53,9 @@ public class BukkitChunkGeneratorWrapper extends ChunkGenerator implements Gener
popMan.attach(new OrePopulator(main));
popMan.attach(new TreePopulator(main));
popMan.attach(new FloraPopulator(main));
populators.add(new CavePopulator(main));
populators.add(new StructurePopulator(main));
populators.add(popMan);
}
@@ -56,7 +63,6 @@ public class BukkitChunkGeneratorWrapper extends ChunkGenerator implements Gener
for(Map.Entry<com.dfsek.terra.api.platform.world.World, PopulationManager> e : popMap.entrySet()) {
try {
e.getValue().saveBlocks(e.getKey());
Debug.info("Saved data for world " + e.getKey().getName());
} catch(IOException ioException) {
ioException.printStackTrace();
}
@@ -77,6 +83,8 @@ public class BukkitChunkGeneratorWrapper extends ChunkGenerator implements Gener
e.printStackTrace();
}
popMap.put(w, popMan);
main.getWorld(w).getProfiler().addMeasurement(new Measurement(15000000, DataType.PERIOD_MILLISECONDS), "PopulationManagerTime");
popMan.attachProfiler(main.getWorld(w).getProfiler());
needsLoad = false;
}
@@ -90,7 +98,7 @@ public class BukkitChunkGeneratorWrapper extends ChunkGenerator implements Gener
@Override
public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
return Stream.of(new CavePopulator(main), new StructurePopulator(main), popMan).map(BukkitPopulatorWrapper::new).collect(Collectors.toList());
return populators.stream().map(BukkitPopulatorWrapper::new).collect(Collectors.toList());
}
@Override

View File

@@ -1,8 +1,8 @@
package com.dfsek.terra.bukkit.generator;
import com.dfsek.terra.api.platform.generator.BlockPopulator;
import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.platform.world.generator.BlockPopulator;
import com.dfsek.terra.bukkit.world.BukkitChunk;
import com.dfsek.terra.bukkit.world.BukkitWorld;

View File

@@ -1,13 +1,10 @@
package com.dfsek.terra.bukkit.handles;
import com.dfsek.terra.api.platform.TerraPlugin;
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;
import com.dfsek.terra.api.platform.handle.WorldHandle;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.api.platform.world.entity.EntityType;
import com.dfsek.terra.api.transform.Transformer;
import com.dfsek.terra.bukkit.world.block.BukkitMaterialData;
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockData;
import com.dfsek.terra.bukkit.world.entity.BukkitEntityType;
@@ -15,15 +12,6 @@ import org.bukkit.Bukkit;
import org.bukkit.Material;
public class BukkitWorldHandle implements WorldHandle {
private Transformer<String, Tree> treeTransformer;
public BukkitWorldHandle(TerraPlugin main) {
}
public void setTreeTransformer(Transformer<String, Tree> treeTransformer) {
this.treeTransformer = treeTransformer;
}
@Override
public void setBlockData(Block block, BlockData data, boolean physics) {
block.setBlockData(data, physics);
@@ -50,11 +38,6 @@ public class BukkitWorldHandle implements WorldHandle {
return new BukkitMaterialData(Material.matchMaterial(data));
}
@Override
public Tree getTree(String id) {
return treeTransformer.translate(id);
}
@Override
public EntityType getEntity(String id) {
return new BukkitEntityType(org.bukkit.entity.EntityType.valueOf(id));

View File

@@ -1,16 +1,16 @@
package com.dfsek.terra.bukkit.listeners;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.api.core.TerraPlugin;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.TerraPlugin;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.transform.MapTransform;
import com.dfsek.terra.api.transform.Transformer;
import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.api.world.tree.Tree;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.pack.ConfigPack;
import com.dfsek.terra.registry.TreeRegistry;
import com.dfsek.terra.world.TerraWorld;
import org.bukkit.Material;
import org.bukkit.TreeType;
import org.bukkit.block.Block;

View File

@@ -1,18 +1,14 @@
package com.dfsek.terra.bukkit.listeners;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.api.platform.TerraPlugin;
import com.dfsek.terra.api.core.TerraPlugin;
import com.dfsek.terra.async.AsyncStructureFinder;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.debug.Debug;
import com.dfsek.terra.population.items.TerraStructure;
import com.dfsek.terra.world.TerraWorld;
import com.dfsek.terra.world.population.items.TerraStructure;
import io.papermc.paper.event.world.StructureLocateEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
/**
* Placeholder, will be used once Paper accepts StructureLocateEvent PR.
*/
public class PaperListener implements Listener {
private final TerraPlugin main;
@@ -22,17 +18,17 @@ public class PaperListener implements Listener {
@EventHandler
public void onStructureLocate(StructureLocateEvent e) {
if(!TerraWorld.isTerraWorld(BukkitAdapter.adapt(e.getWorld()))) return;
e.setResult(null); // Assume no result.
String name = "minecraft:" + e.getType().getName();
if(!TerraWorld.isTerraWorld(BukkitAdapter.adapt(e.getWorld()))) return;
Debug.info("Overriding structure location for \"" + name + "\"");
main.getDebugLogger().info("Overriding structure location for \"" + name + "\"");
TerraWorld tw = main.getWorld(BukkitAdapter.adapt(e.getWorld()));
TerraStructure config = tw.getConfig().getStructure(tw.getConfig().getTemplate().getLocatable().get(name));
if(config != null) {
AsyncStructureFinder finder = new AsyncStructureFinder(tw.getGrid(), config, BukkitAdapter.adapt(e.getOrigin()), 0, 500, location -> {
AsyncStructureFinder finder = new AsyncStructureFinder(tw.getBiomeProvider(), config, BukkitAdapter.adapt(e.getOrigin()), 0, 500, location -> {
if(location != null)
e.setResult(BukkitAdapter.adapt(location.toLocation(BukkitAdapter.adapt(e.getWorld()))));
Debug.info("Location: " + location);
main.getDebugLogger().info("Location: " + location);
}, main);
finder.run(); // Do this synchronously.
} else {

View File

@@ -1,11 +1,10 @@
package com.dfsek.terra.bukkit.listeners;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.api.platform.TerraPlugin;
import com.dfsek.terra.api.core.TerraPlugin;
import com.dfsek.terra.async.AsyncStructureFinder;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.debug.Debug;
import com.dfsek.terra.population.items.TerraStructure;
import com.dfsek.terra.world.TerraWorld;
import com.dfsek.terra.world.population.items.TerraStructure;
import org.bukkit.entity.EnderSignal;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
@@ -34,17 +33,17 @@ public class SpigotListener implements Listener {
public void onEnderEye(EntitySpawnEvent e) {
Entity entity = e.getEntity();
if(e.getEntityType().equals(EntityType.ENDER_SIGNAL)) {
Debug.info("Detected Ender Signal...");
main.getDebugLogger().info("Detected Ender Signal...");
if(!TerraWorld.isTerraWorld(BukkitAdapter.adapt(e.getEntity().getWorld()))) return;
TerraWorld tw = main.getWorld(BukkitAdapter.adapt(e.getEntity().getWorld()));
EnderSignal signal = (EnderSignal) entity;
TerraStructure config = tw.getConfig().getStructure(tw.getConfig().getTemplate().getLocatable().get("STRONGHOLD"));
if(config != null) {
Debug.info("Overriding Ender Signal...");
AsyncStructureFinder finder = new AsyncStructureFinder(tw.getGrid(), config, BukkitAdapter.adapt(e.getLocation()), 0, 500, location -> {
main.getDebugLogger().info("Overriding Ender Signal...");
AsyncStructureFinder finder = new AsyncStructureFinder(tw.getBiomeProvider(), config, BukkitAdapter.adapt(e.getLocation()), 0, 500, location -> {
if(location != null)
signal.setTargetLocation(BukkitAdapter.adapt(location.toLocation(BukkitAdapter.adapt(signal.getWorld()))));
Debug.info("Location: " + location);
main.getDebugLogger().info("Location: " + location);
}, main);
finder.run(); // Do this synchronously so eye doesn't change direction several ticks after spawning.
} else

View File

@@ -0,0 +1,50 @@
package com.dfsek.terra.bukkit.population;
import com.dfsek.terra.api.platform.world.Chunk;
import java.io.Serializable;
import java.util.UUID;
public class ChunkCoordinate implements Serializable {
public static final long serialVersionUID = 7102462856296750285L;
private final int x;
private final int z;
private final UUID worldID;
public ChunkCoordinate(int x, int z, UUID worldID) {
this.x = x;
this.z = z;
this.worldID = worldID;
}
public ChunkCoordinate(Chunk c) {
this.x = c.getX();
this.z = c.getZ();
this.worldID = c.getWorld().getUID();
}
public UUID getWorldID() {
return worldID;
}
public int getX() {
return x;
}
public int getZ() {
return z;
}
@Override
public int hashCode() {
return x * 31 + z;
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof ChunkCoordinate)) return false;
ChunkCoordinate other = (ChunkCoordinate) obj;
return other.getX() == x && other.getZ() == z;
}
}

View File

@@ -0,0 +1,20 @@
package com.dfsek.terra.bukkit.population;
import com.dfsek.terra.api.platform.world.World;
import java.io.File;
public class Gaea {
private static boolean debug;
public static File getGaeaFolder(World w) {
File f = new File(w.getWorldFolder(), "gaea");
f.mkdirs();
return f;
}
public static boolean isDebug() {
return debug;
}
}

View File

@@ -0,0 +1,95 @@
package com.dfsek.terra.bukkit.population;
import com.dfsek.terra.api.core.TerraPlugin;
import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.api.util.GlueList;
import com.dfsek.terra.api.world.generation.TerraBlockPopulator;
import com.dfsek.terra.profiler.ProfileFuture;
import com.dfsek.terra.profiler.WorldProfiler;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
/**
* Cursed management class for the horrors of Bukkit population
*/
public class PopulationManager implements TerraBlockPopulator {
private final List<TerraBlockPopulator> attachedPopulators = new GlueList<>();
private final HashSet<ChunkCoordinate> needsPop = new HashSet<>();
private final TerraPlugin main;
private WorldProfiler profiler;
public PopulationManager(TerraPlugin main) {
this.main = main;
}
public void attach(TerraBlockPopulator populator) {
this.attachedPopulators.add(populator);
}
@Override
@SuppressWarnings("try")
public void populate(@NotNull World world, @NotNull Chunk chunk) {
try(ProfileFuture ignored = measure()) {
needsPop.add(new ChunkCoordinate(chunk));
int x = chunk.getX();
int z = chunk.getZ();
if(main.isEnabled()) {
for(int xi = -1; xi <= 1; xi++) {
for(int zi = -1; zi <= 1; zi++) {
if(xi == 0 && zi == 0) continue;
if(world.isChunkGenerated(xi + x, zi + z)) checkNeighbors(xi + x, zi + z, world);
}
}
}
}
}
private ProfileFuture measure() {
if(profiler != null) return profiler.measure("PopulationManagerTime");
return null;
}
public void attachProfiler(WorldProfiler p) {
this.profiler = p;
}
@SuppressWarnings("unchecked")
public synchronized void saveBlocks(World w) throws IOException {
File f = new File(Gaea.getGaeaFolder(w), "chunks.bin");
f.createNewFile();
SerializationUtil.toFile((HashSet<ChunkCoordinate>) needsPop.clone(), f);
}
@SuppressWarnings("unchecked")
public synchronized void loadBlocks(World w) throws IOException, ClassNotFoundException {
File f = new File(Gaea.getGaeaFolder(w), "chunks.bin");
needsPop.addAll((HashSet<ChunkCoordinate>) SerializationUtil.fromFile(f));
}
// Synchronize to prevent chunks from being queued for population multiple times.
public synchronized void checkNeighbors(int x, int z, World w) {
ChunkCoordinate c = new ChunkCoordinate(x, z, w.getUID());
if(w.isChunkGenerated(x + 1, z)
&& w.isChunkGenerated(x - 1, z)
&& w.isChunkGenerated(x, z + 1)
&& w.isChunkGenerated(x, z - 1) && needsPop.contains(c)) {
Random random = new FastRandom(w.getSeed());
long xRand = (random.nextLong() / 2L << 1L) + 1L;
long zRand = (random.nextLong() / 2L << 1L) + 1L;
random.setSeed((long) x * xRand + (long) z * zRand ^ w.getSeed());
Chunk currentChunk = w.getChunkAt(x, z);
for(TerraBlockPopulator r : attachedPopulators) {
r.populate(w, currentChunk);
}
needsPop.remove(c);
}
}
}

View File

@@ -0,0 +1,70 @@
package com.dfsek.terra.bukkit.population;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
import java.io.Serializable;
import java.lang.reflect.Field;
public class SerializationUtil {
public static Object fromFile(File f) throws IOException, ClassNotFoundException {
ObjectInputStream ois = new MovedObjectInputStream(new FileInputStream(f), "com.dfsek.terra.api.world.generation.population", "com.dfsek.terra.bukkit.population"); // Backwards compat with old Gaea location
Object o = ois.readObject();
ois.close();
return o;
}
public static void toFile(Serializable o, File f) throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
oos.writeObject(o);
oos.close();
}
public static class MovedObjectInputStream extends ObjectInputStream {
private final String oldNameSpace;
private final String newNameSpace;
public MovedObjectInputStream(InputStream in, String oldNameSpace, String newNameSpace) throws IOException {
super(in);
this.oldNameSpace = oldNameSpace;
this.newNameSpace = newNameSpace;
}
@Override
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
ObjectStreamClass result = super.readClassDescriptor();
try {
if(result.getName().contains(oldNameSpace)) {
String newClassName = result.getName().replace(oldNameSpace, newNameSpace);
Class localClass = Class.forName(newClassName);
Field nameField = ObjectStreamClass.class.getDeclaredField("name");
nameField.setAccessible(true);
nameField.set(result, newClassName);
ObjectStreamClass localClassDescriptor = ObjectStreamClass.lookup(localClass);
Field suidField = ObjectStreamClass.class.getDeclaredField("suid");
suidField.setAccessible(true);
suidField.set(result, localClassDescriptor.getSerialVersionUID());
}
} catch(Exception e) {
throw new IOException("Exception when trying to replace namespace", e);
}
return result;
}
@Override
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
if(desc.getName().contains(oldNameSpace)) {
String newClassName = desc.getName().replace(oldNameSpace, newNameSpace);
return Class.forName(newClassName);
}
return super.resolveClass(desc);
}
}
}

View File

@@ -4,6 +4,7 @@ package com.dfsek.terra.bukkit.world;
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.platform.CommandSender;
import com.dfsek.terra.api.platform.block.Axis;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.block.BlockFace;
import com.dfsek.terra.api.platform.block.data.Bisected;
import com.dfsek.terra.api.platform.block.data.Rail;
@@ -13,15 +14,34 @@ import com.dfsek.terra.api.platform.block.data.Stairs;
import com.dfsek.terra.api.platform.inventory.item.Enchantment;
import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.transform.MapTransform;
import com.dfsek.terra.api.transform.Transformer;
import com.dfsek.terra.bukkit.BukkitCommandSender;
import com.dfsek.terra.bukkit.BukkitPlayer;
import com.dfsek.terra.bukkit.world.block.data.BukkitBlockData;
import com.dfsek.terra.bukkit.world.inventory.meta.BukkitEnchantment;
import org.bukkit.Location;
import org.bukkit.TreeType;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
/**
* Utility class to adapt Bukkit enums to Terra enums.
*/
public final class BukkitAdapter {
public static Transformer<TreeType, String> TREE_TRANSFORMER = new Transformer.Builder<TreeType, String>()
.addTransform(new MapTransform<TreeType, String>()
.add(TreeType.COCOA_TREE, "JUNGLE_COCOA")
.add(TreeType.BIG_TREE, "LARGE_OAK")
.add(TreeType.TALL_REDWOOD, "LARGE_SPRUCE")
.add(TreeType.REDWOOD, "SPRUCE")
.add(TreeType.TREE, "OAK")
.add(TreeType.MEGA_REDWOOD, "MEGA_SPRUCE")
.add(TreeType.SWAMP, "SWAMP_OAK"))
.addTransform(TreeType::toString)
.build();
public static Stairs.Shape adapt(org.bukkit.block.data.type.Stairs.Shape shape) {
switch(shape) {
case STRAIGHT:
@@ -39,6 +59,14 @@ public final class BukkitAdapter {
}
}
public static BlockData adapt(org.bukkit.block.data.BlockData data) {
return BukkitBlockData.newInstance(data);
}
public static org.bukkit.block.data.BlockData adapt(BlockData data) {
return ((BukkitBlockData) data).getHandle();
}
public static Axis adapt(org.bukkit.Axis axis) {
switch(axis) {
case X:
@@ -348,4 +376,12 @@ public final class BukkitAdapter {
public static org.bukkit.enchantments.Enchantment adapt(Enchantment enchantment) {
return ((BukkitEnchantment) enchantment).getHandle();
}
public static Player adapt(com.dfsek.terra.api.platform.Player player) {
return ((BukkitPlayer) player).getHandle();
}
public static com.dfsek.terra.api.platform.Player adapt(Player player) {
return new BukkitPlayer(player);
}
}

View File

@@ -1,9 +1,11 @@
package com.dfsek.terra.bukkit.world;
import com.dfsek.terra.api.platform.block.Block;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.bukkit.world.block.BukkitBlock;
import org.jetbrains.annotations.NotNull;
public class BukkitChunk implements Chunk {
private final org.bukkit.Chunk delegate;
@@ -36,4 +38,14 @@ public class BukkitChunk implements Chunk {
public org.bukkit.Chunk getHandle() {
return delegate;
}
@Override
public void setBlock(int x, int y, int z, @NotNull BlockData blockData) {
delegate.getBlock(x, y, z).setBlockData(BukkitAdapter.adapt(blockData));
}
@Override
public @NotNull BlockData getBlockData(int x, int y, int z) {
return getBlock(x, y, z).getBlockData();
}
}

View File

@@ -1,10 +1,10 @@
package com.dfsek.terra.bukkit.world;
import com.dfsek.terra.api.core.TerraPlugin;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.TerraPlugin;
import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.api.platform.handle.WorldHandle;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.api.world.tree.Tree;
import com.dfsek.terra.util.MaterialSet;
import org.bukkit.TreeType;
@@ -41,11 +41,6 @@ public class BukkitTree implements Tree {
}
}
@Override
public TreeType getHandle() {
return delegate;
}
@Override
public boolean plant(Location l, Random r) {
return ((BukkitWorld) l.getWorld()).getHandle().generateTree(BukkitAdapter.adapt(l), delegate);

View File

@@ -2,12 +2,11 @@ package com.dfsek.terra.bukkit.world;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.block.Block;
import com.dfsek.terra.api.platform.generator.ChunkGenerator;
import com.dfsek.terra.api.platform.entity.Entity;
import com.dfsek.terra.api.platform.entity.EntityType;
import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.platform.world.entity.Entity;
import com.dfsek.terra.api.platform.world.entity.EntityType;
import com.dfsek.terra.api.platform.world.generator.ChunkGenerator;
import com.dfsek.terra.bukkit.BukkitEntity;
import com.dfsek.terra.bukkit.generator.BukkitChunkGenerator;
import com.dfsek.terra.bukkit.world.block.BukkitBlock;
@@ -73,11 +72,6 @@ public class BukkitWorld implements World {
return new BukkitBlock(delegate.getBlockAt(l.getBlockX(), l.getBlockY(), l.getBlockZ()));
}
@Override
public boolean generateTree(Location l, Tree vanillaTreeType) {
return delegate.generateTree(new org.bukkit.Location(delegate, l.getX(), l.getY(), l.getZ()), ((BukkitTree) vanillaTreeType).getHandle());
}
@Override
public Entity spawnEntity(Location location, EntityType entityType) {
return new BukkitEntity(delegate.spawnEntity(BukkitAdapter.adapt(location), ((BukkitEntityType) entityType).getHandle()));

View File

@@ -2,7 +2,7 @@ package com.dfsek.terra.bukkit.world.block.state;
import com.dfsek.terra.api.platform.block.state.MobSpawner;
import com.dfsek.terra.api.platform.block.state.SerialState;
import com.dfsek.terra.api.platform.world.entity.EntityType;
import com.dfsek.terra.api.platform.entity.EntityType;
import com.dfsek.terra.bukkit.world.entity.BukkitEntityType;
import org.bukkit.block.CreatureSpawner;
import org.jetbrains.annotations.NotNull;

View File

@@ -1,6 +1,6 @@
package com.dfsek.terra.bukkit.world.entity;
import com.dfsek.terra.api.platform.world.entity.EntityType;
import com.dfsek.terra.api.platform.entity.EntityType;
public class BukkitEntityType implements EntityType {
private final org.bukkit.entity.EntityType delegate;