Skip to content

Commit 15fbd05

Browse files
author
tonimatasdev
committed
fix: Update item when toggle target direction
1 parent ef69722 commit 15fbd05

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

src/main/java/dev/tonimatas/mekanismcurios/MekanismCurios.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
import top.theillusivec4.curios.api.CuriosApi;
1818
import top.theillusivec4.curios.api.CuriosCapability;
1919

20-
import java.util.Queue;
21-
import java.util.concurrent.ConcurrentLinkedQueue;
22-
2320
@Mod(MekanismCurios.MODID)
2421
public class MekanismCurios {
2522
public static final String MODID = "mekanismcurios";
@@ -42,10 +39,15 @@ public void registerNetworking(final RegisterPayloadHandlersEvent event) {
4239
}
4340

4441
public static ItemStack getQIO(Player player) {
45-
return CuriosApi.getCuriosInventory(player).map(iCuriosItemHandler -> iCuriosItemHandler.getCurios().get("qio").getStacks().getStackInSlot(0)).orElse(ItemStack.EMPTY);
42+
return CuriosApi.getCuriosInventory(player).map(iCuriosItemHandler ->
43+
iCuriosItemHandler.getCurios().get("qio").getStacks().getStackInSlot(0)).orElse(ItemStack.EMPTY);
4644
}
47-
48-
45+
46+
public static void setQIO(Player player, ItemStack stack) {
47+
CuriosApi.getCuriosInventory(player).ifPresent(curiosInventory ->
48+
curiosInventory.setEquippedCurio("qio", 0, stack));
49+
}
50+
4951
public static ItemStack getHandOrCuriosItem(Player player, InteractionHand hand) {
5052
if (hand == null) {
5153
return MekanismCurios.getQIO(player);

src/main/java/dev/tonimatas/mekanismcurios/mixins/PacketItemButtonPressMixin.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
import net.minecraft.world.InteractionHand;
88
import net.minecraft.world.entity.player.Player;
99
import net.minecraft.world.item.ItemStack;
10-
import org.spongepowered.asm.mixin.Final;
1110
import org.spongepowered.asm.mixin.Mixin;
12-
import org.spongepowered.asm.mixin.Shadow;
1311
import org.spongepowered.asm.mixin.injection.At;
1412
import org.spongepowered.asm.mixin.injection.Redirect;
1513

src/main/java/dev/tonimatas/mekanismcurios/mixins/PortableQIODashboardContainerMixin.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
import dev.tonimatas.mekanismcurios.MekanismCurios;
44
import mekanism.common.inventory.container.item.PortableQIODashboardContainer;
5+
import mekanism.common.inventory.container.sync.SyncableItemStack;
56
import net.minecraft.world.InteractionHand;
7+
import net.minecraft.world.entity.player.Inventory;
68
import net.minecraft.world.entity.player.Player;
79
import net.minecraft.world.item.ItemStack;
810
import org.spongepowered.asm.mixin.Final;
911
import org.spongepowered.asm.mixin.Mixin;
1012
import org.spongepowered.asm.mixin.Shadow;
1113
import org.spongepowered.asm.mixin.injection.At;
1214
import org.spongepowered.asm.mixin.injection.Inject;
15+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1316
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1417

1518
@Mixin(PortableQIODashboardContainer.class)
@@ -26,4 +29,16 @@ public abstract class PortableQIODashboardContainerMixin {
2629
cir.setReturnValue(validCurios);
2730
}
2831
}
32+
33+
@Inject(method = "addInventorySlots", at = @At("RETURN"))
34+
private void mci$addInventorySlots(Inventory inv, CallbackInfo ci) {
35+
if (this.hand == null) {
36+
((PortableQIODashboardContainer) (Object) this).track(SyncableItemStack.create(() -> MekanismCurios.getQIO(inv.player), item -> {
37+
MekanismCurios.setQIO(inv.player, item);
38+
if (stack.is(item.getItem())) {
39+
stack = item;
40+
}
41+
}));
42+
}
43+
}
2944
}

0 commit comments

Comments
 (0)