Sentinel *placeholder name*
Polluting the environment for your protection.

Made for, and tested in, ComputerCraft 1.80pr1 (a beta build for Minecraft 1.12).


Download

https://pastebin.com/W2u8RLPH

Click the link above for the program or execute the following in your turtle


pastebin get W2u8RLPH <name>

Description

This turtle program makes use of the seldom used Melee Turtle. It is fairly new, and still being debugged/improved. This is one of the few programs I have worked on (for ComputerCraft), and the first since a ~150 day hiatus. I do not have much experience programming in Lua, but this project has proved - and is proving - to be a valuable learning experience for me. I plan on adding more to this program once I have gotten all currently implemented features working properly; which hopefully won't take long. If you find a bug in this program or have any suggestions, please let me know in a reply or message.

Program Function

The turtle will patrol, progressing through an (ideally enclosed) area.

If the turtle encounters any entity (player/mob), it will attack and pursue that entity. The turtle compensates for attack knockback by progressing forward to match the knockback distance. This distance is set (to 3 by default) near the beginning of the program, and can be changed based on the weapon's specifications; it is best to overcompensate for knockback distance because the turtle pushes entities (allowing for direct contact and ensuring entity is in-range). If the entity is lost (or not detected) during combat, the turtle surveys the perimeter for entities within its range; also accounting for the areas above and below it. The turtle detects entities in three places while in one position: in-front, above, and below it; as long as an entity is able to occupy that area (not occupied by any block). If an entity is no longer detected, the turtle continues its route; if an entity is killed, the turtle stores dropped items.

The turtle moves through an area by going back and forth between the area's walls, moving 1 block forward along the wall each time it encounters a wall; similar to a winding snake or a square wave. If the floor of the area declines, the turtle assures that it is grounded by matching the ground level and taking note of how far below its initial height it is; compensating for inclines if its below the initial ground level (it is best to start the program with the turtle positioned on the highest point of the area floor).

The program features a refueling function which allows the turtle to refuel if fuel is present in its inventory, if the fuel limit is finite (requiring fuel for turtle movement), and if the turtle's fuel level is 0 (out of fuel). The turtle searches its inventory for fuel, only taking the time to select possible fuel sources (based on the limited sensory capabilities of a turtle). If the turtle locates fuel in its inventory, the maximum amount of fuel the turtle can store of the selected item will be used (given the aforementioned circumstances); the maximum fuel storage capacity is defined by the fuel limit set for the type of turtle in question. If the turtle does not locate fuel in its inventory, it will remain ready to engage any detected entities from various angles of attack (as attacking and turning require no fuel); whenever fuel is placed/found in the turtles inventory, the turtle will make use of it (as previously described) and continue its patrol.

The program features a weapon equipping function which allows the turtle to equip weapons if they are present in its inventory and if a weapon is not already equipped (in a certain slot). The turtle searches its inventory for weapons, only taking the time to select possible weapons (based on the limited sensory capabilities of a turtle). If the turtle locates a weapon in its inventory, the weapon is equip to a slot that has no equipped weapon; if both slots are equipped with weapons, no search is conducted as no weapons are needed (see circumstances described previously). If the turtle does not locate a weapon, the turtle will continue on its patrol and equip a weapon once one is present in the turtle's inventory.

Bugs

These are known bugs for this program. I will update this list as I find and fix bugs in the program. Please let me know if you find a bug.
  • Turtle does not detect/equip weapons in inventory when weapon slots are unoccupied. (Compensate by manually equipping weapons to weapon slots)
  • Refueling function does not account for the different amounts of fuel provided by different fuel sources, making refueling to the maximum fuel limit a matter of the amount of fuel items present; not of the amount of fuel provided by the amount of fuel items present (which is dependent on the fuel source).
  • (Possibly) Turtle movement on uneven terrain featuring inclines and declines may lead to the turtle getting stuck, among other possibilities; this is not known, but very likely considering the lack of testing done regarding uneven terrain.
Plans/Ideas

If you have an idea that you would like to contribute or see an idea that you dislike/would-change, let me know. This list is what I've come up with during the writing of this post, I may be forgetting something that I'll come to append later. I will update this list as plans and ideas are produced and implemented.
  • Implement password protection to allow those with the password to access certain information, settings, and permissions; such as the three listed separately below.
  • Allow for the disabling of turtle hostility/attacks by those with the correct password (requires password protection).
  • Display turtle statistics (such as fuel level, etc.) to those with the correct password (requires password protection).
  • Protect turtle's inventory by attacking entities that remove items from the turtle's inventory without entering the correct password; verifying authority and granting permission to manage inventory (requires password protection)
  • Account for different amounts of fuel provided by different fuel sources (refueling function).
  • Deduce and equip the best of the weapons in the turtle's inventory or weapon slots (weapon equipping function).
  • (If possible) Make the attack knockback compensation specific to the equipped weapon (by recognizing knockback enchants or weapon types).
* This post will be updated throughout the program development process.