Farmland water plugin

Discussion in 'Spigot Plugin Development' started by MaxJacobsYT123, Jun 3, 2017.

  1. So, I am trying to make a plugin that allows soil to become rich soil even if water is placed below it, not next to or 1 block above it. I am completely stuck and require some help. Thanks in advance!

    EDIT: So, I found a way, but setData((byte) 7); is crossed out by eclipse, and the plugin doesn't work. I can't figure it out as I am not getting an error in console. Please help! Thank you!
    Code (Text):
    package me.plugin.soil;

    import java.util.Set;

    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockFace;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockFadeEvent;
    import org.bukkit.event.player.PlayerBucketEmptyEvent;

    import net.minecraft.server.v1_11_R1.Blocks;

    public class Soil extends JavaPlugin implements Listener {
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        public void onBucketEmpty(PlayerBucketEmptyEvent e) {
            if (e.getBucket() == Material.WATER_BUCKET) {
                Player p = e.getPlayer();
                Block b = p.getTargetBlock((Set<Material>) null, 100);
                Block b1 = b.getLocation().getBlock().getRelative(BlockFace.UP);
                if (b1.getType().equals(Blocks.FARMLAND)) {
        public void onFarmFade(BlockFadeEvent e) {
            if (e.getBlock().equals(Blocks.FARMLAND)) {
    #1 MaxJacobsYT123, Jun 3, 2017
    Last edited: Jun 4, 2017
  2. Check for every block in a certain radius if it's soil. And update the soil.

    On the block update event, check if there is water nearby and cancel the event.
  3. I would start by getting the location where they placed the water and make an if statement to check if the block above it is soil and if it is then set it's water value (not sure what Minecraft calls it :/) to be the highest
  4. I have tried that, and it said that I can not change a boolean to a block.
    I tried:
    How exactly would I do that?
  5. My way would save on ram and cpu usage. All you have to do is do a emptying bucket event, check if it is water, gets the block it was placed(do this by getting where the player was looking at then add 1 on the y axis) then check if it is soil if so grab the soil and change it to be watered, also why would it be saying you can't turn a Boolean into a block? Did you make a bad if statement?
  6. I don't know about the if statement. But I am also not 100% sure how to get where the player was looking?
  7. It along the lines of player.getBlockLookLocation or something, if you are using eclipse it should help you a little bit by showing all the potential methods for it.
  8. You can clearly see you don't have any experience. Why use the block that the player is looking at, what if he places water sideways or underneath. You wouldn't target the block above the water. Also it won't save on ram and cpu usage as 2 events barely even change the ram.

    if it's water, create this for loop
    Code (Text):
     Location l = event.getBlockClicked().getRelative(event.getBlockFace()).getLocation();

    for (int x = l.getX() -3; x < l.getX() + 3; x++)
        for (int y = l.getY() -3; y < l.getY() + 3; y++)
           for (int z = l.getZ() -3; y < l.getZ() + 3; y++)  {
             //This will check for every block in a radius of 3
            Location loc = new Location(l.getWorld(), x, y, z);
            if (l.getWorld().getBlockAt(loc) != null) if (l.getWorld().getBlockAt(loc).getType() == Material.SOIL) {
                    (l.getWorld().getBlockAt(loc).setData((byte) 7);
    Check if it's soil, then check in a loop if there is water, if that's true, event.setCancelled(true); and break;