Skip to content

Commit

Permalink
update nei drag
Browse files Browse the repository at this point in the history
  • Loading branch information
vfyjxf committed Jan 31, 2022
1 parent 37f181a commit a983a36
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 25 deletions.
44 changes: 34 additions & 10 deletions src/main/java/com/github/vfyjxf/nee/client/GuiEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.lwjgl.input.Mouse;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static com.github.vfyjxf.nee.config.NEEConfig.draggedStackDefaultSize;
Expand Down Expand Up @@ -163,20 +164,43 @@ public List<TaggedInventoryArea> getInventoryAreas(GuiContainer gui) {
@Override
public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) {
//When NEIAddons exist, give them to NEIAddons to handle
if(NEEConfig.enableNEIDragNDrop || !Loader.isModLoaded("NEIAddons")) {
if(Loader.isModLoaded("NEIAddons") && NEEConfig.useNEIDragFromNEIAddons){
return false;
}

if (NEEConfig.enableNEIDragNDrop) {
if (gui instanceof AEBaseGui) {
if (button != 2 && draggedStack != null) {
if (draggedStack != null) {
Slot currentSlot = gui.getSlotAtPosition(mouseX, mouseY);
if (currentSlot instanceof SlotFake && ((SlotFake) currentSlot).isEnabled()) {
List<Integer> slots = new ArrayList<>();
slots.add(currentSlot.slotNumber);
if (currentSlot instanceof SlotFake) {
ItemStack slotStack = currentSlot.getStack();
ItemStack copyStack = draggedStack.copy();
copyStack.stackSize = useStackSizeFromNEI ? draggedStack.stackSize : draggedStackDefaultSize;
NEENetworkHandler.getInstance().sendToServer(new PacketSlotStackChange(copyStack, slots));
if (!NEEConfig.keepGhostitems) {
draggedStack.stackSize = 0;
boolean sendPacket = false;
int copySize = useStackSizeFromNEI ? copyStack.stackSize : draggedStackDefaultSize;
if (button == 0) {
boolean areStackEqual = slotStack != null && slotStack.isItemEqual(copyStack) && ItemStack.areItemStackTagsEqual(slotStack, copyStack);
copyStack.stackSize = areStackEqual ? Math.min(slotStack.stackSize + copySize, 127) : Math.min(copySize, 127);
sendPacket = true;
} else if (button == 1) {
boolean areStackEqual = slotStack != null && slotStack.isItemEqual(copyStack) && ItemStack.areItemStackTagsEqual(slotStack, copyStack);
if (areStackEqual) {
copyStack.stackSize = Math.min(slotStack.stackSize + 1, 127);
} else {
copyStack.stackSize = slotStack == null ? 1 : copySize;
}
sendPacket = true;
}
return true;

if (sendPacket) {
NEENetworkHandler.getInstance().sendToServer(new PacketSlotStackChange(copyStack, Collections.singletonList(currentSlot.slotNumber)));
if (!NEEConfig.keepGhostitems) {
draggedStack.stackSize = 0;
}
return true;
}
}
if (button == 2) {
draggedStack.stackSize = 0;
}
}
}
Expand Down
66 changes: 51 additions & 15 deletions src/main/java/com/github/vfyjxf/nee/config/NEEConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class NEEConfig {
public static boolean matchOtherItems = true;
public static boolean drawHighlight = true;
public static boolean allowSynchronousSwitchIngredient = true;
public static boolean useNEIDragFromNEIAddons = false;
public static boolean enableNEIDragNDrop = true;
public static boolean useStackSizeFromNEI = true;
public static boolean keepGhostitems = true;
Expand Down Expand Up @@ -60,6 +61,7 @@ public static void loadConfig(File configFile) {
itemCombinationWhitelist = config.get(CATEGORY_PATTERN_TRANSFER, "itemCombinationWhitelist", itemCombinationWhitelist,
"Whitelist for item combination").getStringList();
}

{
matchOtherItems = config.get(CATEGORY_CRAFTING_HELPER, "matchOnCraftableItems", true,
"If true, Crafting Helper will match other items even they can't auto-crafting").getBoolean();
Expand All @@ -70,10 +72,13 @@ public static void loadConfig(File configFile) {
enableCraftAmountSettingGui = config.get(CATEGORY_CRAFTING_HELPER, "enableCraftAmountSettingGui", false,
"If true, it will open a gui to set craft amount after ctrl + click [?] button").getBoolean();
}

{
allowSynchronousSwitchIngredient = config.get(CATEGORY_OTHER_SETTINGS, "allowSynchronousSwitchIngredient", true,
"If true, it will make all similar ingredient switch at the same time").getBoolean(true);

useNEIDragFromNEIAddons = config.get(CATEGORY_OTHER_SETTINGS, "useNEIDragFromNEIAddons", false, "Use the NEI Drag from NEI Addons").getBoolean();

enableNEIDragNDrop = config.get(CATEGORY_OTHER_SETTINGS, "enableNEIDragNDrop", true, "").getBoolean();

useStackSizeFromNEI = config.get(CATEGORY_OTHER_SETTINGS, "useStackSizeFromNEI", true,
Expand All @@ -84,30 +89,61 @@ public static void loadConfig(File configFile) {
draggedStackDefaultSize = config.get(CATEGORY_OTHER_SETTINGS, "draggedStackDefaultSize", 1,
"The default size of the dragged ItemStack when it is put in slot(Used when useStackSizeFromNEI is false)", 1, 64).getInt();
}

if (config.hasChanged()) config.save();
}

public static void reload() {
config.load();
transformBlacklist = config.get(CATEGORY_PATTERN_TRANSFER, "transformItemBlacklist", new String[0],
"If item in the blacklist, it will not be transferred.\n" +
"the format is \" {modid:modid,name:name,meta:meta,recipeProcessor:recipeProcessorID,identifier:identifier}\"\n" +
"example: \"{modid:minecraft,name:iron_ingot,recipeProcessor:EnderIO,identifier:EnderIOAlloySmelter}\"").getStringList();
transformPriorityList = config.get(CATEGORY_PATTERN_TRANSFER, "transformItemPriorityList", new String[0],
"If item in the priority list, it will be transferred first.").getStringList();

transformPriorityModList = config.get(CATEGORY_PATTERN_TRANSFER, "transformPriorityModList", new String[0],
"if oredict has this mod's item, use it first").getStringList();
{
transformBlacklist = config.get(CATEGORY_PATTERN_TRANSFER, "transformItemBlacklist", new String[0],
"If item in the blacklist, it will not be transferred.\n" +
"the format is \" {modid:modid,name:name,meta:meta,recipeProcessor:recipeProcessorID,identifier:identifier}\"\n" +
"example: \"{modid:minecraft,name:iron_ingot,recipeProcessor:EnderIO,identifier:EnderIOAlloySmelter}\"").getStringList();
transformPriorityList = config.get(CATEGORY_PATTERN_TRANSFER, "transformItemPriorityList", new String[0],
"If item in the priority list, it will be transferred first.").getStringList();

transformPriorityModList = config.get(CATEGORY_PATTERN_TRANSFER, "transformPriorityModList", new String[0],
"if oredict has this mod's item, use it first").getStringList();

noShift = config.get(CATEGORY_PATTERN_TRANSFER, "noShift", true,
"if true, you don't need to press shift to use NEI's transfer system in CratingTerminal and PatternTerminal").getBoolean();
noShift = config.get(CATEGORY_PATTERN_TRANSFER, "noShift", true,
"if true, you don't need to press shift to use NEI's transfer system in CratingTerminal and PatternTerminal").getBoolean();

itemCombinationMode = config.get(CATEGORY_PATTERN_TRANSFER, "itemCombinationMode", itemCombinationMode,
"Item Combination Mode Setting, here are all the modes. \n"
+ "\"ENABLED\"" + " " + "\"DISABLED\"" + " " + "WHITELIST").getString();

itemCombinationWhitelist = config.get(CATEGORY_PATTERN_TRANSFER, "itemCombinationWhitelist", itemCombinationWhitelist,
"Whitelist for item combination").getStringList();
}

itemCombinationMode = config.get(CATEGORY_PATTERN_TRANSFER, "itemCombinationMode", itemCombinationMode,
"Item Combination Mode Setting, here are all the modes. \n"
+ "\"ENABLED\"" + " " + "\"DISABLED\"" + " " + "WHITELIST").getString();
{
matchOtherItems = config.get(CATEGORY_CRAFTING_HELPER, "matchOnCraftableItems", true,
"If true, Crafting Helper will match other items even they can't auto-crafting").getBoolean();

drawHighlight = config.get(CATEGORY_CRAFTING_HELPER, "drawHighlight", true,
"if true,it will draw highlight for missing items and item which can autocraft in nei").getBoolean();

enableCraftAmountSettingGui = config.get(CATEGORY_CRAFTING_HELPER, "enableCraftAmountSettingGui", false,
"If true, it will open a gui to set craft amount after ctrl + click [?] button").getBoolean();
}

{
allowSynchronousSwitchIngredient = config.get(CATEGORY_OTHER_SETTINGS, "allowSynchronousSwitchIngredient", true,
"If true, it will make all similar ingredient switch at the same time").getBoolean(true);

enableNEIDragNDrop = config.get(CATEGORY_OTHER_SETTINGS, "enableNEIDragNDrop", true, "").getBoolean();

useStackSizeFromNEI = config.get(CATEGORY_OTHER_SETTINGS, "useStackSizeFromNEI", true,
"Use the StackSize set by NEI").getBoolean();

keepGhostitems = config.get(CATEGORY_OTHER_SETTINGS, "keepGhostitems", true, "keep ghost items after click").getBoolean();

draggedStackDefaultSize = config.get(CATEGORY_OTHER_SETTINGS, "draggedStackDefaultSize", 1,
"The default size of the dragged ItemStack when it is put in slot(Used when useStackSizeFromNEI is false)", 1, 64).getInt();
}

itemCombinationWhitelist = config.get(CATEGORY_PATTERN_TRANSFER, "itemCombinationWhitelist", itemCombinationWhitelist,
"Whitelist for item combination").getStringList();
ItemUtils.reloadConfig();
}

Expand Down

0 comments on commit a983a36

Please sign in to comment.