-
Notifications
You must be signed in to change notification settings - Fork 497
/
CropManager.java
82 lines (68 loc) · 2.34 KB
/
CropManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package buildcraft.api.crops;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public final class CropManager {
private static List<ICropHandler> handlers = new ArrayList<ICropHandler>();
private static ICropHandler defaultHandler;
private CropManager() {
}
public static void registerHandler(ICropHandler cropHandler) {
handlers.add(cropHandler);
}
public static void setDefaultHandler(ICropHandler cropHandler) {
defaultHandler = cropHandler;
}
public static ICropHandler getDefaultHandler() {
return defaultHandler;
}
public static boolean isSeed(ItemStack stack) {
for (ICropHandler cropHandler : handlers) {
if (cropHandler.isSeed(stack)) {
return true;
}
}
return defaultHandler.isSeed(stack);
}
public static boolean canSustainPlant(World world, ItemStack seed, int x, int y, int z) {
for (ICropHandler cropHandler : handlers) {
if (cropHandler.isSeed(seed) && cropHandler.canSustainPlant(world, seed, x, y, z)) {
return true;
}
}
return defaultHandler.canSustainPlant(world, seed, x, y, z);
}
public static boolean plantCrop(World world, EntityPlayer player, ItemStack seed, int x, int y,
int z) {
for (ICropHandler cropHandler : handlers) {
if (cropHandler.isSeed(seed) && cropHandler.canSustainPlant(world, seed, x, y, z)
&& cropHandler.plantCrop(world, player, seed, x, y, z)) {
return true;
}
}
return defaultHandler.plantCrop(world, player, seed, x, y, z);
}
public static boolean isMature(IBlockAccess blockAccess, Block block, int meta, int x, int y,
int z) {
for (ICropHandler cropHandler : handlers) {
if (cropHandler.isMature(blockAccess, block, meta, x, y, z)) {
return true;
}
}
return defaultHandler.isMature(blockAccess, block, meta, x, y, z);
}
public static boolean harvestCrop(World world, int x, int y, int z, List<ItemStack> drops) {
for (ICropHandler cropHandler : handlers) {
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
if (cropHandler.isMature(world, block, meta, x, y, z)) {
return cropHandler.harvestCrop(world, x, y, z, drops);
}
}
return defaultHandler.harvestCrop(world, x, y, z, drops);
}
}