Add death waypoints when the player dies, fixes #75

This commit is contained in:
Brady 2018-08-22 21:26:45 -05:00
parent 5760d0fb8d
commit 9dcadc979e
No known key found for this signature in database
GPG Key ID: 73A788379A197567
8 changed files with 114 additions and 12 deletions

View File

@ -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())) {

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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()));
}
}

View File

@ -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<RememberedInventory> getInventoryFromWindow(int windowId) {
return this.rememberedInventories.values().stream().filter(i -> i.windowId == windowId).findFirst();
}

View File

@ -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);
}

View File

@ -83,4 +83,7 @@ public interface AbstractGameEventListener extends IGameEventListener {
@Override
default void onBlockInteract(BlockInteractEvent event) {}
@Override
default void onPlayerDeath() {}
}

View File

@ -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();
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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 = "<init>", at = @At("RETURN"))
private void onInit() {
Baritone.INSTANCE.getGameEventHandler().onPlayerDeath();
}
}

View File

@ -13,6 +13,7 @@
"MixinEntityRenderer",
"MixinGameSettings",
"MixinGuiContainer",
"MixinGuiGameOver",
"MixinGuiScreen",
"MixinInventoryPlayer",
"MixinKeyBinding",