Skip to content

Commit 8561291

Browse files
committed
actually fix syncing to client (please)
1 parent 7c39e00 commit 8561291

File tree

5 files changed

+38
-48
lines changed

5 files changed

+38
-48
lines changed

src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import net.minecraft.util.math.RayTraceResult;
3838
import net.minecraft.world.IBlockAccess;
3939
import net.minecraft.world.World;
40-
import net.minecraftforge.common.ForgeHooks;
4140
import net.minecraftforge.common.capabilities.Capability;
4241
import net.minecraftforge.common.capabilities.ICapabilityProvider;
4342
import net.minecraftforge.common.util.INBTSerializable;
@@ -76,7 +75,8 @@
7675

7776
public class ItemGTToolbelt extends ItemGTTool implements IDyeableItem {
7877

79-
private static final ThreadLocal<Integer> slotThread = ThreadLocal.withInitial(() -> -999);
78+
private static final ThreadLocal<Integer> lastSlot = ThreadLocal.withInitial(() -> -999);
79+
private static final ThreadLocal<EntityPlayer> lastPlayer = ThreadLocal.withInitial(() -> null);
8080

8181
public ItemGTToolbelt(String domain, String id, Supplier<ItemStack> markerItem, IToolBehavior... behaviors) {
8282
super(domain, id, -1,
@@ -391,8 +391,8 @@ public void setOnCraftIngredient(ItemStack stack, Ingredient ingredient) {
391391
int match = getHandler(stack).checkIngredientAgainstTools(ingredient);
392392
if (match != -1) {
393393
setSelectedTool(match, stack);
394-
PacketToolbeltSelectionChange.toClient(match, slotThread.get(),
395-
(EntityPlayerMP) ForgeHooks.getCraftingPlayer());
394+
PacketToolbeltSelectionChange.toClient(match,
395+
lastSlot.get(), (EntityPlayerMP) lastPlayer.get());
396396
}
397397
}
398398

@@ -525,8 +525,9 @@ public static boolean checkIngredientAgainstToolbelt(@NotNull ItemStack input, @
525525
return false;
526526
}
527527

528-
public static void setCraftingSlot(int slot) {
529-
slotThread.set(slot);
528+
public static void setCraftingSlot(int slot, EntityPlayer player) {
529+
lastSlot.set(slot);
530+
lastPlayer.set(player);
530531
}
531532

532533
public static boolean checkToolAgainstToolbelt(@NotNull ItemStack toolbelt, @NotNull ItemStack tool) {

src/main/java/gregtech/core/network/packets/PacketToolbeltSelectionChange.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public void decode(PacketBuffer buf) {
3939
}
4040

4141
public static void toClient(int slot, int matrixSlot, EntityPlayerMP player) {
42+
if (player == null) return;
4243
GregTechAPI.networkHandler.sendTo(new Client(slot, matrixSlot), player);
4344
}
4445

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package gregtech.mixins.minecraft;
2+
3+
import gregtech.api.items.toolitem.ItemGTToolbelt;
4+
5+
import net.minecraft.entity.player.EntityPlayer;
6+
import net.minecraft.inventory.ClickType;
7+
import net.minecraft.inventory.Container;
8+
import net.minecraft.item.ItemStack;
9+
10+
import org.spongepowered.asm.mixin.Mixin;
11+
import org.spongepowered.asm.mixin.injection.At;
12+
import org.spongepowered.asm.mixin.injection.Inject;
13+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
14+
15+
@Mixin(Container.class)
16+
public abstract class ContainerMixin {
17+
18+
@Inject(method = "slotClick",
19+
at = @At(value = "INVOKE",
20+
target = "Lnet/minecraft/item/ItemStack;splitStack(I)Lnet/minecraft/item/ItemStack;",
21+
ordinal = 1))
22+
private void setPlayer(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player,
23+
CallbackInfoReturnable<ItemStack> cir) {
24+
var playerStack = player.inventory.getItemStack();
25+
if (playerStack.getItem() instanceof ItemGTToolbelt) {
26+
ItemGTToolbelt.setCraftingSlot(slotId, player);
27+
}
28+
}
29+
}

src/main/java/gregtech/mixins/minecraft/NetworkHandlerMixin.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/main/resources/mixins.gregtech.minecraft.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"mixins": [
1111
"BlockConcretePowderMixin",
12-
"NetworkHandlerMixin",
12+
"ContainerMixin",
1313
"BlockRenderLayerMixin",
1414
"DamageSourceMixin",
1515
"EnchantmentCanApplyMixin",

0 commit comments

Comments
 (0)