Skip to content

Commit

Permalink
Update to mc1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
NotRyken committed Nov 4, 2024
1 parent 824a204 commit 00b9526
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 29 deletions.
10 changes: 10 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ plugins {
id("net.neoforged.moddev")
}

// Workaround for NeoForge transitive deps conflict
configurations.all {
resolutionStrategy {
force "org.ow2.asm:asm:9.7"
force "org.ow2.asm:asm-commons:9.7"
force "org.ow2.asm:asm-tree:9.7"
force "org.ow2.asm:asm-util:9.7"
}
}

dependencies {
compileOnly("org.spongepowered:mixin:${mixin_version}")
compileOnly("io.github.llamalad7:mixinextras-common:${mixinextras_version}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import dev.terminalmc.clientsort.util.inject.ISlot;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen;
import net.minecraft.client.gui.screens.inventory.EffectRenderingInventoryScreen;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.inventory.Slot;
Expand Down Expand Up @@ -63,7 +62,7 @@ public int getScope(Slot slot, boolean preferSmallerScopes) {
if (slot.container == null || ((ISlot) slot).mouseWheelie_getIndexInInv() >= slot.container.getContainerSize() || !slot.mayPlace(ItemStack.EMPTY)) {
return INVALID_SCOPE;
}
if (screen instanceof EffectRenderingInventoryScreen) {
if (screen instanceof AbstractContainerScreen) {
if (slot.container instanceof Inventory) {
if (isHotbarSlot(slot)) {
Config.Options options = Config.get().options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.*;

import java.util.ArrayDeque;
import java.util.ArrayList;
Expand Down Expand Up @@ -136,6 +136,17 @@ protected void sortOnClient(int[] sortedIds) {
}
if (stacks[i].isEmpty()) doneSlashEmpty.set(slotCount + i); // mark if it's empty
}

// Bundles require special handling. Specifically, to perform a swap between the carried
// item and the target slot, you normally use left-click (0), but if holding a bundle
// you must use right-click (1).
// It isn't possible to always use right-click because right-clicking a bundle on an empty
// slot does nothing, and right-clicking on a stack while carrying nothing takes half.
// The current workaround is to maintain a copy of the theoretical inventory state to inform
// the click decision. This will break if items enter or leave the inventory unexpectedly.
Item carriedItem = Items.AIR;
Item[] backingStacks = Arrays.stream(stacks.clone()).map(ItemStack::getItem).toArray(Item[]::new);

// Iterate all slots, with i as the target slot index
// sortedIds[i] is therefore the origin slot
for (int i = 0; i < slotCount; i++) {
Expand All @@ -149,8 +160,11 @@ protected void sortOnClient(int[] sortedIds) {

// This is where the action happens.
// Pick up the stack at the origin slot.
InteractionManager.push(screenHelper.createClickEvent(inventorySlots[sortedIds[i]], 0, ClickType.PICKUP));
doneSlashEmpty.set(slotCount + sortedIds[i]); // Mark the origin slot as empty (because we picked the stack up, duh)
Item temp = backingStacks[sortedIds[i]];
backingStacks[sortedIds[i]] = carriedItem;
carriedItem = temp;
InteractionManager.push(screenHelper.createClickEvent(inventorySlots[sortedIds[i]], 0, ClickType.PICKUP));
doneSlashEmpty.set(slotCount + sortedIds[i]); // Mark the origin slot as empty (because we picked the stack up, duh)
currentStack = stacks[sortedIds[i]]; // Save the stack we're currently working with
Slot workingSlot = inventorySlots[sortedIds[i]]; // A slot that we can use when fiddling around with swapping stacks
int id = i; // id will reflect the target slot in the following loop
Expand All @@ -170,6 +184,9 @@ protected void sortOnClient(int[] sortedIds) {
if (currentStack.getCount() < stacks[id].getCount()) { // Clicking with a low stack on a full stack does nothing
// The workaround is: click working slot, click target slot, click working slot, click target slot, click working slot
Slot targetSlot = inventorySlots[id];
temp = backingStacks[id];
backingStacks[id] = carriedItem;
carriedItem = temp;
InteractionManager.push(screenHelper.createClickEvent(workingSlot, 0, ClickType.PICKUP));
InteractionManager.push(screenHelper.createClickEvent(targetSlot, 0, ClickType.PICKUP));
InteractionManager.push(screenHelper.createClickEvent(workingSlot, 0, ClickType.PICKUP));
Expand All @@ -184,7 +201,18 @@ protected void sortOnClient(int[] sortedIds) {
}

// swap the current stack with the target stack
InteractionManager.push(screenHelper.createClickEvent(inventorySlots[id], 0, ClickType.PICKUP));
if ((backingStacks[id] instanceof BundleItem && !(carriedItem instanceof AirItem))
|| (carriedItem instanceof BundleItem && !(backingStacks[id] instanceof AirItem))) {
temp = backingStacks[id];
backingStacks[id] = carriedItem;
carriedItem = temp;
InteractionManager.push(screenHelper.createClickEvent(inventorySlots[id], 1, ClickType.PICKUP));
} else {
temp = backingStacks[id];
backingStacks[id] = carriedItem;
carriedItem = temp;
InteractionManager.push(screenHelper.createClickEvent(inventorySlots[id], 0, ClickType.PICKUP));
}
currentStack = stacks[id];
doneSlashEmpty.set(id); // mark the current target as done
// If the target that we just swapped with was empty before, then this breaks the chain.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import net.minecraft.network.Connection;
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
import net.minecraft.network.protocol.game.ClientboundLoginPacket;
import net.minecraft.network.protocol.game.ClientboundSetCarriedItemPacket;
import net.minecraft.network.protocol.game.ClientboundSetCursorItemPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -43,8 +43,8 @@ private void onLogin(ClientboundLoginPacket packet, CallbackInfo ci) {
ClientSort.searchOrderUpdated = false;
}

@Inject(method = "handleSetCarriedItem", at = @At("HEAD"))
public void onHeldItemChangeBegin(ClientboundSetCarriedItemPacket packet, CallbackInfo ci) {
@Inject(method = "handleSetCursorItem", at = @At("HEAD"))
public void onHeldItemChangeBegin(ClientboundSetCursorItemPacket packet, CallbackInfo ci) {
InteractionManager.triggerSend(InteractionManager.TriggerType.HELD_ITEM_CHANGE);
}

Expand Down
38 changes: 19 additions & 19 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Neo/Forge version ranges: https://maven.apache.org/enforcer/enforcer-rules/versionRanges.html

# Project
mod_version=1.0.1+1.21
mod_version=1.0.1+1.21.3
mod_group=dev.terminalmc
mod_id=clientsort
mod_name=ClientSort
Expand All @@ -24,35 +24,35 @@ java_versions_fabric=>=21
java_versions_neoforge=[21,)

# Minecraft
minecraft_version=1.21
minecraft_versions_fabric=>1.20.6 <1.22
minecraft_versions_neoforge=(1.20.6, 1.22)
minecraft_version=1.21.3
minecraft_versions_fabric=>1.21.1 <1.22
minecraft_versions_neoforge=(1.21.1, 1.22)

# Parchment https://parchmentmc.org/docs/getting-started#choose-a-version
parchment_minecraft_version=1.21
parchment_version=2024.07.28

# Fabric https://fabricmc.net/develop
fabric_loader_version=0.16.5
fabric_loader_version=0.16.9
fabric_loader_versions=>=0.15.0
fabric_api_version=0.102.0+1.21
fabric_api_version=0.107.0+1.21.3
fabric_api_versions=*

# NeoForge https://projects.neoforged.net/neoforged/neoforge
neoforge_loader_versions=[1,)
neoforge_version=21.0.167
neoforge_versions=[21.0.143, 22)
neoforge_version=21.3.10-beta
neoforge_versions=[21.3.0-beta, 22)
# NeoForm https://projects.neoforged.net/neoforged/neoform
neoform_version=1.21-20240613.152323
neoform_version=1.21.3-20241023.131943

# Cloth Config https://modrinth.com/mod/9s6osm5g/versions
clothconfig_version=15.0.140
clothconfig_versions_fabric=>=15
clothconfig_versions_neoforge=[15,)
clothconfig_version=16.0.141
clothconfig_versions_fabric=>=16
clothconfig_versions_neoforge=[16,)

# ModMenu https://modrinth.com/mod/mOgUt4GM/versions
modmenu_version=11.0.2
modmenu_versions_fabric=>10
modmenu_version=12.0.0-beta.1
modmenu_versions_fabric=>11

# GitHub, Modrinth, CurseForge releases
# Plural properties expect CSV lists
Expand All @@ -64,12 +64,12 @@ curseforge_id=1049891
release_type=release
# Fabric
release_mod_loaders_fabric=fabric
release_game_versions_fabric=1.21,1.21.1
release_game_versions_fabric=1.21.2,1.21.3
release_required_dep_ids_fabric_mr=P7dR8mSH,mOgUt4GM,9s6osm5g
release_required_dep_ids_fabric_cf=fabric-api,modmenu,cloth-config
# NeoForge
release_mod_loaders_neoforge=neoforge
release_game_versions_neoforge=1.21,1.21.1
release_game_versions_neoforge=1.21.2,1.21.3
release_required_dep_ids_neoforge_mr=9s6osm5g
release_required_dep_ids_neoforge_cf=cloth-config

Expand All @@ -80,17 +80,17 @@ mixinextras_version=0.4.1

# Plugins
# Fabric Loom https://mvnrepository.com/artifact/net.fabricmc/fabric-loom
loom_version=1.7.4
loom_version=1.8.10
# ModDev https://plugins.gradle.org/plugin/net.neoforged.moddev
moddev_version=1.0.19
moddev_version=1.0.21
# Minotaur https://plugins.gradle.org/plugin/com.modrinth.minotaur
minotaur_version=2.8.7
# CurseForgeGradle https://plugins.gradle.org/plugin/net.darkhax.curseforgegradle
curseforgegradle_version=1.1.25
# github-release https://plugins.gradle.org/plugin/com.github.breadmoirai.github-release
githubrelease_version=2.5.2
# grgit-service https://github.com/ajoberstar/grgit/releases
grgitservice_version=5.2.2
grgitservice_version=5.3.0
# licenser https://plugins.gradle.org/plugin/org.cadixdev.licenser
licenser_version=0.6.1

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down

0 comments on commit 00b9526

Please sign in to comment.