mirror of
https://github.com/BentoBoxWorld/Greenhouses.git
synced 2025-02-01 12:51:31 +01:00
Use internal bounding box
This commit is contained in:
parent
fad9936e24
commit
5a4d1a35c3
@ -13,6 +13,7 @@ import world.bentobox.bentobox.api.flags.Flag.Mode;
|
||||
import world.bentobox.bentobox.api.flags.Flag.Type;
|
||||
import world.bentobox.greenhouses.managers.GreenhouseManager;
|
||||
import world.bentobox.greenhouses.managers.RecipeManager;
|
||||
import world.bentobox.greenhouses.ui.admin.AdminCmd;
|
||||
import world.bentobox.greenhouses.ui.user.UserCommand;
|
||||
|
||||
/**
|
||||
@ -71,6 +72,7 @@ public class Greenhouses extends Addon {
|
||||
.forEach(gm -> {
|
||||
// Register command
|
||||
gm.getPlayerCommand().ifPresent(playerCmd -> new UserCommand(this, playerCmd));
|
||||
gm.getAdminCommand().ifPresent(playerCmd -> new AdminCmd(this, playerCmd));
|
||||
// Log
|
||||
this.log("Hooking into " + gm.getDescription().getName());
|
||||
// Store active world
|
||||
|
@ -161,6 +161,14 @@ public class Greenhouse implements DataObject {
|
||||
return boundingBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a bounding box of the greenhouse that does not include the walls or roof
|
||||
*/
|
||||
@Nullable
|
||||
public BoundingBox getInternalBoundingBox() {
|
||||
return boundingBox == null ? null : boundingBox.clone().expand(-1D);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boundingBox the boundingBox to set
|
||||
*/
|
||||
|
@ -14,6 +14,7 @@ import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Hopper;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.util.NumberConversions;
|
||||
|
||||
import world.bentobox.greenhouses.Greenhouses;
|
||||
import world.bentobox.greenhouses.data.Greenhouse;
|
||||
@ -85,10 +86,10 @@ public class EcoSystemManager {
|
||||
if(!gh.getLocation().getWorld().isChunkLoaded(((int) gh.getBoundingBox().getMaxX()) >> 4, ((int) gh.getBoundingBox().getMaxZ()) >> 4) || !gh.getLocation().getWorld().isChunkLoaded(((int) gh.getBoundingBox().getMinX()) >> 4, ((int) gh.getBoundingBox().getMinZ()) >> 4)){
|
||||
return;
|
||||
}
|
||||
for (int x = (int)gh.getBoundingBox().getMinX() + 1; x < (int)gh.getBoundingBox().getMaxX(); x++) {
|
||||
for (int z = (int)gh.getBoundingBox().getMinZ() + 1; z < (int)gh.getBoundingBox().getMaxZ(); z++) {
|
||||
for (int y = (int)gh.getBoundingBox().getMaxY() - 2; y >= (int)gh.getBoundingBox().getMinY() && y > 0; y--) {
|
||||
Block b = gh.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.DOWN);
|
||||
for (double x = gh.getInternalBoundingBox().getMinX(); x < gh.getInternalBoundingBox().getMaxX(); x++) {
|
||||
for (double z = gh.getInternalBoundingBox().getMinZ(); z < gh.getInternalBoundingBox().getMaxZ(); z++) {
|
||||
for (double y = gh.getInternalBoundingBox().getMaxY() - 1; y >= gh.getBoundingBox().getMinY() && y > 0; y--) {
|
||||
Block b = gh.getWorld().getBlockAt(NumberConversions.floor(x), NumberConversions.floor(y), NumberConversions.floor(z)).getRelative(BlockFace.DOWN);
|
||||
if (!b.isEmpty()) gh.getBiomeRecipe().convertBlock(gh, b);
|
||||
}
|
||||
}
|
||||
@ -184,12 +185,12 @@ public class EcoSystemManager {
|
||||
* @param ignoreliquid - true if liquid blocks should be treated like air blocks
|
||||
* @return List of blocks
|
||||
*/
|
||||
List<Block> getAvailableBlocks(Greenhouse gh, boolean ignoreLiquid) {
|
||||
public List<Block> getAvailableBlocks(Greenhouse gh, boolean ignoreLiquid) {
|
||||
List<Block> result = new ArrayList<>();
|
||||
for (int x = (int)gh.getBoundingBox().getMinX() + 1; x < (int)gh.getBoundingBox().getMaxX(); x++) {
|
||||
for (int z = (int)gh.getBoundingBox().getMinZ() + 1; z < (int)gh.getBoundingBox().getMaxZ(); z++) {
|
||||
for (int y = (int)gh.getBoundingBox().getMaxY() - 2; y >= (int)gh.getBoundingBox().getMinY(); y--) {
|
||||
Block b = gh.getWorld().getBlockAt(x, y, z);
|
||||
for (double x = gh.getInternalBoundingBox().getMinX(); x < gh.getInternalBoundingBox().getMaxX(); x++) {
|
||||
for (double z = gh.getInternalBoundingBox().getMinZ(); z < gh.getInternalBoundingBox().getMaxZ(); z++) {
|
||||
for (double y = gh.getInternalBoundingBox().getMaxY() - 1; y >= gh.getBoundingBox().getMinY(); y--) {
|
||||
Block b = gh.getWorld().getBlockAt(NumberConversions.floor(x), NumberConversions.floor(y), NumberConversions.floor(z));
|
||||
if (!(b.isEmpty() || (ignoreLiquid && b.isLiquid()))
|
||||
&& (b.getRelative(BlockFace.UP).isEmpty()
|
||||
|| (b.getRelative(BlockFace.UP).isPassable() && !b.isLiquid())
|
||||
|
@ -10,10 +10,10 @@ import world.bentobox.greenhouses.Greenhouses;
|
||||
* This class handles commands for admins
|
||||
*
|
||||
*/
|
||||
class AdminCmd extends CompositeCommand {
|
||||
public class AdminCmd extends CompositeCommand {
|
||||
|
||||
public AdminCmd(Greenhouses greenhouses) {
|
||||
super(greenhouses, "gadmin");
|
||||
public AdminCmd(Greenhouses greenhouses, CompositeCommand parent) {
|
||||
super(greenhouses, parent, "gadmin");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -23,7 +23,7 @@ class AdminCmd extends CompositeCommand {
|
||||
this.setParametersHelp("greenhouses.admin.parameters");
|
||||
this.setDescription("greenhouses.admin.description");
|
||||
|
||||
new GreenhousesAdminReloadCommand(this);
|
||||
//new GreenhousesAdminReloadCommand(this);
|
||||
new GreenhousesAdminInfoCommand(this);
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,15 @@
|
||||
package world.bentobox.greenhouses.ui.admin;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.greenhouses.Greenhouses;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
@ -11,11 +17,18 @@ import world.bentobox.bentobox.api.user.User;
|
||||
*/
|
||||
class GreenhousesAdminInfoCommand extends CompositeCommand {
|
||||
|
||||
private Greenhouses addon = Greenhouses.getInstance();
|
||||
private static final Set<Material> transparent = new HashSet<>();
|
||||
{
|
||||
transparent.add(Material.AIR);
|
||||
transparent.add(Material.GLASS);
|
||||
}
|
||||
/**
|
||||
* @param parent - parent user command, e.g, /island
|
||||
*/
|
||||
public GreenhousesAdminInfoCommand(CompositeCommand parent) {
|
||||
super(parent, "info");
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@ -32,8 +45,14 @@ class GreenhousesAdminInfoCommand extends CompositeCommand {
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
Location l = user.getPlayer().getLineOfSight(transparent, 5).get(0).getLocation();
|
||||
addon.getManager().getMap().getGreenhouse(l).ifPresent(gh ->
|
||||
{
|
||||
addon.log("There are " + addon.getManager().getEcoMgr().getAvailableBlocks(gh, false).size());
|
||||
addon.getManager().getEcoMgr().getAvailableBlocks(gh, false).forEach(b -> user.getPlayer().sendBlockChange(b.getLocation(), Material.CYAN_STAINED_GLASS.createBlockData()));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import static org.mockito.Mockito.when;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
@ -35,7 +36,6 @@ import world.bentobox.greenhouses.data.Greenhouse;
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class})
|
||||
public class EcoSystemManagerTest {
|
||||
|
||||
@Mock
|
||||
private Greenhouse gh;
|
||||
@Mock
|
||||
private World world;
|
||||
@ -55,11 +55,13 @@ public class EcoSystemManagerTest {
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
gh = new Greenhouse();
|
||||
// 4x4x4 greenhouse
|
||||
BoundingBox bb = BoundingBox.of(new Vector(0,0,0), new Vector(5,5,5));
|
||||
when(gh.getBoundingBox()).thenReturn(bb);
|
||||
BoundingBox bb = BoundingBox.of(new Vector(0,0,0), new Vector(6,5,6));
|
||||
gh.setBoundingBox(bb);
|
||||
// World
|
||||
when(gh.getWorld()).thenReturn(world);
|
||||
Location l = new Location(world, 0,0,0);
|
||||
gh.setLocation(l);
|
||||
when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(block);
|
||||
// Blocks
|
||||
// Air
|
||||
@ -76,13 +78,13 @@ public class EcoSystemManagerTest {
|
||||
// Empty false
|
||||
when(liquid.isLiquid()).thenReturn(true);
|
||||
when(liquid.isPassable()).thenReturn(true);
|
||||
when(liquid.getRelative(eq(BlockFace.UP))).thenReturn(air);
|
||||
when(liquid.getRelative(eq(BlockFace.UP))).thenReturn(air);
|
||||
// Default for block
|
||||
// Empty false
|
||||
// Passable false
|
||||
// Liquid false
|
||||
when(block.getRelative(eq(BlockFace.UP))).thenReturn(air);
|
||||
|
||||
|
||||
eco = new EcoSystemManager(null, null);
|
||||
}
|
||||
|
||||
@ -175,7 +177,7 @@ public class EcoSystemManagerTest {
|
||||
assertEquals(air, result.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.greenhouses.managers.EcoSystemManager#getAvailableBlocks(world.bentobox.greenhouses.data.Greenhouse)}.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user