NaturesAura/src/main/java/de/ellpeck/naturesaura/compat/jei/AnimalSpawnerCategory.java
2020-01-23 20:57:56 +01:00

76 lines
2.6 KiB
Java

package de.ellpeck.naturesaura.compat.jei;
import com.google.common.collect.ImmutableList;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.recipes.AnimalSpawnerRecipe;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.ingredient.IGuiItemStackGroup;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.EntityType;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.registries.ForgeRegistries;
import java.util.Arrays;
public class AnimalSpawnerCategory implements IRecipeCategory<AnimalSpawnerRecipe> {
private final IDrawable background;
public AnimalSpawnerCategory(IGuiHelper helper) {
this.background = helper.createDrawable(new ResourceLocation(NaturesAura.MOD_ID, "textures/gui/jei/animal_spawner.png"), 0, 0, 72, 86);
}
@Override
public ResourceLocation getUid() {
return JEINaturesAuraPlugin.SPAWNER;
}
@Override
public Class<? extends AnimalSpawnerRecipe> getRecipeClass() {
return AnimalSpawnerRecipe.class;
}
@Override
public String getTitle() {
return I18n.format("container." + JEINaturesAuraPlugin.SPAWNER + ".name");
}
@Override
public IDrawable getBackground() {
return this.background;
}
@Override
public IDrawable getIcon() {
return null;
}
@Override
public void setIngredients(AnimalSpawnerRecipe animalSpawnerRecipe, IIngredients iIngredients) {
ImmutableList.Builder<ItemStack> builder = ImmutableList.builder();
for (Ingredient ing : animalSpawnerRecipe.ingredients)
builder.add(ing.getMatchingStacks());
iIngredients.setInputs(VanillaTypes.ITEM, builder.build());
EntityType entry = ForgeRegistries.ENTITIES.getValue(animalSpawnerRecipe.entity);
iIngredients.setOutput(VanillaTypes.ITEM, new ItemStack(SpawnEggItem.getEgg(entry)));
}
@Override
public void setRecipe(IRecipeLayout iRecipeLayout, AnimalSpawnerRecipe recipe, IIngredients iIngredients) {
IGuiItemStackGroup group = iRecipeLayout.getItemStacks();
for (int i = 0; i < recipe.ingredients.length; i++) {
group.init(i, true, i * 18, 68);
group.set(i, Arrays.asList(recipe.ingredients[i].getMatchingStacks()));
}
}
}