Search in sources :

Example 1 with ICustomBee

use of com.teamresourceful.resourcefulbees.api.ICustomBee in project ResourcefulBees by Resourceful-Bees.

the class BeeBreedGoal method canUse.

@Override
public boolean canUse() {
    if (!this.animal.isInLove()) {
        return false;
    } else {
        this.partner = this.getFreePartner();
        if (partner instanceof ICustomBee) {
            ICustomBee parent1 = ((ICustomBee) partner);
            ICustomBee parent2 = ((ICustomBee) animal);
            return BeeRegistry.getRegistry().canParentsBreed(parent1.getBeeType(), parent2.getBeeType());
        } else
            return false;
    }
}
Also used : ICustomBee(com.teamresourceful.resourcefulbees.api.ICustomBee)

Example 2 with ICustomBee

use of com.teamresourceful.resourcefulbees.api.ICustomBee 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 3 with ICustomBee

use of com.teamresourceful.resourcefulbees.api.ICustomBee in project ResourcefulBees by Resourceful-Bees.

the class TieredBeehiveTileEntity method addOccupantWithPresetTicks.

@Override
public void addOccupantWithPresetTicks(@NotNull Entity bee, boolean hasNectar, int ticksInHive) {
    if (this.stored.size() < getMaxBees()) {
        bee.ejectPassengers();
        CompoundTag nbt = new CompoundTag();
        bee.save(nbt);
        if (this.level != null && bee instanceof Bee) {
            int maxTimeInHive = getMaxTimeInHive(bee instanceof ICustomBee ? ((ICustomBee) bee).getCoreData().getMaxTimeInHive() : BeeConstants.MAX_TIME_IN_HIVE);
            this.stored.add(new BeeData(nbt, ticksInHive, hasNectar ? maxTimeInHive : MIN_HIVE_TIME));
            BlockPos pos = this.getBlockPos();
            this.level.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BEEHIVE_ENTER, SoundSource.BLOCKS, 1.0F, 1.0F);
            bee.remove();
        }
    }
}
Also used : ICustomBee(com.teamresourceful.resourcefulbees.api.ICustomBee) Bee(net.minecraft.world.entity.animal.Bee) ICustomBee(com.teamresourceful.resourcefulbees.api.ICustomBee) BlockPos(net.minecraft.core.BlockPos) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 4 with ICustomBee

use of com.teamresourceful.resourcefulbees.api.ICustomBee in project ResourcefulBees by Resourceful-Bees.

the class BeeInfoUtils method createJarBeeTag.

@NotNull
public static CompoundTag createJarBeeTag(Bee beeEntity, String nbtTagID) {
    String type = EntityType.getKey(beeEntity.getType()).toString();
    CompoundTag nbt = new CompoundTag();
    nbt.putString(nbtTagID, type);
    beeEntity.saveWithoutId(nbt);
    String beeColor = VANILLA_BEE_COLOR;
    if (beeEntity instanceof ICustomBee) {
        ICustomBee iCustomBee = (ICustomBee) beeEntity;
        nbt.putString(NBTConstants.NBT_BEE_TYPE, iCustomBee.getBeeType());
        beeColor = iCustomBee.getRenderData().getColorData().getJarColor().toString();
    }
    nbt.putString(NBTConstants.NBT_COLOR, beeColor);
    return nbt;
}
Also used : ICustomBee(com.teamresourceful.resourcefulbees.api.ICustomBee) CompoundTag(net.minecraft.nbt.CompoundTag) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with ICustomBee

use of com.teamresourceful.resourcefulbees.api.ICustomBee in project ResourcefulBees by Resourceful-Bees.

the class TieredBeehiveTileEntity method releaseOccupant.

@Override
public boolean releaseOccupant(@NotNull BlockState state, @NotNull BeehiveBlockEntity.BeeData tileBee, @Nullable List<Entity> entities, @NotNull BeehiveBlockEntity.BeeReleaseStatus beehiveState) {
    BlockPos blockpos = this.getBlockPos();
    if (shouldStayInHive(beehiveState)) {
        return false;
    } else {
        CompoundTag nbt = tileBee.entityData;
        nbt.remove("Passengers");
        nbt.remove("Leash");
        nbt.remove("UUID");
        Direction direction = state.getValue(BeehiveBlock.FACING);
        BlockPos blockpos1 = blockpos.relative(direction);
        if (level == null) {
            return false;
        } else {
            if (!this.level.getBlockState(blockpos1).getCollisionShape(this.level, blockpos1).isEmpty() && beehiveState != BeeReleaseStatus.EMERGENCY) {
                return false;
            }
            Entity entity = EntityType.loadEntityRecursive(nbt, this.level, entity1 -> entity1);
            if (entity != null) {
                BeeInfoUtils.setEntityLocationAndAngle(blockpos, direction, entity);
                if (entity instanceof Bee) {
                    Bee vanillaBeeEntity = (Bee) entity;
                    ItemStack honeycomb = new ItemStack(Items.HONEYCOMB);
                    if (beehiveState == BeeReleaseStatus.HONEY_DELIVERED) {
                        vanillaBeeEntity.dropOffNectar();
                        int i = getHoneyLevel(state);
                        if (i < 5) {
                            if (entity instanceof ICustomBee && !((ICustomBee) entity).getHoneycombData().getHoneycombType().equals(HoneycombType.NONE)) {
                                honeycomb = ((ICustomBee) entity).getHoneycombData().getHoneycomb().getDefaultInstance();
                            }
                            if (!honeycomb.isEmpty())
                                this.honeycombs.add(0, honeycomb);
                            recalculateHoneyLevel();
                        }
                    }
                    BeeInfoUtils.ageBee(((BTEBeeAccessor) tileBee).getTicksInHive(), vanillaBeeEntity);
                    if (entities != null)
                        entities.add(entity);
                }
                BlockPos hivePos = this.getBlockPos();
                this.level.playSound(null, hivePos.getX(), hivePos.getY(), hivePos.getZ(), SoundEvents.BEEHIVE_EXIT, SoundSource.BLOCKS, 1.0F, 1.0F);
                return this.level.addFreshEntity(entity);
            } else {
                return true;
            }
        }
    }
}
Also used : BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity) Entity(net.minecraft.world.entity.Entity) ICustomBee(com.teamresourceful.resourcefulbees.api.ICustomBee) Bee(net.minecraft.world.entity.animal.Bee) ICustomBee(com.teamresourceful.resourcefulbees.api.ICustomBee) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) Direction(net.minecraft.core.Direction) CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

ICustomBee (com.teamresourceful.resourcefulbees.api.ICustomBee)6 CompoundTag (net.minecraft.nbt.CompoundTag)4 Entity (net.minecraft.world.entity.Entity)3 ItemStack (net.minecraft.world.item.ItemStack)3 BlockPos (net.minecraft.core.BlockPos)2 Bee (net.minecraft.world.entity.animal.Bee)2 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)2 TickableBlockEntity (net.minecraft.world.level.block.entity.TickableBlockEntity)2 BeeFamily (com.teamresourceful.resourcefulbees.api.beedata.breeding.BeeFamily)1 BreedData (com.teamresourceful.resourcefulbees.api.beedata.breeding.BreedData)1 CustomBeeEntity (com.teamresourceful.resourcefulbees.entity.passive.CustomBeeEntity)1 BeeJar (com.teamresourceful.resourcefulbees.item.BeeJar)1 UpgradeItem (com.teamresourceful.resourcefulbees.item.UpgradeItem)1 Direction (net.minecraft.core.Direction)1 AbstractContainerMenu.consideredTheSameItem (net.minecraft.world.inventory.AbstractContainerMenu.consideredTheSameItem)1 Item (net.minecraft.world.item.Item)1 BeehiveBlockEntity (net.minecraft.world.level.block.entity.BeehiveBlockEntity)1 NotNull (org.jetbrains.annotations.NotNull)1