Prevents snow from damaging walls
https://github.com/BentoBoxWorld/Greenhouses/issues/29
This commit is contained in:
parent
54fd683906
commit
15b2c63450
|
@ -14,6 +14,7 @@ import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.Hopper;
|
import org.bukkit.block.Hopper;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockFormEvent;
|
||||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
@ -42,8 +43,8 @@ public class SnowTracker implements Listener {
|
||||||
private boolean getAirBlocks(Greenhouse gh) {
|
private boolean getAirBlocks(Greenhouse gh) {
|
||||||
boolean createdSnow = false;
|
boolean createdSnow = false;
|
||||||
List<Block> waterBlocks = new ArrayList<>();
|
List<Block> waterBlocks = new ArrayList<>();
|
||||||
for (int x = (int)gh.getBoundingBox().getMinX() + 1; x < (int)gh.getBoundingBox().getMaxX(); x++) {
|
for (int x = (int)gh.getBoundingBox().getMinX() + 1; x < (int)gh.getBoundingBox().getMaxX() -1; x++) {
|
||||||
for (int z = (int)gh.getBoundingBox().getMinZ() + 1; z < (int)gh.getBoundingBox().getMaxZ(); z++) {
|
for (int z = (int)gh.getBoundingBox().getMinZ() + 1; z < (int)gh.getBoundingBox().getMaxZ() - 1; z++) {
|
||||||
for (int y = (int)gh.getBoundingBox().getMaxY() - 2; y >= (int)gh.getBoundingBox().getMinY(); y--) {
|
for (int y = (int)gh.getBoundingBox().getMaxY() - 2; y >= (int)gh.getBoundingBox().getMinY(); y--) {
|
||||||
Block b = gh.getLocation().getWorld().getBlockAt(x, y, z);
|
Block b = gh.getLocation().getWorld().getBlockAt(x, y, z);
|
||||||
Material type = b.getType();
|
Material type = b.getType();
|
||||||
|
@ -55,7 +56,9 @@ public class SnowTracker implements Listener {
|
||||||
waterBlocks.add(b);
|
waterBlocks.add(b);
|
||||||
} else {
|
} else {
|
||||||
// Not water
|
// Not water
|
||||||
if (Math.random() < addon.getSettings().getSnowDensity() && !b.isLiquid()) {
|
if (Math.random() < addon.getSettings().getSnowDensity()
|
||||||
|
&& !b.isLiquid()
|
||||||
|
&& b.getRelative(BlockFace.UP).getType().equals(Material.AIR)) {
|
||||||
b.getRelative(BlockFace.UP).setType(Material.SNOW);
|
b.getRelative(BlockFace.UP).setType(Material.SNOW);
|
||||||
createdSnow = true;
|
createdSnow = true;
|
||||||
}
|
}
|
||||||
|
@ -67,13 +70,27 @@ public class SnowTracker implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check if any water blocks can be turned to ice
|
// Check if any water blocks can be turned to ice
|
||||||
|
/*
|
||||||
|
* TODO - find a way to calculate water blocks
|
||||||
int maxSize = waterBlocks.size() - (gh.getArea() / gh.getBiomeRecipe().getWaterCoverage());
|
int maxSize = waterBlocks.size() - (gh.getArea() / gh.getBiomeRecipe().getWaterCoverage());
|
||||||
if (maxSize > 0) {
|
if (maxSize > 0) {
|
||||||
waterBlocks.stream().limit(maxSize).filter(b -> Math.random() < addon.getSettings().getSnowDensity()).forEach(b -> b.setType(Material.ICE));
|
waterBlocks.stream().limit(maxSize).filter(b -> Math.random() < addon.getSettings().getSnowDensity()).forEach(b -> b.setType(Material.ICE));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
return createdSnow;
|
return createdSnow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO finish
|
||||||
|
* @param e
|
||||||
|
*/
|
||||||
|
@EventHandler
|
||||||
|
public void onBlockFormEvent(final BlockFormEvent e) {
|
||||||
|
if (e.getNewState().getType().equals(Material.SNOW) && addon.getManager().getMap().isAboveGreenhouse(e.getBlock().getLocation())) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onWeatherChangeEvent(final WeatherChangeEvent e) {
|
public void onWeatherChangeEvent(final WeatherChangeEvent e) {
|
||||||
if (!addon.getActiveWorlds().contains(e.getWorld())) {
|
if (!addon.getActiveWorlds().contains(e.getWorld())) {
|
||||||
|
|
|
@ -1,93 +0,0 @@
|
||||||
package world.bentobox.greenhouses.listeners;
|
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author tastybento
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class GreenhouseEventsTest {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws java.lang.Exception
|
|
||||||
*/
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#GreenhouseEvents(world.bentobox.greenhouses.Greenhouses)}.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testGreenhouseEvents() {
|
|
||||||
fail("Not yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPlayerInteract(org.bukkit.event.player.PlayerInteractEvent)}.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testOnPlayerInteract() {
|
|
||||||
fail("Not yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onIceBreak(org.bukkit.event.block.BlockBreakEvent)}.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testOnIceBreak() {
|
|
||||||
fail("Not yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testOnPlayerMove() {
|
|
||||||
fail("Not yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPlayerTeleport(org.bukkit.event.player.PlayerTeleportEvent)}.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testOnPlayerTeleport() {
|
|
||||||
fail("Not yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onBlockBreak(org.bukkit.event.block.BlockBreakEvent)}.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testOnBlockBreak() {
|
|
||||||
fail("Not yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPlayerBlockPlace(org.bukkit.event.block.BlockPlaceEvent)}.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testOnPlayerBlockPlace() {
|
|
||||||
fail("Not yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link world.bentobox.greenhouses.listeners.GreenhouseEvents#onPistonPush(org.bukkit.event.block.BlockPistonExtendEvent)}.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testOnPistonPush() {
|
|
||||||
fail("Not yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue