-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathInfernalFarm.java
More file actions
109 lines (90 loc) · 3.31 KB
/
InfernalFarm.java
File metadata and controls
109 lines (90 loc) · 3.31 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package io.github.thebusybiscuit.sensibletoolbox.blocks.machines;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.Ageable;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapedRecipe;
import io.github.thebusybiscuit.sensibletoolbox.items.GoldCombineHoe;
import io.github.thebusybiscuit.sensibletoolbox.items.components.MachineFrame;
public class InfernalFarm extends AutoFarm {
private static final int RADIUS = 5;
private Set<Block> blocks;
private Material buffer;
public InfernalFarm() {
blocks = new HashSet<>();
}
public InfernalFarm(ConfigurationSection conf) {
super(conf);
blocks = new HashSet<>();
}
@Override
public Material getMaterial() {
return Material.NETHER_BRICKS;
}
@Override
public String getItemName() {
return "Infernal Farm";
}
@Override
public String[] getLore() {
return new String[] { "Automatically harvests and replants", "Nether Warts", "in a " + RADIUS + "x" + RADIUS + " Radius 2 Blocks above the Machine" };
}
@Override
public Recipe getRecipe() {
MachineFrame frame = new MachineFrame();
GoldCombineHoe hoe = new GoldCombineHoe();
registerCustomIngredients(frame, hoe);
ShapedRecipe res = new ShapedRecipe(getKey(), toItemStack());
res.shape("NHN", "IFI", "RGR");
res.setIngredient('R', Material.REDSTONE);
res.setIngredient('G', Material.GOLD_INGOT);
res.setIngredient('I', Material.IRON_INGOT);
res.setIngredient('H', hoe.getMaterial());
res.setIngredient('F', frame.getMaterial());
res.setIngredient('N', Material.NETHER_BRICK);
return res;
}
@Override
public void onBlockRegistered(Location location, boolean isPlacing) {
int range = RADIUS / 2;
Block block = location.getBlock();
for (int x = -range; x <= range; x++) {
for (int z = -range; z <= range; z++) {
blocks.add(block.getRelative(x, 2, z));
}
}
super.onBlockRegistered(location, isPlacing);
}
@Override
public void onServerTick() {
if (!isJammed()) {
if (getCharge() >= getScuPerCycle()) {
for (Block crop : blocks) {
if (crop.getType() == Material.NETHER_WART) {
Ageable ageable = (Ageable) crop.getBlockData();
if (ageable.getAge() >= ageable.getMaximumAge()) {
setCharge(getCharge() - getScuPerCycle());
ageable.setAge(0);
crop.getWorld().playEffect(crop.getLocation(), Effect.STEP_SOUND, crop.getType());
crop.setBlockData(ageable);
setJammed(!output(Material.NETHER_WART));
break;
}
}
}
}
} else if (buffer != null) {
setJammed(!output(buffer));
}
super.onServerTick();
}
@Override
public double getScuPerCycle() {
return 50.0;
}
}