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

Allow Trajectories to be used with off-hand item #4546

Merged

Conversation

snarkyerica
Copy link
Contributor

Type of change

  • Bug fix
  • New feature

Description

Allows Trajectories to be used with off-hand item stack, by checking both the MainHand and OffHand stacks when determining whether the item in the stack is in the whitelist instead of just the MainHand stack before returning, even if the MainHand stack is not null.

How Has This Been Tested?

image

Checklist:

  • My code follows the style guidelines of this project.
  • I have added comments to my code in more complex areas.
  • I have tested the code in both development and production environments.

@abb3v
Copy link
Contributor

abb3v commented Apr 24, 2024

You're making a redundant function call twice @snarkyerica; you are checking the off-hand stack twice if the main hand stack does not contain an item in the list items, this can easily be simplified down to;

ItemStack itemStack = player.getMainHandStack();
if (itemStack == null || !items.get().contains(itemStack.getItem())) {
    itemStack = player.getOffHandStack();
    if (itemStack == null || !items.get().contains(itemStack.getItem())) return;
}

// Calculate paths
if (!simulator.set(player, itemStack, 0, accurate.get(), tickDelta)) return;

@RacoonDog
Copy link
Contributor

You're making a redundant function call twice @snarkyerica; you are checking the off-hand stack twice if the main hand stack does not contain an item in the list items, this can easily be simplified down to;

ItemStack itemStack = player.getMainHandStack();
if (itemStack == null || !items.get().contains(itemStack.getItem())) {
    itemStack = player.getOffHandStack();
    if (itemStack == null || !items.get().contains(itemStack.getItem())) return;
}

// Calculate paths
if (!simulator.set(player, itemStack, 0, accurate.get(), tickDelta)) return;

I’d have to double-check to be sure, but I’m not entirely certain these methods can return null values in the first place. IIRC they return a constant empty ItemStack instance and you can omit null checks entirely.

@snarkyerica
Copy link
Contributor Author

snarkyerica commented Apr 24, 2024

Yeah, I don't think they can return null, looking at the underlying methods, they always seem to return ItemStack.EMPTY if no other item is found, and IDEA doesn't complain about it potentially returning null, so I've removed those checks. sorry for the initial commit being hacky, it was done with no sleep lol

@abb3v
Copy link
Contributor

abb3v commented Apr 24, 2024

You're making a redundant function call twice @snarkyerica; you are checking the off-hand stack twice if the main hand stack does not contain an item in the list items, this can easily be simplified down to;

ItemStack itemStack = player.getMainHandStack();
if (itemStack == null || !items.get().contains(itemStack.getItem())) {
    itemStack = player.getOffHandStack();
    if (itemStack == null || !items.get().contains(itemStack.getItem())) return;
}

// Calculate paths
if (!simulator.set(player, itemStack, 0, accurate.get(), tickDelta)) return;

I’d have to double-check to be sure, but I’m not entirely certain these methods can return null values in the first place. IIRC they return a constant empty ItemStack instance and you can omit null checks entirely.

Ah right, I didn't bother looking at the functions, I just noticed that, if that were a correct implementation, then it was formatted incorrectly. Though I see no problems with this latest commit.

@Wide-Cat Wide-Cat merged commit 15036c7 into MeteorDevelopment:master Apr 26, 2024
1 check passed
@snarkyerica snarkyerica deleted the feature-fixtrajectoryoffhand branch April 26, 2024 17:21
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.

4 participants