From 511941c7146135f28bde29dbe48f8459cd5efccb Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Tue, 15 Mar 2022 18:39:19 -0700 Subject: [PATCH] reimplement death and bed waypoints --- src/api/java/baritone/api/Settings.java | 11 +++ src/main/java/baritone/Baritone.java | 2 + .../baritone/behavior/WaypointBehavior.java | 92 +++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 src/main/java/baritone/behavior/WaypointBehavior.java diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index b0eda748..0637f859 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -550,6 +550,17 @@ public final class Settings { */ public final Setting slowPathTimeoutMS = new Setting<>(40000L); + + /** + * allows baritone to save bed waypoints when interacting with beds + */ + public final Setting doBedWaypoints = new Setting<>(true); + + /** + * allows baritone to save death waypoints + */ + public final Setting doDeathWaypoints = new Setting<>(true); + /** * The big one. Download all chunks in simplified 2-bit format and save them for better very-long-distance pathing. */ diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 82451514..71c2c455 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -69,6 +69,7 @@ public class Baritone implements IBaritone { private PathingBehavior pathingBehavior; private LookBehavior lookBehavior; private InventoryBehavior inventoryBehavior; + private WaypointBehavior waypointBehavior; private InputOverrideHandler inputOverrideHandler; private FollowProcess followProcess; @@ -101,6 +102,7 @@ public class Baritone implements IBaritone { lookBehavior = new LookBehavior(this); inventoryBehavior = new InventoryBehavior(this); inputOverrideHandler = new InputOverrideHandler(this); + waypointBehavior = new WaypointBehavior(this); } this.pathingControlManager = new PathingControlManager(this); diff --git a/src/main/java/baritone/behavior/WaypointBehavior.java b/src/main/java/baritone/behavior/WaypointBehavior.java new file mode 100644 index 00000000..b21e080e --- /dev/null +++ b/src/main/java/baritone/behavior/WaypointBehavior.java @@ -0,0 +1,92 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +package baritone.behavior; + +import baritone.Baritone; +import baritone.api.cache.IWaypoint; +import baritone.api.cache.Waypoint; +import baritone.api.event.events.BlockInteractEvent; +import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.Helper; +import baritone.utils.BlockStateInterface; +import net.minecraft.block.BlockBed; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.event.ClickEvent; +import net.minecraft.util.text.event.HoverEvent; + +import java.util.Set; + +import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; + +public class WaypointBehavior extends Behavior { + + + public WaypointBehavior(Baritone baritone) { + super(baritone); + } + + @Override + public void onBlockInteract(BlockInteractEvent event) { + if (!Baritone.settings().doBedWaypoints.value) + return; + if (event.getType() == BlockInteractEvent.Type.USE) { + BetterBlockPos pos = BetterBlockPos.from(event.getPos()); + IBlockState state = BlockStateInterface.get(ctx, pos); + if (state.getBlock() instanceof BlockBed) { + if (state.getValue(BlockBed.PART) == BlockBed.EnumPartType.FOOT) { + pos = pos.offset(state.getValue(BlockBed.FACING)); + } + Set waypoints = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getByTag(IWaypoint.Tag.BED); + boolean exists = waypoints.stream().map(IWaypoint::getLocation).filter(pos::equals).findFirst().isPresent(); + if (!exists) { + baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("bed", Waypoint.Tag.BED, pos)); + } + } + } + } + + @Override + public void onPlayerDeath() { + if (!Baritone.settings().doDeathWaypoints.value) + return; + Waypoint deathWaypoint = new Waypoint("death", Waypoint.Tag.DEATH, ctx.playerFeet()); + baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(deathWaypoint); + ITextComponent component = new TextComponentString("Death position saved."); + component.getStyle() + .setColor(TextFormatting.WHITE) + .setHoverEvent(new HoverEvent( + HoverEvent.Action.SHOW_TEXT, + new TextComponentString("Click to goto death") + )) + .setClickEvent(new ClickEvent( + ClickEvent.Action.RUN_COMMAND, + String.format( + "%s%s goto %s @ %d", + FORCE_COMMAND_PREFIX, + "wp", + deathWaypoint.getTag().getName(), + deathWaypoint.getCreationTimestamp() + ) + )); + Helper.HELPER.logDirect(component); + } + +}