mirror of
https://github.com/BentoBoxWorld/Greenhouses.git
synced 2025-02-01 12:51:31 +01:00
Mostly working. Still WIP.
Animal spawn not working.
This commit is contained in:
parent
fb3d150820
commit
374f549c4f
@ -285,9 +285,9 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||
|
||||
private Optional<GreenhousePlant> getRandomPlant() {
|
||||
// Grow a random plant that can grow
|
||||
Double key = plantTree.ceilingKey(random.nextDouble());
|
||||
double r = random.nextDouble();
|
||||
Double key = plantTree.ceilingKey(r);
|
||||
return key == null ? Optional.empty() : Optional.ofNullable(plantTree.get(key));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,21 +1,17 @@
|
||||
package world.bentobox.greenhouses.listeners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Hopper;
|
||||
import org.bukkit.block.data.type.Snow;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||
@ -32,7 +28,6 @@ import world.bentobox.greenhouses.data.Greenhouse;
|
||||
*/
|
||||
public class SnowTracker implements Listener {
|
||||
private final Greenhouses addon;
|
||||
private final static List<Biome> SNOWBIOMES = Arrays.stream(Biome.values()).filter(b -> b.name().contains("COLD") || b.name().contains("ICE") || b.name().contains("FROZEN")).collect(Collectors.toList());
|
||||
private Map<World, BukkitTask> snowTasks;
|
||||
|
||||
public SnowTracker(Greenhouses addon) {
|
||||
@ -46,16 +41,18 @@ public class SnowTracker implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onWeatherChangeEvent(final WeatherChangeEvent e) {
|
||||
addon.log("DEBUG: weather change");
|
||||
if (!addon.getActiveWorlds().contains(e.getWorld())) {
|
||||
return;
|
||||
}
|
||||
addon.log("DEBUG: in worlds");
|
||||
if (e.toWeatherState()) {
|
||||
// It's raining
|
||||
//addon.logger(3,"It's raining!");
|
||||
addon.log("It's raining!");
|
||||
startSnow(e.getWorld());
|
||||
} else {
|
||||
// It's stopped raining!
|
||||
//addon.logger(3,"Stopped raining!");
|
||||
addon.log("Stopped raining!");
|
||||
stopSnow(e.getWorld());
|
||||
}
|
||||
}
|
||||
@ -73,17 +70,17 @@ public class SnowTracker implements Listener {
|
||||
}
|
||||
|
||||
private void shakeGlobes(World world) {
|
||||
addon.getManager().getMap().getGreenhouses().stream().filter(g -> SNOWBIOMES.contains(g.getBiomeRecipe().getBiome()))
|
||||
addon.getManager().getMap().getGreenhouses().stream().filter(g -> g.getBiomeRecipe().getIceCoverage() > 0)
|
||||
.filter(g -> g.getLocation().getWorld().equals(world))
|
||||
.filter(g -> !g.isBroken())
|
||||
.filter(g -> g.getRoofHopperLocation() != null)
|
||||
.filter(g -> g.getRoofHopperLocation().getBlock().getType().equals(Material.HOPPER))
|
||||
.filter(g -> ((Hopper)g.getRoofHopperLocation().getBlock()).getInventory().contains(Material.WATER_BUCKET))
|
||||
.filter(g -> ((Hopper)g.getRoofHopperLocation().getBlock().getState()).getInventory().contains(Material.WATER_BUCKET))
|
||||
.forEach(this::removeWaterBucketAndShake);
|
||||
}
|
||||
|
||||
private void removeWaterBucketAndShake(Greenhouse g) {
|
||||
Hopper h = ((Hopper)g.getRoofHopperLocation().getBlock());
|
||||
Hopper h = ((Hopper)g.getRoofHopperLocation().getBlock().getState());
|
||||
h.getInventory().removeItem(new ItemStack(Material.WATER_BUCKET));
|
||||
h.getInventory().addItem(new ItemStack(Material.BUCKET));
|
||||
// Scatter snow
|
||||
@ -97,7 +94,7 @@ public class SnowTracker implements Listener {
|
||||
for (int z = (int)gh.getFootprint().getMinY() + 1; z < (int)gh.getFootprint().getMaxY(); z++) {
|
||||
for (int y = gh.getCeilingHeight() - 1; y >= gh.getFloorHeight(); y--) {
|
||||
Block b = gh.getLocation().getWorld().getBlockAt(x, y, z);
|
||||
if (b.getType().equals(Material.AIR)) {
|
||||
if (b.getType().equals(Material.AIR) || b.getType().equals(Material.SNOW)) {
|
||||
b.getWorld().spawnParticle(Particle.SNOWBALL, b.getLocation(), 5);
|
||||
} else {
|
||||
// Add snow
|
||||
@ -106,7 +103,7 @@ public class SnowTracker implements Listener {
|
||||
} else {
|
||||
// Not water
|
||||
if (Math.random() < addon.getSettings().getSnowDensity() && !b.isLiquid()) {
|
||||
addSnow(b);
|
||||
b.getRelative(BlockFace.UP).setType(Material.SNOW);
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,14 +119,4 @@ public class SnowTracker implements Listener {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void addSnow(Block b) {
|
||||
Block above = b.getRelative(BlockFace.UP);
|
||||
if (above.getType().equals(Material.SNOW) || above.getType().equals(Material.AIR)) {
|
||||
above.setType(Material.SNOW);
|
||||
Snow snow = (Snow)above;
|
||||
snow.setLayers(Math.min(snow.getMaximumLayers(), snow.getLayers() + 1));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -7,6 +7,7 @@ import java.util.Objects;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Hopper;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
@ -92,7 +93,8 @@ public class EcoSystemManager {
|
||||
int bonemeal = getBoneMeal(gh);
|
||||
if (bonemeal > 0) {
|
||||
// Get a list of all available blocks
|
||||
setBoneMeal(gh, bonemeal - getAvailableBlocks(gh).stream().limit(bonemeal).mapToInt(bl -> gh.getBiomeRecipe().growPlant(bl) ? 1 : 0).sum());
|
||||
int bonemealUsed = getAvailableBlocks(gh).stream().limit(bonemeal).mapToInt(bl -> gh.getBiomeRecipe().growPlant(bl) ? 1 : 0).sum();
|
||||
setBoneMeal(gh, bonemeal - bonemealUsed);
|
||||
}
|
||||
|
||||
}
|
||||
@ -112,7 +114,7 @@ public class EcoSystemManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of the highest block inside the greenhouse
|
||||
* Get a list of the lowest level air blocks inside the greenhouse
|
||||
* @param gh - greenhouse
|
||||
* @return List of blocks
|
||||
*/
|
||||
@ -122,8 +124,8 @@ public class EcoSystemManager {
|
||||
for (int z = (int)gh.getFootprint().getMinY() + 1; z < (int)gh.getFootprint().getMaxY(); z++) {
|
||||
for (int y = gh.getCeilingHeight() - 1; y >= gh.getFloorHeight(); y--) {
|
||||
Block b = gh.getLocation().getWorld().getBlockAt(x, y, z);
|
||||
if (!b.getType().equals(Material.AIR)) {
|
||||
result.add(b);
|
||||
if (!b.getType().equals(Material.AIR) && b.getRelative(BlockFace.UP).getType().equals(Material.AIR)) {
|
||||
result.add(b.getRelative(BlockFace.UP));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
@ -36,10 +35,7 @@ public class GreenhouseMap {
|
||||
if (greenhouse.getLocation() == null) {
|
||||
return GreenhouseResult.NULL;
|
||||
}
|
||||
Bukkit.getLogger().info("Adding greenhouse " + greenhouse.getLocation());
|
||||
Bukkit.getLogger().info("Island = " + addon.getIslands().getIslandAt(greenhouse.getLocation()).isPresent());
|
||||
return addon.getIslands().getIslandAt(greenhouse.getLocation()).map(i -> {
|
||||
Bukkit.getLogger().info("Island found!");
|
||||
greenhouses.putIfAbsent(i, new ArrayList<>());
|
||||
// Check if overlapping
|
||||
if (!isOverlapping(greenhouse)) {
|
||||
|
@ -58,10 +58,10 @@ biomes:
|
||||
contents:
|
||||
SPRUCE_LOG: 3
|
||||
SPRUCE_LEAVES: 3
|
||||
GRASS: 3
|
||||
GRASS_BLOCK: 3
|
||||
icecoverage: 10
|
||||
plants:
|
||||
TALL_GRASS: 10:GRASS
|
||||
TALL_GRASS: 10:GRASS_BLOCK
|
||||
mobs:
|
||||
WOLF: 10:SNOW
|
||||
moblimit: 9
|
||||
@ -73,10 +73,10 @@ biomes:
|
||||
contents:
|
||||
SPRUCE_LOG: 3
|
||||
SPRUCE_LEAVES: 3
|
||||
GRASS: 3
|
||||
GRASS_BLOCK: 3
|
||||
icecoverage: 10
|
||||
plants:
|
||||
TALL_GRASS: 10:GRASS
|
||||
TALL_GRASS: 10:GRASS_BLOCK
|
||||
mobs:
|
||||
RABBIT: 10:SNOW
|
||||
moblimit: 9
|
||||
@ -108,12 +108,12 @@ biomes:
|
||||
contents:
|
||||
OAK_LOG: 3
|
||||
OAK_LEAVES: 4
|
||||
GRASS: 4
|
||||
GRASS_BLOCK: 4
|
||||
plants:
|
||||
PINK_TULIP: 2:GRASS
|
||||
ORANGE_TULIP: 2:GRASS
|
||||
SUNFLOWER: 4:GRASS
|
||||
TALL_GRASS: 20:GRASS
|
||||
PINK_TULIP: 2:GRASS_BLOCK
|
||||
ORANGE_TULIP: 2:GRASS_BLOCK
|
||||
SUNFLOWER: 4:GRASS_BLOCK
|
||||
TALL_GRASS: 20:GRASS_BLOCK
|
||||
NETHER:
|
||||
friendlyname: "&cNether"
|
||||
biome: NETHER
|
||||
@ -134,15 +134,15 @@ biomes:
|
||||
icon: VINE
|
||||
priority: 6
|
||||
contents:
|
||||
GRASS: 4
|
||||
GRASS_BLOCK: 4
|
||||
JUNGLE_LOG: 3
|
||||
JUNGLE_LEAVES: 4
|
||||
plants:
|
||||
DANDELION: 20:GRASS
|
||||
MELON: 10:GRASS
|
||||
ROSE_BUSH: 20:GRASS
|
||||
FERN: 20:GRASS
|
||||
TALL_GRASS: 20:GRASS
|
||||
DANDELION: 20:GRASS_BLOCK
|
||||
MELON: 10:GRASS_BLOCK
|
||||
ROSE_BUSH: 20:GRASS_BLOCK
|
||||
FERN: 20:GRASS_BLOCK
|
||||
TALL_GRASS: 20:GRASS_BLOCK
|
||||
MUSHROOM_FIELDS:
|
||||
friendlyname: "Mushroom Fields"
|
||||
biome: MUSHROOM_FIELDS
|
||||
@ -170,14 +170,14 @@ biomes:
|
||||
PLAINS:
|
||||
friendlyname: "Horse Plains"
|
||||
biome: PLAINS
|
||||
icon: GRASS
|
||||
icon: GRASS_BLOCK
|
||||
priority: 1
|
||||
contents:
|
||||
GRASS: 3
|
||||
GRASS_BLOCK: 3
|
||||
plants:
|
||||
TALL_GRASS: 10:GRASS
|
||||
TALL_GRASS: 10:GRASS_BLOCK
|
||||
mobs:
|
||||
HORSE: 10:GRASS
|
||||
HORSE: 10:GRASS_BLOCK
|
||||
moblimit: 9
|
||||
RIVER:
|
||||
friendlyname: "Clay river"
|
||||
@ -201,23 +201,23 @@ biomes:
|
||||
contents:
|
||||
ACACIA_LOG: 3
|
||||
ACACIA_LEAVES: 4
|
||||
GRASS: 4
|
||||
GRASS_BLOCK: 4
|
||||
plants:
|
||||
TALL_GRASS: 10:GRASS
|
||||
TALL_GRASS: 10:GRASS_BLOCK
|
||||
SWAMP:
|
||||
friendlyname: "&2Slimy Swamp"
|
||||
biome: SWAMP
|
||||
icon: LILY_PAD
|
||||
priority: 13
|
||||
contents:
|
||||
GRASS: 4
|
||||
GRASS_BLOCK: 4
|
||||
OAK_LOG: 3
|
||||
OAK_LEAVES: 4
|
||||
# 50% water coverage required
|
||||
watercoverage: 50
|
||||
plants:
|
||||
RED_MUSHROOM: 20:GRASS
|
||||
BROWN_MUSHROOM: 20:GRASS
|
||||
RED_MUSHROOM: 20:GRASS_BLOCK
|
||||
BROWN_MUSHROOM: 20:GRASS_BLOCK
|
||||
LILY_PAD: 5:WATER
|
||||
mobs:
|
||||
SLIME: 5:WATER
|
||||
|
Loading…
Reference in New Issue
Block a user