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

Refactor detector covers #1659

Merged
merged 16 commits into from
Apr 8, 2023
Merged

Conversation

LAGIdiot
Copy link
Contributor

@LAGIdiot LAGIdiot commented Mar 29, 2023

What

All basic detect covers had duplicated functionality for handling screwdriver, syncing data and handling option to invert value of redstone signal.

Implementation Details

Introduction of base class CoverDetectorBase which all detector covers extends.
New util function for calculating redstone signal strength. And move all redstone utils to own file RedstoneUtil.

Outcome

Detector covers has less of redundant code.
Closes: #1542

Additional Information

All functionality was preserved and testing did not find any problems related to upgrade.

There are 2 additions to lang files. I was able to handle only en_us and ja_jp. Rest of translations has to provided by others.

Potential Compatibility Issues

None expected.

As reading of inverted NBT key for CoverDetectorEnergyAdvanced was preserved and normalize for future.

@LAGIdiot LAGIdiot added the type: refactor Suggestion to refactor a section of code label Mar 29, 2023
Comment on lines +28 to +30
protected void setInverted(boolean isInverted) {
this.isInverted = isInverted;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this also need the cover holder notifications that are present in toggleInvertedWithNotification?

Right now, setInverted is called from the GUI button presses, and the notifications only happen when the cover is screwdriver clicked. I would imagine that the notifications need to happen for all cases. Which if that is true, I don't see a point to the two different invert toggle methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When setInverted is called from GUI, it will get automatically synced as GUI will handle it. That is why only screwdriving has synchronization.

src/main/java/gregtech/api/util/GTUtility.java Outdated Show resolved Hide resolved
import net.minecraft.util.EnumHand;
import net.minecraft.util.text.TextComponentTranslation;

public abstract class CoverDetectorBase extends CoverBehavior {
Copy link
Contributor

Choose a reason for hiding this comment

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

Right now all the subclasses of this base class implement the ITickable interface. Would it make sense for this base class to implement the interface instead and move the common functionality here? (I think the common functionality would just be checking the offset timer though)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am aware of this but I don't feel that providing custom function which would do exactly same thing as update (except for offset timer check) is great idea. As the added values is too small to obscure fact that cover is ticking which can be easily recognized by the update function.

@TechLord22 TechLord22 merged commit ed3142b into master Apr 8, 2023
@TechLord22 TechLord22 deleted the lagidiot-detector-cover-refactor branch April 8, 2023 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: refactor Suggestion to refactor a section of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clean up Detector Covers
3 participants