mirror of
https://github.com/songoda/EpicFarming.git
synced 2025-02-26 01:11:29 +01:00
Farms will now use bone meal in its inventory to add additional crops on harvest.
This commit is contained in:
parent
076e762f4e
commit
b8a6ee3e32
@ -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<>();
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user