Skip to content
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

Support quick move for Botania pattern items in loom UI #4551

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions Xplat/src/main/java/vazkii/botania/mixin/LoomMenuMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,33 @@

import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.LoomMenu;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BannerPattern;

import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import vazkii.botania.common.item.ItemWithBannerPattern;

import java.util.List;

@Mixin(LoomMenu.class)
public class LoomMenuMixin {
public abstract class LoomMenuMixin extends AbstractContainerMenu {
protected LoomMenuMixin(@Nullable MenuType<?> menuType, int containerId) {
super(menuType, containerId);
}

@Inject(at = @At("HEAD"), method = "getSelectablePatterns(Lnet/minecraft/world/item/ItemStack;)Ljava/util/List;", cancellable = true)
private void handleBotaniaPatternItems(ItemStack stack, CallbackInfoReturnable<List<Holder<BannerPattern>>> cir) {
if (stack.getItem() instanceof ItemWithBannerPattern p) {
Expand All @@ -27,5 +39,19 @@ private void handleBotaniaPatternItems(ItemStack stack, CallbackInfoReturnable<L
}
}

// todo also mixin into quickMoveStack to support shift clicking of our banner pattern items
@Shadow
@Final
Slot patternSlot;

@Inject(
at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/item/ItemStack;getItem()Lnet/minecraft/world/item/Item;"),
method = "quickMoveStack", cancellable = true, locals = LocalCapture.CAPTURE_FAILSOFT
)
private void handleBotaniaPatternQuickMoveStack(Player player, int slotIndex, CallbackInfoReturnable<ItemStack> cir, ItemStack dummyStack,
Slot slot, ItemStack movedStack) {
if (movedStack.getItem() instanceof ItemWithBannerPattern
&& moveItemStackTo(movedStack, this.patternSlot.index, this.patternSlot.index + 1, false)) {
cir.setReturnValue(ItemStack.EMPTY);
}
}
}
Loading