Skip to content
Closed
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,23 @@ apiPackage =
accessTransformersFile = nei_at.cfg

# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
usesMixins = false
usesMixins = true

# Set to a non-empty string to configure mixins in a separate source set under src/VALUE, instead of src/main.
# This can speed up compile times thanks to not running the mixin annotation processor on all input sources.
# Mixin classes will have access to "main" classes, but not the other way around.
separateMixinSourceSet =

# Adds some debug arguments like verbose output and class export.
usesMixinDebug = false
usesMixinDebug = true

# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
mixinPlugin =

# Specify the package that contains all of your Mixins. The package must exist or
# the build will fail. If you have a package property defined in your mixins.<modid>.json,
# it must match with this or the build will fail.
mixinsPackage =
mixinsPackage = mixins

# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
# This parameter is for legacy compatibility only
Expand Down
11 changes: 2 additions & 9 deletions src/main/java/codechicken/nei/NEIClientUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiContainerCreative;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.player.EntityPlayer;
Expand Down Expand Up @@ -274,16 +273,10 @@ public static void giveStack(ItemStack base, int i, boolean infinite) {
if (given >= stack.stackSize) break;
}
if (given > 0) {
if (mc().currentScreen instanceof GuiContainerCreative gcc) {
mc().thePlayer.inventory.addItemStackToInventory(stack);
gcc.inventorySlots.detectAndSendChanges();
} else NEICPH.sendGiveItem(copyStack(typestack, given), false, false);
NEICPH.sendGiveItem(copyStack(typestack, given), false, false);
}
} else {
if (mc().currentScreen instanceof GuiContainerCreative gcc) {
mc().thePlayer.inventory.addItemStackToInventory(stack);
gcc.inventorySlots.detectAndSendChanges();
} else NEICPH.sendGiveItem(stack, infinite, true);
NEICPH.sendGiveItem(stack, infinite, true);
}
} else {
for (int given = 0; given < stack.stackSize;) {
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/codechicken/nei/mixins/MixinMinecraft_Container.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package codechicken.nei.mixins;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainerCreative;
import net.minecraft.inventory.Container;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(Container.class)
public class MixinMinecraft_Container {

// Disable client -> server slots sync
@Redirect(
method = "slotClick",
at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/Container;detectAndSendChanges()V"))
private void nei$cancelClientToServerSync(Container instance) {
if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainerCreative)) instance.detectAndSendChanges();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package codechicken.nei.mixins;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainerCreative;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.C0EPacketClickWindow;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import codechicken.nei.NEIClientUtils;

@Mixin(GuiContainerCreative.class)
public class MixinMinecraft_GuiContainerCreative {

// Replace client side click handler with usual click handler
@Redirect(
method = "handleMouseClick",
at = @At(
value = "INVOKE",
ordinal = 0,
target = "Lnet/minecraft/inventory/Container;slotClick(IIILnet/minecraft/entity/player/EntityPlayer;)Lnet/minecraft/item/ItemStack;"))
private ItemStack nei$cancelClientSlotClick(Container instance, int slotId, int clickedButton, int clickType,
EntityPlayer player) {
return Minecraft.getMinecraft().playerController
.windowClick(instance.windowId, slotId, clickedButton, clickType, player);
}

// Creative tabs set slots
@Redirect(
method = "handleMouseClick",
at = @At(
value = "INVOKE",
ordinal = 1,
target = "Lnet/minecraft/inventory/Container;slotClick(IIILnet/minecraft/entity/player/EntityPlayer;)Lnet/minecraft/item/ItemStack;"))
private ItemStack nei$forkSlotClick(Container instance, int slotId, int clickedButton, int clickType,
EntityPlayer player) {
Minecraft mc = Minecraft.getMinecraft();
if (mc.currentScreen instanceof GuiContainerCreative gcc) {
// Client side
short short1 = player.openContainer.getNextTransactionID(player.inventory);
ItemStack itemstack = player.openContainer.slotClick(slotId, clickedButton, clickType, player);

// Server side
slotId = slotId != -999 ? slotId - gcc.inventorySlots.inventorySlots.size() + 9 + 36 : -999;
((MixinMinecraft_PlayerControllerMP) mc.playerController).nei$getNetClientHandler().addToSendQueue(
new C0EPacketClickWindow(instance.windowId, slotId, clickedButton, clickType, itemstack, short1));
}

return null;
}

// Move from creative tabs to hotbar by keyboard number keys
@Redirect(
method = "handleMouseClick",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/entity/player/InventoryPlayer;setInventorySlotContents(ILnet/minecraft/item/ItemStack;)V"))
private void nei$cancelClientSetInventory(InventoryPlayer instance, int index, ItemStack stack) {
Minecraft.getMinecraft().playerController.sendSlotPacket(stack, 36 + index);

// Because mc not allow sync packet from server for creative tabs gui
instance.setInventorySlotContents(index, stack);
}

// Need when you take stack from creative tab and then drag move in inventory tab
@Redirect(
method = "handleMouseClick",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/entity/player/InventoryPlayer;setItemStack(Lnet/minecraft/item/ItemStack;)V"))
private void nei$setServerHandItem(InventoryPlayer instance, ItemStack itemStack, Slot slotIn, int slotId,
int clickedButton, int clickType) {
if (itemStack != null && clickType == 1) itemStack.stackSize = itemStack.getMaxStackSize();
NEIClientUtils.setSlotContents(-999, itemStack, false);
}

// Use mixin for sync
@Redirect(
method = "handleMouseClick",
at = @At(
value = "INVOKE",
ordinal = 2,
target = "Lnet/minecraft/client/multiplayer/PlayerControllerMP;sendSlotPacket(Lnet/minecraft/item/ItemStack;I)V"))
private void nei$cancelClientToServerSetSlot(PlayerControllerMP instance, ItemStack itemStackIn, int slotId) {}

// Disable client -> server slots sync
@Redirect(
method = "handleMouseClick",
at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/Container;detectAndSendChanges()V"))
private void nei$cancelClientToServerSync(Container instance) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package codechicken.nei.mixins;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainerCreative;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.inventory.Slot;
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(targets = "net.minecraft.client.gui.inventory.GuiContainerCreative$ContainerCreative")
public class MixinMinecraft_GuiContainerCreative_ContainerCreative {

// Fix double click grab
@Inject(method = "func_94530_a", at = @At(value = "TAIL"), cancellable = true)
private void nei$doubleClickGrab(ItemStack p_94530_1_, Slot p_94530_2_, CallbackInfoReturnable<Boolean> cir) {
Minecraft mc = Minecraft.getMinecraft();
if (mc.currentScreen instanceof GuiContainerCreative gcc) {
if (gcc.func_147056_g() == CreativeTabs.tabInventory.getTabIndex()) cir.setReturnValue(true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package codechicken.nei.mixins;

import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.client.network.NetHandlerPlayClient;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(PlayerControllerMP.class)
public interface MixinMinecraft_PlayerControllerMP {

@Accessor("netClientHandler")
NetHandlerPlayClient nei$getNetClientHandler();

}
14 changes: 4 additions & 10 deletions src/main/java/codechicken/nei/recipe/CheatItemHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,10 @@ public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemSta
.min(contents + add, Math.min(overSlot.getSlotStackLimit(), draggedStack.getMaxStackSize()));

if (total > contents) {
if (mc.currentScreen instanceof GuiContainerCreative gcc) {
mc.thePlayer.inventory.addItemStackToInventory(draggedStack);
gcc.inventorySlots.detectAndSendChanges();
} else {
NEIClientUtils.setSlotContents(
overSlot.slotNumber,
NEIServerUtils.copyStack(draggedStack, total),
true);
NEICPH.sendGiveItem(NEIServerUtils.copyStack(draggedStack, total), false, false);
}
final int slotNumber = mc.currentScreen instanceof GuiContainerCreative ? overSlot.getSlotIndex()
: overSlot.slotNumber;
NEIClientUtils.setSlotContents(slotNumber, NEIServerUtils.copyStack(draggedStack, total), true);
NEICPH.sendGiveItem(NEIServerUtils.copyStack(draggedStack, total), false, false);
draggedStack.stackSize -= total - contents;
}

Expand Down
16 changes: 16 additions & 0 deletions src/main/resources/mixins.NotEnoughItems.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"required": true,
"minVersion": "0.8.5-GTNH",
"package": "codechicken.nei.mixins",
"refmap": "mixins.NotEnoughItems.refmap.json",
"target": "@env(DEFAULT)",
"compatibilityLevel": "JAVA_8",
"client": [
"MixinMinecraft_GuiContainerCreative",
"MixinMinecraft_GuiContainerCreative_ContainerCreative",
"MixinMinecraft_PlayerControllerMP",
"MixinMinecraft_Container"
],
"server": [],
"mixins": []
}
Loading