Fix for glow lichen growing
Fixes https://github.com/BentoBoxWorld/Greenhouses/issues/96
This commit is contained in:
parent
717903e346
commit
02490d3b85
|
@ -24,6 +24,7 @@ import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.data.Bisected;
|
import org.bukkit.block.data.Bisected;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
import org.bukkit.block.data.type.GlowLichen;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Hoglin;
|
import org.bukkit.entity.Hoglin;
|
||||||
|
@ -441,7 +442,7 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||||
}
|
}
|
||||||
return getRandomPlant().map(p -> {
|
return getRandomPlant().map(p -> {
|
||||||
if (bl.getY() != 0 && canGrowOn(block, p)) {
|
if (bl.getY() != 0 && canGrowOn(block, p)) {
|
||||||
if (!isBisected(bl, p)) {
|
if (!plantIt(bl, p)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bl.getWorld().spawnParticle(Particle.SNOWBALL, bl.getLocation(), 10, 2, 2, 2);
|
bl.getWorld().spawnParticle(Particle.SNOWBALL, bl.getLocation(), 10, 2, 2, 2);
|
||||||
|
@ -451,9 +452,17 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||||
}).orElse(false);
|
}).orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isBisected(Block bl, GreenhousePlant p) {
|
/**
|
||||||
|
* Plants the plant
|
||||||
|
* @param bl - block to turn into a plant
|
||||||
|
* @param p - the greenhouse plant to be grown
|
||||||
|
* @return true if successful, false if not
|
||||||
|
*/
|
||||||
|
private boolean plantIt(Block bl, GreenhousePlant p) {
|
||||||
BlockData dataBottom = p.plantMaterial().createBlockData();
|
BlockData dataBottom = p.plantMaterial().createBlockData();
|
||||||
|
// Check if this is a double-height plant
|
||||||
if (dataBottom instanceof Bisected bi) {
|
if (dataBottom instanceof Bisected bi) {
|
||||||
|
// Double-height plant
|
||||||
bi.setHalf(Bisected.Half.BOTTOM);
|
bi.setHalf(Bisected.Half.BOTTOM);
|
||||||
BlockData dataTop = p.plantMaterial().createBlockData();
|
BlockData dataTop = p.plantMaterial().createBlockData();
|
||||||
((Bisected) dataTop).setHalf(Bisected.Half.TOP);
|
((Bisected) dataTop).setHalf(Bisected.Half.TOP);
|
||||||
|
@ -463,12 +472,62 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||||
} else {
|
} else {
|
||||||
return false; // No room
|
return false; // No room
|
||||||
}
|
}
|
||||||
|
} else if (p.plantMaterial().equals(Material.GLOW_LICHEN)) {
|
||||||
|
return placeLichen(bl);
|
||||||
} else {
|
} else {
|
||||||
|
// Single height plant
|
||||||
bl.setBlockData(dataBottom, false);
|
bl.setBlockData(dataBottom, false);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the placing of Glow Lichen. This needs to stick to a block rather than grow on it.
|
||||||
|
* If the block is set to Glow Lichen then it appears as an air block with 6 sides of lichen so
|
||||||
|
* they need to be switched off and only the side next to the block should be set.
|
||||||
|
* @param bl - block where plants would usually be placed
|
||||||
|
* @return true if successful, false if not
|
||||||
|
*/
|
||||||
|
private boolean placeLichen(Block bl) {
|
||||||
|
// Get the source block below this one
|
||||||
|
Block b = bl.getRelative(BlockFace.DOWN);
|
||||||
|
|
||||||
|
// Find a spot for licen
|
||||||
|
BlockFace d = null;
|
||||||
|
boolean waterLogged = false;
|
||||||
|
for (BlockFace adj : ADJ_BLOCKS) {
|
||||||
|
if (b.getRelative(adj).getType().equals(Material.AIR)) {
|
||||||
|
d = adj;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Lichen can grow under water too
|
||||||
|
if (b.getRelative(adj).getType().equals(Material.WATER)) {
|
||||||
|
d = adj;
|
||||||
|
waterLogged = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (d == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Block bb = b.getRelative(d);
|
||||||
|
bb.setType(Material.GLOW_LICHEN);
|
||||||
|
BlockFace opp = d.getOppositeFace();
|
||||||
|
|
||||||
|
if(bb.getBlockData() instanceof GlowLichen v){
|
||||||
|
for (BlockFace f : v.getAllowedFaces()) {
|
||||||
|
v.setFace(f, false);
|
||||||
|
}
|
||||||
|
v.setFace(opp, true);
|
||||||
|
v.setWaterlogged(waterLogged);
|
||||||
|
bb.setBlockData(v);
|
||||||
|
bb.getState().setBlockData(v);
|
||||||
|
bb.getState().update(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean canGrowOn(GrowthBlock block, GreenhousePlant p) {
|
private boolean canGrowOn(GrowthBlock block, GreenhousePlant p) {
|
||||||
// Ceiling plants can only grow on ceiling blocks
|
// Ceiling plants can only grow on ceiling blocks
|
||||||
if (CEILING_PLANTS.contains(p.plantMaterial()) && Boolean.TRUE.equals(block.floor())) {
|
if (CEILING_PLANTS.contains(p.plantMaterial()) && Boolean.TRUE.equals(block.floor())) {
|
||||||
|
|
|
@ -285,3 +285,22 @@ biomes:
|
||||||
mobs:
|
mobs:
|
||||||
SLIME: 5:WATER
|
SLIME: 5:WATER
|
||||||
moblimit: 3
|
moblimit: 3
|
||||||
|
DRIPSTONE_CAVES:
|
||||||
|
friendlyname: "&6Drippy Drops"
|
||||||
|
biome: dripstone_caves
|
||||||
|
icon: DRIPSTONE_BLOCK
|
||||||
|
priority: 15
|
||||||
|
contents:
|
||||||
|
STONE: 8
|
||||||
|
CLAY: 8
|
||||||
|
# 50% water cove rage required
|
||||||
|
watercoverage: 25
|
||||||
|
conversions:
|
||||||
|
CLAY: 50:DRIPSTONE_BLOCK:WATER
|
||||||
|
STONE: 0.005:COPPER_ORE:STONE
|
||||||
|
plants:
|
||||||
|
GLOW_LICHEN: 20:STONE
|
||||||
|
mobs:
|
||||||
|
skeleton: 5:STONE
|
||||||
|
glow_squid: 5:WATER
|
||||||
|
moblimit: 5
|
Loading…
Reference in New Issue