Skip to content

Commit d12ae85

Browse files
IntybyteWalshyDev
andauthored
api/Open up range field (#4231)
Co-authored-by: Daniel Walsh <walshydev@gmail.com>
1 parent 0a7fea8 commit d12ae85

File tree

2 files changed

+40
-16
lines changed

2 files changed

+40
-16
lines changed

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

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,35 +44,43 @@ 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+
53+
@Deprecated(since = "RC-38", forRemoval = true)
5054
@ParametersAreNonnullByDefault
5155
public ExpCollector(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
56+
this(itemGroup, item, recipeType, recipe, 4.0);
57+
}
58+
59+
@ParametersAreNonnullByDefault
60+
public ExpCollector(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, double range) {
5261
super(itemGroup, item, recipeType, recipe);
62+
this.range = range;
5363

5464
createPreset(this, this::constructMenu);
55-
5665
addItemHandler(onPlace(), onBreak());
5766
}
5867

59-
@Nonnull
60-
private BlockPlaceHandler onPlace() {
68+
69+
private @Nonnull BlockPlaceHandler onPlace() {
6170
return new BlockPlaceHandler(false) {
6271

6372
@Override
64-
public void onPlayerPlace(BlockPlaceEvent e) {
73+
public void onPlayerPlace(@Nonnull BlockPlaceEvent e) {
6574
BlockStorage.addBlockInfo(e.getBlock(), "owner", e.getPlayer().getUniqueId().toString());
6675
}
6776
};
6877
}
6978

70-
@Nonnull
71-
private ItemHandler onBreak() {
79+
private @Nonnull ItemHandler onBreak() {
7280
return new SimpleBlockBreakHandler() {
7381

7482
@Override
75-
public void onBlockBreak(Block b) {
83+
public void onBlockBreak(@Nonnull Block b) {
7684
BlockMenu inv = BlockStorage.getInventory(b);
7785

7886
if (inv != null) {
@@ -97,11 +105,6 @@ public EnergyNetComponentType getEnergyComponentType() {
97105
return EnergyNetComponentType.CONSUMER;
98106
}
99107

100-
@Override
101-
public int getCapacity() {
102-
return 1024;
103-
}
104-
105108
protected void constructMenu(BlockMenuPreset preset) {
106109
for (int slot : border) {
107110
preset.addItem(slot, new CustomItemStack(Material.PURPLE_STAINED_GLASS_PANE, " "), (p, s, item, action) -> false);
@@ -126,19 +129,19 @@ public boolean isSynchronized() {
126129

127130
protected void tick(Block block) {
128131
Location location = block.getLocation();
129-
Iterator<Entity> iterator = block.getWorld().getNearbyEntities(location, 4.0, 4.0, 4.0, n -> n instanceof ExperienceOrb && n.isValid()).iterator();
132+
Iterator<Entity> iterator = block.getWorld().getNearbyEntities(location, range, range, range, n -> n instanceof ExperienceOrb && n.isValid()).iterator();
130133
int experiencePoints = 0;
131134

132135
while (iterator.hasNext() && experiencePoints == 0) {
133136
ExperienceOrb orb = (ExperienceOrb) iterator.next();
134137

135-
if (getCharge(location) < ENERGY_CONSUMPTION) {
138+
if (getCharge(location) < getEnergyConsumption()) {
136139
return;
137140
}
138141

139142
experiencePoints = getStoredExperience(location) + orb.getExperience();
140143

141-
removeCharge(location, ENERGY_CONSUMPTION);
144+
removeCharge(location, getEnergyConsumption());
142145
orb.remove();
143146
produceFlasks(location, experiencePoints);
144147
}
@@ -179,4 +182,23 @@ private int getStoredExperience(Location location) {
179182
return 0;
180183
}
181184
}
185+
186+
public int getEnergyConsumption() {
187+
return energyConsumedPerTick;
188+
}
189+
190+
public ExpCollector setEnergyConsumption(int energyConsumedPerTick) {
191+
this.energyConsumedPerTick = energyConsumedPerTick;
192+
return this;
193+
}
194+
195+
@Override
196+
public int getCapacity() {
197+
return energyCapacity;
198+
}
199+
200+
public ExpCollector setCapacity(int energyCapacity) {
201+
this.energyCapacity = energyCapacity;
202+
return this;
203+
}
182204
}

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,6 +2387,8 @@ public int getEnergyConsumption() {
23872387

23882388
new ExpCollector(itemGroups.electricity, SlimefunItems.EXP_COLLECTOR, RecipeType.ENHANCED_CRAFTING_TABLE,
23892389
new ItemStack[] {null, SlimefunItems.BLISTERING_INGOT_3, null, SlimefunItems.WITHER_PROOF_OBSIDIAN, SlimefunItems.AUTO_ENCHANTER, SlimefunItems.WITHER_PROOF_OBSIDIAN, SlimefunItems.ALUMINUM_BRONZE_INGOT, SlimefunItems.ELECTRIC_MOTOR, SlimefunItems.ALUMINUM_BRONZE_INGOT})
2390+
.setEnergyConsumption(10)
2391+
.setCapacity(1024)
23902392
.register(plugin);
23912393

23922394
new FoodComposter(itemGroups.electricity, SlimefunItems.FOOD_COMPOSTER, RecipeType.ENHANCED_CRAFTING_TABLE,

0 commit comments

Comments
 (0)