use of com.teamresourceful.resourcefulbees.api.beedata.breeding.BeeFamily in project ResourcefulBees by Resourceful-Bees.
the class ApiaryStorageTileEntity method breedComplete.
public boolean breedComplete(String p1, String p2) {
if (inventoryHasSpace()) {
BeeFamily beeFamily = BEE_REGISTRY.getWeightedChild(p1, p2);
double breedChance = beeFamily.getChance();
EntityType<?> entityType = beeFamily.getChildData().getEntityType();
BreedData p1BreedData = BEE_REGISTRY.getBeeData(p1).getBreedData();
BreedData p2BreedData = BEE_REGISTRY.getBeeData(p2).getBreedData();
Item p1Returnable = p1BreedData.getFeedReturnItem().orElse(null);
Item p2Returnable = p2BreedData.getFeedReturnItem().orElse(null);
if (level != null) {
Entity entity = entityType.create(level);
if (entity != null) {
ICustomBee beeEntity = (ICustomBee) entity;
CompoundTag nbt = BeeInfoUtils.createJarBeeTag((Bee) beeEntity, NBTConstants.NBT_ENTITY);
ItemStack beeJar = new ItemStack(ModItems.BEE_JAR.get());
ItemStack emptyBeeJar = new ItemStack(ModItems.BEE_JAR.get());
beeJar.setTag(nbt);
BeeJar.renameJar(beeJar, (Bee) beeEntity);
depositItemStack(new ItemStack(p1Returnable, p1BreedData.getFeedAmount()));
depositItemStack(new ItemStack(p2Returnable, p2BreedData.getFeedAmount()));
// if failed, will deposit empty bee jar
float nextFloat = level.random.nextFloat();
if (breedChance >= nextFloat) {
return depositItemStack(beeJar);
} else {
return depositItemStack(emptyBeeJar);
}
}
}
}
return false;
}
use of com.teamresourceful.resourcefulbees.api.beedata.breeding.BeeFamily in project ResourcefulBees by Resourceful-Bees.
the class BeeBreedGoal method breed.
@Override
protected void breed() {
BeeFamily beeFamily = BeeRegistry.getRegistry().getWeightedChild(((ICustomBee) this.partner).getBeeType(), beeType);
final BabyEntitySpawnEvent event = new BabyEntitySpawnEvent(animal, this.partner, createSelectedChild(beeFamily));
if (MinecraftForge.EVENT_BUS.post(event)) {
resetBreed();
return;
}
AgableMob selectedChild = event.getChild();
if (selectedChild != null) {
awardPlayerAdvancement(selectedChild);
resetBreed();
if (beeFamily.getChance() >= level.random.nextFloat()) {
spawnChildInLevel(beeFamily, selectedChild);
} else {
this.animal.playSound(SoundEvents.BEE_HURT, 2.0f, 1.0f);
spawnParticles();
}
}
}
Aggregations