- 128
- 4
- 6
Приветствую, вопрос в следующем, у меня есть блок в котором можно создавать предметы, он без интерфейса, сам крафт уже настроен. Также настроено место с хранением жидкости в нем, но использовать жидкость в крафте, которая в нем хранится не получается. Подсобите в данной проблеме.
Recipe:
public class Recipe {
private final ItemStack output;
private final ImmutableList<Object> inputs;
private final int timeCraft;
private final int stability;
private final FluidStack fluid;
public Recipe(ItemStack output, int timeCraft, @Nullable FluidStack fluid, int stability, Object... inputs) {
this.output = output;
this.timeCraft = timeCraft;
this.stability = stability;
this.fluid = fluid;
ImmutableList.Builder<Object> inputsToSet = ImmutableList.builder();
for (Object obj : inputs) {
if (obj instanceof String || obj instanceof ItemStack) inputsToSet.add(obj);
else throw new IllegalArgumentException("Invalid input");
}
this.inputs = inputsToSet.build();
}
public boolean matches(IItemHandler inv) {
List<Object> inputsMissing = new ArrayList<>(inputs);
for (int i = 0; i < inv.getSlots(); i++) {
ItemStack stack = inv.getStackInSlot(i);
if (stack.isEmpty()) break;
int stackIndex = -1, oredictIndex = -1;
for (int j = 0; j < inputsMissing.size(); j++) {
Object input = inputsMissing.get(j);
if (input instanceof String) {
boolean found = false;
for (ItemStack ostack : OreDictionary.getOres((String) input, false)) {
if (OreDictionary.itemMatches(ostack, stack, false)) {
oredictIndex = j;
found = true;
break;
}
}
if (found) break;
} else if (input instanceof ItemStack && compareStacks((ItemStack) input, stack)) {
stackIndex = j;
break;
}
}
if (stackIndex != -1) inputsMissing.remove(stackIndex);
else if (oredictIndex != -1) inputsMissing.remove(oredictIndex);
else return false;
}
return inputsMissing.isEmpty();
}
private boolean compareStacks(ItemStack recipe, ItemStack supplied) {
return recipe.getItem() == supplied.getItem() &&
recipe.getItemDamage() == supplied.getItemDamage() &&
ItemNBTHelper.matchTag(recipe.getTagCompound(), supplied.getTagCompound());
}
public List<Object> getInputs() { return inputs; }
public ItemStack getOutput() { return output; }
public int getTimeCraft() { return timeCraft; }
public int getStability() { return stability; }
@Nullable public FluidStack getFluidIngredient() {
if (this.fluid != null) return this.fluid.copy();
return null;
}
}
Craft:
public final class Craft {
public static final List<Recipe> recipe = new ArrayList<>();
public static void init() {
C_L = regRecipe(l_block_1, 20 * 18, water, 35, c_block, c_block, c_block, c_block, c_block);
}
public static Recipe regRecipe(ItemStack output, int timeCraft, FluidStack fluid, int stability, Object... inputs) {
Preconditions.checkArgument(inputs.length <= TilePedestal.sizeInv);
Recipe r = new Recipe(output, timeCraft, fluid, stability, inputs);
recipe.add(r);
return r;
}
}
Tile:
for (Recipe recipe : Craft.recipe) {
if (tank.getFluid() != recipe.getFluidIngredient() && recipe.matches(itemHandler)) {
((WorldServer) world).spawnParticle(EnumParticleTypes.SMOKE_NORMAL, pos.getX() + 0.5f, pos.getY() + 2.1f, pos.getZ() + 0.5f, 16, 0.04d, 0.04d, 0.04d, 0.003f, new int[0]);
}
if (!isEmpty() && tank.getFluid() == recipe.getFluidIngredient() && recipe.matches(itemHandler)) {
setStability(recipe.getStability());
setTimeCraft(getTimeCraft() + 1);
tank.drain(100, true);