From e17577db946c67cc4946b75aaa052c38fd28d4a5 Mon Sep 17 00:00:00 2001 From: Jeremiah Winsley Date: Mon, 6 Jun 2022 19:16:30 -0400 Subject: [PATCH] Add config option for piping into harvester --- gradle.properties | 2 +- src/main/java/net/permutated/pylons/ConfigManager.java | 6 ++++++ .../java/net/permutated/pylons/tile/AbstractPylonTile.java | 6 +++++- .../java/net/permutated/pylons/tile/HarvesterPylonTile.java | 6 ++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index fd723bd..04c6888 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ org.gradle.daemon=false mc_version=1.18.2 group=net.permutated mod_id=pylons -version=2.1.0 +version=2.1.1 diff --git a/src/main/java/net/permutated/pylons/ConfigManager.java b/src/main/java/net/permutated/pylons/ConfigManager.java index 9861a5e..50a0437 100644 --- a/src/main/java/net/permutated/pylons/ConfigManager.java +++ b/src/main/java/net/permutated/pylons/ConfigManager.java @@ -43,6 +43,7 @@ public static class ServerConfig { // CATEGORY_HARVESTER public final ForgeConfigSpec.IntValue harvesterWorkDelay; public final ForgeConfigSpec.BooleanValue harvesterRequiresTool; + public final ForgeConfigSpec.BooleanValue harvesterCanBeAutomated; ServerConfig(ForgeConfigSpec.Builder builder) { @@ -109,6 +110,11 @@ public static class ServerConfig { "If enabled, it will use 1 durability per harvest action") .define("harvesterRequiresTool", true); + harvesterCanBeAutomated = builder + .comment("Whether the harvester can have tools piped in to automate it.", + "By default, unbreakable tools are required for full automation.") + .define("harvesterCanBeAutomated", false); + builder.pop(); } } diff --git a/src/main/java/net/permutated/pylons/tile/AbstractPylonTile.java b/src/main/java/net/permutated/pylons/tile/AbstractPylonTile.java index 226f5e8..1b31682 100644 --- a/src/main/java/net/permutated/pylons/tile/AbstractPylonTile.java +++ b/src/main/java/net/permutated/pylons/tile/AbstractPylonTile.java @@ -50,10 +50,14 @@ public boolean isItemValid(int slot, @Nonnull ItemStack stack) { protected final LazyOptional handler = LazyOptional.of(() -> itemStackHandler); + protected boolean canAccessInventory() { + return false; + } + @Nonnull @Override public LazyOptional getCapability(Capability cap, @Nullable Direction side) { - if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && side == null) { + if (cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && (side == null || canAccessInventory())) { return handler.cast(); } return super.getCapability(cap, side); diff --git a/src/main/java/net/permutated/pylons/tile/HarvesterPylonTile.java b/src/main/java/net/permutated/pylons/tile/HarvesterPylonTile.java index 9862359..5fa8487 100644 --- a/src/main/java/net/permutated/pylons/tile/HarvesterPylonTile.java +++ b/src/main/java/net/permutated/pylons/tile/HarvesterPylonTile.java @@ -34,6 +34,12 @@ protected byte[] getRange() { protected boolean isItemValid(ItemStack stack) { return stack.getItem() instanceof HoeItem; } + + @Override + protected boolean canAccessInventory() { + return ConfigManager.SERVER.harvesterCanBeAutomated.get(); + } + private boolean requiresTool() { return Boolean.TRUE.equals(ConfigManager.SERVER.harvesterRequiresTool.get()); }