mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 10:32:30 +00:00
Structure tree sapling overrides no longer require tree to be on ground level
This commit is contained in:
parent
2100718b2a
commit
19162a1924
@ -2,6 +2,7 @@ package com.dfsek.terra;
|
|||||||
|
|
||||||
import com.dfsek.terra.async.AsyncStructureFinder;
|
import com.dfsek.terra.async.AsyncStructureFinder;
|
||||||
import com.dfsek.terra.config.base.ConfigPack;
|
import com.dfsek.terra.config.base.ConfigPack;
|
||||||
|
import com.dfsek.terra.config.genconfig.TreeConfig;
|
||||||
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
|
import com.dfsek.terra.config.genconfig.structure.StructureConfig;
|
||||||
import com.dfsek.terra.registry.TreeRegistry;
|
import com.dfsek.terra.registry.TreeRegistry;
|
||||||
import com.dfsek.terra.util.StructureTypeEnum;
|
import com.dfsek.terra.util.StructureTypeEnum;
|
||||||
@ -80,6 +81,10 @@ public class EventListener implements Listener {
|
|||||||
TreeRegistry registry = c.getTreeRegistry();
|
TreeRegistry registry = c.getTreeRegistry();
|
||||||
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.plant(e.getLocation(), new Random(), Terra.getInstance())) block.setBlockData(data);
|
if(tree instanceof TreeConfig) {
|
||||||
|
if(!((TreeConfig) tree).plantBlockCheck(e.getLocation(), new Random())) {
|
||||||
|
block.setBlockData(data);
|
||||||
|
}
|
||||||
|
} else if(!tree.plant(e.getLocation(), new Random(), Terra.getInstance())) block.setBlockData(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,12 @@ import com.dfsek.terra.config.base.ConfigPack;
|
|||||||
import com.dfsek.terra.config.base.ConfigUtil;
|
import com.dfsek.terra.config.base.ConfigUtil;
|
||||||
import com.dfsek.terra.config.exception.ConfigException;
|
import com.dfsek.terra.config.exception.ConfigException;
|
||||||
import com.dfsek.terra.config.exception.NotFoundException;
|
import com.dfsek.terra.config.exception.NotFoundException;
|
||||||
|
import com.dfsek.terra.procgen.math.Vector2;
|
||||||
import com.dfsek.terra.structure.Rotation;
|
import com.dfsek.terra.structure.Rotation;
|
||||||
import com.dfsek.terra.structure.Structure;
|
import com.dfsek.terra.structure.Structure;
|
||||||
|
import com.dfsek.terra.structure.StructureContainedBlock;
|
||||||
|
import com.dfsek.terra.structure.StructureInfo;
|
||||||
|
import com.dfsek.terra.util.structure.RotationUtil;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
@ -73,4 +77,28 @@ public class TreeConfig extends TerraConfig implements Tree {
|
|||||||
struc.paste(mut, rotation);
|
struc.paste(mut, rotation);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean plantBlockCheck(Location location, Random random) {
|
||||||
|
location.subtract(0, 1, 0);
|
||||||
|
Location mut = location.clone().subtract(0, yOffset, 0);
|
||||||
|
if(!spawnable.contains(location.getBlock().getType())) return false;
|
||||||
|
Structure struc = structure.get(random);
|
||||||
|
Rotation rotation = Rotation.fromDegrees(random.nextInt(4) * 90);
|
||||||
|
StructureInfo info = struc.getStructureInfo();
|
||||||
|
for(StructureContainedBlock spawn : struc.getSpawns()) {
|
||||||
|
Vector2 rot = RotationUtil.getRotatedCoords(new Vector2(spawn.getX() - info.getCenterX(), spawn.getZ() - info.getCenterZ()), rotation);
|
||||||
|
int x = (int) rot.getX();
|
||||||
|
int z = (int) rot.getZ();
|
||||||
|
switch(spawn.getRequirement()) {
|
||||||
|
case AIR:
|
||||||
|
if(!mut.clone().add(x, spawn.getY() - 1, z).getBlock().isPassable()) return false;
|
||||||
|
break;
|
||||||
|
case LAND:
|
||||||
|
if(!mut.clone().add(x, spawn.getY() - 1, z).getBlock().getType().isSolid()) return false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
struc.paste(mut, rotation);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,6 +293,10 @@ public class Structure implements Serializable {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HashSet<StructureContainedBlock> getSpawns() {
|
||||||
|
return spawns;
|
||||||
|
}
|
||||||
|
|
||||||
public HashSet<StructureContainedInventory> getInventories() {
|
public HashSet<StructureContainedInventory> getInventories() {
|
||||||
return inventories;
|
return inventories;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user