NaturesAura/src/main/java/de/ellpeck/naturesaura/api/recipes/AnimalSpawnerRecipe.java

49 lines
1.8 KiB
Java
Raw Normal View History

2018-12-30 20:37:00 +01:00
package de.ellpeck.naturesaura.api.recipes;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
2018-12-30 20:37:00 +01:00
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
2018-12-30 20:37:00 +01:00
import net.minecraft.world.World;
2019-01-01 15:20:12 +01:00
import net.minecraftforge.fml.common.registry.EntityEntry;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
2018-12-30 20:37:00 +01:00
public class AnimalSpawnerRecipe {
public final ResourceLocation name;
public final Ingredient[] ingredients;
2019-01-01 15:20:12 +01:00
public final ResourceLocation entity;
2018-12-30 20:37:00 +01:00
public final int aura;
public final int time;
2019-01-01 15:20:12 +01:00
public AnimalSpawnerRecipe(ResourceLocation name, ResourceLocation entity, int aura, int time, Ingredient... ingredients) {
2018-12-30 20:37:00 +01:00
this.name = name;
this.ingredients = ingredients;
this.entity = entity;
this.aura = aura;
this.time = time;
}
public Entity makeEntity(World world, double x, double y, double z) {
2019-01-01 15:20:12 +01:00
EntityEntry entry = ForgeRegistries.ENTITIES.getValue(this.entity);
if (entry == null)
return null;
Entity entity = entry.newInstance(world);
entity.setLocationAndAngles(x, y, z, MathHelper.wrapDegrees(world.rand.nextFloat() * 360F), 0F);
if (entity instanceof EntityLiving) {
EntityLiving living = (EntityLiving) entity;
living.rotationYawHead = entity.rotationYaw;
living.renderYawOffset = entity.rotationYaw;
living.onInitialSpawn(world.getDifficultyForLocation(living.getPosition()), null);
}
return entity;
2019-01-01 15:20:12 +01:00
}
2018-12-30 20:37:00 +01:00
public AnimalSpawnerRecipe register() {
NaturesAuraAPI.ANIMAL_SPAWNER_RECIPES.put(this.name, this);
return this;
}
}