ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/common/crafting/RecipeBioMash.java

89 lines
2.9 KiB
Java
Raw Normal View History

package de.ellpeck.actuallyadditions.common.crafting;
import de.ellpeck.actuallyadditions.common.items.InitItems;
import de.ellpeck.actuallyadditions.common.items.ItemKnife;
import de.ellpeck.actuallyadditions.common.items.metalists.TheMiscItems;
import de.ellpeck.actuallyadditions.common.util.StackUtil;
import de.ellpeck.actuallyadditions.common.util.crafting.RecipeHelper;
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;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.registries.IForgeRegistryEntry;
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
}
@Override
2019-05-02 09:10:29 +02:00
public boolean matches(InventoryCrafting inv, World world) {
boolean foundFood = false;
boolean hasKnife = false;
2019-05-02 09:10:29 +02:00
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack stack = inv.getStackInSlot(i);
2019-05-02 09:10:29 +02:00
if (StackUtil.isValid(stack)) {
if (stack.getItem() instanceof ItemKnife) {
if (hasKnife) {
return false;
2019-05-02 09:10:29 +02:00
} else {
hasKnife = true;
}
2019-05-02 09:10:29 +02:00
} else if (stack.getItem() instanceof ItemFood) {
foundFood = true;
2019-05-02 09:10:29 +02:00
} else {
return false;
}
}
}
return foundFood && hasKnife;
}
@Override
2019-05-02 09:10:29 +02:00
public ItemStack getCraftingResult(InventoryCrafting inv) {
int amount = 0;
2019-05-02 09:10:29 +02:00
for (int i = 0; i < inv.getSizeInventory(); i++) {
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();
float heal = food.getHealAmount(stack);
float sat = food.getSaturationModifier(stack);
2019-05-02 09:10:29 +02:00
amount += MathHelper.ceil(heal * sat);
}
}
}
2019-05-02 09:10:29 +02:00
if (amount > 0 && amount <= 64) {
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();
}
}
@Override
2019-05-02 09:10:29 +02:00
public boolean canFit(int width, int height) {
return width * height > 5;
}
@Override
2019-05-02 09:10:29 +02:00
public ItemStack getRecipeOutput() {
2017-11-02 22:49:53 +01:00
return StackUtil.getEmpty();
}
@Override
2019-05-02 09:10:29 +02:00
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
return ForgeHooks.defaultRecipeGetRemainingItems(inv);
}
}