Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,38 @@ 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;

@ParametersAreNonnullByDefault
public ExpCollector(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
public ExpCollector(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, double range) {
super(itemGroup, item, recipeType, recipe);

createPreset(this, this::constructMenu);

this.range = range;
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) {
Expand All @@ -97,11 +100,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);
Expand All @@ -126,19 +124,19 @@ public boolean isSynchronized() {

protected void tick(Block block) {
Location location = block.getLocation();
Iterator<Entity> iterator = block.getWorld().getNearbyEntities(location, 4.0, 4.0, 4.0, n -> n instanceof ExperienceOrb && n.isValid()).iterator();
Iterator<Entity> 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);
}
Expand Down Expand Up @@ -179,4 +177,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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2381,7 +2381,9 @@ public int getEnergyConsumption() {
.register(plugin);

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})
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}, 4.0)
.setEnergyConsumption(10)
.setCapacity(1024)
.register(plugin);

new FoodComposter(itemGroups.electricity, SlimefunItems.FOOD_COMPOSTER, RecipeType.ENHANCED_CRAFTING_TABLE,
Expand Down