1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Some refactoring

This commit is contained in:
TheBusyBiscuit 2021-03-10 00:44:20 +01:00
parent bef0cfb413
commit 0be442bc07
4 changed files with 24 additions and 4 deletions

View File

@ -11,6 +11,7 @@ import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.implementation.items.cargo.CargoNode;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
@ -81,11 +82,11 @@ class ItemFilter implements Predicate<ItemStack> {
SlimefunItem item = SlimefunItem.getByID(id);
BlockMenu menu = BlockStorage.getInventory(b.getLocation());
if (item == null || menu == null) {
if (!(item instanceof CargoNode) || menu == null) {
// Don't filter for a non-existing item (safety check)
clear(false);
} else if (id.equals("CARGO_NODE_OUTPUT")) {
// Output Nodes have no filter, allow everything
} else if (((CargoNode) item).hasItemFilter()) {
// Node does not have a filter, allow everything
clear(true);
} else {
this.items.clear();

View File

@ -44,6 +44,11 @@ abstract class AbstractFilterNode extends AbstractCargoNode {
addItemHandler(onBreak());
}
@Override
public boolean hasItemFilter() {
return true;
}
@Nonnull
private BlockBreakHandler onBreak() {
return new SimpleBlockBreakHandler() {

View File

@ -14,7 +14,6 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
* @author TheBusyBiscuit
*
*/
@FunctionalInterface
public interface CargoNode {
/**
@ -27,4 +26,11 @@ public interface CargoNode {
*/
int getSelectedChannel(@Nonnull Block b);
/**
* This returns whether this {@link CargoNode} has item filtering capabilities.
*
* @return Whether this {@link CargoNode} can filter items
*/
boolean hasItemFilter();
}

View File

@ -1,5 +1,7 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.cargo;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -18,10 +20,16 @@ public class CargoOutputNode extends AbstractCargoNode {
private static final int[] BORDER = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 };
@ParametersAreNonnullByDefault
public CargoOutputNode(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
super(category, item, recipeType, recipe, recipeOutput);
}
@Override
public boolean hasItemFilter() {
return false;
}
@Override
protected void onPlace(BlockPlaceEvent e) {
// We only require the default values