CC: Tweaked

CC: Tweaked

57M Downloads

Turtles should be able to detect Equipped Pickaxes

kaseyawolf2 opened this issue · 13 comments

commented

Turtles currently have no way of know if they have pickaxe equipped.

My current workaround is unequipping and detecting if anything appeared in the turtles inventory

It would be nice if turtles, could use the peripheral.Find to detect if theres a pickaxe.

would save me like 2 headaches.

commented

I'm curious as to what you need this for? Is this just to ensure that the turtle has a valid tool?

I'm not opposed to this in principle, but I do want to ensure people don't end up writing code like if turtle.getLeftUpgrade() ~= "minecraft:diamond_pickaxe" then error("Need a pick") end. Otherwise it's just going to be incompatible with people using other pick upgrades (such as those from other mods or added via CraftTweaker).

commented

If tools do become full peripherals then being able to interrogate their mining level would be nice and help justify their classification as a peripheral.

I'm now trying to think of some other peripheral/peripheral-like methods that could be placed on tools. Maybe the ability to strip logs with axes via a peripheral method. Making paths with shovels, which turtle might already be able to do from a block away. Using a hoe to till farmland, which I already know that turtles can do by digging one block away.

commented

Can they? I was under impression that tool or crafting table upgrade was blocking the side.. Must have misremembered.
obraz
Hmm.. I guess they do. Nevermind my suggestion of using the peripheral system..

But still having turtle.getLeftUpgrade() report generic types of pickaxe, axe or shovel would get around the issue of someone making it check for diamond pickaxe. After all pickaxe from other mod would still be a pickaxe ?

commented

Im working on a Turtle Command and control System that assigns Turtles jobs, and one of those jobs will be mining, it would be nice to be able to quickly verify that the turtle has a digging tool equipped. i don't need to explicitly detect if it has a Diamond Pick i was just wanting an easy wait to see if the turtle can dig with out 1. accidently breaking a important block by calling turtle.dig() and checking the results or 2. unequipping checking inventory, and reequipping.

commented

Maybe turtle.getLeftUpgrade() should return a table that contains information about the tool and not (just) the name of the tool.

Something like this may be:

{
  type = "pickaxe",
  miningLevel = 5
}

Also, currently one could check that turtle.dig is defined, but that doesn't tell you if the turtle has a pickaxe or a shovel which can be an important distinction for a miner.

commented

That would work and it gives more info on what's equipped and its ability.

Also, I was under the impression that turtle.dig was always defined. as far as i know it returns false and a string on why it failed to dig, such as No tool, No block, or unbreakable block, or true when it does break.

commented

Turtles can have a block peripheral (e.g. disk drive, chest) and tool upgrade (pick, sword) at the same time, so creating phantom peripherals doesn't feel very nice.

commented

As alternative instead of adding new functions how about making tools and crafting table report their existence as peripherals?

They would be stub peripherals without any methods but having tools report at pickaxe, axe, shovel & craftingtable type peripherals would also give information to user that there is peripheral there that provides pickaxe functionality to turtle same way that they check if there is a modem installed.

This would also get around the if turtle.getLeftUpgrade() ~= "minecraft:diamond_pickaxe" then error("Need a pick") end issue cause pickaxe from some other mod would still report as pickaxe ?

commented

That was my original suggestion that they report back with the find function. Either way works, i just think that there needs to be some way for it to be known to the turtle.

Also crafting tables report under the workbench peripheral

commented

The only issue with making them peripherals is it would completely break compatibly with almost every turtle script since digging would become a peripheral call instead of a turtle call.

we would have to make turtle.dig use the pickaxe peripheral which i imagine isnt impossible but may be annoying idk im lua newbie

commented

turtle.craft already does that kind of thing.

commented

If the hand is (hands are) a peripheral, the turtle can call it's dig function which would left-click the item it contains. advanced programs could query the item stack. The last problem would be querying the tool capabilities ["pickaxe", "shovel", …] and maybe a convenience function hasCapability("pickaxe").

commented

Advanced peripherals has digBlock(). You can use labels for identification and also everything mentioned can be coded.