Override sapling growth to use Terra tree registry

This commit is contained in:
dfsek
2020-11-09 01:48:11 -07:00
parent 57cefea2f3
commit b56f01d606
8 changed files with 37 additions and 1 deletions

View File

@@ -33,7 +33,7 @@ dependencies {
compileOnly("org.spigotmc:spigot-api:1.16.2-R0.1-SNAPSHOT")
compileOnly("org.jetbrains:annotations:20.1.0") // more recent.
implementation("commons-io:commons-io:2.4")
compileOnly(name = "Gaea-1.14.0", group = "")
compileOnly(name = "Gaea-1.14.1", group = "")
implementation("org.apache.commons:commons-imaging:1.0-alpha2")
compileOnly("com.sk89q.worldedit:worldedit-bukkit:7.2.0-SNAPSHOT")
implementation("org.bstats:bstats-bukkit:1.7")

Binary file not shown.

BIN
lib/Gaea-1.14.1-javadoc.jar Normal file

Binary file not shown.

View File

@@ -1,8 +1,13 @@
package com.dfsek.terra;
import com.dfsek.terra.async.AsyncStructureFinder;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
import com.dfsek.terra.tree.TreeRegistry;
import com.dfsek.terra.util.StructureTypeEnum;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.EnderSignal;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
@@ -13,7 +18,12 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.entity.VillagerAcquireTradeEvent;
import org.bukkit.event.entity.VillagerCareerChangeEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.polydev.gaea.GaeaPlugin;
import org.polydev.gaea.tree.Tree;
import org.polydev.gaea.tree.TreeType;
import java.util.Random;
public class EventListener implements Listener {
private final GaeaPlugin main;
@@ -56,4 +66,21 @@ public class EventListener implements Listener {
e.setCancelled(true);
}
}
@EventHandler
public void onSaplingGrow(StructureGrowEvent e) {
if(!TerraWorld.isTerraWorld(e.getWorld())) return;
TerraWorld tw = TerraWorld.getWorld(e.getWorld());
ConfigPack c = tw.getConfig();
if(c.preventSaplingOverride) return;
e.setCancelled(true);
Block block = e.getLocation().getBlock();
BlockData data = block.getBlockData();
block.setType(Material.AIR);
TreeRegistry registry = c.getTreeRegistry();
Tree tree = registry.get(TreeType.fromBukkit(e.getSpecies()).toString());
if(!tree.plant(e.getLocation(), new Random(), Terra.getInstance())) {
block.setBlockData(data);
}
}
}

View File

@@ -7,6 +7,7 @@ import com.dfsek.terra.biome.UserDefinedGrid;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.config.genconfig.BiomeGridConfig;
import com.dfsek.terra.generation.TerraChunkGenerator;
import org.bukkit.Bukkit;
import org.bukkit.World;
@@ -116,4 +117,8 @@ public class TerraWorld {
public boolean isSafe() {
return safe;
}
public static boolean isTerraWorld(World w) {
return w.getGenerator() instanceof TerraChunkGenerator;
}
}

View File

@@ -60,6 +60,8 @@ public class ConfigPack extends YamlConfiguration {
public final boolean vanillaStructures;
public final boolean vanillaDecoration;
public final boolean vanillaMobs;
public final boolean preventSaplingOverride;
public final Map<StructureTypeEnum, StructureConfig> locatable = new HashMap<>();
private final Map<String, OreConfig> ores;
private final Map<String, PaletteConfig> palettes;
@@ -128,6 +130,8 @@ public class ConfigPack extends YamlConfiguration {
vanillaDecoration = getBoolean("vanilla.decorations", false);
vanillaMobs = getBoolean("vanilla.mobs", false);
preventSaplingOverride = getBoolean("prevent-sapling-override", false);
if(vanillaMobs || vanillaDecoration || vanillaStructures || vanillaCaves) {
Terra.getInstance().getLogger().warning("WARNING: Vanilla features have been enabled! These features may not work properly, and are not officially supported! Use at your own risk!");
}