This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 171
Added travel using an elytra feature, the RepairToolTask and some edits around that #194
Open
badpiggies007
wants to merge
24
commits into
gaucho-matrero:main
Choose a base branch
from
badpiggies007:elytra-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
14e3389
Start of the movement with elytra task, and added firework_rocket int…
badpiggies007 a0227b5
Fix fireworks in TaskCatalogue (bad item output number, was 3 instead…
badpiggies007 6bdfcee
Added a new state named 'disableDefence' inside BotBehaviour to disab…
badpiggies007 fe20c5f
Added a command for the GetToXZWithElytraTask, and removed the elytra…
badpiggies007 819f334
Edited the elytra command usage in usage.md
badpiggies007 ee1acad
Made the 'moving to the surface' thing more reliable to find a place …
badpiggies007 60403d2
Merge branch 'main' into elytra-test
badpiggies007 5819a0f
Some elytra edit : added checking elytra durability to avoid falling …
badpiggies007 0cd915f
Edited some comments and optimised import in the elytra travel task
badpiggies007 58f66ae
Added the RepairToolTask, that can repair items that have mending on …
badpiggies007 2db2c72
Now using a better way to detect when landed in the elytra travel task
badpiggies007 17596dd
Merge remote-tracking branch 'origin' into elytra-test
badpiggies007 0c54576
Renamed import of the TimeTimer in RepairToolTask and in GetToXZWithE…
badpiggies007 cecc968
Now using Worldhelper.getGroundHeight in the elytra travel task
badpiggies007 548ef61
Removed code duplicate (isGrounded)
badpiggies007 f754aac
Using PlayerSlot.ARMOR_CHESTPLATE_SLOT instead of PlayerSlot(6)
badpiggies007 72c4454
Removed the _isFinished bool in the elytra task
badpiggies007 f169977
Removed 'magic numbers' from the elytra travel task
badpiggies007 1b23d97
Renamed 'disableDefence' to 'defence' and to 'isDefenseDisabled'
badpiggies007 ee90ed5
Some changes to the repairToolTask
badpiggies007 6a2c7d8
Edited the layers where the bot need to fly to y=325
badpiggies007 eb50987
Forgot to rename SlotRepair to slotRepair in the repair tool task
badpiggies007 2ea8832
Code style/minor adjustments in `RepairToolTask`
TacoTechnica ccbdafa
Elytra flying renaming + `WorldHelper` fixes and adjustments
TacoTechnica File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/adris/altoclef/commands/GotoWithElytraCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package adris.altoclef.commands; | ||
|
||
import adris.altoclef.AltoClef; | ||
import adris.altoclef.commandsystem.Arg; | ||
import adris.altoclef.commandsystem.ArgParser; | ||
import adris.altoclef.commandsystem.Command; | ||
import adris.altoclef.commandsystem.CommandException; | ||
import adris.altoclef.tasks.movement.GetToXZWithElytraTask; | ||
|
||
public class GotoWithElytraCommand extends Command { | ||
public GotoWithElytraCommand() throws CommandException { | ||
super("elytra", "Tell bot to travel to a set of coordinates using Elytra", new Arg(Integer.class, "x"), new Arg(Integer.class, "z")); | ||
} | ||
|
||
@Override | ||
protected void call(AltoClef mod, ArgParser parser) throws CommandException { | ||
int x = parser.get(Integer.class); | ||
int z = parser.get(Integer.class); | ||
mod.runUserTask(new GetToXZWithElytraTask(x,z), this::finish); | ||
} | ||
} |
183 changes: 183 additions & 0 deletions
183
src/main/java/adris/altoclef/tasks/misc/RepairToolTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
package adris.altoclef.tasks.misc; | ||
|
||
import adris.altoclef.AltoClef; | ||
import adris.altoclef.Debug; | ||
import adris.altoclef.tasks.entity.KillEntityTask; | ||
import adris.altoclef.tasks.movement.GetToBlockTask; | ||
import adris.altoclef.tasks.movement.TimeoutWanderTask; | ||
import adris.altoclef.tasks.movement.GetToEntityTask; | ||
import adris.altoclef.tasks.entity.DoToClosestEntityTask; | ||
import adris.altoclef.tasksystem.Task; | ||
import adris.altoclef.util.ItemTarget; | ||
import adris.altoclef.util.helpers.StorageHelper; | ||
import adris.altoclef.util.slots.Slot; | ||
import adris.altoclef.util.slots.PlayerSlot; | ||
import adris.altoclef.util.helpers.ItemHelper; | ||
import net.minecraft.item.Items; | ||
import baritone.api.utils.input.Input; | ||
import net.minecraft.entity.mob.ZombieEntity; | ||
import net.minecraft.entity.ExperienceOrbEntity; | ||
import adris.altoclef.util.time.TimerGame; | ||
import adris.altoclef.util.helpers.LookHelper; | ||
import baritone.api.utils.Rotation; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.enchantment.EnchantmentHelper; | ||
import net.minecraft.enchantment.Enchantments; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.nbt.NbtElement; | ||
import net.minecraft.item.ItemStack; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Arrays; | ||
|
||
public class RepairToolTask extends Task { | ||
|
||
private final ItemTarget[] _toRepair; | ||
|
||
private boolean _finished; | ||
private final TimerGame _throwTimer = new TimerGame(0.5); | ||
|
||
public RepairToolTask(ItemTarget... toRepair) { | ||
_toRepair = toRepair; | ||
} | ||
public RepairToolTask() { //If this task is called without itemtarget, repair anything we can | ||
this( | ||
new ItemTarget(ItemHelper.NETHERITE_ARMORS), | ||
new ItemTarget(ItemHelper.NETHERITE_TOOLS), | ||
new ItemTarget(Items.ELYTRA), | ||
new ItemTarget(ItemHelper.DIAMOND_ARMORS), | ||
new ItemTarget(ItemHelper.DIAMOND_TOOLS), | ||
new ItemTarget(ItemHelper.IRON_ARMORS), | ||
new ItemTarget(ItemHelper.IRON_TOOLS), | ||
new ItemTarget(ItemHelper.GOLDEN_ARMORS), | ||
new ItemTarget(ItemHelper.GOLDEN_TOOLS), | ||
new ItemTarget(ItemHelper.STONE_TOOLS), | ||
new ItemTarget(ItemHelper.LEATHER_ARMORS), | ||
new ItemTarget(ItemHelper.WOODEN_TOOLS), | ||
new ItemTarget(Items.FISHING_ROD), | ||
new ItemTarget(Items.FLINT_AND_STEEL), | ||
new ItemTarget(Items.CARROT_ON_A_STICK), | ||
new ItemTarget(Items.SHEARS), | ||
new ItemTarget(Items.BOW), | ||
new ItemTarget(Items.SHIELD), | ||
new ItemTarget(Items.TRIDENT), | ||
new ItemTarget(Items.CROSSBOW), | ||
new ItemTarget(Items.WARPED_FUNGUS_ON_A_STICK), | ||
new ItemTarget(Items.BOW) | ||
); | ||
} | ||
@Override | ||
protected void onStart(AltoClef mod) { | ||
_throwTimer.reset(); | ||
} | ||
|
||
@Override | ||
protected Task onTick(AltoClef mod) { | ||
//We start this task by filtering out every item type that we can't repair : | ||
//All items without mending or with no damage | ||
ItemTarget[] shouldRepair = Arrays.stream(_toRepair).filter(target -> needRepair(mod, target)).toArray(ItemTarget[]::new); | ||
|
||
//After that, we get the first item type to repair on the list | ||
Optional<ItemTarget> itemTargetOPTRepair = Arrays.stream(shouldRepair).findFirst(); | ||
|
||
if (itemTargetOPTRepair.isPresent()) { //If the list is not empty | ||
ItemTarget itemTargetRepair = itemTargetOPTRepair.get(); //We get the (real) first item on the list | ||
|
||
List<Slot> slotRepairs = mod.getItemStorage().getSlotsWithItemPlayerInventory(false, itemTargetRepair.getMatches()); //And we get a list of every slot with that item | ||
|
||
Optional<Slot> slotRepairTarget = Optional.empty(); | ||
for (Slot couldRepair : slotRepairs) { | ||
if (slotRepairTarget.isEmpty() && StorageHelper.getItemStackInSlot(couldRepair).getDamage() != 0) { //if we can repair it | ||
if (EnchantmentHelper.get(StorageHelper.getItemStackInSlot(couldRepair)).containsKey(Enchantments.MENDING)) { //and it have mending | ||
slotRepairTarget = Optional.of(couldRepair); //Replace the placeholder slot with the slot we found | ||
} | ||
} | ||
} | ||
if (slotRepairTarget.isPresent()) { //If we found our slot, we can now repair the item ! | ||
final Slot ItemToEquip = slotRepairTarget.get(); | ||
setDebugState("Repairing " + StorageHelper.getItemStackInSlot(ItemToEquip).getName().getString()); | ||
if (!_throwTimer.elapsed()){ //If we just used a experience bottle, get the item in our hand to repair | ||
mod.getSlotHandler().forceEquipSlot(ItemToEquip); | ||
return null; | ||
} | ||
//Get the nearest experience orb | ||
boolean isExpPresent = mod.getEntityTracker().entityFound(ExperienceOrbEntity.class); | ||
if (isExpPresent) { //if there is one | ||
setDebugState("Collecting EXP Orbs"); | ||
return new DoToClosestEntityTask(entity -> { //Get to the entity | ||
if (entity.isInRange(mod.getPlayer(), 3)) { //and if the orb is near the player | ||
mod.getSlotHandler().forceEquipSlot(ItemToEquip); //get the item in our hand to repair the item | ||
} | ||
return new GetToEntityTask(entity, 0); | ||
}, ExperienceOrbEntity.class); | ||
} | ||
if (mod.getItemStorage().hasItem(Items.EXPERIENCE_BOTTLE)) { //if we have some experience bottle | ||
setDebugState("Throwing EXP Bottles for EXP"); | ||
if (_throwTimer.elapsed()) { //the timer for throwing a experience bottle | ||
if (!LookHelper.isLookingAt(mod, new Rotation(0, 90))) { | ||
LookHelper.lookAt(mod, new Rotation(0, 90)); //Look at our feet | ||
} | ||
mod.getSlotHandler().forceEquipItem(Items.EXPERIENCE_BOTTLE); //equip it | ||
mod.getInputControls().tryPress(Input.CLICK_RIGHT); //and throw it | ||
_throwTimer.reset(); | ||
} | ||
return null; | ||
} | ||
|
||
setDebugState("Killing Zombies for EXP"); | ||
return new DoToClosestEntityTask(KillEntityTask::new, ZombieEntity.class); | ||
} | ||
} //If there is no items in the list of itemtype to repair, it means there is nothing to repair :) | ||
setDebugState("Done"); | ||
_finished = true; | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isFinished(AltoClef mod) { | ||
return _finished; | ||
} | ||
//Check if a type of item can be repaired. | ||
public static boolean needRepair(AltoClef mod, ItemTarget target) { | ||
List<Slot> slotRepair = mod.getItemStorage().getSlotsWithItemPlayerInventory(false, target.getMatches()); | ||
for (Slot couldRepair : slotRepair) { | ||
if (StorageHelper.getItemStackInSlot(couldRepair).getDamage() != 0) { | ||
if (EnchantmentHelper.get(StorageHelper.getItemStackInSlot(couldRepair)).containsKey(Enchantments.MENDING)) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
//Will get the durability of an item in accordance of the ItemTarget. | ||
//Return the durability of one of the item, or -1 if all targeted items is repaired or doesn't have the targeted item | ||
public static int getDurabilityOfRepairableItem(AltoClef mod, ItemTarget target) { | ||
List<Slot> slotRepairs = mod.getItemStorage().getSlotsWithItemPlayerInventory(false, target.getMatches()); | ||
for (Slot couldRepair : slotRepairs) { | ||
if (StorageHelper.getItemStackInSlot(couldRepair).getDamage() != 0) { | ||
if (EnchantmentHelper.get(StorageHelper.getItemStackInSlot(couldRepair)).containsKey(Enchantments.MENDING)) { | ||
return StorageHelper.getItemStackInSlot(couldRepair).getMaxDamage() - StorageHelper.getItemStackInSlot(couldRepair).getDamage(); | ||
} | ||
} | ||
} | ||
return -1; | ||
} | ||
@Override | ||
protected void onStop(AltoClef mod, Task interruptTask) { | ||
|
||
} | ||
|
||
@Override | ||
protected boolean isEqual(Task other) { | ||
if (other instanceof RepairToolTask task) { | ||
return Arrays.equals(task._toRepair, _toRepair); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
protected String toDebugString() { | ||
return "Repairing: " + Arrays.toString(_toRepair); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making mob defence enabled/disabled an interface. We can talk about how to integrate this later. Discord me if you are interested in learning about this,