diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 8a8720ce..5642323b 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -21,6 +21,7 @@ import baritone.behavior.Behavior; import baritone.behavior.impl.LookBehavior; import baritone.behavior.impl.MemoryBehavior; import baritone.behavior.impl.PathingBehavior; +import baritone.behavior.impl.LocationTrackingBehavior; import baritone.event.GameEventHandler; import baritone.utils.InputOverrideHandler; import net.minecraft.client.Minecraft; @@ -70,6 +71,7 @@ public enum Baritone { registerBehavior(PathingBehavior.INSTANCE); registerBehavior(LookBehavior.INSTANCE); registerBehavior(MemoryBehavior.INSTANCE); + registerBehavior(LocationTrackingBehavior.INSTANCE); } this.dir = new File(Minecraft.getMinecraft().gameDir, "baritone"); if (!Files.exists(dir.toPath())) { diff --git a/src/main/java/baritone/behavior/impl/LocationTrackingBehavior.java b/src/main/java/baritone/behavior/impl/LocationTrackingBehavior.java new file mode 100644 index 00000000..8498690e --- /dev/null +++ b/src/main/java/baritone/behavior/impl/LocationTrackingBehavior.java @@ -0,0 +1,57 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Baritone. If not, see . + */ + +package baritone.behavior.impl; + +import baritone.behavior.Behavior; +import baritone.chunk.Waypoint; +import baritone.chunk.WorldProvider; +import baritone.event.events.BlockInteractEvent; +import baritone.utils.BlockStateInterface; +import net.minecraft.block.BlockBed; + +/** + * A collection of event methods that are used to interact with Baritone's + * waypoint system. This class probably needs a better name. + * + * @see Waypoint + * + * @author Brady + * @since 8/22/2018 + */ +public final class LocationTrackingBehavior extends Behavior { + + public static final LocationTrackingBehavior INSTANCE = new LocationTrackingBehavior(); + + private LocationTrackingBehavior() {} + + @Override + public void onBlockInteract(BlockInteractEvent event) { + if (event.getType() == BlockInteractEvent.Type.USE && BlockStateInterface.get(event.getPos()) instanceof BlockBed) { + createWaypointAtPlayer("bed", Waypoint.Tag.BED); + } + } + + @Override + public void onPlayerDeath() { + createWaypointAtPlayer("death", Waypoint.Tag.DEATH); + } + + private void createWaypointAtPlayer(String name, Waypoint.Tag tag) { + WorldProvider.INSTANCE.getCurrentWorld().waypoints.addWaypoint(new Waypoint(name, tag, playerFeet())); + } +} diff --git a/src/main/java/baritone/behavior/impl/MemoryBehavior.java b/src/main/java/baritone/behavior/impl/MemoryBehavior.java index f8009c43..ed5bd686 100644 --- a/src/main/java/baritone/behavior/impl/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/impl/MemoryBehavior.java @@ -1,14 +1,9 @@ package baritone.behavior.impl; import baritone.behavior.Behavior; -import baritone.chunk.Waypoint; -import baritone.chunk.WorldProvider; -import baritone.event.events.BlockInteractEvent; import baritone.event.events.PacketEvent; import baritone.event.events.PlayerUpdateEvent; import baritone.event.events.type.EventState; -import baritone.utils.BlockStateInterface; -import net.minecraft.block.BlockBed; import net.minecraft.item.ItemStack; import net.minecraft.network.Packet; import net.minecraft.network.play.client.CPacketCloseWindow; @@ -109,13 +104,6 @@ public class MemoryBehavior extends Behavior { } } - @Override - public void onBlockInteract(BlockInteractEvent event) { - if (event.getType() == BlockInteractEvent.Type.USE && BlockStateInterface.get(event.getPos()) instanceof BlockBed) { - WorldProvider.INSTANCE.getCurrentWorld().waypoints.addWaypoint(new Waypoint("bed", Waypoint.Tag.BED, playerFeet())); - } - } - private Optional getInventoryFromWindow(int windowId) { return this.rememberedInventories.values().stream().filter(i -> i.windowId == windowId).findFirst(); } diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java index c61201bf..bfc42219 100644 --- a/src/main/java/baritone/event/GameEventHandler.java +++ b/src/main/java/baritone/event/GameEventHandler.java @@ -179,6 +179,11 @@ public final class GameEventHandler implements IGameEventListener, Helper { dispatch(listener -> listener.onBlockInteract(event)); } + @Override + public void onPlayerDeath() { + dispatch(IGameEventListener::onPlayerDeath); + } + public final void registerEventListener(IGameEventListener listener) { this.listeners.add(listener); } diff --git a/src/main/java/baritone/event/listener/AbstractGameEventListener.java b/src/main/java/baritone/event/listener/AbstractGameEventListener.java index 4f940c38..0f113119 100644 --- a/src/main/java/baritone/event/listener/AbstractGameEventListener.java +++ b/src/main/java/baritone/event/listener/AbstractGameEventListener.java @@ -83,4 +83,7 @@ public interface AbstractGameEventListener extends IGameEventListener { @Override default void onBlockInteract(BlockInteractEvent event) {} + + @Override + default void onPlayerDeath() {} } diff --git a/src/main/java/baritone/event/listener/IGameEventListener.java b/src/main/java/baritone/event/listener/IGameEventListener.java index 1958f0c3..bb52a66d 100644 --- a/src/main/java/baritone/event/listener/IGameEventListener.java +++ b/src/main/java/baritone/event/listener/IGameEventListener.java @@ -39,6 +39,7 @@ import io.netty.util.concurrent.GenericFutureListener; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.GuiGameOver; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.renderer.EntityRenderer; import net.minecraft.client.settings.GameSettings; @@ -46,6 +47,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; +import net.minecraft.util.text.ITextComponent; /** * @author Brady @@ -140,4 +142,11 @@ public interface IGameEventListener { * @see Minecraft#rightClickMouse() */ void onBlockInteract(BlockInteractEvent event); + + /** + * Called when the local player dies, as indicated by the creation of the {@link GuiGameOver} screen. + * + * @see GuiGameOver(ITextComponent) + */ + void onPlayerDeath(); } diff --git a/src/main/java/baritone/launch/mixins/MixinGuiGameOver.java b/src/main/java/baritone/launch/mixins/MixinGuiGameOver.java new file mode 100644 index 00000000..1579d529 --- /dev/null +++ b/src/main/java/baritone/launch/mixins/MixinGuiGameOver.java @@ -0,0 +1,37 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Baritone. If not, see . + */ + +package baritone.launch.mixins; + +import baritone.Baritone; +import net.minecraft.client.gui.GuiGameOver; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; + +/** + * @author Brady + * @since 8/22/2018 + */ +@Mixin(GuiGameOver.class) +public class MixinGuiGameOver { + + @Inject(method = "", at = @At("RETURN")) + private void onInit() { + Baritone.INSTANCE.getGameEventHandler().onPlayerDeath(); + } +} diff --git a/src/main/resources/mixins.baritone.json b/src/main/resources/mixins.baritone.json index 025d42f8..e05bca84 100755 --- a/src/main/resources/mixins.baritone.json +++ b/src/main/resources/mixins.baritone.json @@ -13,6 +13,7 @@ "MixinEntityRenderer", "MixinGameSettings", "MixinGuiContainer", + "MixinGuiGameOver", "MixinGuiScreen", "MixinInventoryPlayer", "MixinKeyBinding",