Skip to content

Commit

Permalink
fix(auto-fish): fixed "invalid rod" caused by durability changed
Browse files Browse the repository at this point in the history
  • Loading branch information
c0nstexpr committed Jul 4, 2024
1 parent 5ee6eba commit cd5ccec
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,4 @@ private void onEntityTrackerUpdate(EntityTrackerUpdateS2CPacket packet, Callback
packet.id(),
packet.trackedValues()));
}

@Inject(method = "onInventory", at = @At("TAIL"))
private void onInventory(InventoryS2CPacket packet, CallbackInfo ci) {
InventoryUpdateEvent.subject.onNext(Unit.INSTANCE);
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ org.gradle.warning.mode=all
org.gradle.parallel=true
# Mod Properties
modGroup=org.c0nstexpr
modVersion=2.1.0
modVersion=2.2.0
modId=fishology
modName=Fishology
20 changes: 4 additions & 16 deletions interact/src/client/kotlin/org/c0nstexpr/fishology/interact/Rod.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package org.c0nstexpr.fishology.interact

import com.badoo.reaktive.disposable.Disposable
import com.badoo.reaktive.disposable.scope.disposableScope
import com.badoo.reaktive.observable.Observable
import com.badoo.reaktive.observable.filter
import com.badoo.reaktive.observable.firstOrComplete
import com.badoo.reaktive.observable.notNull
import com.badoo.reaktive.observable.switchMapMaybe
import com.badoo.reaktive.observable.subscribe
import com.badoo.reaktive.subject.behavior.BehaviorSubject
import net.minecraft.client.MinecraftClient
import org.c0nstexpr.fishology.events.InventoryUpdateEvent
import org.c0nstexpr.fishology.events.UseRodEvent
import org.c0nstexpr.fishology.log.d
import org.c0nstexpr.fishology.logger
Expand All @@ -31,18 +28,9 @@ class Rod(val client: MinecraftClient) : SwitchDisposable() {

override fun onEnable(): Disposable {
logger.d<Rod> { "enable rod interaction" }
return disposableScope {
UseRodEvent.observable.subscribeScoped {
logger.d<Rod> { "save rod status after use rod" }
itemSubject.onNext(RodItem(it.player, it.isThrow, it.hand))
}

UseRodEvent.observable.filter { !it.isThrow }
.switchMapMaybe { InventoryUpdateEvent.observable.firstOrComplete() }
.subscribeScoped {
logger.d<Rod> { "update rod item after inventory update" }
rodItem?.updateStack()
}
return UseRodEvent.observable.subscribe {
logger.d<Rod> { "save rod status after use rod" }
itemSubject.onNext(RodItem(it.player, it.isThrow, it.hand))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package org.c0nstexpr.fishology.interact

import net.minecraft.client.network.ClientPlayerEntity
import net.minecraft.entity.player.PlayerInventory
import net.minecraft.item.ItemStack
import net.minecraft.item.Items
import net.minecraft.util.Hand
import org.c0nstexpr.fishology.utils.getSlotInHand
import org.c0nstexpr.fishology.utils.isSame

class RodItem(
val player: ClientPlayerEntity,
Expand All @@ -14,16 +13,10 @@ class RodItem(
) {
val slotIndex = player.inventory.getSlotInHand(hand)

var stack: ItemStack = player.getStackInHand(hand)
private set

val hand
get() = if (slotIndex == PlayerInventory.OFF_HAND_SLOT) Hand.OFF_HAND
else Hand.MAIN_HAND

fun updateStack() {
stack = player.getStackInHand(hand)
}

fun isValid() = player.getStackInHand(hand).isSame(stack) && !stack.isEmpty
fun isValid() = player.getStackInHand(hand).isOf(Items.FISHING_ROD) &&
player.inventory.getSlotInHand(hand) == slotIndex
}

0 comments on commit cd5ccec

Please sign in to comment.