Skip to content

Expose an interface for custom metals chest condensation rules #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: mc-1.12.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<IMetalsChestCondenseRule> rules = new ArrayList<>();

/**
* Checks if an item can be consumed for condensation
*
* @return the predicate to check if an item matches
*/
Predicate<ItemStack> 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<ItemStack> predicate, int count, ItemStack result) {
return new MetalsChestCondenseRuleImpl(predicate, count, result);
}
}
Original file line number Diff line number Diff line change
@@ -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<ItemStack> predicate;
private final int count;
private final ItemStack output;

MetalsChestCondenseRuleImpl(Predicate<ItemStack> predicate, int count, ItemStack output) {
this.predicate = predicate;
this.count = count;
this.output = output.copy();
}

@Override
public Predicate<ItemStack> getPredicate() {
return predicate;
}

@Override
public int removeCount() {
return count;
}

@Override
public ItemStack getResult() {
return output.copy();
}
}