fix(D-01/A): double item consumption + unchecked cast in TyingInteractionHelper
QA-001: add instanceof V2TyingPlayerTask guard before cast to prevent ClassCastException when a V1 TyingPlayerTask was still active QA-002: remove stack.shrink(1) after tying completion — V2TyingPlayerTask .onComplete() already consumes the held item via heldStack.shrink(1)
This commit is contained in:
@@ -85,9 +85,11 @@ public final class TyingInteractionHelper {
|
|||||||
|
|
||||||
TyingTask currentTask = playerState.getCurrentTyingTask();
|
TyingTask currentTask = playerState.getCurrentTyingTask();
|
||||||
if (currentTask == null
|
if (currentTask == null
|
||||||
|
|| !(currentTask instanceof V2TyingPlayerTask)
|
||||||
|| !currentTask.isSameTarget(target)
|
|| !currentTask.isSameTarget(target)
|
||||||
|| currentTask.isOutdated()
|
|| currentTask.isOutdated()
|
||||||
|| !ItemStack.matches(currentTask.getBind(), stack)) {
|
|| !ItemStack.matches(currentTask.getBind(), stack)) {
|
||||||
|
// Start new task (also handles case where existing task is V1 TyingPlayerTask)
|
||||||
playerState.setCurrentTyingTask(newTask);
|
playerState.setCurrentTyingTask(newTask);
|
||||||
newTask.start();
|
newTask.start();
|
||||||
} else {
|
} else {
|
||||||
@@ -97,7 +99,7 @@ public final class TyingInteractionHelper {
|
|||||||
newTask.update();
|
newTask.update();
|
||||||
|
|
||||||
if (newTask.isStopped()) {
|
if (newTask.isStopped()) {
|
||||||
stack.shrink(1);
|
// Item already consumed by V2TyingPlayerTask.onComplete() — don't shrink again
|
||||||
playerState.setCurrentTyingTask(null);
|
playerState.setCurrentTyingTask(null);
|
||||||
TiedUpMod.LOGGER.info("[TyingInteraction] {} tied {}", player.getName().getString(), target.getName().getString());
|
TiedUpMod.LOGGER.info("[TyingInteraction] {} tied {}", player.getName().getString(), target.getName().getString());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user