Adds support for COCOA #97

This commit is contained in:
tastybento 2023-01-01 22:29:02 -08:00
parent 10a1d63778
commit de6a939bb9
4 changed files with 62 additions and 5 deletions

View File

@ -26,11 +26,13 @@ import org.bukkit.block.BlockFace;
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;
@ -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<>();
@ -491,6 +494,8 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
}
} 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);
@ -503,6 +508,37 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
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

View File

@ -9,6 +9,7 @@ import java.util.Objects;
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;
@ -216,7 +217,7 @@ public class EcoSystemManager {
/**
* 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
@ -237,7 +238,12 @@ public class EcoSystemManager {
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;
}

View File

@ -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
@ -285,7 +286,7 @@ biomes:
mobs:
SLIME: 5:WATER
moblimit: 3
DRIPSTONE_CAVES:
dripstone_caves:
friendlyname: "&6Drippy Drops"
biome: dripstone_caves
icon: DRIPSTONE_BLOCK
@ -293,7 +294,7 @@ biomes:
contents:
STONE: 8
CLAY: 8
# 50% water cove rage required
# 50% water coverage required
watercoverage: 25
conversions:
CLAY: 50:DRIPSTONE_BLOCK:WATER

View File

@ -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;
@ -18,6 +24,9 @@ import org.junit.Before;
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;
@ -30,7 +39,7 @@ import world.bentobox.greenhouses.managers.EcoSystemManager.GrowthBlock;
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class})
@PrepareForTest({Bukkit.class, BentoBox.class, Tag.class})
public class EcoSystemManagerTest {
private Greenhouse gh;
@ -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));