Farms will now use bone meal in its inventory to add additional crops on harvest.

This commit is contained in:
Brianna O'Keefe 2018-09-19 14:41:50 -04:00
parent 076e762f4e
commit b8a6ee3e32
3 changed files with 30 additions and 2 deletions

View File

@ -70,8 +70,8 @@ public class FarmTask extends BukkitRunnable {
if (material == null || farm == null || cropTypeData == null) return false;
ItemStack stack = new ItemStack(cropTypeData.getYieldMaterial());
ItemStack seedStack = new ItemStack(cropTypeData.getSeedMaterial(), random.nextInt(3) + 1);
ItemStack stack = new ItemStack(cropTypeData.getYieldMaterial(), useBoneMeal(farm) ? random.nextInt(2) + 2 : 1);
ItemStack seedStack = new ItemStack(cropTypeData.getSeedMaterial(), random.nextInt(3) + 1 + (useBoneMeal(farm) ? 1 : 0));
if (!canMove(farm.getInventory(), stack)) return false;
farm.getInventory().addItem(stack);
@ -79,6 +79,29 @@ public class FarmTask extends BukkitRunnable {
return true;
}
private boolean useBoneMeal(Farm farm) {
Inventory inventory = farm.getInventory();
for (int i = 27; i < inventory.getSize(); i++) {
if (inventory.getItem(i) == null || inventory.getItem(i).getType() == Material.AIR) continue;
ItemStack item = inventory.getItem(i);
if (item.getType() != Material.BONE_MEAL) continue;
int newAmt = item.getAmount() - 1;
if (newAmt <= 0)
inventory.setItem(i, null);
else
item.setAmount(newAmt);
return true;
}
return false;
}
public List<Block> getCrops(Farm farm, boolean add) {
List<Block> crops = new ArrayList<>();

View File

@ -5,7 +5,11 @@ import com.songoda.epicfarming.farming.Crop;
import org.bukkit.CropState;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Hopper;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Crops;
import org.bukkit.scheduler.BukkitRunnable;

View File

@ -59,6 +59,7 @@ public class HopperTask extends BukkitRunnable {
int amtToMove = 1;
ItemStack item = inventory.getItem(i);
if (item.getType() == Material.BONE_MEAL) continue;
ItemStack toMove = item.clone();
toMove.setAmount(amtToMove);