diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ExpCollector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ExpCollector.java index 3a6cb6d857..4697ec75fd 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ExpCollector.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ExpCollector.java @@ -44,35 +44,43 @@ public class ExpCollector extends SlimefunItem implements InventoryBlock, Energy 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 }; - private static final int ENERGY_CONSUMPTION = 10; private static final String DATA_KEY = "stored-exp"; + private final double range; + private int energyConsumedPerTick = -1; + private int energyCapacity = -1; + + @Deprecated(since = "RC-38", forRemoval = true) @ParametersAreNonnullByDefault public ExpCollector(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { + this(itemGroup, item, recipeType, recipe, 4.0); + } + + @ParametersAreNonnullByDefault + public ExpCollector(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, double range) { super(itemGroup, item, recipeType, recipe); + this.range = range; createPreset(this, this::constructMenu); - addItemHandler(onPlace(), onBreak()); } - @Nonnull - private BlockPlaceHandler onPlace() { + + private @Nonnull BlockPlaceHandler onPlace() { return new BlockPlaceHandler(false) { @Override - public void onPlayerPlace(BlockPlaceEvent e) { + public void onPlayerPlace(@Nonnull BlockPlaceEvent e) { BlockStorage.addBlockInfo(e.getBlock(), "owner", e.getPlayer().getUniqueId().toString()); } }; } - @Nonnull - private ItemHandler onBreak() { + private @Nonnull ItemHandler onBreak() { return new SimpleBlockBreakHandler() { @Override - public void onBlockBreak(Block b) { + public void onBlockBreak(@Nonnull Block b) { BlockMenu inv = BlockStorage.getInventory(b); if (inv != null) { @@ -97,11 +105,6 @@ public EnergyNetComponentType getEnergyComponentType() { return EnergyNetComponentType.CONSUMER; } - @Override - public int getCapacity() { - return 1024; - } - protected void constructMenu(BlockMenuPreset preset) { for (int slot : border) { preset.addItem(slot, new CustomItemStack(Material.PURPLE_STAINED_GLASS_PANE, " "), (p, s, item, action) -> false); @@ -126,19 +129,19 @@ public boolean isSynchronized() { protected void tick(Block block) { Location location = block.getLocation(); - Iterator iterator = block.getWorld().getNearbyEntities(location, 4.0, 4.0, 4.0, n -> n instanceof ExperienceOrb && n.isValid()).iterator(); + Iterator iterator = block.getWorld().getNearbyEntities(location, range, range, range, n -> n instanceof ExperienceOrb && n.isValid()).iterator(); int experiencePoints = 0; while (iterator.hasNext() && experiencePoints == 0) { ExperienceOrb orb = (ExperienceOrb) iterator.next(); - if (getCharge(location) < ENERGY_CONSUMPTION) { + if (getCharge(location) < getEnergyConsumption()) { return; } experiencePoints = getStoredExperience(location) + orb.getExperience(); - removeCharge(location, ENERGY_CONSUMPTION); + removeCharge(location, getEnergyConsumption()); orb.remove(); produceFlasks(location, experiencePoints); } @@ -179,4 +182,23 @@ private int getStoredExperience(Location location) { return 0; } } + + public int getEnergyConsumption() { + return energyConsumedPerTick; + } + + public ExpCollector setEnergyConsumption(int energyConsumedPerTick) { + this.energyConsumedPerTick = energyConsumedPerTick; + return this; + } + + @Override + public int getCapacity() { + return energyCapacity; + } + + public ExpCollector setCapacity(int energyCapacity) { + this.energyCapacity = energyCapacity; + return this; + } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java index 9ade30e843..9eb9b40ad0 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java @@ -2382,6 +2382,8 @@ public int getEnergyConsumption() { new ExpCollector(itemGroups.electricity, SlimefunItems.EXP_COLLECTOR, RecipeType.ENHANCED_CRAFTING_TABLE, 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}) + .setEnergyConsumption(10) + .setCapacity(1024) .register(plugin); new FoodComposter(itemGroups.electricity, SlimefunItems.FOOD_COMPOSTER, RecipeType.ENHANCED_CRAFTING_TABLE,