Skip to content

Commit

Permalink
Fix for glow lichen growing
Browse files Browse the repository at this point in the history
Fixes #96
  • Loading branch information
tastybento committed Dec 29, 2022
1 parent 717903e commit 02490d3
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.GlowLichen;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Hoglin;
Expand Down Expand Up @@ -441,7 +442,7 @@ public boolean growPlant(GrowthBlock block) {
}
return getRandomPlant().map(p -> {
if (bl.getY() != 0 && canGrowOn(block, p)) {
if (!isBisected(bl, p)) {
if (!plantIt(bl, p)) {
return false;
}
bl.getWorld().spawnParticle(Particle.SNOWBALL, bl.getLocation(), 10, 2, 2, 2);
Expand All @@ -451,9 +452,17 @@ public boolean growPlant(GrowthBlock block) {
}).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();
// Check if this is a double-height plant
if (dataBottom instanceof Bisected bi) {
// Double-height plant
bi.setHalf(Bisected.Half.BOTTOM);
BlockData dataTop = p.plantMaterial().createBlockData();
((Bisected) dataTop).setHalf(Bisected.Half.TOP);
Expand All @@ -463,12 +472,62 @@ private boolean isBisected(Block bl, GreenhousePlant p) {
} else {
return false; // No room
}
} else if (p.plantMaterial().equals(Material.GLOW_LICHEN)) {
return placeLichen(bl);
} else {
// Single height plant
bl.setBlockData(dataBottom, false);
}
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) {
// Ceiling plants can only grow on ceiling blocks
if (CEILING_PLANTS.contains(p.plantMaterial()) && Boolean.TRUE.equals(block.floor())) {
Expand Down
19 changes: 19 additions & 0 deletions src/main/resources/biomes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,22 @@ biomes:
mobs:
SLIME: 5:WATER
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

0 comments on commit 02490d3

Please sign in to comment.