Skip to content

Commit

Permalink
Merge branch '1.19' into 1.19.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Siphalor committed Aug 7, 2023
2 parents 6818320 + 5a35739 commit f1e5be1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 41 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ yarn_build=2:v2
loader_version=0.14.11
# Mod Properties
mod_id=mousewheelie
mod_version=1.12.1
mod_version=1.12.2
mod_release=release
mod_mc_version_specifier=1.19.3+
mod_mc_versions=1.19.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public SlotInteractionState getSlotState(Slot slot) {
}
}

public void setSloteState(Slot slot, SlotInteractionState state) {
public void setSlotState(Slot slot, SlotInteractionState state) {
Lock writeLock = slotStatesLock.writeLock();
writeLock.lock();
try {
Expand All @@ -106,7 +106,7 @@ public void setSloteState(Slot slot, SlotInteractionState state) {
}

public void unlockSlot(Slot slot) {
setSloteState(slot, SlotInteractionState.NORMAL);
setSlotState(slot, SlotInteractionState.NORMAL);
}

private InteractionManager.InteractionEvent lockBefore(InteractionManager.InteractionEvent event, Slot slot, SlotInteractionState slotState) {
Expand All @@ -115,7 +115,7 @@ private InteractionManager.InteractionEvent lockBefore(InteractionManager.Intera
}

return new InteractionManager.CallbackEvent(() -> {
setSloteState(slot, slotState);
setSlotState(slot, slotState);
return event.send();
}, event.shouldRunOnMainThread());
}
Expand Down Expand Up @@ -302,11 +302,17 @@ public void sendStackLocked(Slot slot) {
return;
}

InteractionManager.push(unlockAfter(lockBefore(clickEventFactory.create(slot, 0, SlotActionType.QUICK_MOVE), slot, SlotInteractionState.TEMP_LOCKED), slot));
setSlotState(slot, SlotInteractionState.TEMP_LOCKED);
InteractionManager.push(unlockAfter(clickEventFactory.create(slot, 0, SlotActionType.QUICK_MOVE), slot));
}

public void sendAllOfAKind(Slot referenceSlot) {
ItemStack referenceStack = referenceSlot.getStack().copy();
ItemStack stack = referenceSlot.getStack();
if (stack.isEmpty()) {
return;
}

ItemStack referenceStack = stack.copy();
runInScope(getScope(referenceSlot), slot -> {
if (ItemStackUtils.areItemsOfSameKind(slot.getStack(), referenceStack)) {
sendStack(slot);
Expand Down Expand Up @@ -341,11 +347,16 @@ public void depositAllFrom(int scope) {
}

public void restockAllOfAKind(Slot referenceSlot) {
ItemStack referenceStack = referenceSlot.getStack();
if (referenceStack.isEmpty()) {
return;
}

int scope = getScope(referenceSlot, true);
int complementaryScope = getComplementaryScope(scope);
restockAllOfAKind(
screen.getScreenHandler().slots.stream()
.filter(slot -> getScope(slot, true) == scope && ItemStackUtils.areItemsOfSameKind(slot.getStack(), referenceSlot.getStack()))
.filter(slot -> getScope(slot, true) == scope && ItemStackUtils.areItemsOfSameKind(slot.getStack(), referenceStack))
.iterator(),
complementaryScope
);
Expand Down Expand Up @@ -435,11 +446,17 @@ public void dropStackLocked(Slot slot) {
return;
}

InteractionManager.push(unlockAfter(lockBefore(clickEventFactory.create(slot, 1, SlotActionType.THROW), slot, SlotInteractionState.TEMP_LOCKED), slot));
setSlotState(slot, SlotInteractionState.TEMP_LOCKED);
InteractionManager.push(unlockAfter(clickEventFactory.create(slot, 1, SlotActionType.THROW), slot));
}

public void dropAllOfAKind(Slot referenceSlot) {
ItemStack referenceStack = referenceSlot.getStack().copy();
ItemStack stack = referenceSlot.getStack();
if (stack.isEmpty()) {
return;
}

ItemStack referenceStack = stack.copy();
runInScope(getScope(referenceSlot), slot -> {
if (ItemStackUtils.areItemsOfSameKind(slot.getStack(), referenceStack)) {
dropStack(slot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void onMouseDragged(double x, double y, int button, double deltaX, double
}
}
if (slots.isEmpty()) {
if (hoveredSlot != null) {
if (hoveredSlot != null && !hoveredSlot.getStack().isEmpty()) {
slots = Collections.singletonList(hoveredSlot);
} else {
return;
Expand Down Expand Up @@ -180,46 +180,41 @@ public void onMouseDragged(double x, double y, int button, double deltaX, double
@Inject(method = "mouseClicked", at = @At("HEAD"), cancellable = true)
public void onMouseClick(double x, double y, int button, CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
if (button == 0) {
Slot hoveredSlot = getSlotAt(x, y);
if (hoveredSlot == null) {
return;
}

boolean success = true;
if (MWConfig.general.enableDropModifier && MWClient.DROP_MODIFIER.isPressed()) {
Slot hoveredSlot = getSlotAt(x, y);
if (hoveredSlot != null) {
if (MWClient.ALL_OF_KIND_MODIFIER.isPressed()) {
if (MWClient.WHOLE_STACK_MODIFIER.isPressed()) {
screenHelper.get().dropAllFrom(hoveredSlot);
} else {
screenHelper.get().dropAllOfAKind(hoveredSlot);
}
if (MWClient.ALL_OF_KIND_MODIFIER.isPressed()) {
if (MWClient.WHOLE_STACK_MODIFIER.isPressed()) {
screenHelper.get().dropAllFrom(hoveredSlot);
} else {
onMouseClick(hoveredSlot, hoveredSlot.id, 1, SlotActionType.THROW);
screenHelper.get().dropAllOfAKind(hoveredSlot);
}
callbackInfoReturnable.setReturnValue(true);
} else {
onMouseClick(hoveredSlot, hoveredSlot.id, 1, SlotActionType.THROW);
}
} else if (MWClient.ALL_OF_KIND_MODIFIER.isPressed()) {
Slot hoveredSlot = getSlotAt(x, y);
if (hoveredSlot != null) {
if (MWClient.WHOLE_STACK_MODIFIER.isPressed()) {
screenHelper.get().sendAllFrom(hoveredSlot);
} else {
screenHelper.get().sendAllOfAKind(hoveredSlot);
}
callbackInfoReturnable.setReturnValue(true);
if (MWClient.WHOLE_STACK_MODIFIER.isPressed()) {
screenHelper.get().sendAllFrom(hoveredSlot);
} else {
screenHelper.get().sendAllOfAKind(hoveredSlot);
}
} else if (MWClient.DEPOSIT_MODIFIER.isPressed()) {
Slot hoveredSlot = getSlotAt(x, y);
if (hoveredSlot != null) {
screenHelper.get().depositAllFrom(hoveredSlot);
callbackInfoReturnable.setReturnValue(true);
}
screenHelper.get().depositAllFrom(hoveredSlot);
} else if (MWClient.RESTOCK_MODIFIER.isPressed()) {
Slot hoveredSlot = getSlotAt(x, y);
if (hoveredSlot != null) {
if (MWClient.WHOLE_STACK_MODIFIER.isPressed()) {
screenHelper.get().restockAll(hoveredSlot);
} else {
screenHelper.get().restockAllOfAKind(hoveredSlot);
}
callbackInfoReturnable.setReturnValue(true);
if (MWClient.WHOLE_STACK_MODIFIER.isPressed()) {
screenHelper.get().restockAll(hoveredSlot);
} else {
screenHelper.get().restockAllOfAKind(hoveredSlot);
}
} else {
success = false;
}
if (success) {
callbackInfoReturnable.setReturnValue(true);
}
} else if (button == 1) {
ItemStack cursorStack = handler.getCursorStack();
Expand Down

0 comments on commit f1e5be1

Please sign in to comment.