Skip to content

Commit

Permalink
api/Open up range field (#4231)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Walsh <[email protected]>
  • Loading branch information
Intybyte and WalshyDev authored Nov 9, 2024
1 parent 0a7fea8 commit d12ae85
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -126,19 +129,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 +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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2387,6 +2387,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,
Expand Down

0 comments on commit d12ae85

Please sign in to comment.