Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Added travel using an elytra feature, the RepairToolTask and some edits around that #194

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

badpiggies007
Copy link
Contributor

I started woking on this about a week ago mostly for fun, and i think it's ready

In this pull request :

  • Added the firework_rocket (level 1) in taskCatalogue
  • Added a way of disabling mobDefence and the MLG from a task, it's inside BotBehaviour
  • Created the task GetToXZWithElytraTask :
    • Will get fireworks if needed
    • Will fly down if the elytra is going to break
    • Will travel to XZ by foot if it doesn't have an elytra, or it have a broken one
    • Will repair the elytra if it have mending on it
    • Some footage of the bot running the task : https://youtu.be/k0qzBwkhkd4
  • Added a command to travel using elytra : @elytra <x> <z>
  • Added the elytra command and its usage in usage.md
  • Created the task RepairToolTask :
    • Will use bottle of experience if have any
    • Will kill some zombies if doesn't have bottle of experience
    • Can repair any tool that have mending on it
    • Test command : @test repair
    • Doesn't repair equipped armor
    • Some footage of the repair task : https://youtu.be/ccv1X0IKpm0

And i think i listed everything that i added/edited in that PR.

Copy link
Collaborator

@TacoTechnica TacoTechnica left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Hyped to merge this in, just got some code recommendations to go through first.

return null;
}
private boolean isOnGround(AltoClef mod) {
return mod.getPlayer().isSwimming() || mod.getPlayer().isTouchingWater() || mod.getPlayer().isOnGround() || mod.getPlayer().isClimbing();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fault but this code is duplicated like 3 times, it would be nice to add a utility method to EntityHelper called isGrounded(Entity entity) and isGrounded() // defaults to player


//Equip elytra, if didn't equipped,
setDebugState("Equipping elytra");
if (StorageHelper.getItemStackInSlot(new PlayerSlot(6)).getItem() != Items.ELYTRA) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use PlayerSlot.ARMOR_CHESTPLATE_SLOT instead of PlayerSlot(6)

_fz = 0;
mod.getBehaviour().disableDefence(false); //Enable mob defence
if ((int)dist == 0) { //We are where we need to go !
_isFinished = true; //End the task
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would get rid of _isFinished and instead add the check in the isFinished method for whether we're close enough. Also I'd use WorldHelper.inRangeXZ(mod.getPlayer(), _x, _z)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is mob defense even disabled? Doesnt that mean phantoms and mobs that shoot can get us mid-flight?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It disable mob defense while flying because the bot try to avoid it's own firework when using it. and i think the player move faster than the phantoms while flying

_isFinished = true; //End the task
return null;
}
if (dist < 128) { //We are near our goal
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a constant at the top of the file so we don't have magic numbers

ex.

private static final int CLOSE_ENOUGH_TO_WALK = 128;

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
_toRepair = Arrays.stream(_toRepair).filter(target -> needRepair(mod, target)).toArray(ItemTarget[]::new);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd make _toRepair final and make a local variable ItemTarget[] shouldRepair here or something. Instance variables should be final if they're compared to in isEqual, because otherwise the task may continuously re-run onStart


List<Slot> SlotRepair = mod.getItemStorage().getSlotsWithItemPlayerInventory(false, ItemTargetRepair.getMatches()); //And we get a list of every slot with that item

Slot SlotRepairTarget = new PlayerSlot(-1); //Placeholder slot, will never get used if not replaced
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use null as a placeholder instead? -1 can be mistaken for the cursor slot.

if (ItemTargetOPTRepair.isPresent()) { //If the list is not empty
ItemTarget ItemTargetRepair = ItemTargetOPTRepair.get(); //We get the (real) first item on the list

List<Slot> SlotRepair = mod.getItemStorage().getSlotsWithItemPlayerInventory(false, ItemTargetRepair.getMatches()); //And we get a list of every slot with that item
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java uses lowerCamelCase for local variables (slotRepair, not SlotRepair)

return null;
}
//Get the nearest experience orb
Optional<Entity> expentityOPT = mod.getEntityTracker().getClosestEntity(mod.getPlayer().getPos(), ExperienceOrbEntity.class);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an annoying gotcha, but avoid always gunning for the closest entity/block. There could be a ping-pong pattern of the bot getting stuck between two targets (https://youtu.be/uROEqwyzn3o?t=6946)

Using DoToClosest ... Task can fix this, as it checks for this bug.

return new DoToClosestEntityTask(entity -> {
    // Make sure our repair item is equipped when we're about to collect the orb!
    if (entity.isInRange(mod.getPlayer(), 3)) {
        mod.getSlotHandler().forceEquipSlot(SlotRepairTarget);
    }
    return new GetToEntityTask(entity);
});

Copy link

@Bluscream Bluscream Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting ... maybe this is why my @pickup task likes to shit itself sometimes

}

//Test if the itemstack have mending on it
public static boolean haveMending(AltoClef mod, ItemStack target) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EnchantmentHelper.get(itemStack).containsKey(Enchantments.MENDING);

Copy link
Collaborator

@TacoTechnica TacoTechnica left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Am excited to merge this in, just have some code suggestions to check first.

@Bluscream
Copy link

Please fix and merge! Much love <3

@badpiggies007
Copy link
Contributor Author

Still WIP

@TacoTechnica TacoTechnica changed the title Added travel using an elytra feature, the RepairToolTask and some edits around that [WIP] Added travel using an elytra feature, the RepairToolTask and some edits around that Feb 4, 2022
@TacoTechnica
Copy link
Collaborator

Still WIP

Sounds good! When you're done remove the [WIP] from the title and ping me or something so I can check it

@badpiggies007 badpiggies007 changed the title [WIP] Added travel using an elytra feature, the RepairToolTask and some edits around that Added travel using an elytra feature, the RepairToolTask and some edits around that Feb 4, 2022
@badpiggies007
Copy link
Contributor Author

Okay, I made the requested changes, is there still anything else to change in this code :) ?

@wife
Copy link

wife commented Apr 12, 2022

Any update on this now that the code has been changed?

//Way of disabling MLG and defense from a task
public boolean isDefenseDisabled() {
return current().disableDefence;
}
Copy link
Contributor

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,

coinlmao added a commit to coinlmao/altoclef that referenced this pull request Jun 24, 2022
coinlmao added a commit to coinlmao/altoclef that referenced this pull request Jun 24, 2022
coinlmao added a commit to coinlmao/altoclef that referenced this pull request Jun 24, 2022
coinlmao added a commit to coinlmao/altoclef that referenced this pull request Jun 24, 2022
coinlmao added a commit to coinlmao/altoclef that referenced this pull request Jun 24, 2022
coinlmao added a commit to coinlmao/altoclef that referenced this pull request Jun 24, 2022
coinlmao added a commit to coinlmao/altoclef that referenced this pull request Jun 24, 2022
coinlmao added a commit to coinlmao/altoclef that referenced this pull request Jun 24, 2022
coinlmao added a commit to coinlmao/altoclef that referenced this pull request Jun 24, 2022
coinlmao added a commit to coinlmao/altoclef that referenced this pull request Jun 24, 2022
coinlmao added a commit to coinlmao/altoclef that referenced this pull request Jun 24, 2022
coinlmao added a commit to coinlmao/altoclef that referenced this pull request Jun 24, 2022
coinlmao added a commit to coinlmao/altoclef that referenced this pull request Jun 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants