Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@
import io.github.itzispyder.clickcrystals.scripting.syntax.macros.*;
import io.github.itzispyder.clickcrystals.scripting.syntax.macros.camera.SnapToCmd;
import io.github.itzispyder.clickcrystals.scripting.syntax.macros.camera.TurnToCmd;
import io.github.itzispyder.clickcrystals.scripting.syntax.macros.inventory.GuiDropCmd;
import io.github.itzispyder.clickcrystals.scripting.syntax.macros.inventory.GuiQuickMoveCmd;
import io.github.itzispyder.clickcrystals.scripting.syntax.macros.inventory.GuiSwapCmd;
import io.github.itzispyder.clickcrystals.scripting.syntax.macros.inventory.GuiSwitchCmd;
import io.github.itzispyder.clickcrystals.scripting.syntax.macros.inventory.*;
import io.github.itzispyder.clickcrystals.util.minecraft.ChatUtils;
import io.github.itzispyder.clickcrystals.util.misc.TickScheduler;
import net.fabricmc.api.ModInitializer;
Expand Down Expand Up @@ -222,6 +219,8 @@ public void initClickScript() {
ClickScript.register(new CancelPacketCmd());
ClickScript.register(new UncancelPacketCmd());
ClickScript.register(new ToggleInputCmd());
ClickScript.register(new CraftCmd());
ClickScript.register(new CraftInvCmd());
ScriptedModule.runModuleScripts();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public class TextFieldElement extends GuiElement implements Typeable {
private boolean selectionBlinking, selectedAll;
private int selectionBlink;

private final List<String> history = new ArrayList<>();
private int historyIndex = -1;


public TextFieldElement(String preText, int x, int y, int width, int height) {
super(x, y, width, height);
this.selectedStartPoint = new Point();
Expand All @@ -51,6 +55,7 @@ public void onChar(char chr) {
if (Character.isISOControl(chr)) {
return;
}
pushHistory();
onInput(input -> insertInput(String.valueOf(chr)));
shiftRight();
}
Expand Down Expand Up @@ -129,26 +134,33 @@ else if (key == GLFW.GLFW_KEY_A && screen.ctrlKeyPressed) {
return true;
}
else if (key == GLFW.GLFW_KEY_BACKSPACE) {
pushHistory();
onInput(currentContent -> selectionStart > 0 && !currentContent.isEmpty()
? currentContent.substring(0, selectionStart - 1) + currentContent.substring(selectionStart)
: currentContent);
shiftLeft();
return true;
}
else if (key == GLFW.GLFW_KEY_DELETE) {
pushHistory();
onInput(input -> StringUtils.insertString(content, selectionStart + 1, null));
return true;
}
else if (key == GLFW.GLFW_KEY_V && screen.ctrlKeyPressed) {
onInput(input -> insertInput(mc.keyboardHandler.getClipboard()));
shiftRight();
pushHistory();
String content = mc.keyboardHandler.getClipboard();
onInput(input -> insertInput(content));
for (int i = 0; i <= content.length()-1; i++){
shiftRight();
}
return true;
}
else if (key == GLFW.GLFW_KEY_C && screen.ctrlKeyPressed && selectedAll) {
mc.keyboardHandler.setClipboard(content);
return true;
}
else if (key == GLFW.GLFW_KEY_ENTER) {
pushHistory();
onInput(input -> insertInput("\n"));
shiftRight();
shiftRight();
Expand All @@ -171,10 +183,44 @@ else if (key == GLFW.GLFW_KEY_DOWN) {
for (int i = 0; i < 10; i++)
shiftRight();
return true;
} else if (key == GLFW.GLFW_KEY_Z && screen.ctrlKeyPressed) {
undo();
return true;
}
else if (key == GLFW.GLFW_KEY_Y && screen.ctrlKeyPressed) {
redo();
return true;
}
return false;
}

private void undo() {
if (historyIndex < 0) return;
historyIndex--;
content = historyIndex >= 0 ? history.get(historyIndex) : "";
styledContent = style(content);
updateSelection();
}

private void redo() {
if (historyIndex >= history.size() - 1) return;
historyIndex++;
content = history.get(historyIndex);
styledContent = style(content);
updateSelection();
}

private void pushHistory() {
history.subList(historyIndex + 1, history.size()).clear();
history.add(content);
if (history.size() > 667) { // so it doesnt eat memory (unless your script has like 100k lines dw)
history.remove(0);
historyIndex = history.size() - 1;
} else {
historyIndex = history.size() - 1;
}
}

@Override
public void mouseClicked(double mouseX, double mouseY, int button) {
super.mouseClicked(mouseX, mouseY, button);
Expand Down Expand Up @@ -406,4 +452,5 @@ public Pair<String, Boolean> process(String str) {
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.github.itzispyder.clickcrystals.scripting.syntax.macros.inventory;

import io.github.itzispyder.clickcrystals.scripting.ScriptArgs;
import io.github.itzispyder.clickcrystals.scripting.ScriptCommand;
import io.github.itzispyder.clickcrystals.scripting.syntax.ThenChainable;
import io.github.itzispyder.clickcrystals.util.minecraft.InvUtils;
import net.minecraft.client.gui.screens.inventory.CraftingScreen;
import net.minecraft.world.inventory.AbstractContainerMenu;

// @Format craft 1 2 3 4 5 6 7 8 9
// You need to be in a crafting table actually use it
public class CraftCmd extends ScriptCommand implements ThenChainable {
public CraftCmd() {
super("craft");
}

@Override
public void onCommand(ScriptCommand command, String line, ScriptArgs args) {
if (mc.gameMode == null || mc.player == null)
return;


AbstractContainerMenu menu = mc.player.containerMenu;
if (mc.screen instanceof CraftingScreen screen) {
InvUtils.craftCCS(menu, args, 9);
}
executeWithThen(args, 9);
}
}

// sum mf said "i dont like crafting mods" - Server Owners probably
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.github.itzispyder.clickcrystals.scripting.syntax.macros.inventory;

import io.github.itzispyder.clickcrystals.scripting.ScriptArgs;
import io.github.itzispyder.clickcrystals.scripting.ScriptCommand;
import io.github.itzispyder.clickcrystals.scripting.syntax.ThenChainable;
import io.github.itzispyder.clickcrystals.util.minecraft.InvUtils;
import net.minecraft.client.gui.screens.inventory.CraftingScreen;
import net.minecraft.world.inventory.AbstractContainerMenu;

// @Format craft_inv 1 2 3 4
// You DONT need to be in a crafting table actually use it
public class CraftInvCmd extends ScriptCommand implements ThenChainable {
public CraftInvCmd() {
super("craft_inv");
}

@Override
public void onCommand(ScriptCommand command, String line, ScriptArgs args) {
if (mc.gameMode == null || mc.player == null)
return;
if (!(mc.screen instanceof CraftingScreen screen)){ // cuz then it starts goofing around when you have both in same script
AbstractContainerMenu menu = mc.player.containerMenu;
InvUtils.craftCCS(menu, args, 4);
}



executeWithThen(args, 4);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package io.github.itzispyder.clickcrystals.util.minecraft;

import io.github.itzispyder.clickcrystals.Global;
import io.github.itzispyder.clickcrystals.scripting.ScriptArgs;
import io.github.itzispyder.clickcrystals.scripting.ScriptParser;
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
import net.minecraft.network.HashedStack;
import net.minecraft.network.protocol.game.ServerboundContainerClickPacket;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ContainerInput;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;

Expand Down Expand Up @@ -177,4 +181,44 @@ public static boolean sendSlotPacket(int slot, int button, ContainerInput action
PlayerUtils.sendPacket(swap);
return true;
}

public static void craftCCS(AbstractContainerMenu menu, ScriptArgs args, int gridSize){
for (int i = 0; i < gridSize; i++) {
Predicate<ItemStack> item = ScriptParser.parseItemPredicate(args.get(i).toString());

for (Slot slot : menu.slots) {
if (slot.index < 10) continue;
ItemStack stack = slot.getItem();

if (item.test(stack)) {
if (!menu.getCarried().isEmpty()) {
return;
}

int from = slot.index;

mc.gameMode.handleContainerInput(menu.containerId, from, 0, ContainerInput.PICKUP, mc.player);
mc.gameMode.handleContainerInput(menu.containerId, i+1, 1, ContainerInput.PICKUP, mc.player);
mc.gameMode.handleContainerInput(menu.containerId, from, 0, ContainerInput.PICKUP, mc.player);

break;
}
}
}

new Thread(() -> {
try {
Thread.sleep(100); // if your ping is over this, fuck you
mc.execute(() -> {
mc.gameMode.handleContainerInput(
menu.containerId,
0,
0,
ContainerInput.QUICK_MOVE,
mc.player
);
});
} catch (Exception ignored) {}
}).start();
}
}