From 62b8bc0f47d4e0efccb7f4f2abe1cf338aa4a799 Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 23 Sep 2018 17:07:53 -0500 Subject: [PATCH] Create IMemoryBehavior interface --- .../api/behavior/IMemoryBehavior.java | 36 +++++++++++++++++ .../behavior/memory/IRememberedInventory.java | 39 +++++++++++++++++++ .../baritone/behavior/MemoryBehavior.java | 18 ++++++--- 3 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 src/api/java/baritone/api/behavior/IMemoryBehavior.java create mode 100644 src/api/java/baritone/api/behavior/memory/IRememberedInventory.java diff --git a/src/api/java/baritone/api/behavior/IMemoryBehavior.java b/src/api/java/baritone/api/behavior/IMemoryBehavior.java new file mode 100644 index 000000000..ea5e90070 --- /dev/null +++ b/src/api/java/baritone/api/behavior/IMemoryBehavior.java @@ -0,0 +1,36 @@ +/* + * 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.api.behavior; + +import baritone.api.behavior.memory.IRememberedInventory; +import net.minecraft.util.math.BlockPos; + +/** + * @author Brady + * @since 9/23/2018 + */ +public interface IMemoryBehavior extends IBehavior { + + /** + * Gets a remembered inventory by its block position. + * + * @param pos The position of the container block + * @return The remembered inventory + */ + IRememberedInventory getInventoryByPos(BlockPos pos); +} diff --git a/src/api/java/baritone/api/behavior/memory/IRememberedInventory.java b/src/api/java/baritone/api/behavior/memory/IRememberedInventory.java new file mode 100644 index 000000000..c57ded918 --- /dev/null +++ b/src/api/java/baritone/api/behavior/memory/IRememberedInventory.java @@ -0,0 +1,39 @@ +/* + * 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.api.behavior.memory; + +import net.minecraft.item.ItemStack; + +import java.util.List; + +/** + * @author Brady + * @since 9/23/2018 + */ +public interface IRememberedInventory { + + /** + * @return The contents of this inventory + */ + List getContents(); + + /** + * @return The number of slots in this inventory + */ + int getSize(); +} diff --git a/src/main/java/baritone/behavior/MemoryBehavior.java b/src/main/java/baritone/behavior/MemoryBehavior.java index 20ffa1633..b0980322d 100644 --- a/src/main/java/baritone/behavior/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/MemoryBehavior.java @@ -17,6 +17,8 @@ package baritone.behavior; +import baritone.api.behavior.IMemoryBehavior; +import baritone.api.behavior.memory.IRememberedInventory; import baritone.api.event.events.PacketEvent; import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.type.EventState; @@ -37,7 +39,7 @@ import java.util.*; * @author Brady * @since 8/6/2018 9:47 PM */ -public final class MemoryBehavior extends Behavior implements Helper { +public final class MemoryBehavior extends Behavior implements IMemoryBehavior, Helper { public static MemoryBehavior INSTANCE = new MemoryBehavior(); @@ -127,6 +129,7 @@ public final class MemoryBehavior extends Behavior implements Helper { }); } + @Override public final RememberedInventory getInventoryByPos(BlockPos pos) { return this.rememberedInventories.get(pos); } @@ -169,7 +172,7 @@ public final class MemoryBehavior extends Behavior implements Helper { *

* Associated with a {@link BlockPos} in {@link MemoryBehavior#rememberedInventories}. */ - public static class RememberedInventory { + public static class RememberedInventory implements IRememberedInventory { /** * The list of items in the inventory @@ -190,11 +193,14 @@ public final class MemoryBehavior extends Behavior implements Helper { this.items = new ArrayList<>(); } - /** - * @return The list of items in the inventory - */ - public final List getItems() { + @Override + public final List getContents() { return this.items; } + + @Override + public final int getSize() { + return this.size; + } } }