Skip to content

Okayu enchantment#5

Open
cpaca wants to merge 39 commits intodlee13:mainfrom
cpaca:okayu-enchantment
Open

Okayu enchantment#5
cpaca wants to merge 39 commits intodlee13:mainfrom
cpaca:okayu-enchantment

Conversation

@cpaca
Copy link
Copy Markdown
Contributor

@cpaca cpaca commented Feb 24, 2023

Added an enchantment for okayu.

I'd go into more detail but I'd also like to sleep.

Finished implementation (only thing missing was for mods to change/approve recipe) on 2/22, so that's a :meow: in my books.

cpaca and others added 26 commits February 21, 2023 21:08
See title.

Still a lot to do though. For now, they're exactly identical aside from the "when does it autoeat", though while testing I noticed they're both 10 levels to apply when autoeat probably shouldn't be 10 levels.

More importantly, though, the next commit will likely be about letting me make some Enchant's exclusive to other Enchant's. I'll need it anyway to make Haachama's enchant exclusive to Space Bread.
That doesn't mean they have to, but they can be.

I looked everywhere where Enchant.exclusive is used (thanks, IntelliJ). I rewrote Utility.java's usage accordingly, and put comments in Events.java's 4 usages explaining why I didn't touch them.

I have not tested this code; the "test plan" for this is to try to put multiple AutoEat enchantments onto one helmet.
Not implemented yet; I stopped because I realized maybe I should write that in Utility incase we want any other items to recursively search for an item in your inventory.
Yes, I had this code all done when I did the last commit. I just told GH desktop to not commit the last thing in the same commit, so you can look at the code for this one separately.
Hmm... This Utility.recursiveSearchForItem function may need some reworking, though. I can change the ItemStack just fine but it doesn't update in the BlockMetaData.
I put an implNote that says what I think about this implementation.
I might need this later for recipes, or maybe it'll be deleted as better recipes are requested.
This will probably end up changed later, but whatever.
That took a bit longer than I expected.
REMINDER TO SELF:

If you ever, *ever* need to Fix Recipes again, make sure the HoloItem ingredients are in Events.ingredients.
Only one form of AutoEat, which - since it's going on Okayu - I guess I'll name it MoguMogu.

This code doesn't work, but I at least fixed the recipes. Now to fix the rest of the stuff...
Yes, I did just copy Enchant.java from upstream here. Hopefully that fixes the merge conflicts?
Successfully merge upstream commit.
Remove lingering instances of old AutoEats
Since we're just using MoguMogu now.
* Nutrition values from eating certain foods.
* Note: Chorus fruit and cake aren't listed here.
*/
public static final Map<Material, float[]> nutritionValues = new HashMap<>(){{
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

EnumMap

Copy link
Copy Markdown
Owner

@dlee13 dlee13 Mar 20, 2023

Choose a reason for hiding this comment

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

It's possible to get these values from the server internals by using reflection.
Relevant packages are:
net.minecraft.world.food
net.minecraft.world.item
We would want to access the foodProperties field of each Item.

The way to not hardcode this would be to iterate all materials, filtering for the ones that are edible and not legacy -> create a bukkit ItemStack for each -> convert to nms ItemStack -> ItemStack::getItem -> Item::getFoodProperties -> then the food properties instance has a bunch of getters for stuff.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

"Convert to nms ItemStack" Ah, I was avoiding using NMS because I wasn't sure if we were allowed to have it, but since we are, this doesn't have to be hardcoded... might even be able to remove the variable entirely.

Reminder to self: Confirm what happens if you AutoEat Chorus Fruit.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

See discussion in discord

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

We'd better move the Class and Method reflection stuff out to a new class so it'll be more maintainable and not such a mess. For iterating the Materials, it's gonna be:

for (final Material material : Material.values()) {
    if (material.isEdible() && !material.isLegacy()) {
        ... // do the food property getting stuff and insert the values into the map
    }
}

Comment thread src/main/java/com/klin/holoItems/utility/Utility.java Outdated
nutritionValues is still hard-coded though and I don't know how to fix that.

The instructions I was given were "convert to NMS ItemStack" and I don't know how.
cpaca added 2 commits March 21, 2023 23:08
Still not done, but it's progress.

Feels like black magic.
cpaca added 5 commits March 23, 2023 16:02
Note: This will eat chorus fruit but not teleport.
[BROKEN] This code is broken, but I'm uploading it so Termi can take a peek and see if I've missed something or if we'll come to the same conclusion
public MoguMogu(){
super(name, material, lore, durability, shiny, cost, acceptedIds, acceptedTypes, expCost);

// Incase I make an error like use BEETROOTS (block) insteaad of BEETROOT (item)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Could be made into a junit test instead

Copy link
Copy Markdown
Owner

@dlee13 dlee13 Mar 25, 2023

Choose a reason for hiding this comment

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

On second thought, it'll be pointless after we make it not hardcoded.

Comment thread src/main/java/com/klin/holoItems/utility/ReflectionUtils.java
cpaca added 5 commits April 6, 2023 18:47
This is a separate commit to the next one incase I want to undo the next commit but keep the black magic that I've written here.
Unfortunately now the hunger and saturation aren't increasing, for some reason.
I didn't do the nutritionValues changes because I figured we wouldn't need it if I got finishUsingItem to work correctly.

On that note, finishUsingItem should have been fixed the past ... many commits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants