Skip to content

Commit

Permalink
actually fix syncing to client (please)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghzdude committed Dec 18, 2024
1 parent 7c39e00 commit 8561291
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 48 deletions.
13 changes: 7 additions & 6 deletions src/main/java/gregtech/api/items/toolitem/ItemGTToolbelt.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.common.util.INBTSerializable;
Expand Down Expand Up @@ -76,7 +75,8 @@

public class ItemGTToolbelt extends ItemGTTool implements IDyeableItem {

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

public ItemGTToolbelt(String domain, String id, Supplier<ItemStack> markerItem, IToolBehavior... behaviors) {
super(domain, id, -1,
Expand Down Expand Up @@ -391,8 +391,8 @@ public void setOnCraftIngredient(ItemStack stack, Ingredient ingredient) {
int match = getHandler(stack).checkIngredientAgainstTools(ingredient);
if (match != -1) {
setSelectedTool(match, stack);
PacketToolbeltSelectionChange.toClient(match, slotThread.get(),
(EntityPlayerMP) ForgeHooks.getCraftingPlayer());
PacketToolbeltSelectionChange.toClient(match,
lastSlot.get(), (EntityPlayerMP) lastPlayer.get());
}
}

Expand Down Expand Up @@ -525,8 +525,9 @@ public static boolean checkIngredientAgainstToolbelt(@NotNull ItemStack input, @
return false;
}

public static void setCraftingSlot(int slot) {
slotThread.set(slot);
public static void setCraftingSlot(int slot, EntityPlayer player) {
lastSlot.set(slot);
lastPlayer.set(player);
}

public static boolean checkToolAgainstToolbelt(@NotNull ItemStack toolbelt, @NotNull ItemStack tool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void decode(PacketBuffer buf) {
}

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

Expand Down
29 changes: 29 additions & 0 deletions src/main/java/gregtech/mixins/minecraft/ContainerMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package gregtech.mixins.minecraft;

import gregtech.api.items.toolitem.ItemGTToolbelt;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ClickType;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Container.class)
public abstract class ContainerMixin {

@Inject(method = "slotClick",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/item/ItemStack;splitStack(I)Lnet/minecraft/item/ItemStack;",
ordinal = 1))
private void setPlayer(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player,
CallbackInfoReturnable<ItemStack> cir) {
var playerStack = player.inventory.getItemStack();
if (playerStack.getItem() instanceof ItemGTToolbelt) {
ItemGTToolbelt.setCraftingSlot(slotId, player);
}
}
}
41 changes: 0 additions & 41 deletions src/main/java/gregtech/mixins/minecraft/NetworkHandlerMixin.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/resources/mixins.gregtech.minecraft.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"mixins": [
"BlockConcretePowderMixin",
"NetworkHandlerMixin",
"ContainerMixin",
"BlockRenderLayerMixin",
"DamageSourceMixin",
"EnchantmentCanApplyMixin",
Expand Down

0 comments on commit 8561291

Please sign in to comment.