-
-
Notifications
You must be signed in to change notification settings - Fork 497
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
feat(AutoTool): Settings refactoring #5260
base: nextgen
Are you sure you want to change the base?
feat(AutoTool): Settings refactoring #5260
Conversation
src/main/kotlin/net/ccbluex/liquidbounce/utils/inventory/InventoryUtils.kt
Fixed
Show fixed
Hide fixed
private val slot by int("Slot", 0, 0..8) | ||
|
||
override fun getTool(inventory: PlayerInventory, blockState: BlockState?): IntObjectImmutablePair<ItemStack> { | ||
return IntObjectImmutablePair(slot, inventory.getStack(slot)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we want to choose a static slot though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's already there, I didn't change the functionality of AutoTool itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look at what's already available
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see.
fun PlayerInventory.findBestToolToMineBlock( | ||
blockState: BlockState?, | ||
ignoreDurability: Boolean = true | ||
): IntObjectImmutablePair<ItemStack>? { | ||
val (hotbarSlot, stack) = | ||
(0..8).map { | ||
it to getStack(it) | ||
}.filter { (_, stack) -> | ||
val durabilityCheck = (stack.damage < (stack.maxDamage - 2) || ignoreDurability) | ||
(stack.isNothing() || (!player.isCreative && durabilityCheck)) | ||
}.maxByOrNull { (_, stack) -> | ||
stack.getMiningSpeedMultiplier(blockState) | ||
} ?: return null | ||
|
||
val miningSpeedMultiplier = stack.getMiningSpeedMultiplier(blockState) | ||
|
||
// The current slot already matches the best | ||
if (miningSpeedMultiplier == player.inventory.mainHandStack.getMiningSpeedMultiplier(blockState)) { | ||
return null | ||
} | ||
return IntObjectImmutablePair(hotbarSlot, stack) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason to move this into another class when it's not being used multiple times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i did it 'cause of the confusion in this code. Logically, I don't think PacketMine should inherit the AutoTool settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it still does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm confused, make your own verdict, if it has to inherit AutoTool settings, then yes, there is no point in a separate [findBestToolToMineBlock] method.
): IntObjectImmutablePair<ItemStack>? { | ||
val (hotbarSlot, stack) = | ||
(0..8).map { | ||
it to getStack(it) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IntObjectImmutablePair(it, getStack(it))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesnt make sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int to any? -> Pair<Integer, @Nullable Object>
while u has IntObjectImmutablePair
as result type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the end it's not my code (I moved it). If you want to change something, change it and create a pr.
Made the settings more intuitive