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

SlimefunItemStack reimplementation #4251

Draft
wants to merge 44 commits into
base: walshy/mc-1.21
Choose a base branch
from

Conversation

Intybyte
Copy link
Contributor

Description

We can't extend itemstack anymore we need to fix EVERYTHING

Proposed changes

Use a delegate instead of extending itemstack

Related Issues (if applicable)

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 have made sure that the proposed changes do not break compatibility across the supported Minecraft versions (1.16.* - 1.20.*).
  • 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.

Copy link
Contributor

Pro Tip!
You can help us label your Pull Requests by using the following branch naming convention next time you create a pull request. ❤️

Branch naming convention Label
feature/** 🎈 Feature
fix/** ✨ Fix
chore/** 🧹 Chores
api/** 🔧 API
performance/** 💡 Performance Optimization
compatibility/** 🤝 Compatibility

If your changes do not fall into any of these categories, don't worry. You can just ignore this message in that case! 👀

@WalshyDev WalshyDev changed the base branch from master to walshy/mc-1.21 October 22, 2024 20:33
@@ -306,13 +307,13 @@ public void lock() {
}

@Override
public ItemStack clone() {
Copy link
Contributor

Choose a reason for hiding this comment

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

should return ItemStack

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That wouldn't be good logic wise though

pom.xml Outdated
@@ -410,6 +410,13 @@
</exclusions>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

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

i wonder if introducing a new dep is a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is temporary for now, it makes use of all of itemstacks method so we don't have to reimplement it, once it works we can reimplement everything ourself i guess

@JustAHuman-xD
Copy link
Contributor

Really not a fan of getDelegate tbh, not sure a great other solution tho

Comment on lines 337 to 342
/**
* @return underlying ItemStack used
*/
public @Nonnull ItemStack getDelegate() {
return delegate;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Also pretty sure we don't want to do this because then they can just modify delegate which we previously prevent, it'll probably be the case regardless of what we do but gonna point it out anyways

Comment on lines 1188 to 1199
public static @Nullable SlimefunItem getByItem(@Nullable SlimefunItemStack slimefunItemStack) {
if (slimefunItemStack == null) {
return null;
}

var delegate = slimefunItemStack.getDelegate();
if (delegate.getType() == Material.AIR) {
return null;
}

return getById(slimefunItemStack.getItemId());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why the material check is here, can use isEmpty but regardless it's unnecessary, also if we add this method we should probably add the others as well, though its a lot more fluff so ehh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah i am adding these methods where i can for the time being, it is not like i can refactor everything with a simple replace either so this saves from time compared to just replacing stuff normally by hand

NOTE TO FUTURE SELF: Use ForwardingObject over lombok's @DeleGate
@Intybyte
Copy link
Contributor Author

Intybyte commented Oct 25, 2024

Once this works i will try replacing it with google's ForwardingObject rather than adding a new dependency, similar to how many paper classes are implemented so to not get surprises later on

(Edit) this breaks a lot of compatibility compared to using lombok as you need to first get the delegate and then run the methods on the delegate, instead lombok generates code to access said delegate methods directly

This was referenced Nov 7, 2024
@TheBusyBot TheBusyBot added the ⚡ Merge Conflicts This Pull Request has merged conflicts which need to be resolved! label Nov 9, 2024
Copy link
Contributor

github-actions bot commented Nov 9, 2024

Slimefun preview build

A Slimefun preview build is available for testing!
Commit: e362999

https://preview-builds.walshy.dev/download/Slimefun/4251/e362999f

Note: This is not a supported build and is only here for the purposes of testing.
Do not run this on a live server and do not report bugs anywhere but this PR!

# Conflicts:
#	pom.xml
#	src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java
#	src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/CarbonPress.java
#	src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/ElectricPress.java
#	src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/HeatedPressureChamber.java
#	src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/Reactor.java
#	src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/EnderTalisman.java
#	src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java
@Intybyte
Copy link
Contributor Author

No idea why it still says Merge Conflicts when i already solved those, it looks like there are some problems, rewriting them here for consistency

  • SoulBound tests don't pass yet
  • Locked items needs a new implementation, their tests are temporarily disabled
  • Run delombok to remove the dependency that I put on SlimefunItemStack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡ Merge Conflicts This Pull Request has merged conflicts which need to be resolved!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants