mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-01 15:37:24 +00:00
Implement OreVeinGenerateEvent and TreeGenerateEvent
This commit is contained in:
parent
862e9e82a2
commit
454d9ce659
5
.idea/jarRepositories.xml
generated
5
.idea/jarRepositories.xml
generated
@ -6,6 +6,11 @@
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="papermc" />
|
||||
<option name="name" value="papermc" />
|
||||
<option name="url" value="https://papermc.io/repo/repository/maven-public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="parsii.local" />
|
||||
<option name="name" value="parsii" />
|
||||
|
14
pom.xml
14
pom.xml
@ -58,6 +58,10 @@
|
||||
<pattern>parsii</pattern>
|
||||
<shadedPattern>com.dfsek.terra.lib.parsii</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>io.papermc.lib</pattern>
|
||||
<shadedPattern>com.dfsek.terra.lib.paperlib</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
<executions>
|
||||
@ -88,6 +92,10 @@
|
||||
<id>CodeMC</id>
|
||||
<url>https://repo.codemc.org/repository/maven-public</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
@ -149,6 +157,12 @@
|
||||
<artifactId>parsii</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.papermc</groupId>
|
||||
<artifactId>paperlib</artifactId>
|
||||
<version>1.0.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -5,6 +5,7 @@ import com.dfsek.terra.config.base.ConfigUtil;
|
||||
import com.dfsek.terra.config.base.WorldConfig;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.util.PaperUtil;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
@ -52,6 +53,7 @@ public class Terra extends GaeaPlugin {
|
||||
saveDefaultConfig();
|
||||
Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, TerraChunkGenerator::saveAll, ConfigUtil.dataSave, ConfigUtil.dataSave);
|
||||
Bukkit.getPluginManager().registerEvents(new EventListener(this), this);
|
||||
PaperUtil.checkPaper(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,34 @@
|
||||
package com.dfsek.terra.event;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.config.genconfig.OreConfig;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Cancellable;
|
||||
|
||||
public class OreVeinGenerateEvent extends TerraWorldEvent implements Cancellable {
|
||||
private boolean cancelled;
|
||||
private OreConfig config;
|
||||
|
||||
public OreVeinGenerateEvent(TerraWorld tw, Location l, OreConfig config) {
|
||||
super(tw, l);
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public void setConfig(OreConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public OreConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
}
|
37
src/main/java/com/dfsek/terra/event/TerraWorldEvent.java
Normal file
37
src/main/java/com/dfsek/terra/event/TerraWorldEvent.java
Normal file
@ -0,0 +1,37 @@
|
||||
package com.dfsek.terra.event;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class TerraWorldEvent extends Event {
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
private final TerraWorld world;
|
||||
private final Location location;
|
||||
|
||||
public TerraWorldEvent(TerraWorld tw, Location l) {
|
||||
this.world = tw;
|
||||
this.location = l.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public TerraWorld getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
}
|
35
src/main/java/com/dfsek/terra/event/TreeGenerateEvent.java
Normal file
35
src/main/java/com/dfsek/terra/event/TreeGenerateEvent.java
Normal file
@ -0,0 +1,35 @@
|
||||
package com.dfsek.terra.event;
|
||||
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.config.genconfig.TreeConfig;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.polydev.gaea.tree.Tree;
|
||||
|
||||
public class TreeGenerateEvent extends TerraWorldEvent implements Cancellable {
|
||||
private boolean cancelled;
|
||||
private Tree tree;
|
||||
|
||||
public TreeGenerateEvent(TerraWorld tw, Location l, Tree tree) {
|
||||
super(tw, l);
|
||||
this.tree = tree;
|
||||
}
|
||||
|
||||
public void setTree(Tree tree) {
|
||||
this.tree = tree;
|
||||
}
|
||||
|
||||
public Tree getTree() {
|
||||
return tree;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package com.dfsek.terra.events;
|
||||
|
||||
public class OreVeinGenerateEvent {
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package com.dfsek.terra.events;
|
||||
|
||||
public class TerraStructureLocateEvent {
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package com.dfsek.terra.events;
|
||||
|
||||
public class TreeGenerateEvent {
|
||||
}
|
@ -8,8 +8,11 @@ import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
|
||||
import com.dfsek.terra.config.genconfig.biome.BiomeFloraConfig;
|
||||
import com.dfsek.terra.event.TreeGenerateEvent;
|
||||
import com.dfsek.terra.generation.UserDefinedDecorator;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -34,6 +37,8 @@ public class FloraPopulator extends GaeaBlockPopulator {
|
||||
try (ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("FloraTime")) {
|
||||
TerraWorld tw = TerraWorld.getWorld(world);
|
||||
if(!tw.isSafe()) return;
|
||||
int originX = chunk.getX() << 4;
|
||||
int originZ = chunk.getZ() << 4;
|
||||
TerraBiomeGrid grid = tw.getGrid();
|
||||
ConfigPack config = tw.getConfig();
|
||||
for(int x = 0; x < 16; x++) {
|
||||
@ -42,7 +47,9 @@ public class FloraPopulator extends GaeaBlockPopulator {
|
||||
if((x & 1) == 0 && (z & 1) == 0) {
|
||||
int treeChance = biome.getDecorator().getTreeDensity();
|
||||
if(random.nextInt(1000) < treeChance) {
|
||||
if(doTrees(biome, tw, random, chunk, offset(random, x), offset(random, z))) continue;
|
||||
int xt = offset(random, x);
|
||||
int zt = offset(random, z);
|
||||
if(doTrees(biome, tw, random, chunk, xt, zt)) continue;
|
||||
}
|
||||
}
|
||||
if(biome.getDecorator().getFloraChance() <= 0) continue;
|
||||
@ -51,7 +58,7 @@ public class FloraPopulator extends GaeaBlockPopulator {
|
||||
BiomeFloraConfig f = c.getFlora();
|
||||
for(int i = 0; i < f.getFloraAttempts(); i++) {
|
||||
Flora item;
|
||||
if(f.isFloraSimplex()) item = biome.getDecorator().getFlora().get(f.getFloraNoise(), (chunk.getX() << 4) + x, (chunk.getZ() << 4) + z);
|
||||
if(f.isFloraSimplex()) item = biome.getDecorator().getFlora().get(f.getFloraNoise(), originX + x, originZ + z);
|
||||
else item = biome.getDecorator().getFlora().get(random);
|
||||
for(Block highest : item.getValidSpawnsAt(chunk, x, z, c.getFloraHeights(item))) {
|
||||
if(random.nextInt(100) < biome.getDecorator().getFloraChance())
|
||||
@ -69,7 +76,10 @@ public class FloraPopulator extends GaeaBlockPopulator {
|
||||
Range range = world.getConfig().getBiome(biome).getTreeRange(tree);
|
||||
if(!range.isInRange(block.getY())) continue;
|
||||
try {
|
||||
return tree.plant(block.getLocation(), random, Terra.getInstance());
|
||||
Location l = block.getLocation();
|
||||
TreeGenerateEvent event = new TreeGenerateEvent(world, l, tree);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if(!event.isCancelled()) tree.plant(l, random, Terra.getInstance());
|
||||
} catch(NullPointerException ignore) {}
|
||||
}
|
||||
return false;
|
||||
|
@ -3,6 +3,8 @@ package com.dfsek.terra.population;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.genconfig.biome.BiomeOreConfig;
|
||||
import com.dfsek.terra.event.OreVeinGenerateEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import com.dfsek.terra.TerraProfiler;
|
||||
@ -30,13 +32,20 @@ public class OrePopulator extends GaeaBlockPopulator {
|
||||
BiomeOreConfig ores = config.getBiome((UserDefinedBiome) b).getOres();
|
||||
for(Map.Entry<OreConfig, Range> e : ores.getOres().entrySet()) {
|
||||
int num = e.getValue().get(random);
|
||||
int edgeOffset = e.getKey().getChunkEdgeOffset();
|
||||
OreConfig ore = e.getKey();
|
||||
int edgeOffset = ore.getChunkEdgeOffset();
|
||||
for(int i = 0; i < num; i++) {
|
||||
int x = random.nextInt(16 - edgeOffset*2) + edgeOffset;
|
||||
int z = random.nextInt(16 - edgeOffset*2) + edgeOffset;
|
||||
int y = ores.getOreHeights().get(e.getKey()).get(random);
|
||||
if(e.getKey().crossChunks()) e.getKey().doVein(new Vector(x, y, z), chunk, random);
|
||||
else e.getKey().doVeinSingle(new Vector(x, y, z), chunk, random);
|
||||
int y = ores.getOreHeights().get(ore).get(random);
|
||||
|
||||
Vector v = new Vector(x, y, z);
|
||||
OreVeinGenerateEvent event = new OreVeinGenerateEvent(tw, v.toLocation(world), ore);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if(! event.isCancelled()) {
|
||||
if(ore.crossChunks()) ore.doVein(v, chunk, random);
|
||||
else ore.doVeinSingle(new Vector(x, y, z), chunk, random);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import org.polydev.gaea.world.palette.RandomPalette;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class DataUtil {
|
||||
public final class DataUtil {
|
||||
public static final BlockData STONE = Material.STONE.createBlockData();
|
||||
public static final BlockData SNOW = Material.SNOW.createBlockData();
|
||||
public static final BlockData WATER = Material.WATER.createBlockData();
|
||||
|
18
src/main/java/com/dfsek/terra/util/PaperUtil.java
Normal file
18
src/main/java/com/dfsek/terra/util/PaperUtil.java
Normal file
@ -0,0 +1,18 @@
|
||||
package com.dfsek.terra.util;
|
||||
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public final class PaperUtil {
|
||||
public static void checkPaper(JavaPlugin main) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(main, () -> {
|
||||
if(!PaperLib.isPaper()) {
|
||||
LangUtil.log("use-paper", Level.WARNING);
|
||||
}
|
||||
}, 100L);
|
||||
}
|
||||
}
|
@ -5,10 +5,10 @@ import com.dfsek.terra.structure.Structure;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.Rail;
|
||||
|
||||
public class RotationUtil {
|
||||
public final class RotationUtil {
|
||||
/**
|
||||
* Rotate and mirror a coordinate pair.
|
||||
* @param arr Array containing X and Z coordinates.
|
||||
* @param orig Vector to rotate.
|
||||
* @param r Rotation
|
||||
* @return Rotated coordinate pair
|
||||
*/
|
||||
|
@ -11,7 +11,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class WorldEditUtil {
|
||||
public final class WorldEditUtil {
|
||||
public static WorldEditPlugin getWorldEdit() {
|
||||
Plugin p = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
|
||||
if (p instanceof WorldEditPlugin) return (WorldEditPlugin) p;
|
||||
|
@ -106,4 +106,11 @@ warning:
|
||||
error:
|
||||
severe-config: "A severe configuration error has prevented Terra from properly generating terrain at coordinates: %1$s, %2$s. Please check your configuration for errors. Any config errors will have been reported above."
|
||||
debug:
|
||||
data-save: "Saved population data for world \"%s\""
|
||||
data-save: "Saved population data for world \"%s\""
|
||||
use-paper:
|
||||
- "You appear to be using Spigot/CraftBukkit."
|
||||
- "While Terra &odoes&r work on Spigot, some functionality will be lost. (Terra is untested on CraftBukkit; no support will be given for CraftBukkit)."
|
||||
- "To get the most out of Terra, please switch to Paper."
|
||||
- "Plus, Paper offers immense performance improvements over Spigot, and all Spigot plugins should work with Paper!"
|
||||
- "To have the best experience with Terra, and all your plugins, please use Paper."
|
||||
- "Find out more on Paper's website: https://papermc.io/"
|
Loading…
x
Reference in New Issue
Block a user