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

Implement Multimeter Functionality on Generators #3300

Closed

Conversation

md5sha256
Copy link
Contributor

@md5sha256 md5sha256 commented Oct 4, 2021

Description

Implementation of #2314
This is going to break any addons which have implementations of EnergyNetProvider.
I considered two approaches to implementing this. One was the way TheBusyBiscuit mentioned in #2314. The alternative is to perform this breaking change.

Proposed changes

Add a new method EnergyNetProvider#peekGeneratedEnergy
Add a new message messages.multimeter-generating

Related Issues (if applicable)

Resolves #2314

Checklist

  • I have fully tested the proposed changes and promise that they will not break everything into chaos.
  • I have also tested the proposed changes in combination with various popular addons and can confirm my changes do not break them.
  • I followed the existing code standards and didn't mess up the formatting.
  • I did my best to add documentation to any public classes or methods I added.
  • I have added Nonnull and Nullable annotations to my methods to indicate their behaviour for null values
  • I added sufficient Unit Tests to cover my code.

@md5sha256 md5sha256 requested a review from a team as a code owner October 4, 2021 09:46
Comment on lines +205 to +222
if (operation != null) {
if (!operation.isFinished()) {
if (isChargeable()) {
int charge = getCharge(l, data);
if (getCapacity() - charge >= getEnergyProduction()) {
return getEnergyProduction();
}
return 0;
} else {
return getEnergyProduction();
}
} else {
return 0;
}
} else {
return 0;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is overly long. Can we clean this up a bit?

}
}

private int peekGenerateEnergy(@Nonnull Location l, @Nonnull Config data, @Nonnull BlockMenu inv, @Nullable BlockMenu accessPort, FuelOperation operation) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extract some of the dupe code here? There's no reason to do a bunch of this in both peekGenerateEnergy and generateEnergy

@@ -96,6 +98,12 @@ public int getGeneratedOutput(Location l, Config data) {
}
}

@Override
public int peekGeneratedOutput(@Nonnull Location l, @Nonnull Config data) {
// Solar panels will not change when generating energy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Solar panels will not change when generating energy
// Solar panels do not consume fuel, we can fallback to the original method

Comment on lines +68 to +70
Slimefun.getLocalization().sendMessages(p, "messages.multimeter-generating", false, str -> str.replace("%stored%", stored).replace("%capacity%", capacity).replace("%generating%", generating));
} else {
Slimefun.getLocalization().sendMessage(p, "messages.multimeter", false, str -> str.replace("%stored%", stored).replace("%capacity%", capacity));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer moving multimeter out of messages now that it has multiple messages.


import javax.annotation.ParametersAreNonnullByDefault;

import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetProvider;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import belongs with the others

Comment on lines +53 to +55
* The method return how much this {@link EnergyNetProvider} is expected to provide to the {@link EnergyNet}
* and is not to be confused with {@link #getGeneratedOutput(Location, Config)}. This method will not
* consume any fuel or modify the provider in any way.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English here can be improved.

Suggested change
* The method return how much this {@link EnergyNetProvider} is expected to provide to the {@link EnergyNet}
* and is not to be confused with {@link #getGeneratedOutput(Location, Config)}. This method will not
* consume any fuel or modify the provider in any way.
* This method will return how much this {@link EnergyNetProvider} is expected to provide to the {@link EnergyNet}.
* It is not to be confused with {@link #getGeneratedOutput(Location, Config)}.
* This method <b>should not</b> consume any fuel or modify the provider in any way.

* The method return how much this {@link EnergyNetProvider} is expected to provide to the {@link EnergyNet}
* and is not to be confused with {@link #getGeneratedOutput(Location, Config)}. This method will not
* consume any fuel or modify the provider in any way.
* @param l
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line

Suggested change
* @param l
*
* @param l

@TheBusyBiscuit TheBusyBiscuit added the 🎈 Feature This Pull Request adds a new feature. label Oct 4, 2021
Copy link
Member

@TheBusyBiscuit TheBusyBiscuit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a fan of this approach.
Adding this new method will over-complicate the energy generator implementations unnecessarily.
I don't see this feature as a justifiable reason for this over-complication.

I reckon it would be much less intrusive to have Energy networks simply keep a cache of generated energy amounts per generator which is re-populated on each cycle.
The Multimeter could then just read from the current cache.

@TheBusyBiscuit TheBusyBiscuit self-assigned this Oct 4, 2021
@TheBusyBiscuit TheBusyBiscuit added the ⏰ Waiting for response We are waiting for a response. label Oct 21, 2021
@WalshyDev WalshyDev added the hacktoberfest-accepted Manual override to accept a PR for Hacktoberfest label Oct 31, 2021
@TheBusyBiscuit
Copy link
Member

Is this still being worked on or can it be considered stale?

@md5sha256
Copy link
Contributor Author

Can be considered stale. Havent had the time to work on it.

@md5sha256 md5sha256 closed this Nov 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎈 Feature This Pull Request adds a new feature. hacktoberfest-accepted Manual override to accept a PR for Hacktoberfest ⏰ Waiting for response We are waiting for a response.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow the Multimeter to be used on Generators
3 participants