Hello, my goal is to detect if an item is a fish within a certain server then deposit it automatically into whatever the current open container is. Fish detection works fine, the only issue with my code is moving it to the container (for example an open single chest). Currently what happens is the fish is attempted to be moved into the chest but it continuously gets sent back and just doesn't work.
/// api_version=2
var ENABLED = false;
var DEBUG = false;
function Log(message) {
if (DEBUG)
Chat.print(message);
}
var script = registerScript({
name: "AutoFishSave",
version: "1.0.0",
authors: [""]
});
script.registerModule({
name: "AutoFishSave",
category: "Misc",
description: "Automatically deposit fish into your open storage."
}, function (module) {
module.on("enable", function() {
ENABLED = true;
});
module.on("disable", function() {
ENABLED = false;
});
module.on("update", function() {
if (ENABLED) {
Log("Initial execution.")
var Inventory = mc.thePlayer.inventory.mainInventory;
Log("Inventory found, length is " + Inventory.length + ".")
for (var Idx = 0; Idx < Inventory.length; Idx++) {
Log("Iterating through inventory, index is " + Idx + ".")
var Item = Inventory[Idx];
if (Item == null)
continue;
Log("Item found.")
var ToolTipData = Item.getTooltip(mc.thePlayer, true);
if (ToolTipData == null)
continue;
Log("Tooltip data found, length is " + ToolTipData.length + ".")
var IsFish = false; // for debugging set to true;
for (var SubIdx = 0; SubIdx < ToolTipData.length; SubIdx++) {
var TTLine = ToolTipData[SubIdx];
if (TTLine.contains("fish") && !TTLine.contains("rod")) {
IsFish = true;
break;
}
}
Log("IsFish is " + IsFish + ".")
if (!IsFish)
continue;
var CurrentOpenContainer = mc.thePlayer.openContainer;
if (CurrentOpenContainer == null || CurrentOpenContainer.windowId == 0)
continue;
Log("Suitable container found.")
mc.playerController.windowClick(
CurrentOpenContainer.windowId,
Idx,
0,
2,
mc.thePlayer
);
Log("Moved fish to storage.")
}
}
});
});