mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 10:32:30 +00:00
Add optional "irrigable" list to FloraConfig
This commit is contained in:
parent
7d395a4347
commit
f0d982f887
@ -8,6 +8,7 @@ import org.bukkit.Chunk;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.polydev.gaea.math.Range;
|
import org.polydev.gaea.math.Range;
|
||||||
@ -28,8 +29,10 @@ public class FloraConfig extends TerraConfig implements Flora {
|
|||||||
private final boolean physics;
|
private final boolean physics;
|
||||||
private final boolean ceiling;
|
private final boolean ceiling;
|
||||||
|
|
||||||
Set<Material> spawnable;
|
private final Set<Material> irrigable;
|
||||||
Set<Material> replaceable;
|
|
||||||
|
private final Set<Material> spawnable;
|
||||||
|
private final Set<Material> replaceable;
|
||||||
|
|
||||||
public FloraConfig(File file, ConfigPack config) throws IOException, InvalidConfigurationException {
|
public FloraConfig(File file, ConfigPack config) throws IOException, InvalidConfigurationException {
|
||||||
super(file, config);
|
super(file, config);
|
||||||
@ -41,6 +44,11 @@ public class FloraConfig extends TerraConfig implements Flora {
|
|||||||
|
|
||||||
spawnable = ConfigUtil.toBlockData(getStringList("spawnable"), "spawnable", getID());
|
spawnable = ConfigUtil.toBlockData(getStringList("spawnable"), "spawnable", getID());
|
||||||
replaceable = ConfigUtil.toBlockData(getStringList("replaceable"), "replaceable", getID());
|
replaceable = ConfigUtil.toBlockData(getStringList("replaceable"), "replaceable", getID());
|
||||||
|
|
||||||
|
if(contains("irrigable")) {
|
||||||
|
irrigable = ConfigUtil.toBlockData(getStringList("irrigable"), "irrigable", getID());
|
||||||
|
} else irrigable = null;
|
||||||
|
|
||||||
physics = getBoolean("physics", false);
|
physics = getBoolean("physics", false);
|
||||||
ceiling = getBoolean("ceiling", false);
|
ceiling = getBoolean("ceiling", false);
|
||||||
|
|
||||||
@ -59,7 +67,7 @@ public class FloraConfig extends TerraConfig implements Flora {
|
|||||||
if(ceiling) for(int y : range) {
|
if(ceiling) for(int y : range) {
|
||||||
if(y > 255 || y < 1) continue;
|
if(y > 255 || y < 1) continue;
|
||||||
Block check = chunk.getBlock(x, y, z);
|
Block check = chunk.getBlock(x, y, z);
|
||||||
Block other = chunk.getBlock(x, y - 1, z);
|
Block other = check.getRelative(BlockFace.DOWN);
|
||||||
if(spawnable.contains(check.getType()) && replaceable.contains(other.getType())) {
|
if(spawnable.contains(check.getType()) && replaceable.contains(other.getType())) {
|
||||||
blocks.add(check);
|
blocks.add(check);
|
||||||
}
|
}
|
||||||
@ -67,14 +75,22 @@ public class FloraConfig extends TerraConfig implements Flora {
|
|||||||
else for(int y : range) {
|
else for(int y : range) {
|
||||||
if(y > 254 || y < 0) continue;
|
if(y > 254 || y < 0) continue;
|
||||||
Block check = chunk.getBlock(x, y, z);
|
Block check = chunk.getBlock(x, y, z);
|
||||||
Block other = chunk.getBlock(x, y + 1, z);
|
Block other = check.getRelative(BlockFace.UP);
|
||||||
if(spawnable.contains(check.getType()) && replaceable.contains(other.getType())) {
|
if(spawnable.contains(check.getType()) && replaceable.contains(other.getType()) && isIrrigated(check)) {
|
||||||
blocks.add(check);
|
blocks.add(check);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return blocks;
|
return blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isIrrigated(Block b) {
|
||||||
|
if(irrigable == null) return true;
|
||||||
|
return irrigable.contains(b.getRelative(BlockFace.NORTH).getType())
|
||||||
|
|| irrigable.contains(b.getRelative(BlockFace.SOUTH).getType())
|
||||||
|
|| irrigable.contains(b.getRelative(BlockFace.EAST).getType())
|
||||||
|
|| irrigable.contains(b.getRelative(BlockFace.WEST).getType());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean plant(Location location) {
|
public boolean plant(Location location) {
|
||||||
int size = floraPalette.getSize();
|
int size = floraPalette.getSize();
|
||||||
|
@ -26,10 +26,15 @@ flora:
|
|||||||
min: 62
|
min: 62
|
||||||
max: 84
|
max: 84
|
||||||
GRASS:
|
GRASS:
|
||||||
weight: 700
|
weight: 675
|
||||||
y:
|
y:
|
||||||
min: 62
|
min: 62
|
||||||
max: 84
|
max: 84
|
||||||
|
SUGARCANE:
|
||||||
|
weight: 25
|
||||||
|
y:
|
||||||
|
min: 62
|
||||||
|
max: 68
|
||||||
|
|
||||||
ocean:
|
ocean:
|
||||||
palette: "BLOCK:minecraft:water"
|
palette: "BLOCK:minecraft:water"
|
||||||
|
17
src/main/resources/default-config/flora/sugarcane.yml
Normal file
17
src/main/resources/default-config/flora/sugarcane.yml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
layers:
|
||||||
|
- materials:
|
||||||
|
- "minecraft:sugar_cane": 2
|
||||||
|
layers: 1
|
||||||
|
- materials:
|
||||||
|
- "minecraft:sugar_cane": 1
|
||||||
|
- "minecraft:air": 1
|
||||||
|
layers: 1
|
||||||
|
id: "SUGARCANE"
|
||||||
|
spawnable:
|
||||||
|
- "minecraft:sand"
|
||||||
|
- "minecraft:red_sand"
|
||||||
|
- "minecraft:grass_block"
|
||||||
|
replaceable:
|
||||||
|
- "minecraft:air"
|
||||||
|
irrigable:
|
||||||
|
- "minecraft:water"
|
Loading…
x
Reference in New Issue
Block a user