Slimefun / Slimefun4

Slimefun 4 - A unique Spigot/Paper plugin that looks and feels like a modpack. We've been giving you backpacks, jetpacks, reactors and much more since 2013.
GNU General Public License v3.0
966 stars 545 forks source link

SoulboundItem#getByItem(ItemStack) always returns instance of SlimefunItem #2105

Closed mfnalex closed 4 years ago

mfnalex commented 4 years ago

When using SoulboundItem#getByItem(ItemStack), it always returns an instance of SlimefunItem instead of SoulboundItem.

It would be nice if the method would return a SoulboundItem instead. I need that for my AngelChest plugin to be able to detect SoulboundItems. Could that be added?

The following class should @Override the getByItem(ItemStack) method if possible: https://github.com/TheBusyBiscuit/Slimefun4/blob/master/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundItem.java

WalshyDev commented 4 years ago

Firstly, you can just PR this you know. Secondly, you can also just instanceof and cast it.

TheBusyBiscuit commented 4 years ago

You can always do an instanceof check and cast it, adding it to each implementation of SlimefunItem wouldn't be practical in my opinion.

But more importantly, if you are trying to check if an ItemStack is soulbound, then this is the wrong class to look for, only some soulbound SlimefunItems extend SoulboundItem, there is an interface called Soulbound which is used to indicate this behaviour. And even then, using a Soulbound Rune, any ItemStack can be marked as "soulbound", so what you are really looking for is the following method: SlimefunUtils.isSoulbound(ItemStack) which covers both, predefined Soulbound Items and customly made ones.

I would also remind you to please not use our Bug Tracker for this, we have a discord server for these things. There are much more people around and they can usually answer much faster.

TheBusyBot commented 4 years ago

Your issue was closed, it may fall under one or more of the following categories. Please wait for an admin to tick off the points that apply.

Please respond below, if you have any questions. Do not open a new Issue unless explicitly told otherwise, comment below or edit your post instead.

Make sure to check out our article on How to report bugs for even more information.

mfnalex commented 4 years ago

Firstly, you can just PR this you know. Secondly, you can also just instanceof and cast it.

Firstly, I know that second. Secondly, no I cannot:

            if (SoulboundItem.getByItem(item) instanceof SoulboundItem) {
                System.out.println("soulbound");
                return true;

            }

Never returns true for soulbound items.

mfnalex commented 4 years ago

You can always do an instanceof check and cast it, adding it to each implementation of SlimefunItem wouldn't be practical in my opinion.

But more importantly, if you are trying to check if an ItemStack is soulbound, then this is the wrong class to look for, only some soulbound SlimefunItems extend SoulboundItem, there is an interface called Soulbound which is used to indicate this behaviour. And even then, using a Soulbound Rune, any ItemStack can be marked as "soulbound", so what you are really looking for is the following method: SlimefunUtils.isSoulbound(ItemStack) which covers both, predefined Soulbound Items and customly made ones.

I would also remind you to please not use our Bug Tracker for this, we have a discord server for these things. There are much more people around and they can usually answer much faster.

Thanks, I will try that. Although I find it quite pointless to tell me to not use your bugtracker for what I thought was a bug. If a method is called "getXYZ", it should return XYZ.

TheBusyBiscuit commented 4 years ago

Firstly, you can just PR this you know. Secondly, you can also just instanceof and cast it.

Firstly, I know that second. Secondly, no I cannot:

            if (SoulboundItem.getByItem(item) instanceof SoulboundItem) {
                System.out.println("soulbound");
                return true;

            }

Never returns true for soulbound items.

That's because it's the wrong class like I explained above.

Thanks, I will try that. Although I find it quite pointless to tell me to not use your bugtracker for what I thought was a bug. If a method is called "getXYZ", it should return XYZ.

I just wanted to remind you that these sorts of conversations get handled quicker and better on discord. Plus you didn't stick to the format of a bug report, hence why this definitely wouldn't qualify as one. Even if something would qualify as a bug, we still recommend people (in our bug reporting guide) to come onto discord first and exchange with other players who may or may not be able to reproduce the behaviour. It just helps us combat bug report pollution and makes it easier to manage and focus on important fixes.

I can understand the confusion behind this method but I don't think it would really be practical, as it would have to be added to all dozens of subclasses to SlimefunItem if we were to enforce this behaviour. I am open to a debate or pull request on this but I personally don't really see much of a benefit over a simple instanceof check as of right now.

Anyway, I am just asking you kindly to use the correct channels to contact us. I'm still replying here on GitHub, it's just a kind recommendation.