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);
}
}
}
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;
}
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;
}
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);
}
}
}
Aggregations