Skip to content

Commit

Permalink
Cauldron will fill up with snow
Browse files Browse the repository at this point in the history
Also, snow will pile up as expected.

#83
  • Loading branch information
tastybento committed Sep 26, 2021
1 parent c660575 commit 4aec983
Showing 1 changed file with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package world.bentobox.greenhouses.listeners;

import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.bukkit.Bukkit;
import org.bukkit.Material;
Expand All @@ -9,6 +13,8 @@
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Hopper;
import org.bukkit.block.data.Levelled;
import org.bukkit.block.data.type.Snow;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockFormEvent;
Expand Down Expand Up @@ -67,10 +73,11 @@ private boolean getAirBlocks(Greenhouse gh) {
// Not water
if (Math.random() < addon.getSettings().getSnowDensity()
&& !b.isLiquid()
&& b.getRelative(BlockFace.UP).getType().equals(Material.AIR)) {
placeSnow(b);
&& (b.getRelative(BlockFace.UP).getType().equals(Material.AIR)
|| b.getRelative(BlockFace.UP).getType().equals(Material.SNOW))) {

createdSnow = true;

createdSnow = placeSnow(b);
}
}

Expand All @@ -90,13 +97,44 @@ private boolean getAirBlocks(Greenhouse gh) {
return createdSnow;
}

private void placeSnow(Block b) {
private boolean placeSnow(Block b) {
Optional<Material> snowCauldron = Enums.getIfPresent(Material.class, "POWDER_SNOW_CAULDRON");
if (b.getType().equals(Material.CAULDRON) && snowCauldron.isPresent()) {
b.setType(snowCauldron.get());
if (snowCauldron.isPresent()) {
if (b.getType().equals(Material.CAULDRON)) {
b.setType(snowCauldron.get());
return true;
} else if (b.getType().equals(snowCauldron.get())) {
// Fill up the snow cauldron some more
return incrementLevel(b);
}
}
// Pile up snow
if (b.getRelative(BlockFace.UP).getType().equals(Material.SNOW)) {
return incrementLevel(b.getRelative(BlockFace.UP));
} else {
b.getRelative(BlockFace.UP).setType(Material.SNOW);
}
return true;
}

private boolean incrementLevel(Block b) {
if (b.getBlockData() instanceof Levelled data) {
int max = data.getMaximumLevel();
if (data.getLevel() < max) {
data.setLevel(data.getLevel() + 1);
b.setBlockData(data);
return true;
}
}
if (b.getBlockData() instanceof Snow data) {
int max = data.getMaximumLayers();
if (data.getLayers() < max) {
data.setLayers(data.getLayers() + 1);
b.setBlockData(data);
return true;
}
}
return false;
}

/**
Expand Down

0 comments on commit 4aec983

Please sign in to comment.