Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

LiquidBounce Forum

  1. Home
  2. ScriptAPI
  3. Unsure how to fix script issue

Unsure how to fix script issue

Scheduled Pinned Locked Moved Unsolved ScriptAPI
3 Posts 2 Posters 627 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Alt Account 0A Offline
    Alt Account 0A Offline
    Alt Account 0
    wrote on last edited by
    #1

    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.")
                }
            }
        });
    });
    
    1 Reply Last reply
    0
    • FaaatPotatoF Offline
      FaaatPotatoF Offline
      FaaatPotato
      wrote on last edited by FaaatPotato
      #2

      Well i do like that you tried to debug. There are a couple vars that are not needed, e.g. ENABLED because onUpdate will only be called when the module is enabled - you don't need to worry about that.

      I just recoded your script to get it working. I don't know if this is the most memory efficient way to do it tho. If you want to add some Items you will have to do that on your own (via import ...).

      This script won't allow to take fish out of a storage when enabled, so you could optimize it.

      To understand what is going on you could take a look at this script since what you want is basically a reverse chest stealer undefined

      ///api_version=2
      (script = registerScript({
          name: "DepositFish",
          version: "1.0",
          authors: ["some fisherman"]
      }));
      
      var GuiChest = Java.type("net.minecraft.client.gui.inventory.GuiChest"),
          ItemFish = Java.type("net.minecraft.item.ItemFishFood")
          
      script.registerModule({
          name: "DepositFish",
          category: "Misc",
          description: "Stores fish lol"
       }, function (module) {
          module.on("update", function() {
              if (mc.currentScreen instanceof GuiChest) {
                  var inventoryContainer = Java.from(mc.thePlayer.inventoryContainer.getInventory())
                  var openContainer = Java.from(mc.thePlayer.openContainer.getInventory())
                  var fishSlots = inventoryContainer.filter(function (stack) stack && stack.getItem() instanceof ItemFish/*|| you can add more items here, you need to import them*/)
      
                  fishSlots.length && fishSlots.forEach(function (stack) mc.playerController.windowClick(mc.thePlayer.openContainer.windowId, openContainer.indexOf(stack), 0, 1, mc.thePlayer));
              }
          });
      });
      

      PS: Unique way of detecting a fish! :))

      FaaatPotatoF 1 Reply Last reply
      0
      • FaaatPotatoF FaaatPotato

        Well i do like that you tried to debug. There are a couple vars that are not needed, e.g. ENABLED because onUpdate will only be called when the module is enabled - you don't need to worry about that.

        I just recoded your script to get it working. I don't know if this is the most memory efficient way to do it tho. If you want to add some Items you will have to do that on your own (via import ...).

        This script won't allow to take fish out of a storage when enabled, so you could optimize it.

        To understand what is going on you could take a look at this script since what you want is basically a reverse chest stealer undefined

        ///api_version=2
        (script = registerScript({
            name: "DepositFish",
            version: "1.0",
            authors: ["some fisherman"]
        }));
        
        var GuiChest = Java.type("net.minecraft.client.gui.inventory.GuiChest"),
            ItemFish = Java.type("net.minecraft.item.ItemFishFood")
            
        script.registerModule({
            name: "DepositFish",
            category: "Misc",
            description: "Stores fish lol"
         }, function (module) {
            module.on("update", function() {
                if (mc.currentScreen instanceof GuiChest) {
                    var inventoryContainer = Java.from(mc.thePlayer.inventoryContainer.getInventory())
                    var openContainer = Java.from(mc.thePlayer.openContainer.getInventory())
                    var fishSlots = inventoryContainer.filter(function (stack) stack && stack.getItem() instanceof ItemFish/*|| you can add more items here, you need to import them*/)
        
                    fishSlots.length && fishSlots.forEach(function (stack) mc.playerController.windowClick(mc.thePlayer.openContainer.windowId, openContainer.indexOf(stack), 0, 1, mc.thePlayer));
                }
            });
        });
        

        PS: Unique way of detecting a fish! :))

        FaaatPotatoF Offline
        FaaatPotatoF Offline
        FaaatPotato
        wrote on last edited by FaaatPotato
        #3

        @FaaatPotato Actually it is too cool to not be used. So I included your way of doing it and you can whitelist items via text setting

        ///api_version=2
        (script = registerScript({
            name: "DepositFish",
            version: "1.0",
            authors: ["some fisherman"]
        }));
        
        var GuiChest = Java.type("net.minecraft.client.gui.inventory.GuiChest"),
            ItemFish = Java.type("net.minecraft.item.ItemFishFood")
            
        script.registerModule({
            name: "DepositFish",
            category: "Misc",
            description: "Stores fish lol",
            settings: {
                modeValue: mode = Setting.list({
                    name: "Mode",
                    values: ["FaaatPotato", "ToolTip"],
                    default: "FaaatPotato" 
                }),
                itemsValue: items = Setting.text({
                    name: "ItemsToStore",
                    default: "fish",
                    isSupported: function() {
                        return mode.get() == "ToolTip"
                    }
                })
            }
         }, function (module) {
            module.on("update", function() {
                if (mc.currentScreen instanceof GuiChest) {
                    var inventoryContainer = Java.from(mc.thePlayer.inventoryContainer.getInventory())
                    var openContainer = Java.from(mc.thePlayer.openContainer.getInventory())
                    if (mode.get() == "FaaatPotato") {
                        var fishSlots = inventoryContainer.filter(function (stack) stack && stack.getItem() instanceof ItemFish/*|| you can add more items here, you need to import them*/)
                        fishSlots.length && fishSlots.forEach(function (stack) mc.playerController.windowClick(mc.thePlayer.openContainer.windowId, openContainer.indexOf(stack), 0, 1, mc.thePlayer));
                    }
                    if (mode.get() == "ToolTip") {
                        var itemsToStore = items.get().toLowerCase().split(",")
                        var itemSlots = inventoryContainer.filter(function (stack) stack && itemsToStore.some(function (itemName) Java.from(stack.getTooltip(mc.thePlayer, true)).toString().toLowerCase().contains(itemName)))
        
                        itemSlots.length && itemSlots.forEach(function (stack) mc.playerController.windowClick(mc.thePlayer.openContainer.windowId, openContainer.indexOf(stack), 0, 1, mc.thePlayer))
                    }
                }
            });
        });
        

        just make sure to type the whole item name in the text field so no similar items will be put in the storage
        e.g.
        .depositfish itemstostore diamond_sword,fishing_rod,fish

        however this could lead to issues if names contain for example fish as in fishing_rod. Thats why you checked for != contains("rod"). But that should be solvable for you.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        About
        • Terms of Service
        • Privacy Policy
        • Status
        • Contact Us
        Downloads
        • Releases
        • Source code
        • License
        Docs
        • Tutorials
        • CustomHUD
        • AutoSettings
        • ScriptAPI
        Community
        • Forum
        • Guilded
        • YouTube
        • Twitter
        • D.Tube
        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups