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

86 lines
2.8 KiB
Java
Raw Normal View History

2020-09-09 16:49:01 +02:00
package de.ellpeck.actuallyadditions.common.crafting;
2020-09-09 16:49:01 +02:00
import de.ellpeck.actuallyadditions.common.items.ItemPotionRing;
import de.ellpeck.actuallyadditions.common.util.StackUtil;
import de.ellpeck.actuallyadditions.common.util.crafting.RecipeHelper;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
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.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.registries.IForgeRegistryEntry;
2019-05-02 09:10:29 +02:00
public class RecipePotionRingCharging extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe {
2017-06-17 00:48:49 +02:00
2019-05-02 09:10:29 +02:00
public RecipePotionRingCharging(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 worldIn) {
boolean hasRing = 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 ItemPotionRing) {
if (!hasRing) {
hasRing = true;
2019-05-02 09:10:29 +02:00
} else {
return false;
}
2019-05-02 09:10:29 +02:00
} else if (stack.getItem() != Items.BLAZE_POWDER) { return false; }
}
}
return hasRing;
}
@Override
2019-05-02 09:10:29 +02:00
public ItemStack getCraftingResult(InventoryCrafting inv) {
2017-11-02 22:49:53 +01:00
ItemStack inputRing = StackUtil.getEmpty();
int totalBlaze = 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 ItemPotionRing) {
inputRing = stack;
2019-05-02 09:10:29 +02:00
} else if (stack.getItem() == Items.BLAZE_POWDER) {
totalBlaze += 20;
}
}
}
2019-05-02 09:10:29 +02:00
if (StackUtil.isValid(inputRing) && totalBlaze > 0) {
ItemStack copy = inputRing.copy();
2019-05-02 09:10:29 +02:00
int total = ItemPotionRing.getStoredBlaze(copy) + totalBlaze;
if (total <= ItemPotionRing.MAX_BLAZE) {
ItemPotionRing.setStoredBlaze(copy, total);
return copy;
}
}
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 > 3;
}
@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);
}
}