Search in sources :

Example 1 with TieredBeehiveTileEntity

use of com.teamresourceful.resourcefulbees.tileentity.TieredBeehiveTileEntity in project ResourcefulBees by Resourceful-Bees.

the class BeeNestFeature method setNestBees.

private void setNestBees(BlockPos nestPos, @Nullable ResourceKey<Biome> biomeKey, WorldGenLevel worldIn, Random rand) {
    BlockEntity tileEntity = worldIn.getBlockEntity(nestPos);
    if (tileEntity instanceof TieredBeehiveTileEntity) {
        TieredBeehiveTileEntity nestTE = (TieredBeehiveTileEntity) tileEntity;
        int maxBees = Math.round(Config.HIVE_MAX_BEES.get() * 0.5f);
        for (int i = rand.nextInt(maxBees); i < maxBees; i++) {
            if (biomeKey != null && BeeRegistry.isSpawnableBiome(biomeKey.location())) {
                CustomBeeData beeData = BeeRegistry.getSpawnableBiome(biomeKey.location()).next();
                EntityType<?> entityType = beeData.getEntityType();
                addBeeToNest(entityType, worldIn, nestPos, beeData, rand, nestTE);
            } else
                logMissingBiome(biomeKey);
        }
    }
}
Also used : CustomBeeData(com.teamresourceful.resourcefulbees.api.beedata.CustomBeeData) BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) TieredBeehiveTileEntity(com.teamresourceful.resourcefulbees.tileentity.TieredBeehiveTileEntity)

Example 2 with TieredBeehiveTileEntity

use of com.teamresourceful.resourcefulbees.tileentity.TieredBeehiveTileEntity in project ResourcefulBees by Resourceful-Bees.

the class TieredBeehiveBlock method performHoneyHarvest.

@Nullable
private InteractionResult performHoneyHarvest(@NotNull BlockState state, @NotNull Level world, @NotNull BlockPos pos, Player player, @NotNull InteractionHand handIn, ItemStack itemstack, boolean isScraper) {
    world.playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.BEEHIVE_SHEAR, SoundSource.NEUTRAL, 1.0F, 1.0F);
    dropResourceHoneycomb(world, pos, isScraper);
    itemstack.hurtAndBreak(1, player, player1 -> player1.broadcastBreakEvent(handIn));
    BlockEntity tileEntity = world.getBlockEntity(pos);
    if (tileEntity instanceof TieredBeehiveTileEntity) {
        TieredBeehiveTileEntity beehiveTileEntity = (TieredBeehiveTileEntity) tileEntity;
        if (!beehiveTileEntity.hasCombs()) {
            if (isHiveSmoked(pos, world)) {
                this.resetHoneyLevel(world, state, pos);
            } else {
                if (beehiveTileEntity.hasBees() && !(player instanceof FakePlayer)) {
                    this.angerBeesNearby(world, pos);
                }
                this.releaseBeesAndResetHoneyLevel(world, state, pos, player, BeehiveBlockEntity.BeeReleaseStatus.EMERGENCY);
            }
            return InteractionResult.SUCCESS;
        }
    }
    return null;
}
Also used : BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) TieredBeehiveTileEntity(com.teamresourceful.resourcefulbees.tileentity.TieredBeehiveTileEntity) FakePlayer(net.minecraftforge.common.util.FakePlayer) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with TieredBeehiveTileEntity

use of com.teamresourceful.resourcefulbees.tileentity.TieredBeehiveTileEntity in project ResourcefulBees by Resourceful-Bees.

the class TieredBeehiveBlock method performHiveUpgrade.

@Nullable
private InteractionResult performHiveUpgrade(@NotNull BlockState state, @NotNull Level world, @NotNull BlockPos pos, ItemStack itemstack) {
    CompoundTag data = ((UpgradeItem) itemstack.getItem()).getUpgradeData();
    BlockEntity tileEntity = world.getBlockEntity(pos);
    if (tileEntity instanceof TieredBeehiveTileEntity) {
        TieredBeehiveTileEntity beehiveTileEntity = (TieredBeehiveTileEntity) tileEntity;
        if (1 + beehiveTileEntity.getTier() == data.getInt(NBTConstants.NBT_TIER)) {
            int newTier = data.getInt(NBTConstants.NBT_TIER);
            beehiveTileEntity.setTier(newTier);
            beehiveTileEntity.setTierModifier(data.getFloat(NBTConstants.NBT_TIER_MODIFIER));
            beehiveTileEntity.recalculateHoneyLevel();
            itemstack.shrink(1);
            state = state.setValue(TIER_PROPERTY, newTier);
            world.setBlockAndUpdate(pos, state);
            return InteractionResult.SUCCESS;
        }
    }
    return null;
}
Also used : UpgradeItem(com.teamresourceful.resourcefulbees.item.UpgradeItem) CompoundTag(net.minecraft.nbt.CompoundTag) BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) TieredBeehiveTileEntity(com.teamresourceful.resourcefulbees.tileentity.TieredBeehiveTileEntity) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with TieredBeehiveTileEntity

use of com.teamresourceful.resourcefulbees.tileentity.TieredBeehiveTileEntity in project ResourcefulBees by Resourceful-Bees.

the class BeeNestFeature method addBeeToNest.

private void addBeeToNest(@Nullable EntityType<?> entityType, WorldGenLevel worldIn, BlockPos nestPos, CustomBeeData data, Random rand, TieredBeehiveTileEntity nest) {
    if (entityType != null) {
        Entity bee = entityType.create(worldIn.getLevel());
        if (bee != null) {
            bee.setPos(nestPos.getX(), nestPos.getY(), nestPos.getZ());
            CompoundTag compoundNBT = new CompoundTag();
            bee.save(compoundNBT);
            int timeInHive = rand.nextInt(data.getCoreData().getMaxTimeInHive());
            BeehiveBlockEntity.BeeData beehiveTileEntityBee = new BeehiveBlockEntity.BeeData(compoundNBT, 0, timeInHive);
            nest.stored.add(beehiveTileEntityBee);
        }
    }
}
Also used : TieredBeehiveTileEntity(com.teamresourceful.resourcefulbees.tileentity.TieredBeehiveTileEntity) BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) Entity(net.minecraft.world.entity.Entity) CustomBeeData(com.teamresourceful.resourcefulbees.api.beedata.CustomBeeData) BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity) CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

TieredBeehiveTileEntity (com.teamresourceful.resourcefulbees.tileentity.TieredBeehiveTileEntity)4 BeehiveBlockEntity (net.minecraft.world.level.block.entity.BeehiveBlockEntity)4 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)4 CustomBeeData (com.teamresourceful.resourcefulbees.api.beedata.CustomBeeData)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 Nullable (org.jetbrains.annotations.Nullable)2 UpgradeItem (com.teamresourceful.resourcefulbees.item.UpgradeItem)1 Entity (net.minecraft.world.entity.Entity)1 FakePlayer (net.minecraftforge.common.util.FakePlayer)1