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;
|
2019-01-01 15:32:02 +01:00
|
|
|
import net.minecraft.entity.EntityLiving;
|
2018-12-30 20:37:00 +01:00
|
|
|
import net.minecraft.item.crafting.Ingredient;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
2019-01-01 15:32:02 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-01-01 15:32:02 +01:00
|
|
|
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;
|
2019-01-01 15:32:02 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|