mirror of
https://github.com/songoda/EpicFarming.git
synced 2025-02-15 12:02:39 +01:00
Added a system to despawn broken farms.
Fixed issues with some crops not auto replanting. Reimplemented the CropType enum.
This commit is contained in:
parent
4844d25b5f
commit
418fa34f55
@ -65,9 +65,15 @@ public class FarmingHandler {
|
|||||||
|
|
||||||
private void hopRunner() {
|
private void hopRunner() {
|
||||||
for (Farm farm : instance.getFarmManager().getFarms().values()) {
|
for (Farm farm : instance.getFarmManager().getFarms().values()) {
|
||||||
|
if (farm.getLocation().getBlock() == null) {
|
||||||
|
instance.getFarmManager().removeFarm(farm.getLocation());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
Block block = farm.getLocation().getBlock();
|
Block block = farm.getLocation().getBlock();
|
||||||
|
|
||||||
if (block.getRelative(BlockFace.DOWN).getType() == Material.HOPPER) {
|
if (block.getRelative(BlockFace.DOWN).getType() != Material.HOPPER)
|
||||||
|
return;
|
||||||
|
|
||||||
Inventory inventory = farm.getInventory();
|
Inventory inventory = farm.getInventory();
|
||||||
Inventory hopperInventory = ((Hopper) block.getRelative(BlockFace.DOWN).getState()).getInventory();
|
Inventory hopperInventory = ((Hopper) block.getRelative(BlockFace.DOWN).getState()).getInventory();
|
||||||
|
|
||||||
@ -93,7 +99,7 @@ public class FarmingHandler {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canHop(Inventory i, ItemStack item) {
|
private boolean canHop(Inventory i, ItemStack item) {
|
||||||
@ -109,10 +115,11 @@ public class FarmingHandler {
|
|||||||
private boolean doDrop(Farm farm, Material material) {
|
private boolean doDrop(Farm farm, Material material) {
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
|
|
||||||
CropType.CropTypeData cropTypeData = CropType.getCropType(material);
|
CropType cropTypeData = CropType.getCropType(material);
|
||||||
|
|
||||||
if (material == null || farm == null || cropTypeData == null) return false;
|
if (material == null || farm == null || cropTypeData == null) return false;
|
||||||
|
|
||||||
|
|
||||||
ItemStack stack = new ItemStack(cropTypeData.getYieldMaterial());
|
ItemStack stack = new ItemStack(cropTypeData.getYieldMaterial());
|
||||||
ItemStack seedStack = new ItemStack(cropTypeData.getSeedMaterial(), random.nextInt(3) + 1);
|
ItemStack seedStack = new ItemStack(cropTypeData.getSeedMaterial(), random.nextInt(3) + 1);
|
||||||
|
|
||||||
|
@ -6,81 +6,21 @@ import org.bukkit.Material;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
public enum CropType {
|
||||||
* A list of all crop types available in Minecraft that can be
|
|
||||||
* modified by CropsReborn
|
|
||||||
*/
|
|
||||||
public class CropType {
|
|
||||||
private static List<CropTypeData> crops = new ArrayList<>();
|
|
||||||
|
|
||||||
private CropType() {
|
WHEAT("Wheat", Material.WHEAT, Material.WHEAT, Material.WHEAT_SEEDS),
|
||||||
crops.add(new CropTypeData("Wheat", Material.WHEAT, Material.WHEAT, Material.WHEAT_SEEDS));
|
|
||||||
crops.add(new CropTypeData("Carrot", Material.CARROT, Material.CARROT, Material.CARROT));
|
|
||||||
crops.add(new CropTypeData("Potato", Material.POTATO, Material.POTATO, Material.POTATO));
|
|
||||||
crops.add(new CropTypeData("Watermelon", Material.MELON_STEM, Material.MELON, Material.MELON_SEEDS));
|
|
||||||
crops.add(new CropTypeData("Pumpkin", Material.PUMPKIN_STEM, Material.PUMPKIN, Material.PUMPKIN_SEEDS));
|
|
||||||
crops.add(new CropTypeData("Melon", Material.MELON_STEM, Material.MELON, Material.MELON_SEEDS));
|
|
||||||
|
|
||||||
crops.add(new CropTypeData("Nether Wart", Material.NETHER_WART_BLOCK, Material.NETHER_WART, Material.NETHER_WART));
|
CARROT("Carrot", Material.CARROTS, Material.CARROT, Material.CARROT),
|
||||||
crops.add(new CropTypeData("Beetroot", Material.BEETROOT, Material.BEETROOT, Material.BEETROOT_SEEDS));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleAdd() {
|
POTATO("Potato", Material.POTATOES, Material.POTATO, Material.POTATO),
|
||||||
if (crops.size() < 1) {
|
|
||||||
crops.add(new CropTypeData("Wheat", Material.WHEAT, Material.WHEAT, Material.WHEAT_SEEDS));
|
|
||||||
crops.add(new CropTypeData("Carrot", Material.CARROT, Material.CARROT, Material.CARROT));
|
|
||||||
crops.add(new CropTypeData("Potato", Material.POTATO, Material.POTATO, Material.POTATO));
|
|
||||||
crops.add(new CropTypeData("Watermelon", Material.MELON_STEM, Material.MELON, Material.MELON_SEEDS));
|
|
||||||
crops.add(new CropTypeData("Pumpkin", Material.PUMPKIN_STEM, Material.PUMPKIN, Material.PUMPKIN_SEEDS));
|
|
||||||
crops.add(new CropTypeData("Melon", Material.MELON_STEM, Material.MELON, Material.MELON_SEEDS));
|
|
||||||
|
|
||||||
crops.add(new CropTypeData("Nether Wart", Material.NETHER_WART_BLOCK, Material.NETHER_WART, Material.NETHER_WART));
|
BEETROOT("Beetroot", Material.BEETROOTS, Material.BEETROOT, Material.BEETROOT_SEEDS),
|
||||||
crops.add(new CropTypeData("Beetroot", Material.BEETROOT, Material.BEETROOT, Material.BEETROOT_SEEDS)); }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean isCrop(Material material) {
|
|
||||||
for (CropTypeData type : values())
|
|
||||||
if (type.getBlockMaterial() == material) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isCropSeed(Material material) {
|
|
||||||
for (CropTypeData type : values())
|
|
||||||
if (type.getSeedMaterial() == material) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CropTypeData getCropType(Material material) {
|
|
||||||
for (CropTypeData type : values())
|
|
||||||
if (type.getBlockMaterial() == material) return type;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<CropTypeData> values() {
|
|
||||||
if (crops.size() < 1) {
|
|
||||||
new CropType().handleAdd();
|
|
||||||
}
|
|
||||||
return crops;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
WHEAT("Wheat", Material.CROPS, Material.WHEAT, Material.SEEDS),
|
|
||||||
|
|
||||||
CARROT("Carrot", Material.CARROT, Material.CARROT_ITEM, Material.CARROT_ITEM),
|
|
||||||
|
|
||||||
POTATO("Potato", Material.POTATO, Material.CARROT_ITEM, Material.POTATO_ITEM),
|
|
||||||
|
|
||||||
BEETROOT("Beetroot", Material.BEETROOT_BLOCK, Material.BEETROOT, Material.BEETROOT_SEEDS),
|
|
||||||
|
|
||||||
WATER_MELON_STEM("Watermelon", Material.MELON_STEM, Material.MELON, Material.MELON_SEEDS),
|
WATER_MELON_STEM("Watermelon", Material.MELON_STEM, Material.MELON, Material.MELON_SEEDS),
|
||||||
|
|
||||||
PUMPKIN_STEM("Pumpkin", Material.PUMPKIN_STEM, Material.PUMPKIN, Material.PUMPKIN_SEEDS),
|
PUMPKIN_STEM("Pumpkin", Material.PUMPKIN_STEM, Material.PUMPKIN, Material.PUMPKIN_SEEDS),
|
||||||
|
|
||||||
NETHER_WARTS("Nether Wart", Material.NETHER_WART_BLOCK, Material.NETHER_WARTS, Material.NETHER_WARTS);
|
NETHER_WARTS("Nether Wart", Material.NETHER_WART_BLOCK, Material.NETHER_WART, Material.NETHER_WART);
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final Material yieldMaterial, blockMaterial, seedMaterial;
|
private final Material yieldMaterial, blockMaterial, seedMaterial;
|
||||||
@ -92,50 +32,77 @@ public class CropType {
|
|||||||
this.yieldMaterial = yieldMaterial;
|
this.yieldMaterial = yieldMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Material getBlockMaterial() {
|
/**
|
||||||
return blockMaterial;
|
* Get the friendly name of the crop
|
||||||
}
|
*
|
||||||
|
* @return the name of the crop
|
||||||
public Material getYieldMaterial() {
|
|
||||||
return yieldMaterial;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Material getSeedMaterial() {
|
|
||||||
return seedMaterial;
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class CropTypeData {
|
|
||||||
private final String name;
|
|
||||||
private final Material blockMaterial;
|
|
||||||
private final Material seedMaterial;
|
|
||||||
private final Material yieldMaterial;
|
|
||||||
|
|
||||||
public CropTypeData(String _name, Material _blockMaterial, Material _seedMaterial, Material _yieldMaterial) {
|
|
||||||
name = _name;
|
|
||||||
blockMaterial = _blockMaterial;
|
|
||||||
seedMaterial = _seedMaterial;
|
|
||||||
yieldMaterial = _yieldMaterial;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the blockMaterial that represents this crop type
|
||||||
|
*
|
||||||
|
* @return the represented blockMaterial
|
||||||
|
*/
|
||||||
public Material getBlockMaterial() {
|
public Material getBlockMaterial() {
|
||||||
return blockMaterial;
|
return blockMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the yield Material that represents this crop type
|
||||||
|
*
|
||||||
|
* @return the represented yieldMaterial
|
||||||
|
*/
|
||||||
|
public Material getYieldMaterial() {
|
||||||
|
return yieldMaterial;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the blockMaterial that represents the seed item for this crop type
|
||||||
|
*
|
||||||
|
* @return the represented seed blockMaterial
|
||||||
|
*/
|
||||||
public Material getSeedMaterial() {
|
public Material getSeedMaterial() {
|
||||||
return seedMaterial;
|
return seedMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Material getYieldMaterial() {
|
/**
|
||||||
return yieldMaterial;
|
* Check whether a specific blockMaterial is an enumerated crop type or not
|
||||||
|
*
|
||||||
|
* @param material the blockMaterial to check
|
||||||
|
* @return true if it is a crop, false otherwise
|
||||||
|
*/
|
||||||
|
public static boolean isCrop(Material material) {
|
||||||
|
for (CropType type : values())
|
||||||
|
if (type.getBlockMaterial() == material) return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether a specific blockMaterial is an enumerated crop type seed or not
|
||||||
|
*
|
||||||
|
* @param material the blockMaterial to check
|
||||||
|
* @return true if it is a seed, false otherwise
|
||||||
|
*/
|
||||||
|
public static boolean isCropSeed(Material material) {
|
||||||
|
for (CropType type : values())
|
||||||
|
if (type.getSeedMaterial() == material) return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the crop type based on the specified blockMaterial
|
||||||
|
*
|
||||||
|
* @param material the crop blockMaterial
|
||||||
|
* @return the respective CropType. null if none found
|
||||||
|
*/
|
||||||
|
public static CropType getCropType(Material material) {
|
||||||
|
for (CropType type : values())
|
||||||
|
if (type.getBlockMaterial() == material) return type;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user