Skip to content

Commit

Permalink
Adds support for COCOA #97
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jan 2, 2023
1 parent 10a1d63 commit de6a939
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.block.data.type.Cocoa;
import org.bukkit.block.data.type.GlowLichen;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Hoglin;
import org.bukkit.entity.Piglin;
import org.bukkit.material.CocoaPlant;
import org.bukkit.util.Vector;

import com.google.common.base.Enums;
Expand Down Expand Up @@ -63,6 +65,7 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
}

private static final List<BlockFace> ADJ_BLOCKS = Arrays.asList( BlockFace.DOWN, BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.UP, BlockFace.WEST);
private static final List<BlockFace> SIDE_BLOCKS = Arrays.asList( BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST);
private static final List<Material> UNDERWATER_PLANTS;
static {
List<Material> m = new ArrayList<>();
Expand Down Expand Up @@ -491,6 +494,8 @@ private boolean plantIt(Block bl, GreenhousePlant p) {
}
} else if (p.plantMaterial().equals(Material.GLOW_LICHEN)) {
return placeLichen(bl);
} else if (p.plantMaterial().equals(Material.COCOA)) {
return placeCocoa(bl);
} else {
if (dataBottom instanceof Waterlogged wl) {
wl.setWaterlogged(underwater);
Expand All @@ -503,6 +508,37 @@ private boolean plantIt(Block bl, GreenhousePlant p) {
return true;
}

private boolean placeCocoa(Block bl) {
// Get the source block below this one
Block b = bl.getRelative(BlockFace.DOWN);
if (!b.getType().equals(Material.JUNGLE_LOG)) {
return false;
}
// Find a spot for cocoa
BlockFace d = null;
for (BlockFace adj : SIDE_BLOCKS) {
if (b.getRelative(adj).getType().equals(Material.AIR)) {
d = adj;
break;
}
}
if (d == null) {
return false;
}
Block bb = b.getRelative(d);
bb.setType(Material.COCOA);
BlockFace opp = d.getOppositeFace();

if(bb.getBlockData() instanceof Cocoa v){
v.setFacing(opp);
bb.setBlockData(v);
bb.getState().setBlockData(v);
bb.getState().update(true);
return true;
}
return false;
}

/**
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Random;

import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand Down Expand Up @@ -216,7 +217,7 @@ public record GrowthBlock(Block block, Boolean floor) {}

/**
* Get a list of the lowest level blocks inside the greenhouse. May be air, liquid or plants.
* These blocks sit just above solid blocks
* These blocks sit just above solid blocks. Leaves are ignored too.
* @param gh - greenhouse
* @param ignoreLiquid - true if liquid blocks should be treated like air blocks
* @return List of blocks
Expand All @@ -237,7 +238,12 @@ protected List<GrowthBlock> getAvailableBlocks(Greenhouse gh, boolean ignoreLiqu
if (b.isEmpty() && !b.getRelative(BlockFace.UP).isEmpty()) {
result.add(new GrowthBlock(b, false));
}
if (!b.isEmpty() && (b.getRelative(BlockFace.UP).isEmpty() || b.getRelative(BlockFace.UP).isPassable())) {
if (!b.isEmpty() && !Tag.LEAVES.isTagged(b.getType())
&& (b.getRelative(BlockFace.UP).isEmpty()
|| b.getRelative(BlockFace.UP).isPassable()
|| Tag.LEAVES.isTagged(b.getRelative(BlockFace.UP).getType())
)
) {
result.add(new GrowthBlock(b.getRelative(BlockFace.UP), true));
break;
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/biomes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ biomes:
ROSE_BUSH: 20:GRASS_BLOCK
FERN: 20:GRASS_BLOCK
TALL_GRASS: 20:GRASS_BLOCK
COCOA: 10:JUNGLE_LOG
MUSHROOM_FIELDS:
friendlyname: "Mushroom Fields"
biome: MUSHROOM_FIELDS
Expand Down Expand Up @@ -285,15 +286,15 @@ biomes:
mobs:
SLIME: 5:WATER
moblimit: 3
DRIPSTONE_CAVES:
dripstone_caves:
friendlyname: "&6Drippy Drops"
biome: dripstone_caves
icon: DRIPSTONE_BLOCK
priority: 15
contents:
STONE: 8
CLAY: 8
# 50% water cove rage required
# 50% water coverage required
watercoverage: 25
conversions:
CLAY: 50:DRIPSTONE_BLOCK:WATER
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package world.bentobox.greenhouses.managers;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.Keyed;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.Tag;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand All @@ -18,6 +24,9 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.stubbing.OngoingStubbing;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

Expand All @@ -30,7 +39,7 @@
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class})
@PrepareForTest({Bukkit.class, BentoBox.class, Tag.class})
public class EcoSystemManagerTest {

private Greenhouse gh;
Expand All @@ -51,6 +60,11 @@ public class EcoSystemManagerTest {
*/
@Before
public void setUp() {
PowerMockito.mockStatic(Tag.class, Mockito.RETURNS_MOCKS);
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
Tag<Keyed> tag = mock(Tag.class);
when(Bukkit.getTag(anyString(), any(), any())).thenReturn(tag);

gh = new Greenhouse();
// 4x4x4 greenhouse
BoundingBox bb = BoundingBox.of(new Vector(0,0,0), new Vector(6,5,6));
Expand Down

0 comments on commit de6a939

Please sign in to comment.