2017-01-30 18:33:18 +01:00
|
|
|
/*
|
|
|
|
* This file ("RecipeBioMash.java") is part of the Actually Additions mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
|
|
|
* http://ellpeck.de/actaddlicense
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
|
|
|
* © 2015-2017 Ellpeck
|
|
|
|
*/
|
|
|
|
|
|
|
|
package de.ellpeck.actuallyadditions.mod.crafting;
|
|
|
|
|
|
|
|
import de.ellpeck.actuallyadditions.mod.items.InitItems;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.items.ItemKnife;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2017-06-29 18:30:02 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.crafting.RecipeHelper;
|
2017-01-30 18:33:18 +01:00
|
|
|
import net.minecraft.inventory.InventoryCrafting;
|
|
|
|
import net.minecraft.item.ItemFood;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.crafting.IRecipe;
|
|
|
|
import net.minecraft.util.NonNullList;
|
2017-06-17 00:48:49 +02:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2017-01-30 18:33:18 +01:00
|
|
|
import net.minecraft.util.math.MathHelper;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.ForgeHooks;
|
2017-06-29 13:00:11 +02:00
|
|
|
import net.minecraftforge.registries.IForgeRegistryEntry;
|
2017-01-30 18:33:18 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public class RecipeBioMash extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe {
|
2017-06-17 00:48:49 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public RecipeBioMash(ResourceLocation location) {
|
2018-08-04 04:22:20 +02:00
|
|
|
RecipeHelper.addRecipe(location.getPath(), this);
|
2017-06-17 00:48:49 +02:00
|
|
|
}
|
2017-01-30 18:33:18 +01:00
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean matches(InventoryCrafting inv, World world) {
|
2017-01-30 18:33:18 +01:00
|
|
|
boolean foundFood = false;
|
|
|
|
boolean hasKnife = false;
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
for (int i = 0; i < inv.getSizeInventory(); i++) {
|
2017-01-30 18:33:18 +01:00
|
|
|
ItemStack stack = inv.getStackInSlot(i);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (StackUtil.isValid(stack)) {
|
|
|
|
if (stack.getItem() instanceof ItemKnife) {
|
|
|
|
if (hasKnife) {
|
2017-01-30 18:33:18 +01:00
|
|
|
return false;
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2017-01-30 18:33:18 +01:00
|
|
|
hasKnife = true;
|
|
|
|
}
|
2019-05-02 09:10:29 +02:00
|
|
|
} else if (stack.getItem() instanceof ItemFood) {
|
2017-01-30 18:33:18 +01:00
|
|
|
foundFood = true;
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2017-01-30 18:33:18 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return foundFood && hasKnife;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public ItemStack getCraftingResult(InventoryCrafting inv) {
|
2017-01-30 18:33:18 +01:00
|
|
|
int amount = 0;
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
for (int i = 0; i < inv.getSizeInventory(); i++) {
|
2017-01-30 18:33:18 +01:00
|
|
|
ItemStack stack = inv.getStackInSlot(i);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (StackUtil.isValid(stack)) {
|
|
|
|
if (stack.getItem() instanceof ItemFood) {
|
|
|
|
ItemFood food = (ItemFood) stack.getItem();
|
2017-01-30 18:33:18 +01:00
|
|
|
float heal = food.getHealAmount(stack);
|
|
|
|
float sat = food.getSaturationModifier(stack);
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
amount += MathHelper.ceil(heal * sat);
|
2017-01-30 18:33:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (amount > 0 && amount <= 64) {
|
2017-01-30 18:33:18 +01:00
|
|
|
return new ItemStack(InitItems.itemMisc, amount, TheMiscItems.MASHED_FOOD.ordinal());
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2017-11-02 22:49:53 +01:00
|
|
|
return StackUtil.getEmpty();
|
2017-01-30 18:33:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean canFit(int width, int height) {
|
|
|
|
return width * height > 5;
|
2017-01-30 18:33:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public ItemStack getRecipeOutput() {
|
2017-11-02 22:49:53 +01:00
|
|
|
return StackUtil.getEmpty();
|
2017-01-30 18:33:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
|
2017-01-30 18:33:18 +01:00
|
|
|
return ForgeHooks.defaultRecipeGetRemainingItems(inv);
|
|
|
|
}
|
|
|
|
}
|