Skip to content

Commit

Permalink
Merge pull request #2 from slprime/change-controls
Browse files Browse the repository at this point in the history
Change appeng controls
  • Loading branch information
Dream-Master authored Jan 2, 2022
2 parents 29c2e64 + 6d41c5d commit b419f0a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 24 deletions.
67 changes: 49 additions & 18 deletions src/main/scala/net/bdew/neiaddons/appeng/AppEngGuiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,39 @@

public class AppEngGuiHandler extends INEIGuiAdapter {
@Override
public boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button) {
public boolean handleDragNDrop(GuiContainer gui, int mouseX, int mouseY, ItemStack draggedStack, int button) {
if (AddonAppeng.clsBaseGui.isInstance(gui)) {
int slotNum = -1;
Slot slot = null;
for (int k = 0; k < gui.inventorySlots.inventorySlots.size(); k++) {
slot = (Slot) gui.inventorySlots.inventorySlots.get(k);
if (isMouseOverSlot(gui, slot, mousex, mousey)) {
slotNum = k;
break;
}
}
if ((slotNum > 0) && (AddonAppeng.clsSlotFake.isInstance(slot)) && SlotHelper.isSlotEnabled(slot)) {
final Slot currentSlot = getSlotAtPosition(gui, mouseX, mouseY);

if (currentSlot != null && AddonAppeng.clsSlotFake.isInstance(currentSlot) && SlotHelper.isSlotEnabled(currentSlot)) {

if (ClientHandler.enabledCommands.contains(AddonAppeng.setWorkbenchCommand)) {
NBTTagCompound data = new NBTTagCompound();
data.setInteger("slot", slotNum);
NBTTagCompound item = new NBTTagCompound();
draggedStack.writeToNBT(item);
data.setTag("item", item);
PacketHelper.sendToServer(AddonAppeng.setWorkbenchCommand, data);
final ItemStack stack = draggedStack.copy();

stack.stackSize = Math.min(stack.stackSize, 127);

if (button == 0) { //left
setWorkbenchCommand(currentSlot.slotNumber, stack, true);
} else if (button == 1) { //right
stack.stackSize = 1;
setWorkbenchCommand(currentSlot.slotNumber, stack, false);
} else if (button == 2) { //middle
setWorkbenchCommand(currentSlot.slotNumber, stack, true);
draggedStack.stackSize -= stack.stackSize;
}

return true;
} else {
Minecraft.getMinecraft().thePlayer.addChatMessage(
new ChatComponentTranslation("bdew.neiaddons.noserver").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED))
);
}

}

}

return super.handleDragNDrop(gui, mousex, mousey, draggedStack, button);
return super.handleDragNDrop(gui, mouseX, mouseY, draggedStack, button);
}

private boolean isMouseOverSlot(GuiContainer gui, Slot slot, int mouseX, int mouseY) {
Expand All @@ -63,4 +67,31 @@ private boolean isMouseOverSlot(GuiContainer gui, Slot slot, int mouseX, int mou
mouseY -= gui.guiTop;
return mouseX >= slotX - 1 && mouseX < slotX + slotW + 1 && mouseY >= slotY - 1 && mouseY < slotY + slotH + 1;
}

private void setWorkbenchCommand(int slotNum, ItemStack stack, boolean replace)
{
NBTTagCompound message = new NBTTagCompound();
message.setInteger("slot", slotNum);
message.setBoolean("replace", replace);

NBTTagCompound item = new NBTTagCompound();
stack.writeToNBT(item);
message.setTag("item", item);

PacketHelper.sendToServer(AddonAppeng.setWorkbenchCommand, message);
}

private Slot getSlotAtPosition(GuiContainer gui, int x, int y)
{
for (int k = 0; k < gui.inventorySlots.inventorySlots.size(); ++k) {
Slot slot = (Slot)gui.inventorySlots.inventorySlots.get(k);

if (isMouseOverSlot(gui, slot, x, y)) {
return slot;
}
}

return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ public void handle(NBTTagCompound data, EntityPlayerMP player) {
Slot slot = cont.getSlot(slotNum);
if ((slot != null) && AddonAppeng.clsSlotFake.isInstance(slot) && SlotHelper.isSlotEnabled(slot)) {
ItemStack targetStack = slot.getStack();
if (null != targetStack) {
if (stack.isItemEqual(targetStack)) {
stack.stackSize = slot.getStack().stackSize + stack.stackSize;
if (stack.stackSize > 127) { // add this check if no patch this in AE encoder
stack.stackSize = 127;
}
if (null != targetStack && !data.getBoolean("replace") && stack.isItemEqual(targetStack)) {
stack.stackSize = slot.getStack().stackSize + stack.stackSize;
if (stack.stackSize > 127) { // add this check if no patch this in AE encoder
stack.stackSize = 127;
}
}
slot.putStack(stack);
Expand Down

0 comments on commit b419f0a

Please sign in to comment.