Search in sources :

Example 1 with BeeFamily

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;
}
Also used : Item(net.minecraft.world.item.Item) AbstractContainerMenu.consideredTheSameItem(net.minecraft.world.inventory.AbstractContainerMenu.consideredTheSameItem) UpgradeItem(com.teamresourceful.resourcefulbees.item.UpgradeItem) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) TickableBlockEntity(net.minecraft.world.level.block.entity.TickableBlockEntity) Entity(net.minecraft.world.entity.Entity) BreedData(com.teamresourceful.resourcefulbees.api.beedata.breeding.BreedData) ICustomBee(com.teamresourceful.resourcefulbees.api.ICustomBee) BeeFamily(com.teamresourceful.resourcefulbees.api.beedata.breeding.BeeFamily) ItemStack(net.minecraft.world.item.ItemStack) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 2 with BeeFamily

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();
        }
    }
}
Also used : BabyEntitySpawnEvent(net.minecraftforge.event.entity.living.BabyEntitySpawnEvent) AgableMob(net.minecraft.world.entity.AgableMob) BeeFamily(com.teamresourceful.resourcefulbees.api.beedata.breeding.BeeFamily)

Aggregations

BeeFamily (com.teamresourceful.resourcefulbees.api.beedata.breeding.BeeFamily)2 ICustomBee (com.teamresourceful.resourcefulbees.api.ICustomBee)1 BreedData (com.teamresourceful.resourcefulbees.api.beedata.breeding.BreedData)1 UpgradeItem (com.teamresourceful.resourcefulbees.item.UpgradeItem)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 AgableMob (net.minecraft.world.entity.AgableMob)1 Entity (net.minecraft.world.entity.Entity)1 AbstractContainerMenu.consideredTheSameItem (net.minecraft.world.inventory.AbstractContainerMenu.consideredTheSameItem)1 Item (net.minecraft.world.item.Item)1 ItemStack (net.minecraft.world.item.ItemStack)1 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)1 TickableBlockEntity (net.minecraft.world.level.block.entity.TickableBlockEntity)1 BabyEntitySpawnEvent (net.minecraftforge.event.entity.living.BabyEntitySpawnEvent)1