Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api/Open up range field #4231

Merged
merged 9 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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,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
WalshyDev marked this conversation as resolved.
Show resolved Hide resolved
@ParametersAreNonnullByDefault
public ExpCollector(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
this(itemGroup, item, recipeType, recipe, 4.0);
}
Intybyte marked this conversation as resolved.
Show resolved Hide resolved

@ParametersAreNonnullByDefault
public ExpCollector(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, double range) {
Intybyte marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -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,
Expand Down