mirror of
https://github.com/BentoBoxWorld/Greenhouses.git
synced 2025-03-02 10:41:39 +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.bentobox.api.flags.Flag.Type;
|
||||||
import world.bentobox.greenhouses.managers.GreenhouseManager;
|
import world.bentobox.greenhouses.managers.GreenhouseManager;
|
||||||
import world.bentobox.greenhouses.managers.RecipeManager;
|
import world.bentobox.greenhouses.managers.RecipeManager;
|
||||||
|
import world.bentobox.greenhouses.ui.admin.AdminCmd;
|
||||||
import world.bentobox.greenhouses.ui.user.UserCommand;
|
import world.bentobox.greenhouses.ui.user.UserCommand;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,6 +72,7 @@ public class Greenhouses extends Addon {
|
|||||||
.forEach(gm -> {
|
.forEach(gm -> {
|
||||||
// Register command
|
// Register command
|
||||||
gm.getPlayerCommand().ifPresent(playerCmd -> new UserCommand(this, playerCmd));
|
gm.getPlayerCommand().ifPresent(playerCmd -> new UserCommand(this, playerCmd));
|
||||||
|
gm.getAdminCommand().ifPresent(playerCmd -> new AdminCmd(this, playerCmd));
|
||||||
// Log
|
// Log
|
||||||
this.log("Hooking into " + gm.getDescription().getName());
|
this.log("Hooking into " + gm.getDescription().getName());
|
||||||
// Store active world
|
// Store active world
|
||||||
|
@ -161,6 +161,14 @@ public class Greenhouse implements DataObject {
|
|||||||
return boundingBox;
|
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
|
* @param boundingBox the boundingBox to set
|
||||||
*/
|
*/
|
||||||
|
@ -14,6 +14,7 @@ import org.bukkit.block.BlockFace;
|
|||||||
import org.bukkit.block.Hopper;
|
import org.bukkit.block.Hopper;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
import org.bukkit.util.NumberConversions;
|
||||||
|
|
||||||
import world.bentobox.greenhouses.Greenhouses;
|
import world.bentobox.greenhouses.Greenhouses;
|
||||||
import world.bentobox.greenhouses.data.Greenhouse;
|
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)){
|
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;
|
return;
|
||||||
}
|
}
|
||||||
for (int x = (int)gh.getBoundingBox().getMinX() + 1; x < (int)gh.getBoundingBox().getMaxX(); x++) {
|
for (double x = gh.getInternalBoundingBox().getMinX(); x < gh.getInternalBoundingBox().getMaxX(); x++) {
|
||||||
for (int z = (int)gh.getBoundingBox().getMinZ() + 1; z < (int)gh.getBoundingBox().getMaxZ(); z++) {
|
for (double z = gh.getInternalBoundingBox().getMinZ(); z < gh.getInternalBoundingBox().getMaxZ(); z++) {
|
||||||
for (int y = (int)gh.getBoundingBox().getMaxY() - 2; y >= (int)gh.getBoundingBox().getMinY() && y > 0; y--) {
|
for (double y = gh.getInternalBoundingBox().getMaxY() - 1; y >= gh.getBoundingBox().getMinY() && y > 0; y--) {
|
||||||
Block b = gh.getWorld().getBlockAt(x, y, z).getRelative(BlockFace.DOWN);
|
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);
|
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
|
* @param ignoreliquid - true if liquid blocks should be treated like air blocks
|
||||||
* @return List of 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<>();
|
List<Block> result = new ArrayList<>();
|
||||||
for (int x = (int)gh.getBoundingBox().getMinX() + 1; x < (int)gh.getBoundingBox().getMaxX(); x++) {
|
for (double x = gh.getInternalBoundingBox().getMinX(); x < gh.getInternalBoundingBox().getMaxX(); x++) {
|
||||||
for (int z = (int)gh.getBoundingBox().getMinZ() + 1; z < (int)gh.getBoundingBox().getMaxZ(); z++) {
|
for (double z = gh.getInternalBoundingBox().getMinZ(); z < gh.getInternalBoundingBox().getMaxZ(); z++) {
|
||||||
for (int y = (int)gh.getBoundingBox().getMaxY() - 2; y >= (int)gh.getBoundingBox().getMinY(); y--) {
|
for (double y = gh.getInternalBoundingBox().getMaxY() - 1; y >= gh.getBoundingBox().getMinY(); y--) {
|
||||||
Block b = gh.getWorld().getBlockAt(x, y, z);
|
Block b = gh.getWorld().getBlockAt(NumberConversions.floor(x), NumberConversions.floor(y), NumberConversions.floor(z));
|
||||||
if (!(b.isEmpty() || (ignoreLiquid && b.isLiquid()))
|
if (!(b.isEmpty() || (ignoreLiquid && b.isLiquid()))
|
||||||
&& (b.getRelative(BlockFace.UP).isEmpty()
|
&& (b.getRelative(BlockFace.UP).isEmpty()
|
||||||
|| (b.getRelative(BlockFace.UP).isPassable() && !b.isLiquid())
|
|| (b.getRelative(BlockFace.UP).isPassable() && !b.isLiquid())
|
||||||
|
@ -10,10 +10,10 @@ import world.bentobox.greenhouses.Greenhouses;
|
|||||||
* This class handles commands for admins
|
* This class handles commands for admins
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class AdminCmd extends CompositeCommand {
|
public class AdminCmd extends CompositeCommand {
|
||||||
|
|
||||||
public AdminCmd(Greenhouses greenhouses) {
|
public AdminCmd(Greenhouses greenhouses, CompositeCommand parent) {
|
||||||
super(greenhouses, "gadmin");
|
super(greenhouses, parent, "gadmin");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -23,7 +23,7 @@ class AdminCmd extends CompositeCommand {
|
|||||||
this.setParametersHelp("greenhouses.admin.parameters");
|
this.setParametersHelp("greenhouses.admin.parameters");
|
||||||
this.setDescription("greenhouses.admin.description");
|
this.setDescription("greenhouses.admin.description");
|
||||||
|
|
||||||
new GreenhousesAdminReloadCommand(this);
|
//new GreenhousesAdminReloadCommand(this);
|
||||||
new GreenhousesAdminInfoCommand(this);
|
new GreenhousesAdminInfoCommand(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
package world.bentobox.greenhouses.ui.admin;
|
package world.bentobox.greenhouses.ui.admin;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
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.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
import world.bentobox.greenhouses.Greenhouses;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
@ -11,11 +17,18 @@ import world.bentobox.bentobox.api.user.User;
|
|||||||
*/
|
*/
|
||||||
class GreenhousesAdminInfoCommand extends CompositeCommand {
|
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
|
* @param parent - parent user command, e.g, /island
|
||||||
*/
|
*/
|
||||||
public GreenhousesAdminInfoCommand(CompositeCommand parent) {
|
public GreenhousesAdminInfoCommand(CompositeCommand parent) {
|
||||||
super(parent, "info");
|
super(parent, "info");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@ -32,8 +45,14 @@ class GreenhousesAdminInfoCommand extends CompositeCommand {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(User user, String label, List<String> args) {
|
public boolean execute(User user, String label, List<String> args) {
|
||||||
// TODO Auto-generated method stub
|
Location l = user.getPlayer().getLineOfSight(transparent, 5).get(0).getLocation();
|
||||||
return false;
|
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 java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@ -35,7 +36,6 @@ import world.bentobox.greenhouses.data.Greenhouse;
|
|||||||
@PrepareForTest({Bukkit.class, BentoBox.class})
|
@PrepareForTest({Bukkit.class, BentoBox.class})
|
||||||
public class EcoSystemManagerTest {
|
public class EcoSystemManagerTest {
|
||||||
|
|
||||||
@Mock
|
|
||||||
private Greenhouse gh;
|
private Greenhouse gh;
|
||||||
@Mock
|
@Mock
|
||||||
private World world;
|
private World world;
|
||||||
@ -55,11 +55,13 @@ public class EcoSystemManagerTest {
|
|||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
gh = new Greenhouse();
|
||||||
// 4x4x4 greenhouse
|
// 4x4x4 greenhouse
|
||||||
BoundingBox bb = BoundingBox.of(new Vector(0,0,0), new Vector(5,5,5));
|
BoundingBox bb = BoundingBox.of(new Vector(0,0,0), new Vector(6,5,6));
|
||||||
when(gh.getBoundingBox()).thenReturn(bb);
|
gh.setBoundingBox(bb);
|
||||||
// World
|
// 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);
|
when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(block);
|
||||||
// Blocks
|
// Blocks
|
||||||
// Air
|
// Air
|
||||||
|
Loading…
Reference in New Issue
Block a user