NaturesAura/src/main/java/de/ellpeck/naturesaura/compat/patchouli/ProcessorAnimalSpawner.java

43 lines
1.6 KiB
Java
Raw Normal View History

2019-01-01 15:20:12 +01:00
package de.ellpeck.naturesaura.compat.patchouli;
2020-04-29 16:38:50 +02:00
import de.ellpeck.naturesaura.recipes.AnimalSpawnerRecipe;
2021-12-16 21:56:27 +01:00
import net.minecraft.world.item.ItemStack;
2023-07-08 12:32:27 +02:00
import net.minecraft.world.level.Level;
2021-12-16 21:56:27 +01:00
import net.minecraftforge.common.ForgeSpawnEggItem;
2022-06-27 15:24:04 +02:00
import net.minecraftforge.registries.ForgeRegistries;
2019-01-01 15:20:12 +01:00
import vazkii.patchouli.api.IComponentProcessor;
2020-09-22 03:17:02 +02:00
import vazkii.patchouli.api.IVariable;
2019-01-01 15:20:12 +01:00
import vazkii.patchouli.api.IVariableProvider;
public class ProcessorAnimalSpawner implements IComponentProcessor {
private AnimalSpawnerRecipe recipe;
@Override
2023-07-08 12:32:27 +02:00
public void setup(Level level, IVariableProvider provider) {
2020-09-22 03:17:02 +02:00
this.recipe = PatchouliCompat.getRecipe("animal_spawner", provider.get("recipe").asString());
2019-01-01 15:20:12 +01:00
}
@Override
2023-07-08 12:32:27 +02:00
public IVariable process(Level level, String key) {
if (this.recipe == null)
2020-09-22 15:01:16 +02:00
return null;
2019-01-01 15:20:12 +01:00
if (key.startsWith("input")) {
2021-12-16 21:56:27 +01:00
var id = Integer.parseInt(key.substring(5)) - 1;
return this.recipe.ingredients.length > id ? PatchouliCompat.ingredientVariable(this.recipe.ingredients[id]) : null;
2019-01-01 15:20:12 +01:00
} else {
2021-12-16 21:56:27 +01:00
return switch (key) {
case "name" -> IVariable.wrap(this.recipe.entity.getDescription().getString());
case "entity" -> IVariable.wrap(ForgeRegistries.ENTITY_TYPES.getKey(this.recipe.entity).toString());
2021-12-16 21:56:27 +01:00
case "egg" -> IVariable.from(new ItemStack(ForgeSpawnEggItem.fromEntityType(this.recipe.entity)));
default -> null;
};
2019-01-01 15:20:12 +01:00
}
}
@Override
public boolean allowRender(String group) {
return !"seekrit".equals(group);
}
}