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

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

Conversation

Intybyte
Copy link
Contributor

@Intybyte Intybyte commented Oct 22, 2024

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. This is the frontrow for watching all addons burn.
  • 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.

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 Show resolved Hide resolved
@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: 99d2b29

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

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

Intybyte commented Nov 12, 2024

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

@Intybyte Intybyte marked this pull request as ready for review November 16, 2024 13:38
@Intybyte Intybyte requested a review from a team as a code owner November 16, 2024 13:38
@Boomer-1 Boomer-1 added the Build tested Used to indicate the PR preview build has been tested by one of the team label Nov 18, 2024
@Boomer-1
Copy link

tested this and everything seems to be working fine. no errors in console and all items working as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build tested Used to indicate the PR preview build has been tested by one of the team ⚡ 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.

5 participants