From 54e0132033c3e2fac53ae9338b31af2db65e9379 Mon Sep 17 00:00:00 2001 From: liach Date: Sun, 20 Jan 2019 00:04:15 -0800 Subject: [PATCH] Expose an interface for custom metals chest condensation rules Signed-off-by: liach --- .../api/items/IMetalsChestCondenseRule.java | 53 +++++++++++++++++++ .../items/MetalsChestCondenseRuleImpl.java | 39 ++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 src/main/java/mods/railcraft/api/items/IMetalsChestCondenseRule.java create mode 100644 src/main/java/mods/railcraft/api/items/MetalsChestCondenseRuleImpl.java diff --git a/src/main/java/mods/railcraft/api/items/IMetalsChestCondenseRule.java b/src/main/java/mods/railcraft/api/items/IMetalsChestCondenseRule.java new file mode 100644 index 0000000..fc733f1 --- /dev/null +++ b/src/main/java/mods/railcraft/api/items/IMetalsChestCondenseRule.java @@ -0,0 +1,53 @@ +/*------------------------------------------------------------------------------ + Copyright (c) CovertJaguar, 2011-2019 + + This work (the API) is licensed under the "MIT" License, + see LICENSE.md for details. + -----------------------------------------------------------------------------*/ + +package mods.railcraft.api.items; + +import net.minecraft.item.ItemStack; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Predicate; + +/** + * A condensation rule for metal chests. + */ +public interface IMetalsChestCondenseRule { + /** + * A list of metals chest condense rules the metals chest will check. + */ + List rules = new ArrayList<>(); + + /** + * Checks if an item can be consumed for condensation + * + * @return the predicate to check if an item matches + */ + Predicate getPredicate(); + + /** + * Returns the number of item needed for one condensation. + */ + int removeCount(); + + /** + * Gets the condensation result. Make sure to make clean copies! + */ + ItemStack getResult(); + + /** + * Utility method for quickly creating a metals chest condensation rule. + * + * @param predicate the checker + * @param count the requirement count + * @param result the compressed result + * @return the created rule + */ + static IMetalsChestCondenseRule of(Predicate predicate, int count, ItemStack result) { + return new MetalsChestCondenseRuleImpl(predicate, count, result); + } +} diff --git a/src/main/java/mods/railcraft/api/items/MetalsChestCondenseRuleImpl.java b/src/main/java/mods/railcraft/api/items/MetalsChestCondenseRuleImpl.java new file mode 100644 index 0000000..6f4c0da --- /dev/null +++ b/src/main/java/mods/railcraft/api/items/MetalsChestCondenseRuleImpl.java @@ -0,0 +1,39 @@ +/*------------------------------------------------------------------------------ + Copyright (c) CovertJaguar, 2011-2019 + + This work (the API) is licensed under the "MIT" License, + see LICENSE.md for details. + -----------------------------------------------------------------------------*/ + +package mods.railcraft.api.items; + +import net.minecraft.item.ItemStack; + +import java.util.function.Predicate; + +class MetalsChestCondenseRuleImpl implements IMetalsChestCondenseRule { + private final Predicate predicate; + private final int count; + private final ItemStack output; + + MetalsChestCondenseRuleImpl(Predicate predicate, int count, ItemStack output) { + this.predicate = predicate; + this.count = count; + this.output = output.copy(); + } + + @Override + public Predicate getPredicate() { + return predicate; + } + + @Override + public int removeCount() { + return count; + } + + @Override + public ItemStack getResult() { + return output.copy(); + } +}