2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei;
|
|
|
|
|
|
2019-12-30 20:19:16 -08:00
|
|
|
import codechicken.nei.api.API;
|
|
|
|
|
import codechicken.nei.api.GuiInfo;
|
|
|
|
|
import codechicken.nei.api.IInfiniteItemHandler;
|
|
|
|
|
import codechicken.nei.api.INEIGuiHandler;
|
|
|
|
|
import codechicken.nei.api.ItemInfo;
|
2014-04-29 10:54:20 +10:00
|
|
|
import codechicken.nei.guihook.GuiContainerManager;
|
|
|
|
|
import codechicken.nei.guihook.IContainerInputHandler;
|
|
|
|
|
import codechicken.nei.guihook.IContainerSlotClickHandler;
|
2022-03-05 19:05:26 +09:00
|
|
|
import codechicken.nei.recipe.GuiRecipe;
|
2014-04-29 10:54:20 +10:00
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
|
import net.minecraft.client.gui.inventory.GuiContainerCreative;
|
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
|
import net.minecraft.inventory.Slot;
|
|
|
|
|
import net.minecraft.inventory.SlotCrafting;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
|
2019-12-30 20:19:16 -08:00
|
|
|
import java.awt.Point;
|
2014-04-29 10:54:20 +10:00
|
|
|
import java.util.LinkedList;
|
|
|
|
|
|
|
|
|
|
import static codechicken.lib.gui.GuiDraw.getMousePosition;
|
|
|
|
|
|
|
|
|
|
public class NEIController implements IContainerSlotClickHandler, IContainerInputHandler
|
|
|
|
|
{
|
2019-12-30 20:19:16 -08:00
|
|
|
private static final NEIController instance = new NEIController();
|
2014-04-29 10:54:20 +10:00
|
|
|
|
|
|
|
|
public static GuiContainerManager manager;
|
|
|
|
|
public static FastTransferManager fastTransferManager;
|
|
|
|
|
|
|
|
|
|
private static boolean deleteMode;
|
|
|
|
|
private static int pickedUpFromSlot;
|
|
|
|
|
private static IInfiniteItemHandler heldStackInfinite;
|
|
|
|
|
|
|
|
|
|
private static int selectedItem;
|
2014-06-29 20:31:37 +10:00
|
|
|
private ItemStack firstheld;
|
2014-04-29 10:54:20 +10:00
|
|
|
|
|
|
|
|
public static void load() {
|
|
|
|
|
GuiContainerManager.addSlotClickHandler(instance);
|
|
|
|
|
GuiContainerManager.addInputHandler(instance);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void load(GuiContainer gui) {
|
|
|
|
|
manager = GuiContainerManager.getManager(gui);
|
|
|
|
|
deleteMode = false;
|
|
|
|
|
GuiInfo.clearGuiHandlers();
|
|
|
|
|
fastTransferManager = null;
|
|
|
|
|
if (!NEIClientConfig.isEnabled())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
fastTransferManager = new FastTransferManager();
|
|
|
|
|
if (gui instanceof INEIGuiHandler)
|
|
|
|
|
API.registerNEIGuiHandler((INEIGuiHandler) gui);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
public static boolean isSpreading(GuiContainer gui) {
|
|
|
|
|
return gui.field_147007_t && gui.field_147008_s.size() > 1;
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
|
|
|
|
|
public static void updateUnlimitedItems(InventoryPlayer inventory) {
|
|
|
|
|
if (!NEIClientConfig.canPerformAction("item") || !NEIClientConfig.hasSMPCounterPart())
|
|
|
|
|
return;
|
|
|
|
|
|
2019-12-30 20:19:16 -08:00
|
|
|
LinkedList<ItemStack> beforeStacks = new LinkedList<>();
|
2014-04-29 10:54:20 +10:00
|
|
|
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
|
|
|
|
beforeStacks.add(NEIServerUtils.copyStack(inventory.getStackInSlot(i)));
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
|
|
|
|
ItemStack stack = inventory.getStackInSlot(i);
|
|
|
|
|
if (stack == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
for (IInfiniteItemHandler handler : ItemInfo.infiniteHandlers)
|
|
|
|
|
if (handler.canHandleItem(stack) && handler.isItemInfinite(stack))
|
|
|
|
|
handler.replenishInfiniteStack(inventory, i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
|
|
|
|
ItemStack newstack = inventory.getStackInSlot(i);
|
|
|
|
|
|
|
|
|
|
if (!NEIServerUtils.areStacksIdentical(beforeStacks.get(i), newstack)) {
|
|
|
|
|
inventory.setInventorySlotContents(i, beforeStacks.get(i));//restore in case of SMP fail
|
|
|
|
|
NEIClientUtils.setSlotContents(i, newstack, false);//sends via SMP handler ;)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void processCreativeCycling(InventoryPlayer inventory) {
|
|
|
|
|
if (NEIClientConfig.invCreativeMode() && NEIClientUtils.controlKey()) {
|
|
|
|
|
if (selectedItem != inventory.currentItem) {
|
|
|
|
|
if (inventory.currentItem == selectedItem + 1 || (inventory.currentItem == 0 && selectedItem == 8))//foward
|
|
|
|
|
{
|
|
|
|
|
NEICPH.sendCreativeScroll(1);
|
|
|
|
|
inventory.currentItem = selectedItem;
|
|
|
|
|
} else if (inventory.currentItem == selectedItem - 1 || (inventory.currentItem == 8 && selectedItem == 0)) {
|
|
|
|
|
NEICPH.sendCreativeScroll(-1);
|
|
|
|
|
inventory.currentItem = selectedItem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
selectedItem = inventory.currentItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void beforeSlotClick(GuiContainer gui, int slotIndex, int button, Slot slot, int modifier) {
|
|
|
|
|
if (!NEIClientConfig.isEnabled())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
firstheld = NEIClientUtils.getHeldItem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean handleSlotClick(GuiContainer gui, int slotIndex, int button, Slot slot, int modifier, boolean eventconsumed) {
|
2014-06-29 20:31:37 +10:00
|
|
|
if (eventconsumed ||
|
|
|
|
|
!NEIClientConfig.isEnabled() ||
|
|
|
|
|
isSpreading(gui))
|
2014-04-29 10:54:20 +10:00
|
|
|
return eventconsumed;
|
|
|
|
|
|
|
|
|
|
if (deleteMode && slotIndex >= 0 && slot != null) {
|
|
|
|
|
if (NEIClientUtils.shiftKey() && button == 0) {
|
|
|
|
|
ItemStack itemstack1 = slot.getStack();
|
|
|
|
|
if (itemstack1 != null)
|
|
|
|
|
NEIClientUtils.deleteItemsOfType(itemstack1);
|
|
|
|
|
|
|
|
|
|
} else if (button == 1)
|
|
|
|
|
NEIClientUtils.decreaseSlotStack(slot.slotNumber);
|
|
|
|
|
else
|
|
|
|
|
NEIClientUtils.deleteSlotStack(slot.slotNumber);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (button == 1 && slot instanceof SlotCrafting)//right click
|
|
|
|
|
{
|
|
|
|
|
for (int i1 = 0; i1 < 64; i1++)//click this slot 64 times
|
|
|
|
|
manager.handleSlotClick(slot.slotNumber, button, 0);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-29 20:31:37 +10:00
|
|
|
if (NEIClientUtils.controlKey()
|
2022-01-31 07:59:09 +05:00
|
|
|
&& modifier != 4//Drop key pressed: net.minecraft.client.gui.inventory.GuiContainer.keyTyped
|
2014-06-29 20:31:37 +10:00
|
|
|
&& slot != null && slot.getStack() != null
|
|
|
|
|
&& slot.isItemValid(slot.getStack())) {
|
|
|
|
|
NEIClientUtils.cheatItem(slot.getStack(), button, 1);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(GuiInfo.hasCustomSlots(gui))
|
|
|
|
|
return false;
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
if (slotIndex >= 0 && NEIClientUtils.shiftKey() && NEIClientUtils.getHeldItem() != null && !slot.getHasStack()) {
|
|
|
|
|
ItemStack held = NEIClientUtils.getHeldItem();
|
|
|
|
|
manager.handleSlotClick(slot.slotNumber, button, 0);
|
|
|
|
|
if (slot.isItemValid(held) && !ItemInfo.fastTransferExemptions.contains(slot.getClass()))
|
|
|
|
|
fastTransferManager.performMassTransfer(gui, pickedUpFromSlot, slotIndex, held);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (slotIndex == -999 && NEIClientUtils.shiftKey() && button == 0) {
|
|
|
|
|
fastTransferManager.throwAll(gui, pickedUpFromSlot);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void afterSlotClick(GuiContainer gui, int slotIndex, int button, Slot slot, int modifier) {
|
|
|
|
|
if (!NEIClientConfig.isEnabled())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ItemStack nowHeld = NEIClientUtils.getHeldItem();
|
|
|
|
|
|
|
|
|
|
if (firstheld != nowHeld)
|
|
|
|
|
pickedUpFromSlot = slotIndex;
|
|
|
|
|
|
|
|
|
|
if (NEIClientConfig.canPerformAction("item") && NEIClientConfig.hasSMPCounterPart()) {
|
|
|
|
|
if (heldStackInfinite != null && slot != null && slot.inventory == NEIClientUtils.mc().thePlayer.inventory) {
|
|
|
|
|
ItemStack stack = slot.getStack();
|
|
|
|
|
if (stack != null) {
|
|
|
|
|
heldStackInfinite.onPlaceInfinite(stack);
|
|
|
|
|
}
|
|
|
|
|
NEIClientUtils.setSlotContents(slotIndex, stack, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (firstheld != nowHeld)
|
|
|
|
|
heldStackInfinite = null;
|
|
|
|
|
|
|
|
|
|
if (firstheld != nowHeld && nowHeld != null) {
|
|
|
|
|
for (IInfiniteItemHandler handler : ItemInfo.infiniteHandlers) {
|
|
|
|
|
if (handler.canHandleItem(nowHeld) && handler.isItemInfinite(nowHeld)) {
|
|
|
|
|
handler.onPickup(nowHeld);
|
|
|
|
|
NEIClientUtils.setSlotContents(-999, nowHeld, true);
|
|
|
|
|
heldStackInfinite = handler;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyCode) {
|
2014-06-29 20:31:37 +10:00
|
|
|
if (!NEIClientConfig.isEnabled() ||
|
|
|
|
|
GuiInfo.hasCustomSlots(gui) ||
|
|
|
|
|
isSpreading(gui))
|
2014-04-29 10:54:20 +10:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
Slot slot = GuiContainerManager.getSlotMouseOver(gui);
|
|
|
|
|
if (slot == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
int slotIndex = slot.slotNumber;
|
|
|
|
|
|
|
|
|
|
if (keyCode == NEIClientUtils.mc().gameSettings.keyBindDrop.getKeyCode() && NEIClientUtils.shiftKey()) {
|
|
|
|
|
FastTransferManager.clickSlot(gui, slotIndex);
|
|
|
|
|
fastTransferManager.throwAll(gui, slotIndex);
|
|
|
|
|
FastTransferManager.clickSlot(gui, slotIndex);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean mouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {
|
2021-04-10 22:42:09 -07:00
|
|
|
if (!NEIClientConfig.isEnabled() || GuiInfo.hasCustomSlots(gui) || !NEIClientConfig.isMouseScrollTransferEnabled())
|
2014-04-29 10:54:20 +10:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
Point mousePos = getMousePosition();
|
|
|
|
|
Slot mouseover = manager.window.getSlotAtPosition(mousePos.x, mousePos.y);
|
|
|
|
|
if (mouseover != null && mouseover.getHasStack()) {
|
2021-04-10 22:42:09 -07:00
|
|
|
if(NEIClientConfig.shouldInvertMouseScrollTransfer()) {
|
|
|
|
|
scrolled = -scrolled;
|
|
|
|
|
}
|
2014-04-29 10:54:20 +10:00
|
|
|
if (scrolled > 0)
|
|
|
|
|
fastTransferManager.transferItem(manager.window, mouseover.slotNumber);
|
|
|
|
|
else
|
|
|
|
|
fastTransferManager.retrieveItem(manager.window, mouseover.slotNumber);
|
2022-03-05 19:05:26 +09:00
|
|
|
// slot in GuiRecipe does not contain an actual stack
|
|
|
|
|
// and scroll should also be handled by GuiRecipe
|
|
|
|
|
return !(gui instanceof GuiRecipe);
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean keyTyped(GuiContainer gui, char keyChar, int keyCode) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean mouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onKeyTyped(GuiContainer gui, char keyChar, int keyID) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onMouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onMouseDragged(GuiContainer gui, int mousex, int mousey, int button, long heldTime) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onMouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onMouseUp(GuiContainer gui, int mousex, int mousey, int button) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean canUseDeleteMode() {
|
|
|
|
|
return !(NEIClientUtils.getGuiContainer() instanceof GuiContainerCreative);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void toggleDeleteMode() {
|
|
|
|
|
if(canUseDeleteMode())
|
|
|
|
|
deleteMode = !deleteMode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean getDeleteMode() {
|
|
|
|
|
return deleteMode;
|
|
|
|
|
}
|
|
|
|
|
}
|