Skip to content

Commit 948db25

Browse files
committed
Refactor a bit to follow code style + add capacity and consumption methods
1 parent 2fd0f8a commit 948db25

File tree

1 file changed

+30
-15
lines changed
  • src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities

1 file changed

+30
-15
lines changed

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ExpCollector.java

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,35 +44,38 @@ public class ExpCollector extends SlimefunItem implements InventoryBlock, Energy
4444

4545
private final int[] border = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 };
4646

47-
private static final int ENERGY_CONSUMPTION = 10;
4847
private static final String DATA_KEY = "stored-exp";
4948

49+
private final double range;
50+
private int energyConsumedPerTick = -1;
51+
private int energyCapacity = -1;
52+
5053
@ParametersAreNonnullByDefault
51-
public ExpCollector(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
54+
public ExpCollector(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, double range) {
5255
super(itemGroup, item, recipeType, recipe);
5356

5457
createPreset(this, this::constructMenu);
5558

59+
this.range = range;
5660
addItemHandler(onPlace(), onBreak());
5761
}
5862

59-
@Nonnull
60-
private BlockPlaceHandler onPlace() {
63+
64+
private @Nonnull BlockPlaceHandler onPlace() {
6165
return new BlockPlaceHandler(false) {
6266

6367
@Override
64-
public void onPlayerPlace(BlockPlaceEvent e) {
68+
public void onPlayerPlace(@Nonnull BlockPlaceEvent e) {
6569
BlockStorage.addBlockInfo(e.getBlock(), "owner", e.getPlayer().getUniqueId().toString());
6670
}
6771
};
6872
}
6973

70-
@Nonnull
71-
private ItemHandler onBreak() {
74+
private @Nonnull ItemHandler onBreak() {
7275
return new SimpleBlockBreakHandler() {
7376

7477
@Override
75-
public void onBlockBreak(Block b) {
78+
public void onBlockBreak(@Nonnull Block b) {
7679
BlockMenu inv = BlockStorage.getInventory(b);
7780

7881
if (inv != null) {
@@ -97,11 +100,6 @@ public EnergyNetComponentType getEnergyComponentType() {
97100
return EnergyNetComponentType.CONSUMER;
98101
}
99102

100-
@Override
101-
public int getCapacity() {
102-
return 1024;
103-
}
104-
105103
protected void constructMenu(BlockMenuPreset preset) {
106104
for (int slot : border) {
107105
preset.addItem(slot, new CustomItemStack(Material.PURPLE_STAINED_GLASS_PANE, " "), (p, s, item, action) -> false);
@@ -132,13 +130,13 @@ protected void tick(Block block) {
132130
while (iterator.hasNext() && experiencePoints == 0) {
133131
ExperienceOrb orb = (ExperienceOrb) iterator.next();
134132

135-
if (getCharge(location) < ENERGY_CONSUMPTION) {
133+
if (getCharge(location) < getEnergyConsumption()) {
136134
return;
137135
}
138136

139137
experiencePoints = getStoredExperience(location) + orb.getExperience();
140138

141-
removeCharge(location, ENERGY_CONSUMPTION);
139+
removeCharge(location, getEnergyConsumption());
142140
orb.remove();
143141
produceFlasks(location, experiencePoints);
144142
}
@@ -179,4 +177,21 @@ private int getStoredExperience(Location location) {
179177
return 0;
180178
}
181179
}
180+
181+
public int getEnergyConsumption() {
182+
return energyConsumedPerTick;
183+
}
184+
185+
public void setEnergyConsumption(int energyConsumedPerTick) {
186+
this.energyConsumedPerTick = energyConsumedPerTick;
187+
}
188+
189+
@Override
190+
public int getCapacity() {
191+
return energyCapacity;
192+
}
193+
194+
public void setCapacity(int energyCapacity) {
195+
this.energyCapacity = energyCapacity;
196+
}
182197
}

0 commit comments

Comments
 (0)